diff --git a/compare_args.cpp b/compare_args.cpp index 666e88b..fd11243 100644 --- a/compare_args.cpp +++ b/compare_args.cpp @@ -240,7 +240,7 @@ bool CompareArgs::parse_args(const int argc, char **argv) if (not image_a_ or not image_b_) { - error_string_ = "Not enough image files specified\n"; + std::cerr << "Not enough image files specified\n"; return false; } diff --git a/compare_args.h b/compare_args.h index f19bc6e..fdd1193 100644 --- a/compare_args.h +++ b/compare_args.h @@ -60,8 +60,6 @@ class CompareArgs // How many pixels different to ignore. unsigned int threshold_pixels_; - std::string error_string_; - // How much color to use in the metric. // 0.0 is the same as luminance_only_ = true, // 1.0 means full strength. diff --git a/metric.cpp b/metric.cpp index 5432af4..d6bd275 100644 --- a/metric.cpp +++ b/metric.cpp @@ -194,13 +194,14 @@ static unsigned int adaptation(const float num_one_degree_pixels) } -bool yee_compare(CompareArgs &args, +bool yee_compare(const CompareArgs &args, + std::string &output_error_string, std::ostream *output_verbose) { if ((args.image_a_->get_width() != args.image_b_->get_width()) or (args.image_a_->get_height() != args.image_b_->get_height())) { - args.error_string_ = "Image dimensions do not match\n"; + output_error_string = "Image dimensions do not match\n"; return false; } @@ -219,7 +220,7 @@ bool yee_compare(CompareArgs &args, } if (identical) { - args.error_string_ = "Images are binary identical\n"; + output_error_string = "Images are binary identical\n"; return true; } @@ -425,23 +426,23 @@ bool yee_compare(CompareArgs &args, { args.image_difference_->write_to_file(args.image_difference_->get_name()); - args.error_string_ += "Wrote difference image to "; - args.error_string_ += args.image_difference_->get_name(); - args.error_string_ += "\n"; + output_error_string += "Wrote difference image to "; + output_error_string += args.image_difference_->get_name(); + output_error_string += "\n"; } if (pixels_failed < args.threshold_pixels_) { - args.error_string_ = "Images are perceptually indistinguishable\n"; - args.error_string_ += different; + output_error_string = "Images are perceptually indistinguishable\n"; + output_error_string += different; return true; } - args.error_string_ = "Images are visibly different\n"; - args.error_string_ += different; + output_error_string = "Images are visibly different\n"; + output_error_string += different; if (args.sum_errors_) { - args.error_string_ += error_sum_buff; + output_error_string += error_sum_buff; } return false; diff --git a/metric.h b/metric.h index 80bf44d..78834cb 100644 --- a/metric.h +++ b/metric.h @@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #define PERCEPTUALDIFF_METRIC_H #include +#include class CompareArgs; @@ -29,7 +30,8 @@ class CompareArgs; // Image comparison metric using Yee's method. // References: A Perceptual Metric for Production Testing, Hector Yee, Journal // of Graphics Tools 2004 -bool yee_compare(CompareArgs &args, +bool yee_compare(const CompareArgs &args, + std::string &output_error_string, std::ostream *output_verbose=NULL); #endif diff --git a/perceptualdiff.cpp b/perceptualdiff.cpp index f54c632..2bec94b 100644 --- a/perceptualdiff.cpp +++ b/perceptualdiff.cpp @@ -39,7 +39,6 @@ int main(const int argc, char **const argv) { if (not args.parse_args(argc, argv)) { - std::cerr << args.error_string_; return EXIT_FAILURE; } else @@ -50,18 +49,20 @@ int main(const int argc, char **const argv) } } + std::string error_string; const auto passed = yee_compare(args, + error_string, args.verbose_ ? &std::cout : NULL); if (passed) { if (args.verbose_) { - std::cout << "PASS: " << args.error_string_; + std::cout << "PASS: " << error_string; } } else { - std::cout << "FAIL: " << args.error_string_; + std::cout << "FAIL: " << error_string; } return passed ? EXIT_SUCCESS : EXIT_FAILURE;