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

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: use gfx::Rect instead of max co-ordinates 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') | 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) 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;
22 // Bounding box for error
danakj 2014/07/08 16:08:34 nit: comments are sentences including periods. bu
sohanjg 2014/07/08 16:20:34 Done.
23 gfx::Rect bounding_rect = gfx::Rect();
21 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 bounding_rect.set_x(std::min(x, bounding_rect.x()));
41 << "actual RGBA=(" 43 bounding_rect.set_y(std::min(y, bounding_rect.y()));
42 << SkColorGetR(actual_color) << "," 44 bounding_rect.set_width(
43 << SkColorGetG(actual_color) << "," 45 std::max(x, (bounding_rect.x() + bounding_rect.width())) -
44 << SkColorGetB(actual_color) << "," 46 bounding_rect.x());
45 << SkColorGetA(actual_color) << "); " 47 bounding_rect.set_height(
46 << "expected RGBA=(" 48 std::max(y, (bounding_rect.y() + bounding_rect.bottom())) -
47 << SkColorGetR(expected_color) << "," 49 bounding_rect.y());
48 << SkColorGetG(expected_color) << ","
49 << SkColorGetB(expected_color) << ","
50 << SkColorGetA(expected_color) << ")";
51 } 50 }
52 } 51 }
53 } 52 }
54 53
55 if (error_pixels_count != 0) { 54 if (error_pixels_count != 0) {
56 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; 55 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count;
56 LOG(ERROR) << "Error Bounding Box : " << bounding_rect.ToString();
57 return false; 57 return false;
58 } 58 }
59 59
60 return true; 60 return true;
61 } 61 }
62 62
63 FuzzyPixelComparator::FuzzyPixelComparator( 63 FuzzyPixelComparator::FuzzyPixelComparator(
64 const bool discard_alpha, 64 const bool discard_alpha,
65 const float error_pixels_percentage_limit, 65 const float error_pixels_percentage_limit,
66 const float small_error_pixels_percentage_limit, 66 const float small_error_pixels_percentage_limit,
(...skipping 17 matching lines...) Expand all
84 // The per channel sums of absolute errors over all pixels. 84 // The per channel sums of absolute errors over all pixels.
85 int64 sum_abs_error_r = 0; 85 int64 sum_abs_error_r = 0;
86 int64 sum_abs_error_g = 0; 86 int64 sum_abs_error_g = 0;
87 int64 sum_abs_error_b = 0; 87 int64 sum_abs_error_b = 0;
88 int64 sum_abs_error_a = 0; 88 int64 sum_abs_error_a = 0;
89 // The per channel maximum absolute errors over all pixels. 89 // The per channel maximum absolute errors over all pixels.
90 int max_abs_error_r = 0; 90 int max_abs_error_r = 0;
91 int max_abs_error_g = 0; 91 int max_abs_error_g = 0;
92 int max_abs_error_b = 0; 92 int max_abs_error_b = 0;
93 int max_abs_error_a = 0; 93 int max_abs_error_a = 0;
94 // Bounding box for error
95 gfx::Rect bounding_rect = gfx::Rect();
94 96
95 // Check that bitmaps have identical dimensions. 97 // Check that bitmaps have identical dimensions.
96 DCHECK(actual_bmp.width() == expected_bmp.width() && 98 DCHECK(actual_bmp.width() == expected_bmp.width() &&
97 actual_bmp.height() == expected_bmp.height()); 99 actual_bmp.height() == expected_bmp.height());
98 100
99 // Check that bitmaps are not empty. 101 // Check that bitmaps are not empty.
100 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); 102 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0);
101 103
102 SkAutoLockPixels lock_actual_bmp(actual_bmp); 104 SkAutoLockPixels lock_actual_bmp(actual_bmp);
103 SkAutoLockPixels lock_expected_bmp(expected_bmp); 105 SkAutoLockPixels lock_expected_bmp(expected_bmp);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 197
196 for (int x = 0; x < actual_bmp.width(); ++x) { 198 for (int x = 0; x < actual_bmp.width(); ++x) {
197 for (int y = 0; y < actual_bmp.height(); ++y) { 199 for (int y = 0; y < actual_bmp.height(); ++y) {
198 SkColor actual_color = actual_bmp.getColor(x, y); 200 SkColor actual_color = actual_bmp.getColor(x, y);
199 SkColor expected_color = expected_bmp.getColor(x, y); 201 SkColor expected_color = expected_bmp.getColor(x, y);
200 if (discard_alpha_) { 202 if (discard_alpha_) {
201 actual_color = SkColorSetA(actual_color, 0); 203 actual_color = SkColorSetA(actual_color, 0);
202 expected_color = SkColorSetA(expected_color, 0); 204 expected_color = SkColorSetA(expected_color, 0);
203 } 205 }
204 if (actual_color != expected_color) { 206 if (actual_color != expected_color) {
205 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " 207 bounding_rect.set_x(std::min(x, bounding_rect.x()));
206 << "actual RGBA=(" 208 bounding_rect.set_y(std::min(y, bounding_rect.y()));
207 << SkColorGetR(actual_color) << "," 209 bounding_rect.set_width(
208 << SkColorGetG(actual_color) << "," 210 std::max(x, (bounding_rect.x() + bounding_rect.width())) -
209 << SkColorGetB(actual_color) << "," 211 bounding_rect.x());
210 << SkColorGetA(actual_color) << "); " 212 bounding_rect.set_height(
211 << "expected RGBA=(" 213 std::max(y, (bounding_rect.y() + bounding_rect.bottom())) -
212 << SkColorGetR(expected_color) << "," 214 bounding_rect.y());
213 << SkColorGetG(expected_color) << ","
214 << SkColorGetB(expected_color) << ","
215 << SkColorGetA(expected_color) << ")";
216 } 215 }
217 } 216 }
218 } 217 }
219 218 LOG(ERROR) << "Error Bounding Box : " << bounding_rect.ToString();
220 return false; 219 return false;
221 } else { 220 } else {
222 return true; 221 return true;
223 } 222 }
224 } 223 }
225 224
226 } // namespace cc 225 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/test/pixel_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698