Skip to content

Commit 0c4d8d3

Browse files
committed
Change calling convention to const ref
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 098ff8d commit 0c4d8d3

5 files changed

Lines changed: 44 additions & 37 deletions

File tree

src/include/OpenImageIO/image_span.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ template<typename T> using image1d_span = image_span<T, 2>;
365365
/// covering the same range of memory.
366366
template<typename T, size_t Rank>
367367
image_span<const std::byte>
368-
as_image_span_bytes(image_span<T, Rank> src) noexcept
368+
as_image_span_bytes(const image_span<T, Rank>& src) noexcept
369369
{
370370
return image_span<const std::byte>(
371371
reinterpret_cast<const std::byte*>(src.data()), src.nchannels(),
@@ -378,7 +378,7 @@ as_image_span_bytes(image_span<T, Rank> src) noexcept
378378
/// the same range of memory.
379379
template<typename T, size_t Rank>
380380
image_span<std::byte>
381-
as_image_span_writable_bytes(image_span<T, Rank> src) noexcept
381+
as_image_span_writable_bytes(const image_span<T, Rank>& src) noexcept
382382
{
383383
return image_span<std::byte>(reinterpret_cast<std::byte*>(src.data()),
384384
src.nchannels(), src.width(), src.height(),

src/include/OpenImageIO/imageio.h

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,12 +2296,13 @@ class OIIO_API ImageOutput {
22962296
/// y, and z).
22972297
/// @returns `true` upon success, or `false` upon failure.
22982298
///
2299-
virtual bool write_image(TypeDesc format, image_span<const std::byte> data);
2299+
virtual bool write_image(TypeDesc format,
2300+
const image_span<const std::byte>& data);
23002301

23012302
/// A version of `write_image()` taking an `image_span<T>`, where the type
23022303
/// of the underlying data is `T`. This is a convenience wrapper around
23032304
/// the `write_image()` that takes an `image_span<const std::byte>`.
2304-
template<typename T> bool write_image(image_span<T> data)
2305+
template<typename T> bool write_image(const image_span<T>& data)
23052306
{
23062307
return write_image(TypeDescFromC<T>::value(),
23072308
as_image_span_bytes(data));
@@ -2340,13 +2341,14 @@ class OIIO_API ImageOutput {
23402341
/// @returns `true` upon success, or `false` upon failure.
23412342
///
23422343
virtual bool write_scanline(int y, int z, TypeDesc format,
2343-
image_span<const std::byte> data);
2344+
const image_span<const std::byte>& data);
23442345

23452346
/// A version of `write_scanline()` taking an `image_span<T>`, where the
23462347
/// type of the underlying data is `T`. This is a convenience wrapper
23472348
/// around the `write_scanline()` that takes an `image_span<const
23482349
/// std::byte>`.
2349-
template<typename T> bool write_scanline(int y, int z, image_span<T> data)
2350+
template<typename T>
2351+
bool write_scanline(int y, int z, const image_span<T>& data)
23502352
{
23512353
// reduce to type + image_span<byte>
23522354
return write_scanline(y, z, TypeDescFromC<T>::value(),
@@ -2389,14 +2391,14 @@ class OIIO_API ImageOutput {
23892391
/// @returns `true` upon success, or `false` upon failure.
23902392
///
23912393
virtual bool write_scanlines(int ybegin, int yend, int z, TypeDesc format,
2392-
image_span<const std::byte> data);
2394+
const image_span<const std::byte>& data);
23932395

23942396
/// A version of `write_scanlines()` taking an `image_span<T>`, where the
23952397
/// type of the underlying data is `T`. This is a convenience wrapper
23962398
/// around the `write_scanlines()` that takes an `image_span<const
23972399
/// std::byte>`.
23982400
template<typename T>
2399-
bool write_scanlines(int ybegin, int yend, int z, image_span<T> data)
2401+
bool write_scanlines(int ybegin, int yend, int z, const image_span<T>& data)
24002402
{
24012403
// image_span<T>: reduces to type + byte_buffer
24022404
return write_scanlines(ybegin, yend, z, TypeDescFromC<T>::value(),
@@ -2442,13 +2444,13 @@ class OIIO_API ImageOutput {
24422444
/// @returns `true` upon success, or `false` upon failure.
24432445
///
24442446
virtual bool write_tile(int x, int y, int z, TypeDesc format,
2445-
image_span<const std::byte> data);
2447+
const image_span<const std::byte>& data);
24462448

24472449
/// A version of `write_tile()` taking an `image_span<T>`, where the type
24482450
/// of the underlying data is `T`. This is a convenience wrapper around
24492451
/// the `write_tile()` that takes an `image_span<const std::byte>`.
24502452
template<typename T>
2451-
bool write_tile(int x, int y, int z, image_span<T> data)
2453+
bool write_tile(int x, int y, int z, const image_span<T>& data)
24522454
{
24532455
return write_tile(x, y, z, TypeDescFromC<T>::value(),
24542456
as_image_span_bytes(data));
@@ -2495,14 +2497,14 @@ class OIIO_API ImageOutput {
24952497
///
24962498
virtual bool write_tiles(int xbegin, int xend, int ybegin, int yend,
24972499
int zbegin, int zend, TypeDesc format,
2498-
image_span<const std::byte> data);
2500+
const image_span<const std::byte>& data);
24992501

25002502
/// A version of `write_tiles()` taking an `image_span<T>`, where the type
25012503
/// of the underlying data is `T`. This is a convenience wrapper around
25022504
/// the `write_tiles()` that takes an `image_span<const std::byte>`.
25032505
template<typename T>
25042506
bool write_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin,
2505-
int zend, image_span<T> data)
2507+
int zend, const image_span<T>& data)
25062508
{
25072509
return write_tiles(xbegin, xend, ybegin, yend, zbegin, zend,
25082510
TypeDescFromC<T>::value(),
@@ -2550,15 +2552,15 @@ class OIIO_API ImageOutput {
25502552
///
25512553
virtual bool write_rectangle(int xbegin, int xend, int ybegin, int yend,
25522554
int zbegin, int zend, TypeDesc format,
2553-
image_span<const std::byte> data);
2555+
const image_span<const std::byte>& data);
25542556

25552557
/// A version of `write_rectangle()` taking an `image_span<T>`, where the
25562558
/// type of the underlying data is `T`. This is a convenience wrapper
25572559
/// around the `write_rectangle()` that takes an `image_span<const
25582560
/// std::byte>`.
25592561
template<typename T>
25602562
bool write_rectangle(int xbegin, int xend, int ybegin, int yend, int zbegin,
2561-
int zend, image_span<T> data)
2563+
int zend, const image_span<T>& data)
25622564
{
25632565
return write_rectangle(xbegin, xend, ybegin, yend, zbegin, zend,
25642566
TypeDescFromC<T>::value(),
@@ -3141,7 +3143,7 @@ class OIIO_API ImageOutput {
31413143
/// the pixels to the right position in the dither pattern.
31423144
template<typename T>
31433145
cspan<std::byte> to_native(int xbegin, int xend, int ybegin, int yend,
3144-
int zbegin, int zend, image_span<T> data,
3146+
int zbegin, int zend, const image_span<T>& data,
31453147
std::vector<unsigned char>& scratch,
31463148
unsigned int dither = 0, int xorigin = 0,
31473149
int yorigin = 0, int zorigin = 0)
@@ -3158,7 +3160,7 @@ class OIIO_API ImageOutput {
31583160
/// `format` and an image_span of generic (std::byte) data.
31593161
cspan<std::byte> to_native(int xbegin, int xend, int ybegin, int yend,
31603162
int zbegin, int zend, TypeDesc format,
3161-
image_span<const std::byte> data,
3163+
const image_span<const std::byte>& data,
31623164
std::vector<unsigned char>& scratch,
31633165
unsigned int dither = 0, int xorigin = 0,
31643166
int yorigin = 0, int zorigin = 0);
@@ -3856,7 +3858,7 @@ OIIO_API bool convert_image (int nchannels, int width, int height, int depth,
38563858
/// Return true if ok, false if it didn't know how to do the conversion.
38573859
template<typename SrcType, typename DstType>
38583860
bool
3859-
convert_image(image_span<SrcType> src, image_span<DstType> dst)
3861+
convert_image(const image_span<SrcType>& src, const image_span<DstType>& dst)
38603862
{
38613863
// For now, just implement by wrapping the pointer-based version.
38623864
OIIO_DASSERT(src.nchannels() == dst.nchannels()
@@ -3876,8 +3878,8 @@ convert_image(image_span<SrcType> src, image_span<DstType> dst)
38763878
/// `TypeDesc`, and the spans are untyped bytes that provide the dimensions
38773879
/// and memory layout.
38783880
inline bool
3879-
convert_image(image_span<const std::byte> src, TypeDesc src_type,
3880-
image_span<std::byte> dst, TypeDesc dst_type)
3881+
convert_image(const image_span<const std::byte>& src, TypeDesc src_type,
3882+
const image_span<std::byte>& dst, TypeDesc dst_type)
38813883
{
38823884
// For now, just implement by wrapping the pointer-based version.
38833885
OIIO_DASSERT(src.nchannels() == dst.nchannels()
@@ -3908,8 +3910,8 @@ OIIO_API bool parallel_convert_image (
39083910
/// threads. The data types are taken from the spans.
39093911
template<typename SrcType, typename DstType>
39103912
bool
3911-
parallel_convert_image(image_span<SrcType> src, image_span<DstType> dst,
3912-
int nthreads = 0)
3913+
parallel_convert_image(const image_span<SrcType>& src,
3914+
const image_span<DstType>& dst, int nthreads = 0)
39133915
{
39143916
// For now, just implement by wrapping the pointer-based version.
39153917
OIIO_DASSERT(src.nchannels() == dst.nchannels()
@@ -3927,9 +3929,9 @@ parallel_convert_image(image_span<SrcType> src, image_span<DstType> dst,
39273929
/// threads. The data types are passed as `TypeDesc`, and the spans are
39283930
/// untyped bytes that provide the dimensions and memory layout.
39293931
inline bool
3930-
parallel_convert_image(image_span<const std::byte> src, TypeDesc src_type,
3931-
image_span<std::byte> dst, TypeDesc dst_type,
3932-
int nthreads = 0)
3932+
parallel_convert_image(const image_span<const std::byte>& src,
3933+
TypeDesc src_type, const image_span<std::byte>& dst,
3934+
TypeDesc dst_type, int nthreads = 0)
39333935
{
39343936
// For now, just implement by wrapping the pointer-based version.
39353937
OIIO_DASSERT(src.nchannels() == dst.nchannels()
@@ -3995,7 +3997,8 @@ OIIO_API bool copy_image (int nchannels, int width, int height, int depth,
39953997
/// strides. Return true if ok, false if it couldn't do it. (Reserved for
39963998
/// future use; currently is always succeeds)
39973999
template<typename D, size_t Drank, typename S, size_t Srank>
3998-
bool copy_image(image_span<D, Drank> dst, image_span<S, Srank> src)
4000+
bool copy_image(const image_span<D, Drank>& dst,
4001+
const image_span<S, Srank>& src)
39994002
{
40004003
// Arbitrary types are handled by just converting to generic byte
40014004
// image_spans.
@@ -4005,7 +4008,8 @@ bool copy_image(image_span<D, Drank> dst, image_span<S, Srank> src)
40054008

40064009
/// copy_image base case: generic span of bytes.
40074010
OIIO_API bool
4008-
copy_image(image_span<std::byte> dst, image_span<const std::byte> src);
4011+
copy_image(const image_span<std::byte> &dst,
4012+
const image_span<const std::byte>& src);
40094013

40104014

40114015

src/include/imageio_pvt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ get_default_quantize(TypeDesc format, long long& quant_min,
8989
/// which is either dst or src (if the strides indicated that data were
9090
/// already contiguous).
9191
OIIO_API span<const std::byte>
92-
contiguize(image_span<const std::byte> src, span<std::byte> dst);
92+
contiguize(const image_span<const std::byte>& src, span<std::byte> dst);
9393

9494
/// Turn potentially non-contiguous-stride data (e.g. "RGBxRGBx") into
9595
/// contiguous-stride ("RGBRGB"), for any format or stride values

src/libOpenImageIO/imageio.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ _contiguize(const T* src, int nchannels, stride_t xstride, stride_t ystride,
734734

735735

736736
span<const std::byte>
737-
pvt::contiguize(image_span<const std::byte> src, span<std::byte> dst)
737+
pvt::contiguize(const image_span<const std::byte>& src, span<std::byte> dst)
738738
{
739739
// Contiguized result must fit in dst
740740
OIIO_DASSERT(src.size_bytes() <= dst.size_bytes());
@@ -1053,7 +1053,8 @@ copy_image(int nchannels, int width, int height, int depth, const void* src,
10531053

10541054
template<typename T>
10551055
void
1056-
aligned_copy_image(image_span<std::byte> dst, image_span<const std::byte> src)
1056+
aligned_copy_image(const image_span<std::byte>& dst,
1057+
const image_span<const std::byte>& src)
10571058
{
10581059
size_t systride = src.ystride();
10591060
size_t dystride = dst.ystride();
@@ -1081,7 +1082,8 @@ aligned_copy_image(image_span<std::byte> dst, image_span<const std::byte> src)
10811082

10821083

10831084
bool
1084-
copy_image(image_span<std::byte> dst, image_span<const std::byte> src)
1085+
copy_image(const image_span<std::byte>& dst,
1086+
const image_span<const std::byte>& src)
10851087
{
10861088
OIIO_DASSERT(src.width() == dst.width() && src.height() == dst.height()
10871089
&& src.depth() == dst.depth()

src/libOpenImageIO/imageoutput.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ImageOutput::write_scanline(int /*y*/, int /*z*/, TypeDesc /*format*/,
112112

113113
bool
114114
ImageOutput::write_scanline(int y, int z, TypeDesc format,
115-
image_span<const std::byte> data)
115+
const image_span<const std::byte>& data)
116116
{
117117
size_t sz = (format == TypeUnknown ? m_spec.pixel_bytes(true /*native*/)
118118
: format.size() * m_spec.nchannels)
@@ -154,7 +154,7 @@ ImageOutput::write_scanlines(int ybegin, int yend, int z, TypeDesc format,
154154

155155
bool
156156
ImageOutput::write_scanlines(int ybegin, int yend, int z, TypeDesc format,
157-
image_span<const std::byte> data)
157+
const image_span<const std::byte>& data)
158158
{
159159
size_t sz = (format == TypeUnknown ? m_spec.pixel_bytes(true /*native*/)
160160
: format.size() * m_spec.nchannels)
@@ -186,7 +186,7 @@ ImageOutput::write_tile(int /*x*/, int /*y*/, int /*z*/, TypeDesc /*format*/,
186186

187187
bool
188188
ImageOutput::write_tile(int x, int y, int z, TypeDesc format,
189-
image_span<const std::byte> data)
189+
const image_span<const std::byte>& data)
190190
{
191191
size_t sz = format == TypeUnknown
192192
? m_spec.pixel_bytes(true /*native*/)
@@ -267,7 +267,7 @@ ImageOutput::write_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin,
267267
bool
268268
ImageOutput::write_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin,
269269
int zend, TypeDesc format,
270-
image_span<const std::byte> data)
270+
const image_span<const std::byte>& data)
271271
{
272272
// Default implementation (for now): call the old pointer+stride
273273
return write_tiles(xbegin, xend, ybegin, yend, zbegin, zend, format,
@@ -293,7 +293,7 @@ bool
293293
ImageOutput::write_rectangle(int /*xbegin*/, int /*xend*/, int /*ybegin*/,
294294
int /*yend*/, int /*zbegin*/, int /*zend*/,
295295
TypeDesc /*format*/,
296-
image_span<const std::byte> /*data*/)
296+
const image_span<const std::byte>& /*data*/)
297297
{
298298
return false;
299299
}
@@ -570,7 +570,7 @@ ImageOutput::to_native_rectangle(int xbegin, int xend, int ybegin, int yend,
570570
cspan<std::byte>
571571
ImageOutput::to_native(int xbegin, int xend, int ybegin, int yend, int zbegin,
572572
int zend, TypeDesc format,
573-
image_span<const std::byte> data,
573+
const image_span<const std::byte>& data,
574574
std::vector<unsigned char>& scratch, unsigned int dither,
575575
int xorigin, int yorigin, int zorigin)
576576
{
@@ -682,7 +682,8 @@ ImageOutput::write_image(TypeDesc format, const void* data, stride_t xstride,
682682

683683

684684
bool
685-
ImageOutput::write_image(TypeDesc format, image_span<const std::byte> data)
685+
ImageOutput::write_image(TypeDesc format,
686+
const image_span<const std::byte>& data)
686687
{
687688
size_t sz = m_spec.image_bytes(/*native=*/format == TypeUnknown);
688689
if (sz != data.size_bytes()) {

0 commit comments

Comments
 (0)