@@ -2773,8 +2773,8 @@ set_pixels_(ImageBuf& buf, ROI roi, const void* data_, stride_t xstride,
27732773
27742774
27752775bool
2776- ImageBuf::set_pixels (ROI roi, TypeDesc format, const void * data,
2777- stride_t xstride, stride_t ystride, stride_t zstride )
2776+ ImageBuf::set_pixels (ROI roi, TypeDesc format,
2777+ const image_span< const std::byte>& buffer )
27782778{
27792779 if (!initialized ()) {
27802780 errorfmt (" Cannot set_pixels() on an uninitialized ImageBuf" );
@@ -2784,17 +2784,42 @@ ImageBuf::set_pixels(ROI roi, TypeDesc format, const void* data,
27842784 roi = this ->roi ();
27852785 roi.chend = std::min (roi.chend , nchannels ());
27862786
2787- ImageSpec::auto_stride (xstride, ystride, zstride, format.size (),
2788- roi.nchannels (), roi.width (), roi.height ());
2787+ if (buffer.chanstride () != stride_t (format.size ())) {
2788+ errorfmt (
2789+ " set_pixels does not currently support image_span source with non-contiguous channels" );
2790+ return false ;
2791+ }
2792+ if (size_t (roi.nchannels ()) > buffer.nchannels ()
2793+ || size_t (roi.width ()) > buffer.width ()
2794+ || size_t (roi.height ()) > buffer.height ()
2795+ || size_t (roi.depth ()) > buffer.depth ()) {
2796+ errorfmt (
2797+ " set_pixels source image_span was not big enough for the specified ROI." );
2798+ return false ;
2799+ }
27892800
27902801 bool ok;
27912802 OIIO_DISPATCH_TYPES2 (ok, " set_pixels" , set_pixels_, spec ().format , format,
2792- *this , roi, data, xstride, ystride, zstride);
2803+ *this , roi, buffer.data (), buffer.xstride (),
2804+ buffer.ystride (), buffer.zstride ());
27932805 return ok;
27942806}
27952807
27962808
27972809
2810+ bool
2811+ ImageBuf::set_pixels (ROI roi, TypeDesc format, const void * data,
2812+ stride_t xstride, stride_t ystride, stride_t zstride)
2813+ {
2814+ image_span<const std::byte> s (reinterpret_cast <const std::byte*>(data),
2815+ roi.nchannels (), roi.width (), roi.height (),
2816+ roi.depth (), format.size (), xstride, ystride,
2817+ zstride);
2818+ return set_pixels (roi, format, s);
2819+ }
2820+
2821+
2822+
27982823bool
27992824ImageBuf::set_pixels (ROI roi, TypeDesc format, cspan<std::byte> buffer,
28002825 const void * buforigin, stride_t xstride, stride_t ystride,
0 commit comments