diff --git a/src/libOpenImageIO/imagebufalgo_compare.cpp b/src/libOpenImageIO/imagebufalgo_compare.cpp index f917697942..658a227c86 100644 --- a/src/libOpenImageIO/imagebufalgo_compare.cpp +++ b/src/libOpenImageIO/imagebufalgo_compare.cpp @@ -297,8 +297,9 @@ compare_(const ImageBuf& A, const ImageBuf& B, float failthresh, if (deep) { for (int i = 0; i < batchsize && !a.done(); ++i, ++a, ++b) { bool warned = false, failed = false; // For this pixel + auto nsamps = std::max(a.deep_samples(), b.deep_samples()); for (int c = roi.chbegin; c < roi.chend; ++c) - for (int s = 0, e = a.deep_samples(); s < e; ++s) { + for (int s = 0, e = nsamps; s < e; ++s) { compare_value(a, c, a.deep_value(c, s), b.deep_value(c, s), result, maxval, batcherror, batch_sqrerror, failed, diff --git a/testsuite/oiiotool-deep/ref/out.txt b/testsuite/oiiotool-deep/ref/out.txt index 99695cbcca..fe76ec8543 100644 --- a/testsuite/oiiotool-deep/ref/out.txt +++ b/testsuite/oiiotool-deep/ref/out.txt @@ -1,3 +1,19 @@ +Computing diff of "src/deep-nosamples.exr" vs "src/deep-onesample.exr" + Mean error = 42 + RMS error = 42 + Peak SNR = 0 + Max error = 42 @ (0, 0, Z) + 1 pixels (100%) over 1e-06 + 0 pixels (0%) over 100 +WARNING +Computing diff of "src/deep-onesample.exr" vs "src/deep-nosamples.exr" + Mean error = 42 + RMS error = 42 + Peak SNR = 0 + Max error = 42 @ (0, 0, Z) + 1 pixels (100%) over 1e-06 + 0 pixels (0%) over 100 +WARNING Comparing "flat.exr" and "ref/flat.exr" PASS Comparing "ch.exr" and "ref/ch.exr" diff --git a/testsuite/oiiotool-deep/run.py b/testsuite/oiiotool-deep/run.py index 84290268e4..406932a30a 100755 --- a/testsuite/oiiotool-deep/run.py +++ b/testsuite/oiiotool-deep/run.py @@ -40,6 +40,26 @@ # --resample command += oiiotool (exrdir+"/Balls.exr -resample 128x72 -o resampled-balls.exr") + + +# Regression test: it used to be that comparing deep image, it would loop +# only over A's samples, so if A had no samples in a pixel but B had +# samples, then the comparison would fail to see a difference. Be sure to +# test both orderings. +# Compare with both orderings +command += oiiotool ("--fail 100 src/deep-nosamples.exr src/deep-onesample.exr --diff") +command += oiiotool ("--fail 100 src/deep-onesample.exr src/deep-nosamples.exr --diff") + # Recipe for creating the files: + # spec = oiio.ImageSpec (1, 1, 1, oiio.TypeDesc.TypeFloat) + # spec.channelnames = ("Z") + # spec.deep = True + # buf = oiio.ImageBuf (spec) + # buf.write ("src/deep-nosamples.exr") # write a deep image with no samples + # buf.set_deep_samples (0, 0, 0, 1) + # buf.set_deep_value (0, 0, 0, 0, 0, 42.0) + # buf.write ("src/deep-onesample.exr") # write another deep image with 1 sample + + # To add more tests, just append more lines like the above and also add # the new 'feature.tif' (or whatever you call it) to the outputs list, # below. diff --git a/testsuite/oiiotool-deep/src/deep-nosamples.exr b/testsuite/oiiotool-deep/src/deep-nosamples.exr new file mode 100644 index 0000000000..fa827e5950 Binary files /dev/null and b/testsuite/oiiotool-deep/src/deep-nosamples.exr differ diff --git a/testsuite/oiiotool-deep/src/deep-onesample.exr b/testsuite/oiiotool-deep/src/deep-onesample.exr new file mode 100644 index 0000000000..9b4ee6a82d Binary files /dev/null and b/testsuite/oiiotool-deep/src/deep-onesample.exr differ