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

Side by Side Diff: ui/gfx/skbitmap_operations_unittest.cc

Issue 10823012: Fix the errors of ui unittests caused by packing colors for Android (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Remove disabled cases Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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 #include "ui/gfx/skbitmap_operations.h" 5 #include "ui/gfx/skbitmap_operations.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "third_party/skia/include/core/SkColorPriv.h" 9 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkUnPreMultiply.h" 10 #include "third_party/skia/include/core/SkUnPreMultiply.h"
11 11
12 namespace { 12 namespace {
13 13
14 // Returns true if each channel of the given two colors are "close." This is 14 // Returns true if each channel of the given two colors are "close." This is
15 // used for comparing colors where rounding errors may cause off-by-one. 15 // used for comparing colors where rounding errors may cause off-by-one.
16 inline bool ColorsClose(uint32_t a, uint32_t b) { 16 inline bool ColorsClose(uint32_t a, uint32_t b) {
17 return abs(static_cast<int>(SkColorGetB(a) - SkColorGetB(b))) <= 2 && 17 return abs(static_cast<int>(SkColorGetB(a) - SkColorGetB(b))) <= 2 &&
18 abs(static_cast<int>(SkColorGetG(a) - SkColorGetG(b))) <= 2 && 18 abs(static_cast<int>(SkColorGetG(a) - SkColorGetG(b))) <= 2 &&
19 abs(static_cast<int>(SkColorGetR(a) - SkColorGetR(b))) <= 2 && 19 abs(static_cast<int>(SkColorGetR(a) - SkColorGetR(b))) <= 2 &&
20 abs(static_cast<int>(SkColorGetA(a) - SkColorGetA(b))) <= 2; 20 abs(static_cast<int>(SkColorGetA(a) - SkColorGetA(b))) <= 2;
21 } 21 }
22 22
23 inline uint32_t SetPackedColor(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
sky 2012/08/02 21:02:00 Same comment as other file.
24 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) |
25 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
26 }
27
23 inline bool MultipliedColorsClose(uint32_t a, uint32_t b) { 28 inline bool MultipliedColorsClose(uint32_t a, uint32_t b) {
24 return ColorsClose(SkUnPreMultiply::PMColorToColor(a), 29 return ColorsClose(SkUnPreMultiply::PMColorToColor(a),
25 SkUnPreMultiply::PMColorToColor(b)); 30 SkUnPreMultiply::PMColorToColor(b));
26 } 31 }
27 32
28 bool BitmapsClose(const SkBitmap& a, const SkBitmap& b) { 33 bool BitmapsClose(const SkBitmap& a, const SkBitmap& b) {
29 SkAutoLockPixels a_lock(a); 34 SkAutoLockPixels a_lock(a);
30 SkAutoLockPixels b_lock(b); 35 SkAutoLockPixels b_lock(b);
31 36
32 for (int y = 0; y < a.height(); y++) { 37 for (int y = 0; y < a.height(); y++) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 color_utils::HSL hsl = { 0, -1, -1 }; 272 color_utils::HSL hsl = { 0, -1, -1 };
268 273
269 SkBitmap shifted = SkBitmapOperations::CreateHSLShiftedBitmap(src, hsl); 274 SkBitmap shifted = SkBitmapOperations::CreateHSLShiftedBitmap(src, hsl);
270 275
271 SkAutoLockPixels src_lock(src); 276 SkAutoLockPixels src_lock(src);
272 SkAutoLockPixels shifted_lock(shifted); 277 SkAutoLockPixels shifted_lock(shifted);
273 278
274 for (int y = 0, i = 0; y < src_h; y++) { 279 for (int y = 0, i = 0; y < src_h; y++) {
275 for (int x = 0; x < src_w; x++) { 280 for (int x = 0; x < src_w; x++) {
276 EXPECT_TRUE(ColorsClose(*shifted.getAddr32(x, y), 281 EXPECT_TRUE(ColorsClose(*shifted.getAddr32(x, y),
277 SkColorSetARGB(255, i % 255, 0, 0))); 282 SetPackedColor(255, i % 255, 0, 0)));
278 i++; 283 i++;
279 } 284 }
280 } 285 }
281 } 286 }
282 287
283 // Validate HSL shift. 288 // Validate HSL shift.
284 TEST(SkBitmapOperationsTest, ValidateHSLShift) { 289 TEST(SkBitmapOperationsTest, ValidateHSLShift) {
285 // Note: 255/51 = 5 (exactly) => 6 including 0! 290 // Note: 255/51 = 5 (exactly) => 6 including 0!
286 const int inc = 51; 291 const int inc = 51;
287 const int dim = 255 / inc + 1; 292 const int dim = 255 / inc + 1;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 *input.getAddr32(0, 0) = 0x80000000; 485 *input.getAddr32(0, 0) = 0x80000000;
481 *input.getAddr32(1, 0) = 0x80808080; 486 *input.getAddr32(1, 0) = 0x80808080;
482 *input.getAddr32(0, 1) = 0xFF00CC88; 487 *input.getAddr32(0, 1) = 0xFF00CC88;
483 *input.getAddr32(1, 1) = 0x0000CC88; 488 *input.getAddr32(1, 1) = 0x0000CC88;
484 489
485 SkBitmap result = SkBitmapOperations::UnPreMultiply(input); 490 SkBitmap result = SkBitmapOperations::UnPreMultiply(input);
486 EXPECT_EQ(2, result.width()); 491 EXPECT_EQ(2, result.width());
487 EXPECT_EQ(2, result.height()); 492 EXPECT_EQ(2, result.height());
488 493
489 SkAutoLockPixels lock(result); 494 SkAutoLockPixels lock(result);
490 EXPECT_EQ(0x80000000, *result.getAddr32(0, 0)); 495 EXPECT_EQ(SetPackedColor(0x80, 0x00, 0x00, 0x00), *result.getAddr32(0, 0));
491 EXPECT_EQ(0x80FFFFFF, *result.getAddr32(1, 0)); 496 EXPECT_EQ(SetPackedColor(0x80, 0xFF, 0xFF, 0xFF), *result.getAddr32(1, 0));
492 EXPECT_EQ(0xFF00CC88, *result.getAddr32(0, 1)); 497 EXPECT_EQ(SetPackedColor(0xFF, 0x00, 0xCC, 0x88), *result.getAddr32(0, 1));
493 EXPECT_EQ(0x00000000u, *result.getAddr32(1, 1)); // "Division by zero". 498 // "Division by zero".
499 EXPECT_EQ(SetPackedColor(0x00, 0x00, 0x00, 0x00), *result.getAddr32(1, 1));
494 } 500 }
495 501
496 TEST(SkBitmapOperationsTest, CreateTransposedBitmap) { 502 TEST(SkBitmapOperationsTest, CreateTransposedBitmap) {
497 SkBitmap input; 503 SkBitmap input;
498 input.setConfig(SkBitmap::kARGB_8888_Config, 2, 3); 504 input.setConfig(SkBitmap::kARGB_8888_Config, 2, 3);
499 input.allocPixels(); 505 input.allocPixels();
500 506
501 for (int x = 0; x < input.width(); ++x) { 507 for (int x = 0; x < input.width(); ++x) {
502 for (int y = 0; y < input.height(); ++y) { 508 for (int y = 0; y < input.height(); ++y) {
503 *input.getAddr32(x, y) = x * input.width() + y; 509 *input.getAddr32(x, y) = x * input.width() + y;
504 } 510 }
505 } 511 }
506 512
507 SkBitmap result = SkBitmapOperations::CreateTransposedBitmap(input); 513 SkBitmap result = SkBitmapOperations::CreateTransposedBitmap(input);
508 EXPECT_EQ(3, result.width()); 514 EXPECT_EQ(3, result.width());
509 EXPECT_EQ(2, result.height()); 515 EXPECT_EQ(2, result.height());
510 516
511 SkAutoLockPixels lock(result); 517 SkAutoLockPixels lock(result);
512 for (int x = 0; x < input.width(); ++x) { 518 for (int x = 0; x < input.width(); ++x) {
513 for (int y = 0; y < input.height(); ++y) { 519 for (int y = 0; y < input.height(); ++y) {
514 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x)); 520 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x));
515 } 521 }
516 } 522 }
517 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698