Skip to content

Commit d8f2aea

Browse files
authored
perf(oiiotool): oiiotool --mosaic improve type conversion (#3979)
`oiiotool --mosaic` was always allocating a `float` buffer for the result. Instead, make it use the "widest" data type of the input images. So, for example, if you are making a mosaic of uint8 images, the result buffer should be uint8, not have to allocate 4x bigger nor do uint8->float conversions as it pastes the images. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 86186b8 commit d8f2aea

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/oiiotool/oiiotool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4884,6 +4884,7 @@ action_mosaic(Oiiotool& ot, cspan<const char*> argv)
48844884
}
48854885

48864886
int widest = 0, highest = 0, nchannels = 0;
4887+
TypeDesc outtype = TypeUnknown;
48874888
std::vector<ImageRecRef> images(nimages);
48884889
for (int i = nimages - 1; i >= 0; --i) {
48894890
ImageRecRef img = ot.pop();
@@ -4892,6 +4893,7 @@ action_mosaic(Oiiotool& ot, cspan<const char*> argv)
48924893
widest = std::max(widest, img->spec()->full_width);
48934894
highest = std::max(highest, img->spec()->full_height);
48944895
nchannels = std::max(nchannels, img->spec()->nchannels);
4896+
outtype = TypeDesc::basetype_merge(outtype, img->spec()->format);
48954897
}
48964898

48974899
auto options = ot.extract_options(command);
@@ -4916,7 +4918,7 @@ action_mosaic(Oiiotool& ot, cspan<const char*> argv)
49164918

49174919
ImageSpec Rspec(ximages * widest + (ximages - 1) * pad,
49184920
yimages * highest + (yimages - 1) * pad, nchannels,
4919-
TypeDesc::FLOAT);
4921+
outtype);
49204922
ImageRecRef R(new ImageRec("mosaic", Rspec, ot.imagecache));
49214923
ot.push(R);
49224924

0 commit comments

Comments
 (0)