summaryrefslogtreecommitdiffstats
path: root/cc/test/pixel_test_utils.cc
diff options
context:
space:
mode:
authorernstm@chromium.org <ernstm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-29 04:09:47 +0000
committerernstm@chromium.org <ernstm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-29 04:09:47 +0000
commitca43568db4c8e1d54bddeac27fa8e95387476556 (patch)
treeb2474fd80562c16f303df5725740ad7de48ab287 /cc/test/pixel_test_utils.cc
parent292ff3178fd8c6037b9d7dda01904b15fb4662f9 (diff)
downloadchromium_src-ca43568db4c8e1d54bddeac27fa8e95387476556.zip
chromium_src-ca43568db4c8e1d54bddeac27fa8e95387476556.tar.gz
chromium_src-ca43568db4c8e1d54bddeac27fa8e95387476556.tar.bz2
cc: Made image comparison for pixel tests error tolerant.
Added PixelComparator interface and two implementations of it: ExactPixelComparator and FuzzyPixelComparator. The FuzzyPixelComparator tolerates an adjustable amount of error in the image. BUG=180460 Review URL: https://chromiumcodereview.appspot.com/12558003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test/pixel_test_utils.cc')
-rw-r--r--cc/test/pixel_test_utils.cc47
1 files changed, 13 insertions, 34 deletions
diff --git a/cc/test/pixel_test_utils.cc b/cc/test/pixel_test_utils.cc
index cedb386..1ef0b74 100644
--- a/cc/test/pixel_test_utils.cc
+++ b/cc/test/pixel_test_utils.cc
@@ -37,51 +37,30 @@ bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) {
bitmap);
}
-bool IsSameAsPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path,
- bool discard_transparency) {
+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()) {
+ // Check if images size matches
+ if (gen_bmp.width() != ref_bmp.width() ||
+ gen_bmp.height() != ref_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() << ")";
+ << "Dimensions do not match! "
+ << "Actual: " << gen_bmp.width() << "x" << gen_bmp.height()
+ << "; "
+ << "Expected: " << ref_bmp.width() << "x" << ref_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;
- if (discard_transparency)
- kAlphaMask = 0x00FFFFFF;
- else
- kAlphaMask = 0xFFFFFFFF;
-
- 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;
- }
+ // Shortcut for empty images. They are always equal.
+ if (gen_bmp.width() == 0 || gen_bmp.height() == 0)
+ return true;
- return true;
+ return comparator.Compare(gen_bmp, ref_bmp);
}
} // namespace cc