| OLD | NEW |
| 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 // Because the unit tests for gfx::Image are spread across multiple | 5 // Because the unit tests for gfx::Image are spread across multiple |
| 6 // implementation files, this header contains the reusable components. | 6 // implementation files, this header contains the reusable components. |
| 7 | 7 |
| 8 #include "ui/gfx/image/image_unittest_util.h" | 8 #include "ui/gfx/image/image_unittest_util.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (bmp1.isNull() && bmp2.isNull()) | 130 if (bmp1.isNull() && bmp2.isNull()) |
| 131 return true; | 131 return true; |
| 132 | 132 |
| 133 if (bmp1.width() != bmp2.width() || | 133 if (bmp1.width() != bmp2.width() || |
| 134 bmp1.height() != bmp2.height() || | 134 bmp1.height() != bmp2.height() || |
| 135 bmp1.colorType() != kN32_SkColorType || | 135 bmp1.colorType() != kN32_SkColorType || |
| 136 bmp2.colorType() != kN32_SkColorType) { | 136 bmp2.colorType() != kN32_SkColorType) { |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 SkAutoLockPixels lock1(bmp1); | |
| 141 SkAutoLockPixels lock2(bmp2); | |
| 142 if (!bmp1.getPixels() || !bmp2.getPixels()) | 140 if (!bmp1.getPixels() || !bmp2.getPixels()) |
| 143 return false; | 141 return false; |
| 144 | 142 |
| 145 for (int y = 0; y < bmp1.height(); ++y) { | 143 for (int y = 0; y < bmp1.height(); ++y) { |
| 146 for (int x = 0; x < bmp1.width(); ++x) { | 144 for (int x = 0; x < bmp1.width(); ++x) { |
| 147 if (!ColorsClose(bmp1.getColor(x,y), bmp2.getColor(x,y), max_deviation)) | 145 if (!ColorsClose(bmp1.getColor(x,y), bmp2.getColor(x,y), max_deviation)) |
| 148 return false; | 146 return false; |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 | 149 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 | 165 |
| 168 int MaxColorSpaceConversionColorShift() { | 166 int MaxColorSpaceConversionColorShift() { |
| 169 return kMaxColorSpaceConversionColorShift; | 167 return kMaxColorSpaceConversionColorShift; |
| 170 } | 168 } |
| 171 | 169 |
| 172 void CheckImageIndicatesPNGDecodeFailure(const gfx::Image& image) { | 170 void CheckImageIndicatesPNGDecodeFailure(const gfx::Image& image) { |
| 173 SkBitmap bitmap = image.AsBitmap(); | 171 SkBitmap bitmap = image.AsBitmap(); |
| 174 EXPECT_FALSE(bitmap.isNull()); | 172 EXPECT_FALSE(bitmap.isNull()); |
| 175 EXPECT_LE(16, bitmap.width()); | 173 EXPECT_LE(16, bitmap.width()); |
| 176 EXPECT_LE(16, bitmap.height()); | 174 EXPECT_LE(16, bitmap.height()); |
| 177 SkAutoLockPixels auto_lock(bitmap); | |
| 178 CheckColors(bitmap.getColor(10, 10), SK_ColorRED); | 175 CheckColors(bitmap.getColor(10, 10), SK_ColorRED); |
| 179 } | 176 } |
| 180 | 177 |
| 181 bool ImageSkiaStructureMatches( | 178 bool ImageSkiaStructureMatches( |
| 182 const gfx::ImageSkia& image_skia, | 179 const gfx::ImageSkia& image_skia, |
| 183 int width, | 180 int width, |
| 184 int height, | 181 int height, |
| 185 const std::vector<float>& scales) { | 182 const std::vector<float>& scales) { |
| 186 if (image_skia.isNull() || | 183 if (image_skia.isNull() || |
| 187 image_skia.width() != width || | 184 image_skia.width() != width || |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return image.CopyNSImage(); | 261 return image.CopyNSImage(); |
| 265 #else | 262 #else |
| 266 return image.AsImageSkia(); | 263 return image.AsImageSkia(); |
| 267 #endif | 264 #endif |
| 268 } | 265 } |
| 269 | 266 |
| 270 #if defined(OS_MACOSX) | 267 #if defined(OS_MACOSX) |
| 271 // Defined in image_unittest_util_mac.mm. | 268 // Defined in image_unittest_util_mac.mm. |
| 272 #else | 269 #else |
| 273 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { | 270 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { |
| 274 SkBitmap bitmap = *image.bitmap(); | 271 return image.bitmap()->getColor(x, y); |
| 275 SkAutoLockPixels auto_lock(bitmap); | |
| 276 return bitmap.getColor(x, y); | |
| 277 } | 272 } |
| 278 #endif | 273 #endif |
| 279 | 274 |
| 280 void CheckColors(SkColor color1, SkColor color2) { | 275 void CheckColors(SkColor color1, SkColor color2) { |
| 281 EXPECT_TRUE(ColorsClose(color1, color2, MaxColorSpaceConversionColorShift())); | 276 EXPECT_TRUE(ColorsClose(color1, color2, MaxColorSpaceConversionColorShift())); |
| 282 } | 277 } |
| 283 | 278 |
| 284 void CheckIsTransparent(SkColor color) { | 279 void CheckIsTransparent(SkColor color) { |
| 285 EXPECT_LT(SkColorGetA(color) / 255.0, 0.05); | 280 EXPECT_LT(SkColorGetA(color) / 255.0, 0.05); |
| 286 } | 281 } |
| 287 | 282 |
| 288 bool IsPlatformImageValid(PlatformImage image) { | 283 bool IsPlatformImageValid(PlatformImage image) { |
| 289 #if defined(OS_MACOSX) | 284 #if defined(OS_MACOSX) |
| 290 return image != NULL; | 285 return image != NULL; |
| 291 #else | 286 #else |
| 292 return !image.isNull(); | 287 return !image.isNull(); |
| 293 #endif | 288 #endif |
| 294 } | 289 } |
| 295 | 290 |
| 296 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { | 291 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { |
| 297 #if defined(OS_MACOSX) | 292 #if defined(OS_MACOSX) |
| 298 return image1 == image2; | 293 return image1 == image2; |
| 299 #else | 294 #else |
| 300 return image1.BackedBySameObjectAs(image2); | 295 return image1.BackedBySameObjectAs(image2); |
| 301 #endif | 296 #endif |
| 302 } | 297 } |
| 303 | 298 |
| 304 } // namespace test | 299 } // namespace test |
| 305 } // namespace gfx | 300 } // namespace gfx |
| OLD | NEW |