Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4077,14 +4077,17 @@ nonzero_region_all_subimages(ImageRecRef A)
ROI nonzero_region;
for (int s = 0; s < A->subimages(); ++s) {
ROI roi = ImageBufAlgo::nonzero_region((*A)(s));
if (roi.npixels() == 0) {
// Special case -- all zero; but doctor to make it 1 zero pixel
roi = (*A)(s).roi();
roi.xend = roi.xbegin + 1;
roi.yend = roi.ybegin + 1;
roi.zend = roi.zbegin + 1;
if (roi.npixels() != 0) {
nonzero_region = roi_union(nonzero_region, roi);
}
nonzero_region = roi_union(nonzero_region, roi);
}
if (!nonzero_region.defined()) {
// Special case -- all zero
// fallback to 1st subimage ROI, but doctor to make it 1 zero pixel
nonzero_region = (*A)(0).roi();
nonzero_region.xend = nonzero_region.xbegin + 1;
nonzero_region.yend = nonzero_region.ybegin + 1;
nonzero_region.zend = nonzero_region.zbegin + 1;
}
return nonzero_region;
}
Expand Down
4 changes: 4 additions & 0 deletions testsuite/oiiotool/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ Comparing "autotrim.tif" and "ref/autotrim.tif"
PASS
Comparing "trim.tif" and "ref/trim.tif"
PASS
Comparing "trimempty.tif" and "ref/trimempty.tif"
PASS
Comparing "trimsubimages.tif" and "ref/trimsubimages.tif"
PASS
Comparing "trimemptysubimages.tif" and "ref/trimemptysubimages.tif"
PASS
Comparing "add.exr" and "ref/add.exr"
PASS
Comparing "cadd1.exr" and "ref/cadd1.exr"
Expand Down
Binary file added testsuite/oiiotool/ref/trimempty.tif
Binary file not shown.
Binary file added testsuite/oiiotool/ref/trimemptysubimages.tif
Binary file not shown.
13 changes: 12 additions & 1 deletion testsuite/oiiotool/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,21 @@
command += oiiotool ("--create 320x240 3 -fill:color=.1,.5,.1 120x80+50+70 "
+ " -rotate 30 -trim -origin +0+0 -fullpixels -d uint8 -o trim.tif")

# test --trim on empty image
command += oiiotool ("--create 320x240 3 "
+ " -trim -origin +0+0 -fullpixels -d uint8 -o trimempty.tif")

# test --trim, tricky case of multiple subimages
command += oiiotool ( "-a --create 320x240 3 -fill:color=.1,.5,.1 120x80+50+70 -rotate 30 "
+ "--create 320x240 3 -fill:color=.5,.5,.1 100x10+70+70 -rotate 140 "
+ "--siappend -trim -origin +0+0 -fullpixels -d uint8 -o trimsubimages.tif")

# test --trim, tricky case of multiple subimages including one empty one
command += oiiotool ( "-a --create 320x240 3 -fill:color=.1,.5,.1 120x80+50+70 -rotate 30 "
+ "--create 320x240 3 -fill:color=.5,.5,.1 100x10+70+70 -rotate 140 "
+ "--create 320x240 3 "
+ "--siappendall -trim -origin +0+0 -fullpixels -d uint8 -o trimemptysubimages.tif")

# test hole filling
command += oiiotool ("ref/hole.tif --fillholes -o tahoe-filled.tif")
# test hole filling for a cropped image
Expand Down Expand Up @@ -262,7 +272,8 @@
outputs = [
"filled.tif",
"autotrim.tif",
"trim.tif", "trimsubimages.tif",
"trim.tif", "trimempty.tif",
"trimsubimages.tif", "trimemptysubimages.tif",
"add.exr", "cadd1.exr", "cadd2.exr",
"sub.exr", "subc.exr",
"mul.exr", "cmul1.exr", "cmul2.exr",
Expand Down
Loading