Chromium Code Reviews| 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 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 ExactPixelComparator::ExactPixelComparator(const bool discard_alpha) | 13 ExactPixelComparator::ExactPixelComparator(const bool discard_alpha) |
| 14 : discard_alpha_(discard_alpha) { | 14 : discard_alpha_(discard_alpha) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp, | 17 bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp, |
| 18 const SkBitmap& expected_bmp) const { | 18 const SkBitmap& expected_bmp) const { |
| 19 // Number of pixels with an error | 19 // Number of pixels with an error |
| 20 int error_pixels_count = 0; | 20 int error_pixels_count = 0; |
| 21 // Min/Max X,Y for bounding box | |
| 22 int minimum_difference_x = -99; | |
|
danakj
2014/07/07 16:07:02
Can you just use a gfx::Rect that starts empty and
sohanjg
2014/07/08 07:31:08
Done.
| |
| 23 int minimum_difference_y = -99; | |
| 24 int maximum_difference_x = 0; | |
| 25 int maximum_difference_y = 0; | |
| 21 | 26 |
| 22 // Check that bitmaps have identical dimensions. | 27 // Check that bitmaps have identical dimensions. |
| 23 DCHECK(actual_bmp.width() == expected_bmp.width() && | 28 DCHECK(actual_bmp.width() == expected_bmp.width() && |
| 24 actual_bmp.height() == expected_bmp.height()); | 29 actual_bmp.height() == expected_bmp.height()); |
| 25 | 30 |
| 26 SkAutoLockPixels lock_actual_bmp(actual_bmp); | 31 SkAutoLockPixels lock_actual_bmp(actual_bmp); |
| 27 SkAutoLockPixels lock_expected_bmp(expected_bmp); | 32 SkAutoLockPixels lock_expected_bmp(expected_bmp); |
| 28 | |
| 29 for (int x = 0; x < actual_bmp.width(); ++x) { | 33 for (int x = 0; x < actual_bmp.width(); ++x) { |
| 30 for (int y = 0; y < actual_bmp.height(); ++y) { | 34 for (int y = 0; y < actual_bmp.height(); ++y) { |
| 31 SkColor actual_color = actual_bmp.getColor(x, y); | 35 SkColor actual_color = actual_bmp.getColor(x, y); |
| 32 SkColor expected_color = expected_bmp.getColor(x, y); | 36 SkColor expected_color = expected_bmp.getColor(x, y); |
| 33 if (discard_alpha_) { | 37 if (discard_alpha_) { |
| 34 actual_color = SkColorSetA(actual_color, 0); | 38 actual_color = SkColorSetA(actual_color, 0); |
| 35 expected_color = SkColorSetA(expected_color, 0); | 39 expected_color = SkColorSetA(expected_color, 0); |
| 36 } | 40 } |
| 37 | |
| 38 if (actual_color != expected_color) { | 41 if (actual_color != expected_color) { |
| 39 ++error_pixels_count; | 42 ++error_pixels_count; |
| 40 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " | 43 int difference_color = actual_color - expected_color; |
| 41 << "actual RGBA=(" | 44 if (difference_color < 0) |
| 42 << SkColorGetR(actual_color) << "," | 45 difference_color = 0 - difference_color; |
| 43 << SkColorGetG(actual_color) << "," | 46 if ((error_pixels_count == 1) || |
| 44 << SkColorGetB(actual_color) << "," | 47 (x < minimum_difference_x && y < minimum_difference_y)) { |
| 45 << SkColorGetA(actual_color) << "); " | 48 minimum_difference_x = x; |
| 46 << "expected RGBA=(" | 49 minimum_difference_y = y; |
| 47 << SkColorGetR(expected_color) << "," | 50 } |
| 48 << SkColorGetG(expected_color) << "," | 51 if (x > maximum_difference_x && y > maximum_difference_y) { |
| 49 << SkColorGetB(expected_color) << "," | 52 maximum_difference_x = x; |
| 50 << SkColorGetA(expected_color) << ")"; | 53 maximum_difference_y = y; |
| 54 } | |
| 51 } | 55 } |
| 52 } | 56 } |
| 53 } | 57 } |
| 54 | 58 |
| 55 if (error_pixels_count != 0) { | 59 if (error_pixels_count != 0) { |
| 56 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; | 60 LOG(ERROR) << "Number of pixel with an error: " << error_pixels_count; |
| 61 LOG(ERROR) << "Error Bounding Box : " | |
| 62 << " Max X-Y Co-ordinates X = " << maximum_difference_x | |
|
danakj
2014/07/07 16:07:02
You can just use ToString() on the Rect if you use
sohanjg
2014/07/08 07:31:08
Done.
| |
| 63 << " Y = " << maximum_difference_y; | |
| 64 LOG(ERROR) << "Error Bounding Box : " | |
| 65 << " Min X-Y Co-ordinates X = " << minimum_difference_x | |
| 66 << " Y = " << minimum_difference_y; | |
| 57 return false; | 67 return false; |
| 58 } | 68 } |
| 59 | 69 |
| 60 return true; | 70 return true; |
| 61 } | 71 } |
| 62 | 72 |
| 63 FuzzyPixelComparator::FuzzyPixelComparator( | 73 FuzzyPixelComparator::FuzzyPixelComparator( |
| 64 const bool discard_alpha, | 74 const bool discard_alpha, |
| 65 const float error_pixels_percentage_limit, | 75 const float error_pixels_percentage_limit, |
| 66 const float small_error_pixels_percentage_limit, | 76 const float small_error_pixels_percentage_limit, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 85 int64 sum_abs_error_r = 0; | 95 int64 sum_abs_error_r = 0; |
| 86 int64 sum_abs_error_g = 0; | 96 int64 sum_abs_error_g = 0; |
| 87 int64 sum_abs_error_b = 0; | 97 int64 sum_abs_error_b = 0; |
| 88 int64 sum_abs_error_a = 0; | 98 int64 sum_abs_error_a = 0; |
| 89 // The per channel maximum absolute errors over all pixels. | 99 // The per channel maximum absolute errors over all pixels. |
| 90 int max_abs_error_r = 0; | 100 int max_abs_error_r = 0; |
| 91 int max_abs_error_g = 0; | 101 int max_abs_error_g = 0; |
| 92 int max_abs_error_b = 0; | 102 int max_abs_error_b = 0; |
| 93 int max_abs_error_a = 0; | 103 int max_abs_error_a = 0; |
| 94 | 104 |
| 105 // Min/Max X,Y for bounding box | |
| 106 int minimum_difference_x = -99; | |
| 107 int minimum_difference_y = -99; | |
| 108 int maximum_difference_x = 0; | |
| 109 int maximum_difference_y = 0; | |
| 110 | |
| 95 // Check that bitmaps have identical dimensions. | 111 // Check that bitmaps have identical dimensions. |
| 96 DCHECK(actual_bmp.width() == expected_bmp.width() && | 112 DCHECK(actual_bmp.width() == expected_bmp.width() && |
| 97 actual_bmp.height() == expected_bmp.height()); | 113 actual_bmp.height() == expected_bmp.height()); |
| 98 | 114 |
| 99 // Check that bitmaps are not empty. | 115 // Check that bitmaps are not empty. |
| 100 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); | 116 DCHECK(actual_bmp.width() > 0 && actual_bmp.height() > 0); |
| 101 | 117 |
| 102 SkAutoLockPixels lock_actual_bmp(actual_bmp); | 118 SkAutoLockPixels lock_actual_bmp(actual_bmp); |
| 103 SkAutoLockPixels lock_expected_bmp(expected_bmp); | 119 SkAutoLockPixels lock_expected_bmp(expected_bmp); |
| 104 | 120 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 LOG(ERROR) << "Average absolute error (excluding identical pixels): " | 201 LOG(ERROR) << "Average absolute error (excluding identical pixels): " |
| 186 << "R=" << avg_abs_error_r << " " | 202 << "R=" << avg_abs_error_r << " " |
| 187 << "G=" << avg_abs_error_g << " " | 203 << "G=" << avg_abs_error_g << " " |
| 188 << "B=" << avg_abs_error_b << " " | 204 << "B=" << avg_abs_error_b << " " |
| 189 << "A=" << avg_abs_error_a; | 205 << "A=" << avg_abs_error_a; |
| 190 LOG(ERROR) << "Largest absolute error: " | 206 LOG(ERROR) << "Largest absolute error: " |
| 191 << "R=" << max_abs_error_r << " " | 207 << "R=" << max_abs_error_r << " " |
| 192 << "G=" << max_abs_error_g << " " | 208 << "G=" << max_abs_error_g << " " |
| 193 << "B=" << max_abs_error_b << " " | 209 << "B=" << max_abs_error_b << " " |
| 194 << "A=" << max_abs_error_a; | 210 << "A=" << max_abs_error_a; |
| 195 | 211 error_pixels_count = 0; |
| 196 for (int x = 0; x < actual_bmp.width(); ++x) { | 212 for (int x = 0; x < actual_bmp.width(); ++x) { |
| 197 for (int y = 0; y < actual_bmp.height(); ++y) { | 213 for (int y = 0; y < actual_bmp.height(); ++y) { |
| 198 SkColor actual_color = actual_bmp.getColor(x, y); | 214 SkColor actual_color = actual_bmp.getColor(x, y); |
| 199 SkColor expected_color = expected_bmp.getColor(x, y); | 215 SkColor expected_color = expected_bmp.getColor(x, y); |
| 200 if (discard_alpha_) { | 216 if (discard_alpha_) { |
| 201 actual_color = SkColorSetA(actual_color, 0); | 217 actual_color = SkColorSetA(actual_color, 0); |
| 202 expected_color = SkColorSetA(expected_color, 0); | 218 expected_color = SkColorSetA(expected_color, 0); |
| 203 } | 219 } |
| 204 if (actual_color != expected_color) { | 220 if (actual_color != expected_color) { |
| 205 LOG(ERROR) << "Pixel error at x=" << x << " y=" << y << "; " | 221 ++error_pixels_count; |
| 206 << "actual RGBA=(" | 222 int difference_color = actual_color - expected_color; |
| 207 << SkColorGetR(actual_color) << "," | 223 if (difference_color < 0) |
| 208 << SkColorGetG(actual_color) << "," | 224 difference_color = 0 - difference_color; |
| 209 << SkColorGetB(actual_color) << "," | 225 if ((error_pixels_count == 1) || |
| 210 << SkColorGetA(actual_color) << "); " | 226 (x < minimum_difference_x && y < minimum_difference_y)) { |
| 211 << "expected RGBA=(" | 227 minimum_difference_x = x; |
| 212 << SkColorGetR(expected_color) << "," | 228 minimum_difference_y = y; |
| 213 << SkColorGetG(expected_color) << "," | 229 } |
| 214 << SkColorGetB(expected_color) << "," | 230 if (x > maximum_difference_x && y > maximum_difference_y) { |
| 215 << SkColorGetA(expected_color) << ")"; | 231 maximum_difference_x = x; |
| 232 maximum_difference_y = y; | |
| 233 } | |
| 216 } | 234 } |
| 217 } | 235 } |
| 218 } | 236 } |
| 219 | 237 LOG(ERROR) << "Error Bounding Box : " |
| 238 << " Max X-Y Co-ordinates X = " << maximum_difference_x | |
| 239 << " Y = " << maximum_difference_y; | |
| 240 LOG(ERROR) << "Error Bounding Box : " | |
| 241 << " Min X-Y Co-ordinates X = " << minimum_difference_x | |
| 242 << " Y = " << minimum_difference_y; | |
| 220 return false; | 243 return false; |
| 221 } else { | 244 } else { |
| 222 return true; | 245 return true; |
| 223 } | 246 } |
| 224 } | 247 } |
| 225 | 248 |
| 226 } // namespace cc | 249 } // namespace cc |
| OLD | NEW |