diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 01:28:50 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 01:28:50 +0000 |
commit | 29acfb3095a9e484443ffc149d43908ecb17f42f (patch) | |
tree | 3580cea2099fc7bd286a97d31508a54749f5df89 /skia | |
parent | 57abdc68e5759f837c36add4ca6bbeff6ba88198 (diff) | |
download | chromium_src-29acfb3095a9e484443ffc149d43908ecb17f42f.zip chromium_src-29acfb3095a9e484443ffc149d43908ecb17f42f.tar.gz chromium_src-29acfb3095a9e484443ffc149d43908ecb17f42f.tar.bz2 |
Our masker didn't account for the source image also having alpha.
BUG=17568
TEST=none
Review URL: http://codereview.chromium.org/160034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/image_operations.cc | 4 | ||||
-rw-r--r-- | skia/ext/image_operations_unittest.cc | 23 |
2 files changed, 15 insertions, 12 deletions
diff --git a/skia/ext/image_operations.cc b/skia/ext/image_operations.cc index ff16fe5..9b0beb1 100644 --- a/skia/ext/image_operations.cc +++ b/skia/ext/image_operations.cc @@ -395,9 +395,9 @@ SkBitmap ImageOperations::CreateMaskedBitmap(const SkBitmap& rgb, for (int x = 0; x < rgb.width(); x++) { uint32 alpha_pixel = alpha_row[x]; - uint32 rgb_pixel = rgb_row[x]; + SkColor rgb_pixel = SkUnPreMultiply::PMColorToColor(rgb_row[x]); - int alpha = SkColorGetA(alpha_pixel); + int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), SkColorGetA(alpha_pixel)); dst_row[x] = SkColorSetARGB(alpha, SkAlphaMul(SkColorGetR(rgb_pixel), alpha), SkAlphaMul(SkColorGetG(rgb_pixel), alpha), diff --git a/skia/ext/image_operations_unittest.cc b/skia/ext/image_operations_unittest.cc index b422371..40e63bd 100644 --- a/skia/ext/image_operations_unittest.cc +++ b/skia/ext/image_operations_unittest.cc @@ -6,8 +6,9 @@ #include "skia/ext/image_operations.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkColorPriv.h" +#include "third_party/skia/include/core/SkUnPreMultiply.h" namespace { @@ -218,18 +219,20 @@ TEST(ImageOperations, CreateMaskedBitmap) { for (int y = 0; y < src_h; y++) { for (int x = 0; x < src_w; x++) { // Test that the alpha is equal. - SkColor src_pixel = *src.getAddr32(x, y); - SkColor alpha_pixel = *alpha.getAddr32(x, y); + SkColor src_pixel = SkUnPreMultiply::PMColorToColor(*src.getAddr32(x, y)); + SkColor alpha_pixel = + SkUnPreMultiply::PMColorToColor(*alpha.getAddr32(x, y)); SkColor masked_pixel = *masked.getAddr32(x, y); - // Test that the alpha is equal. - unsigned int alpha = (alpha_pixel & 0xff000000) >> SK_A32_SHIFT; - EXPECT_EQ(alpha, (masked_pixel & 0xff000000) >> SK_A32_SHIFT); + int alpha_value = SkAlphaMul(SkColorGetA(src_pixel), + SkColorGetA(alpha_pixel)); + SkColor expected_pixel = SkColorSetARGB( + alpha_value, + SkAlphaMul(SkColorGetR(src_pixel), alpha_value), + SkAlphaMul(SkColorGetG(src_pixel), alpha_value), + SkAlphaMul(SkColorGetB(src_pixel), alpha_value)); - // Test that the colors are right - SkBitmaps have premultiplied alpha, - // so we can't just do a direct comparison. - EXPECT_EQ(SkColorGetR(masked_pixel), - SkAlphaMul(SkColorGetR(src_pixel), alpha)); + EXPECT_TRUE(ColorsClose(expected_pixel, masked_pixel)); } } } |