OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "gfx/skbitmap_operations.h" | 5 #include "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 453 matching lines...) Loading... |
464 // Test multiple steps of downsampling. | 464 // Test multiple steps of downsampling. |
465 SkBitmap large; | 465 SkBitmap large; |
466 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); | 466 large.setConfig(SkBitmap::kARGB_8888_Config, 100, 43); |
467 large.allocPixels(); | 467 large.allocPixels(); |
468 result = SkBitmapOperations::DownsampleByTwoUntilSize(large, 6, 6); | 468 result = SkBitmapOperations::DownsampleByTwoUntilSize(large, 6, 6); |
469 | 469 |
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 |
| 475 TEST(SkBitmapOperationsTest, UnPreMultiply) { |
| 476 SkBitmap input; |
| 477 input.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
| 478 input.allocPixels(); |
| 479 |
| 480 *input.getAddr32(0, 0) = 0x80000000; |
| 481 *input.getAddr32(1, 0) = 0x80808080; |
| 482 *input.getAddr32(0, 1) = 0xFF00CC88; |
| 483 *input.getAddr32(1, 1) = 0x0000CC88; |
| 484 |
| 485 SkBitmap result = SkBitmapOperations::UnPreMultiply(input); |
| 486 EXPECT_EQ(2, result.width()); |
| 487 EXPECT_EQ(2, result.height()); |
| 488 |
| 489 SkAutoLockPixels lock(result); |
| 490 EXPECT_EQ(0x80000000, *result.getAddr32(0, 0)); |
| 491 EXPECT_EQ(0x80FFFFFF, *result.getAddr32(1, 0)); |
| 492 EXPECT_EQ(0xFF00CC88, *result.getAddr32(0, 1)); |
| 493 EXPECT_EQ(0x00000000u, *result.getAddr32(1, 1)); // "Division by zero". |
| 494 } |
OLD | NEW |