Permalink
Browse files

Change idiff and oiiotool -diff to only print pixel reports if the co…

…mparison fails or if verbose mode is on. That is, images that pass the comparison will not pointlessly print pixel info.
  • Loading branch information...
1 parent 4506104 commit 98eacfd4ec9192ecf604ab7354fdc2fed970e02b @lgritz lgritz committed Mar 5, 2012
Showing with 117 additions and 103 deletions.
  1. +1 −1 src/doc/idiff.tex
  2. +60 −52 src/idiff/idiff.cpp
  3. +56 −50 src/oiiotool/diff.cpp
View
@@ -136,7 +136,7 @@ \subsection*{General options}
\apiitem{-v}
Verbose output --- more detail about what it finds when comparing
-images. (Currently, there is no extra info to print.)
+images, even when the comparison does not fail.
\apiend
\apiitem{-a}
View
@@ -184,13 +184,30 @@ safe_double_print (double val)
+inline void
+print_subimage (ImageBuf &img0, int subimage, int miplevel)
+{
+ if (img0.nsubimages() > 1)
+ std::cout << "Subimage " << subimage << ' ';
+ if (img0.nmiplevels() > 1)
+ std::cout << " MIP level " << miplevel << ' ';
+ if (img0.nsubimages() > 1 || img0.nmiplevels() > 1)
+ std::cout << ": ";
+ std::cout << img0.spec().width << " x " << img0.spec().height;
+ if (img0.spec().depth > 1)
+ std::cout << " x " << img0.spec().depth;
+ std::cout << ", " << img0.spec().nchannels << " channel\n";
+}
+
+
+
int
main (int argc, char *argv[])
{
getargs (argc, argv);
std::cout << "Comparing \"" << filenames[0]
- << "\" and \"" << filenames[1] << "\"\n";
+ << "\" and \"" << filenames[1] << "\"\n";
// Create a private ImageCache so we can customize its cache size
// and instruct it store everything internally as floats.
@@ -218,17 +235,11 @@ main (int argc, char *argv[])
if (subimage >= img1.nsubimages())
break;
- if (compareall) {
- std::cout << "Subimage " << subimage << ": ";
- std::cout << img0.spec().width << " x " << img0.spec().height;
- if (img0.spec().depth > 1)
- std::cout << " x " << img0.spec().depth;
- std::cout << ", " << img0.spec().nchannels << " channel\n";
- }
-
if (! read_input (filenames[0], img0, imagecache, subimage) ||
- ! read_input (filenames[1], img1, imagecache, subimage))
+ ! read_input (filenames[1], img1, imagecache, subimage)) {
+ std::cout << "Failed to read subimage " << subimage << "\n";
return ErrFile;
+ }
if (img0.nmiplevels() != img1.nmiplevels()) {
std::cout << "Files do not match in their number of MIPmap levels\n";
@@ -247,18 +258,11 @@ main (int argc, char *argv[])
! read_input (filenames[1], img1, imagecache, subimage, m))
return ErrFile;
- if (compareall && img0.nmiplevels() > 1) {
- std::cout << " MIP level " << m << ": ";
- std::cout << img0.spec().width << " x " << img0.spec().height;
- if (img0.spec().depth > 1)
- std::cout << " x " << img0.spec().depth;
- std::cout << ", " << img0.spec().nchannels << " channel\n";
- }
-
// Compare the dimensions of the images. Fail if they
// aren't the same resolution and number of channels. No
// problem, though, if they aren't the same data type.
if (! same_size (img0, img1)) {
+ print_subimage (img0, subimage, m);
std::cout << "Images do not match in size: ";
std::cout << "(" << img0.spec().width << "x" << img0.spec().height;
if (img0.spec().depth > 1)
@@ -287,47 +291,51 @@ main (int argc, char *argv[])
if (perceptual)
yee_failures = ImageBufAlgo::compare_Yee (img0, img1);
+ if (cr.nfail > (failpercent/100.0 * npels) || cr.maxerror > hardfail ||
+ yee_failures > (failpercent/100.0 * npels)) {
+ ret = ErrFail;
+ } else if (cr.nwarn > (warnpercent/100.0 * npels) || cr.maxerror > hardwarn) {
+ if (ret != ErrFail)
+ ret = ErrWarn;
+ }
+
// Print the report
//
- std::cout << " Mean error = ";
- safe_double_print (cr.meanerror);
- std::cout << " RMS error = ";
- safe_double_print (cr.rms_error);
- std::cout << " Peak SNR = ";
- safe_double_print (cr.PSNR);
- std::cout << " Max error = " << cr.maxerror;
- if (cr.maxerror != 0) {
- std::cout << " @ (" << cr.maxx << ", " << cr.maxy;
- if (img0.spec().depth > 1)
- std::cout << ", " << cr.maxz;
- std::cout << ", " << img0.spec().channelnames[cr.maxc] << ')';
- }
- std::cout << "\n";
+ if (verbose || ret != ErrOK) {
+ if (compareall)
+ print_subimage (img0, subimage, m);
+ std::cout << " Mean error = ";
+ safe_double_print (cr.meanerror);
+ std::cout << " RMS error = ";
+ safe_double_print (cr.rms_error);
+ std::cout << " Peak SNR = ";
+ safe_double_print (cr.PSNR);
+ std::cout << " Max error = " << cr.maxerror;
+ if (cr.maxerror != 0) {
+ std::cout << " @ (" << cr.maxx << ", " << cr.maxy;
+ if (img0.spec().depth > 1)
+ std::cout << ", " << cr.maxz;
+ std::cout << ", " << img0.spec().channelnames[cr.maxc] << ')';
+ }
+ std::cout << "\n";
// when Visual Studio is used float values in scientific foramt are
// printed with three digit exponent. We change this behaviour to fit
// Linux way
#ifdef _MSC_VER
- _set_output_format(_TWO_DIGIT_EXPONENT);
+ _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
- std::streamsize precis = std::cout.precision();
- std::cout << " " << cr.nwarn << " pixels ("
- << std::setprecision(3) << (100.0*cr.nwarn / npels)
- << std::setprecision(precis) << "%) over " << warnthresh << "\n";
- std::cout << " " << cr.nfail << " pixels ("
- << std::setprecision(3) << (100.0*cr.nfail / npels)
- << std::setprecision(precis) << "%) over " << failthresh << "\n";
- if (perceptual)
- std::cout << " " << yee_failures << " pixels ("
- << std::setprecision(3) << (100.0*yee_failures / npels)
- << std::setprecision(precis)
- << "%) failed the perceptual test\n";
-
- if (cr.nfail > (failpercent/100.0 * npels) || cr.maxerror > hardfail ||
- yee_failures > (failpercent/100.0 * npels)) {
- ret = ErrFail;
- } else if (cr.nwarn > (warnpercent/100.0 * npels) || cr.maxerror > hardwarn) {
- if (ret != ErrFail)
- ret = ErrWarn;
+ std::streamsize precis = std::cout.precision();
+ std::cout << " " << cr.nwarn << " pixels ("
+ << std::setprecision(3) << (100.0*cr.nwarn / npels)
+ << std::setprecision(precis) << "%) over " << warnthresh << "\n";
+ std::cout << " " << cr.nfail << " pixels ("
+ << std::setprecision(3) << (100.0*cr.nfail / npels)
+ << std::setprecision(precis) << "%) over " << failthresh << "\n";
+ if (perceptual)
+ std::cout << " " << yee_failures << " pixels ("
+ << std::setprecision(3) << (100.0*yee_failures / npels)
+ << std::setprecision(precis)
+ << "%) failed the perceptual test\n";
}
// If the user requested that a difference image be output,
View
@@ -81,6 +81,24 @@ safe_double_print (double val)
+inline void
+print_subimage (ImageRec &img0, int subimage, int miplevel)
+{
+ if (img0.subimages() > 1)
+ std::cout << "Subimage " << subimage << ' ';
+ if (img0.miplevels(subimage) > 1)
+ std::cout << " MIP level " << miplevel << ' ';
+ if (img0.subimages() > 1 || img0.miplevels(subimage) > 1)
+ std::cout << ": ";
+ const ImageSpec &spec (*img0.spec(subimage));
+ std::cout << spec.width << " x " << spec.height;
+ if (spec.depth > 1)
+ std::cout << " x " << spec.depth;
+ std::cout << ", " << spec.nchannels << " channel\n";
+}
+
+
+
int
OiioTool::do_action_diff (ImageRec &ir0, ImageRec &ir1,
Oiiotool &ot)
@@ -97,15 +115,6 @@ OiioTool::do_action_diff (ImageRec &ir0, ImageRec &ir1,
if (subimage >= ir1.subimages())
break;
- if (ot.allsubimages) {
- std::cout << "Subimage " << subimage << ": ";
- const ImageSpec &spec (*ir0.spec(subimage));
- std::cout << spec.width << " x " << spec.height;
- if (spec.depth > 1)
- std::cout << " x " << spec.depth;
- std::cout << ", " << spec.nchannels << " channel\n";
- }
-
if (ir0.miplevels(subimage) != ir1.miplevels(subimage)) {
std::cout << "Files do not match in their number of MIPmap levels\n";
}
@@ -122,18 +131,11 @@ OiioTool::do_action_diff (ImageRec &ir0, ImageRec &ir1,
ImageBuf &img0 (ir0(subimage,m));
ImageBuf &img1 (ir1(subimage,m));
- if (ot.allsubimages && ir0.miplevels(subimage) > 1) {
- std::cout << " MIP level " << m << ": ";
- std::cout << img0.spec().width << " x " << img0.spec().height;
- if (img0.spec().depth > 1)
- std::cout << " x " << img0.spec().depth;
- std::cout << ", " << img0.spec().nchannels << " channel\n";
- }
-
// Compare the dimensions of the images. Fail if they
// aren't the same resolution and number of channels. No
// problem, though, if they aren't the same data type.
if (! same_size (img0, img1)) {
+ print_subimage (ir0, subimage, m);
std::cout << "Images do not match in size: ";
std::cout << "(" << img0.spec().width << "x" << img0.spec().height;
if (img0.spec().depth > 1)
@@ -163,49 +165,53 @@ OiioTool::do_action_diff (ImageRec &ir0, ImageRec &ir1,
if (perceptual)
yee_failures = ImageBufAlgo::compare_Yee (img0, img1);
#endif
+ if (cr.nfail > (ot.diff_failpercent/100.0 * npels) || cr.maxerror > ot.diff_hardfail ||
+ yee_failures > (ot.diff_failpercent/100.0 * npels)) {
+ ret = DiffErrFail;
+ } else if (cr.nwarn > (ot.diff_warnpercent/100.0 * npels) || cr.maxerror > ot.diff_hardwarn) {
+ if (ret != DiffErrFail)
+ ret = DiffErrWarn;
+ }
// Print the report
//
- std::cout << " Mean error = ";
- safe_double_print (cr.meanerror);
- std::cout << " RMS error = ";
- safe_double_print (cr.rms_error);
- std::cout << " Peak SNR = ";
- safe_double_print (cr.PSNR);
- std::cout << " Max error = " << cr.maxerror;
- if (cr.maxerror != 0) {
- std::cout << " @ (" << cr.maxx << ", " << cr.maxy;
- if (img0.spec().depth > 1)
- std::cout << ", " << cr.maxz;
- std::cout << ", " << img0.spec().channelnames[cr.maxc] << ')';
- }
- std::cout << "\n";
+ if (ot.verbose || ret != DiffErrOK) {
+ if (ot.allsubimages)
+ print_subimage (ir0, subimage, m);
+ std::cout << " Mean error = ";
+ safe_double_print (cr.meanerror);
+ std::cout << " RMS error = ";
+ safe_double_print (cr.rms_error);
+ std::cout << " Peak SNR = ";
+ safe_double_print (cr.PSNR);
+ std::cout << " Max error = " << cr.maxerror;
+ if (cr.maxerror != 0) {
+ std::cout << " @ (" << cr.maxx << ", " << cr.maxy;
+ if (img0.spec().depth > 1)
+ std::cout << ", " << cr.maxz;
+ std::cout << ", " << img0.spec().channelnames[cr.maxc] << ')';
+ }
+ std::cout << "\n";
// when Visual Studio is used float values in scientific foramt are
// printed with three digit exponent. We change this behaviour to fit
// Linux way
#ifdef _MSC_VER
- _set_output_format(_TWO_DIGIT_EXPONENT);
+ _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
- std::streamsize precis = std::cout.precision();
- std::cout << " " << cr.nwarn << " pixels ("
- << std::setprecision(3) << (100.0*cr.nwarn / npels)
- << std::setprecision(precis) << "%) over " << ot.diff_warnthresh << "\n";
- std::cout << " " << cr.nfail << " pixels ("
- << std::setprecision(3) << (100.0*cr.nfail / npels)
- << std::setprecision(precis) << "%) over " << ot.diff_failthresh << "\n";
+ std::streamsize precis = std::cout.precision();
+ std::cout << " " << cr.nwarn << " pixels ("
+ << std::setprecision(3) << (100.0*cr.nwarn / npels)
+ << std::setprecision(precis) << "%) over " << ot.diff_warnthresh << "\n";
+ std::cout << " " << cr.nfail << " pixels ("
+ << std::setprecision(3) << (100.0*cr.nfail / npels)
+ << std::setprecision(precis) << "%) over " << ot.diff_failthresh << "\n";
#if 0
- if (perceptual)
- std::cout << " " << yee_failures << " pixels ("
- << std::setprecision(3) << (100.0*yee_failures / npels)
- << std::setprecision(precis)
- << "%) failed the perceptual test\n";
+ if (perceptual)
+ std::cout << " " << yee_failures << " pixels ("
+ << std::setprecision(3) << (100.0*yee_failures / npels)
+ << std::setprecision(precis)
+ << "%) failed the perceptual test\n";
#endif
- if (cr.nfail > (ot.diff_failpercent/100.0 * npels) || cr.maxerror > ot.diff_hardfail ||
- yee_failures > (ot.diff_failpercent/100.0 * npels)) {
- ret = DiffErrFail;
- } else if (cr.nwarn > (ot.diff_warnpercent/100.0 * npels) || cr.maxerror > ot.diff_hardwarn) {
- if (ret != DiffErrFail)
- ret = DiffErrWarn;
}
#if 0

0 comments on commit 98eacfd

Please sign in to comment.