Skip to content

Commit

Permalink
Separate output from input
Browse files Browse the repository at this point in the history
  • Loading branch information
myint committed Nov 23, 2016
1 parent 8b0ea69 commit cee6af3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion compare_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions compare_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 12 additions & 11 deletions metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#define PERCEPTUALDIFF_METRIC_H

#include <ostream>
#include <string>


class CompareArgs;
Expand All @@ -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
7 changes: 4 additions & 3 deletions perceptualdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit cee6af3

Please sign in to comment.