Skip to content

Commit f460da5

Browse files
authored
fix(iba): IBA::transpose() didn't set output image's format to input (#4391)
Because IBA::transpose changes resolution, it doesn't pass the input image to IBAPrep(), and there was a special case there that always set destination to float if there were no source images. So change transpose to specifically request a format, to be the same as the input image. And that required a tweak to IBAPrep allowing us to specify such a thing (there was already an option that meant "force it to float", but not the general case of an arbitrary type). Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 1677f9e commit f460da5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/include/OpenImageIO/imagebufalgo_util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ parallel_image(ROI roi, std::function<void(ROI)> f)
158158
/// If nonzero and dst is uninitialized, then initialize it to float
159159
/// regardless of the pixel types of the input images.
160160
///
161+
/// - "dst_datatype" : string (default: "")
162+
///
163+
/// If not empty and dst is uninitialized, then initialize it to the data
164+
/// type indicated by the string regardless of the pixel types of any
165+
/// input images.
166+
///
161167
/// - "minimize_nchannels" : int (default: 0)
162168
///
163169
/// If nonzero and dst is uninitialized and the multiple input images do

src/libOpenImageIO/imagebufalgo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ ImageBufAlgo::IBAprep(ROI& roi, ImageBuf& dst, cspan<const ImageBuf*> srcs,
504504
spec.nchannels = roi.chend;
505505
spec.default_channel_names();
506506
}
507+
508+
// If the user passed a dst_format, use it.
509+
TypeDesc requested_format(options.get_string("dst_format"));
510+
if (requested_format != TypeUnknown) {
511+
spec.set_format(requested_format);
512+
}
513+
507514
// Set the image dimensions based on ROI.
508515
set_roi(spec, roi);
509516
if (full_roi.defined())

src/libOpenImageIO/imagebufalgo_orient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ ImageBufAlgo::transpose(ImageBuf& dst, const ImageBuf& src, ROI roi,
427427
ROI dst_roi(roi.ybegin, roi.yend, roi.xbegin, roi.xend, roi.zbegin,
428428
roi.zend, roi.chbegin, roi.chend);
429429
bool dst_initialized = dst.initialized();
430-
if (!IBAprep(dst_roi, &dst))
430+
ParamValue options[] = { { "dst_format", src.spec().format.c_str() } };
431+
if (!IBAprep(dst_roi, dst, {}, options))
431432
return false;
432433
if (!dst_initialized) {
433434
ROI r = src.roi_full();

0 commit comments

Comments
 (0)