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

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: Rebase 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
« no previous file with comments | « build/android/gtest_filter/ui_unittests_disabled ('k') | no next file » | 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) 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"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Shift to red. 266 // Shift to red.
267 color_utils::HSL hsl = { 0, -1, -1 }; 267 color_utils::HSL hsl = { 0, -1, -1 };
268 268
269 SkBitmap shifted = SkBitmapOperations::CreateHSLShiftedBitmap(src, hsl); 269 SkBitmap shifted = SkBitmapOperations::CreateHSLShiftedBitmap(src, hsl);
270 270
271 SkAutoLockPixels src_lock(src); 271 SkAutoLockPixels src_lock(src);
272 SkAutoLockPixels shifted_lock(shifted); 272 SkAutoLockPixels shifted_lock(shifted);
273 273
274 for (int y = 0, i = 0; y < src_h; y++) { 274 for (int y = 0, i = 0; y < src_h; y++) {
275 for (int x = 0; x < src_w; x++) { 275 for (int x = 0; x < src_w; x++) {
276 EXPECT_TRUE(ColorsClose(*shifted.getAddr32(x, y), 276 EXPECT_TRUE(ColorsClose(shifted.getColor(x, y),
277 SkColorSetARGB(255, i % 255, 0, 0))); 277 SkColorSetARGB(255, i % 255, 0, 0)));
278 i++; 278 i++;
279 } 279 }
280 } 280 }
281 } 281 }
282 282
283 // Validate HSL shift. 283 // Validate HSL shift.
284 TEST(SkBitmapOperationsTest, ValidateHSLShift) { 284 TEST(SkBitmapOperationsTest, ValidateHSLShift) {
285 // Note: 255/51 = 5 (exactly) => 6 including 0! 285 // Note: 255/51 = 5 (exactly) => 6 including 0!
286 const int inc = 51; 286 const int inc = 51;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // The result should be divided in half 100x43 -> 50x22 -> 25x11 470 // The result should be divided in half 100x43 -> 50x22 -> 25x11
471 EXPECT_EQ(25, result.width()); 471 EXPECT_EQ(25, result.width());
472 EXPECT_EQ(11, result.height()); 472 EXPECT_EQ(11, result.height());
473 } 473 }
474 474
475 TEST(SkBitmapOperationsTest, UnPreMultiply) { 475 TEST(SkBitmapOperationsTest, UnPreMultiply) {
476 SkBitmap input; 476 SkBitmap input;
477 input.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); 477 input.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
478 input.allocPixels(); 478 input.allocPixels();
479 479
480 *input.getAddr32(0, 0) = 0x80000000; 480 // Set PMColors into the bitmap
481 *input.getAddr32(1, 0) = 0x80808080; 481 *input.getAddr32(0, 0) = SkPackARGB32NoCheck(0x80, 0x00, 0x00, 0x00);
482 *input.getAddr32(0, 1) = 0xFF00CC88; 482 *input.getAddr32(1, 0) = SkPackARGB32NoCheck(0x80, 0x80, 0x80, 0x80);
483 *input.getAddr32(1, 1) = 0x0000CC88; 483 *input.getAddr32(0, 1) = SkPackARGB32NoCheck(0xFF, 0x00, 0xCC, 0x88);
484 *input.getAddr32(1, 1) = SkPackARGB32NoCheck(0x00, 0x00, 0xCC, 0x88);
484 485
485 SkBitmap result = SkBitmapOperations::UnPreMultiply(input); 486 SkBitmap result = SkBitmapOperations::UnPreMultiply(input);
486 EXPECT_EQ(2, result.width()); 487 EXPECT_EQ(2, result.width());
487 EXPECT_EQ(2, result.height()); 488 EXPECT_EQ(2, result.height());
488 489
489 SkAutoLockPixels lock(result); 490 SkAutoLockPixels lock(result);
490 EXPECT_EQ(0x80000000, *result.getAddr32(0, 0)); 491 EXPECT_EQ(0x80000000, *result.getAddr32(0, 0));
491 EXPECT_EQ(0x80FFFFFF, *result.getAddr32(1, 0)); 492 EXPECT_EQ(0x80FFFFFF, *result.getAddr32(1, 0));
492 EXPECT_EQ(0xFF00CC88, *result.getAddr32(0, 1)); 493 EXPECT_EQ(0xFF00CC88, *result.getAddr32(0, 1));
493 EXPECT_EQ(0x00000000u, *result.getAddr32(1, 1)); // "Division by zero". 494 EXPECT_EQ(0x00000000u, *result.getAddr32(1, 1)); // "Division by zero".
(...skipping 14 matching lines...) Expand all
508 EXPECT_EQ(3, result.width()); 509 EXPECT_EQ(3, result.width());
509 EXPECT_EQ(2, result.height()); 510 EXPECT_EQ(2, result.height());
510 511
511 SkAutoLockPixels lock(result); 512 SkAutoLockPixels lock(result);
512 for (int x = 0; x < input.width(); ++x) { 513 for (int x = 0; x < input.width(); ++x) {
513 for (int y = 0; y < input.height(); ++y) { 514 for (int y = 0; y < input.height(); ++y) {
514 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x)); 515 EXPECT_EQ(*input.getAddr32(x, y), *result.getAddr32(y, x));
515 } 516 }
516 } 517 }
517 } 518 }
OLDNEW
« no previous file with comments | « build/android/gtest_filter/ui_unittests_disabled ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698