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

Side by Side 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: 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 unified diff | Download patch
« cc/test/image_comparator.cc ('K') | « cc/test/pixel_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/pixel_test_utils.h" 5 #include "cc/test/pixel_test_utils.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/codec/png_codec.h" 10 #include "ui/gfx/codec/png_codec.h"
(...skipping 16 matching lines...) Expand all
27 27
28 bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) { 28 bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) {
29 DCHECK(bitmap); 29 DCHECK(bitmap);
30 std::string png_data; 30 std::string png_data;
31 return file_util::ReadFileToString(file_path, &png_data) && 31 return file_util::ReadFileToString(file_path, &png_data) &&
32 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), 32 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]),
33 png_data.length(), 33 png_data.length(),
34 bitmap); 34 bitmap);
35 } 35 }
36 36
37 bool IsSameAsPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path) { 37 bool MatchesPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path,
38 const ImageComparator& comparator) {
38 SkBitmap ref_bmp; 39 SkBitmap ref_bmp;
39 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { 40 if (!ReadPNGFile(ref_img_path, &ref_bmp)) {
40 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); 41 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value();
41 return false; 42 return false;
42 } 43 }
43 44
44 if (ref_bmp.width() != gen_bmp.width() || 45 if (ref_bmp.width() != gen_bmp.width() ||
45 ref_bmp.height() != gen_bmp.height()) { 46 ref_bmp.height() != gen_bmp.height()) {
46 LOG(ERROR) 47 LOG(ERROR)
47 << "Dimensions do not match (Expected) vs (Actual):" 48 << "Dimensions do not match (Expected) vs (Actual):"
48 << "(" << ref_bmp.width() << "x" << ref_bmp.height() 49 << "(" << ref_bmp.width() << "x" << ref_bmp.height()
49 << ") vs. " 50 << ") vs. "
50 << "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")"; 51 << "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")";
51 return false; 52 return false;
52 } 53 }
53 54
54 // Compare pixels and create a simple diff image. 55 ImageComparator::ErrorMetrics metrics;
55 int diff_pixels_count = 0; 56 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.
56 SkAutoLockPixels lock_bmp(gen_bmp); 57 LOG(ERROR) << "Percentage of pixels that are different: "
57 SkAutoLockPixels lock_ref_bmp(ref_bmp); 58 << metrics.error_pixels_percentage << "; "
58 // The reference images were saved with no alpha channel. Use the mask to 59 << "Percentage of pixels with errors not greater than "
59 // set alpha to 0. 60 << metrics.small_error_threshold << ": "
60 uint32_t kAlphaMask = 0x00FFFFFF; 61 << metrics.small_error_pixels_percentage << "; "
61 for (int x = 0; x < gen_bmp.width(); ++x) { 62 << "Average absolute error over different pixels: "
62 for (int y = 0; y < gen_bmp.height(); ++y) { 63 << "R=" << metrics.avg_abs_error_r << " "
63 if ((*gen_bmp.getAddr32(x, y) & kAlphaMask) != 64 << "G=" << metrics.avg_abs_error_g << " "
64 (*ref_bmp.getAddr32(x, y) & kAlphaMask)) { 65 << "B=" << metrics.avg_abs_error_b << "; "
65 ++diff_pixels_count; 66 << "Maximum absolute error: "
66 } 67 << "R=" << metrics.max_abs_error_r << " "
67 } 68 << "G=" << metrics.max_abs_error_g << " "
68 } 69 << "B=" << metrics.max_abs_error_b;
69 70
70 if (diff_pixels_count != 0) {
71 LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count;
72 return false; 71 return false;
73 } 72 }
74 73
75 return true; 74 return true;
76 } 75 }
77 76
78 } // namespace cc 77 } // namespace cc
OLDNEW
« cc/test/image_comparator.cc ('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