Index: cc/test/pixel_test_utils.cc |
diff --git a/cc/test/pixel_test_utils.cc b/cc/test/pixel_test_utils.cc |
index d1101b381f332ebc913316b17114768b5d0d25a6..9bd665c99449ae87896a03d2a8e861a1921db58f 100644 |
--- a/cc/test/pixel_test_utils.cc |
+++ b/cc/test/pixel_test_utils.cc |
@@ -34,7 +34,8 @@ bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) { |
bitmap); |
} |
-bool IsSameAsPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path) { |
+bool MatchesPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path, |
+ const ImageComparator& comparator) { |
SkBitmap ref_bmp; |
if (!ReadPNGFile(ref_img_path, &ref_bmp)) { |
LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); |
@@ -51,24 +52,22 @@ bool IsSameAsPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path) { |
return false; |
} |
- // Compare pixels and create a simple diff image. |
- int diff_pixels_count = 0; |
- SkAutoLockPixels lock_bmp(gen_bmp); |
- SkAutoLockPixels lock_ref_bmp(ref_bmp); |
- // The reference images were saved with no alpha channel. Use the mask to |
- // set alpha to 0. |
- uint32_t kAlphaMask = 0x00FFFFFF; |
- for (int x = 0; x < gen_bmp.width(); ++x) { |
- for (int y = 0; y < gen_bmp.height(); ++y) { |
- if ((*gen_bmp.getAddr32(x, y) & kAlphaMask) != |
- (*ref_bmp.getAddr32(x, y) & kAlphaMask)) { |
- ++diff_pixels_count; |
- } |
- } |
- } |
+ ImageComparator::ErrorMetrics metrics; |
+ if (!comparator.Compare(gen_bmp, ref_bmp, &metrics)) { |
reveman
2013/03/07 07:50:44
could the comparator instead be responsible for pr
ernstm
2013/03/07 19:30:07
Done.
|
+ LOG(ERROR) << "Percentage of pixels that are different: " |
+ << metrics.error_pixels_percentage << "; " |
+ << "Percentage of pixels with errors not greater than " |
+ << metrics.small_error_threshold << ": " |
+ << metrics.small_error_pixels_percentage << "; " |
+ << "Average absolute error over different pixels: " |
+ << "R=" << metrics.avg_abs_error_r << " " |
+ << "G=" << metrics.avg_abs_error_g << " " |
+ << "B=" << metrics.avg_abs_error_b << "; " |
+ << "Maximum absolute error: " |
+ << "R=" << metrics.max_abs_error_r << " " |
+ << "G=" << metrics.max_abs_error_g << " " |
+ << "B=" << metrics.max_abs_error_b; |
- if (diff_pixels_count != 0) { |
- LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count; |
return false; |
} |