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

Side by Side Diff: cc/test/pixel_comparator.cc

Issue 371863002: cc: For cc pixel test, create data url for pngs and print bounding rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed. Created 6 years, 5 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
« no previous file with comments | « no previous file | cc/test/pixel_test_utils.h » ('j') | cc/test/pixel_test_utils.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_comparator.h" 5 #include "cc/test/pixel_comparator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/gfx/rect.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 ExactPixelComparator::ExactPixelComparator(const bool discard_alpha) 14 ExactPixelComparator::ExactPixelComparator(const bool discard_alpha)
14 : discard_alpha_(discard_alpha) { 15 : discard_alpha_(discard_alpha) {
15 } 16 }
16 17
17 bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp, 18 bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp,
18 const SkBitmap& expected_bmp) const { 19 const SkBitmap& expected_bmp) const {
19 // Number of pixels with an error 20 // Number of pixels with an error
20 int error_pixels_count = 0; 21 int error_pixels_count = 0;
21 22
23 gfx::Rect error_bounding_rect = gfx::Rect();
24
22 // Check that bitmaps have identical dimensions. 25 // Check that bitmaps have identical dimensions.
23 DCHECK(actual_bmp.width() == expected_bmp.width() && 26 DCHECK(actual_bmp.width() == expected_bmp.width() &&
24 actual_bmp.height() == expected_bmp.height()); 27 actual_bmp.height() == expected_bmp.height());
25 28
26 SkAutoLockPixels lock_actual_bmp(actual_bmp); 29 SkAutoLockPixels lock_actual_bmp(actual_bmp);
27 SkAutoLockPixels lock_expected_bmp(expected_bmp); 30 SkAutoLockPixels lock_expected_bmp(expected_bmp);
28 31
29 for (int x = 0; x < actual_bmp.width(); ++x) { 32 for (int x = 0; x < actual_bmp.width(); ++x) {
30 for (int y = 0; y < actual_bmp.height(); ++y) { 33 for (int y = 0; y < actual_bmp.height(); ++y) {
31 SkColor actual_color = actual_bmp.getColor(x, y); 34 SkColor actual_color = actual_bmp.getColor(x, y);
32 SkColor expected_color = expected_bmp.getColor(x, y); 35 SkColor expected_color = expected_bmp.getColor(x, y);
33 if (discard_alpha_) { 36 if (discard_alpha_) {
34 actual_color = SkColorSetA(actual_color, 0); 37 actual_color = SkColorSetA(actual_color, 0);
35 expected_color = SkColorSetA(expected_color, 0); 38 expected_color = SkColorSetA(expected_color, 0);
36 } 39 }
37
38 if (actual_color != expected_color) { 40 if (actual_color != expected_color) {
39 ++error_pixels_count; 41 ++error_pixels_count;
40 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " 42 error_bounding_rect.Union(gfx::Rect(x, y, 1, 1));
41 << "actual RGBA=("
42 << SkColorGetR(actual_color) << ","
43 << SkColorGetG(actual_color) << ","
44 << SkColorGetB(actual_color) << ","
45 << SkColorGetA(actual_color) << "); "
46 << "expected RGBA=("
47 << SkColorGetR(expected_color) << ","
48 << SkColorGetG(expected_color) << ","
49 << SkColorGetB(expected_color) << ","
50 << SkColorGetA(expected_color) << ")";
51 } 43 }
52 } 44 }
53 } 45 }
54 46
55 if (error_pixels_count != 0) { 47 if (error_pixels_count != 0) {
56 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; 48 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count;
49 LOG(ERROR) << "Error Bounding Box : " << error_bounding_rect.ToString();
57 return false; 50 return false;
58 } 51 }
59 52
60 return true; 53 return true;
61 } 54 }
62 55
63 FuzzyPixelComparator::FuzzyPixelComparator( 56 FuzzyPixelComparator::FuzzyPixelComparator(
64 const bool discard_alpha, 57 const bool discard_alpha,
65 const float error_pixels_percentage_limit, 58 const float error_pixels_percentage_limit,
66 const float small_error_pixels_percentage_limit, 59 const float small_error_pixels_percentage_limit,
(...skipping 18 matching lines...) Expand all
85 int64 sum_abs_error_r = 0; 78 int64 sum_abs_error_r = 0;
86 int64 sum_abs_error_g = 0; 79 int64 sum_abs_error_g = 0;
87 int64 sum_abs_error_b = 0; 80 int64 sum_abs_error_b = 0;
88 int64 sum_abs_error_a = 0; 81 int64 sum_abs_error_a = 0;
89 // The per channel maximum absolute errors over all pixels. 82 // The per channel maximum absolute errors over all pixels.
90 int max_abs_error_r = 0; 83 int max_abs_error_r = 0;
91 int max_abs_error_g = 0; 84 int max_abs_error_g = 0;
92 int max_abs_error_b = 0; 85 int max_abs_error_b = 0;
93 int max_abs_error_a = 0; 86 int max_abs_error_a = 0;
94 87
88 gfx::Rect error_bounding_rect = gfx::Rect();
89
95 // Check that bitmaps have identical dimensions. 90 // Check that bitmaps have identical dimensions.
96 DCHECK(actual_bmp.width() == expected_bmp.width() && 91 DCHECK(actual_bmp.width() == expected_bmp.width() &&
97 actual_bmp.height() == expected_bmp.height()); 92 actual_bmp.height() == expected_bmp.height());
98 93
99 // Check that bitmaps are not empty. 94 // Check that bitmaps are not empty.
100 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); 95 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0);
101 96
102 SkAutoLockPixels lock_actual_bmp(actual_bmp); 97 SkAutoLockPixels lock_actual_bmp(actual_bmp);
103 SkAutoLockPixels lock_expected_bmp(expected_bmp); 98 SkAutoLockPixels lock_expected_bmp(expected_bmp);
104 99
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 << "A=" << max_abs_error_a; 189 << "A=" << max_abs_error_a;
195 190
196 for (int x = 0; x < actual_bmp.width(); ++x) { 191 for (int x = 0; x < actual_bmp.width(); ++x) {
197 for (int y = 0; y < actual_bmp.height(); ++y) { 192 for (int y = 0; y < actual_bmp.height(); ++y) {
198 SkColor actual_color = actual_bmp.getColor(x, y); 193 SkColor actual_color = actual_bmp.getColor(x, y);
199 SkColor expected_color = expected_bmp.getColor(x, y); 194 SkColor expected_color = expected_bmp.getColor(x, y);
200 if (discard_alpha_) { 195 if (discard_alpha_) {
201 actual_color = SkColorSetA(actual_color, 0); 196 actual_color = SkColorSetA(actual_color, 0);
202 expected_color = SkColorSetA(expected_color, 0); 197 expected_color = SkColorSetA(expected_color, 0);
203 } 198 }
204 if (actual_color != expected_color) { 199 if (actual_color != expected_color)
205 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " 200 error_bounding_rect.Union(gfx::Rect(x, y, 1, 1));
206 << "actual RGBA=("
207 << SkColorGetR(actual_color) << ","
208 << SkColorGetG(actual_color) << ","
209 << SkColorGetB(actual_color) << ","
210 << SkColorGetA(actual_color) << "); "
211 << "expected RGBA=("
212 << SkColorGetR(expected_color) << ","
213 << SkColorGetG(expected_color) << ","
214 << SkColorGetB(expected_color) << ","
215 << SkColorGetA(expected_color) << ")";
216 }
217 } 201 }
218 } 202 }
219 203 LOG(ERROR) << "Error Bounding Box : " << error_bounding_rect.ToString();
220 return false; 204 return false;
221 } else { 205 } else {
222 return true; 206 return true;
223 } 207 }
224 } 208 }
225 209
226 } // namespace cc 210 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/test/pixel_test_utils.h » ('j') | cc/test/pixel_test_utils.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698