Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1887)

Unified Diff: cc/test/pixel_test_utils.cc

Issue 12558003: cc: Made image comparison for pixel tests error tolerant. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduced PixelComparator interface. Refactored code. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/test/pixel_test_utils.h ('K') | « cc/test/pixel_test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ac8089f399d3c310c6b891575c709c83634fb989 100644
--- a/cc/test/pixel_test_utils.cc
+++ b/cc/test/pixel_test_utils.cc
@@ -34,45 +34,15 @@ 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 PixelComparator& comparator) {
SkBitmap ref_bmp;
if (!ReadPNGFile(ref_img_path, &ref_bmp)) {
LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value();
return false;
}
- if (ref_bmp.width() != gen_bmp.width() ||
- ref_bmp.height() != gen_bmp.height()) {
- LOG(ERROR)
- << "Dimensions do not match (Expected) vs (Actual):"
- << "(" << ref_bmp.width() << "x" << ref_bmp.height()
- << ") vs. "
- << "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")";
- 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;
- }
- }
- }
-
- if (diff_pixels_count != 0) {
- LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count;
- return false;
- }
-
- return true;
+ return comparator.Compare(gen_bmp, ref_bmp);
}
} // namespace cc
« cc/test/pixel_test_utils.h ('K') | « cc/test/pixel_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698