OLD | NEW |
---|---|
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.set_x(std::min(x, error_bounding_rect.x())); |
danakj
2014/07/08 16:46:47
Sorry, I had asked about this earlier and missed a
sohanjg
2014/07/09 05:25:52
Done.
Sorry i missed it, this essentially was doin
| |
41 << "actual RGBA=(" | 43 error_bounding_rect.set_y(std::min(y, error_bounding_rect.y())); |
42 << SkColorGetR(actual_color) << "," | 44 error_bounding_rect.set_width( |
43 << SkColorGetG(actual_color) << "," | 45 std::max(x, |
44 << SkColorGetB(actual_color) << "," | 46 (error_bounding_rect.x() + error_bounding_rect.width())) - |
45 << SkColorGetA(actual_color) << "); " | 47 error_bounding_rect.x()); |
46 << "expected RGBA=(" | 48 error_bounding_rect.set_height( |
47 << SkColorGetR(expected_color) << "," | 49 std::max(y, |
48 << SkColorGetG(expected_color) << "," | 50 (error_bounding_rect.y() + error_bounding_rect.bottom())) - |
49 << SkColorGetB(expected_color) << "," | 51 error_bounding_rect.y()); |
50 << SkColorGetA(expected_color) << ")"; | |
51 } | 52 } |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 if (error_pixels_count != 0) { | 56 if (error_pixels_count != 0) { |
56 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; | 57 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; |
58 LOG(ERROR) << "Error Bounding Box : " << error_bounding_rect.ToString(); | |
57 return false; | 59 return false; |
58 } | 60 } |
59 | 61 |
60 return true; | 62 return true; |
61 } | 63 } |
62 | 64 |
63 FuzzyPixelComparator::FuzzyPixelComparator( | 65 FuzzyPixelComparator::FuzzyPixelComparator( |
64 const bool discard_alpha, | 66 const bool discard_alpha, |
65 const float error_pixels_percentage_limit, | 67 const float error_pixels_percentage_limit, |
66 const float small_error_pixels_percentage_limit, | 68 const float small_error_pixels_percentage_limit, |
(...skipping 18 matching lines...) Expand all Loading... | |
85 int64 sum_abs_error_r = 0; | 87 int64 sum_abs_error_r = 0; |
86 int64 sum_abs_error_g = 0; | 88 int64 sum_abs_error_g = 0; |
87 int64 sum_abs_error_b = 0; | 89 int64 sum_abs_error_b = 0; |
88 int64 sum_abs_error_a = 0; | 90 int64 sum_abs_error_a = 0; |
89 // The per channel maximum absolute errors over all pixels. | 91 // The per channel maximum absolute errors over all pixels. |
90 int max_abs_error_r = 0; | 92 int max_abs_error_r = 0; |
91 int max_abs_error_g = 0; | 93 int max_abs_error_g = 0; |
92 int max_abs_error_b = 0; | 94 int max_abs_error_b = 0; |
93 int max_abs_error_a = 0; | 95 int max_abs_error_a = 0; |
94 | 96 |
97 gfx::Rect error_bounding_rect = gfx::Rect(); | |
98 | |
95 // Check that bitmaps have identical dimensions. | 99 // Check that bitmaps have identical dimensions. |
96 DCHECK(actual_bmp.width() == expected_bmp.width() && | 100 DCHECK(actual_bmp.width() == expected_bmp.width() && |
97 actual_bmp.height() == expected_bmp.height()); | 101 actual_bmp.height() == expected_bmp.height()); |
98 | 102 |
99 // Check that bitmaps are not empty. | 103 // Check that bitmaps are not empty. |
100 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); | 104 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); |
101 | 105 |
102 SkAutoLockPixels lock_actual_bmp(actual_bmp); | 106 SkAutoLockPixels lock_actual_bmp(actual_bmp); |
103 SkAutoLockPixels lock_expected_bmp(expected_bmp); | 107 SkAutoLockPixels lock_expected_bmp(expected_bmp); |
104 | 108 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 | 199 |
196 for (int x = 0; x < actual_bmp.width(); ++x) { | 200 for (int x = 0; x < actual_bmp.width(); ++x) { |
197 for (int y = 0; y < actual_bmp.height(); ++y) { | 201 for (int y = 0; y < actual_bmp.height(); ++y) { |
198 SkColor actual_color = actual_bmp.getColor(x, y); | 202 SkColor actual_color = actual_bmp.getColor(x, y); |
199 SkColor expected_color = expected_bmp.getColor(x, y); | 203 SkColor expected_color = expected_bmp.getColor(x, y); |
200 if (discard_alpha_) { | 204 if (discard_alpha_) { |
201 actual_color = SkColorSetA(actual_color, 0); | 205 actual_color = SkColorSetA(actual_color, 0); |
202 expected_color = SkColorSetA(expected_color, 0); | 206 expected_color = SkColorSetA(expected_color, 0); |
203 } | 207 } |
204 if (actual_color != expected_color) { | 208 if (actual_color != expected_color) { |
205 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " | 209 error_bounding_rect.set_x(std::min(x, error_bounding_rect.x())); |
206 << "actual RGBA=(" | 210 error_bounding_rect.set_y(std::min(y, error_bounding_rect.y())); |
207 << SkColorGetR(actual_color) << "," | 211 error_bounding_rect.set_width( |
208 << SkColorGetG(actual_color) << "," | 212 std::max( |
209 << SkColorGetB(actual_color) << "," | 213 x, |
210 << SkColorGetA(actual_color) << "); " | 214 (error_bounding_rect.x() + error_bounding_rect.width())) - |
211 << "expected RGBA=(" | 215 error_bounding_rect.x()); |
212 << SkColorGetR(expected_color) << "," | 216 error_bounding_rect.set_height( |
213 << SkColorGetG(expected_color) << "," | 217 std::max( |
214 << SkColorGetB(expected_color) << "," | 218 y, |
215 << SkColorGetA(expected_color) << ")"; | 219 (error_bounding_rect.y() + error_bounding_rect.bottom())) - |
220 error_bounding_rect.y()); | |
216 } | 221 } |
217 } | 222 } |
218 } | 223 } |
219 | 224 LOG(ERROR) << "Error Bounding Box : " << error_bounding_rect.ToString(); |
220 return false; | 225 return false; |
221 } else { | 226 } else { |
222 return true; | 227 return true; |
223 } | 228 } |
224 } | 229 } |
225 | 230 |
226 } // namespace cc | 231 } // namespace cc |
OLD | NEW |