From 6479f85bcd6d6e7347fe84c270fdc0e6f762863c Mon Sep 17 00:00:00 2001 From: "varunjain@chromium.org" Date: Fri, 31 Aug 2012 22:47:38 +0000 Subject: Fix SkBitmapOperations::CreateMaskedBitmap. SkAlphaMul expects alpha value in range 0..256 while SkColor has values in 0..255. BUG=none Review URL: https://chromiumcodereview.appspot.com/10919037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154524 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/gfx/image/image_skia_operations.cc | 2 +- ui/gfx/skbitmap_operations.cc | 11 +++++++---- ui/gfx/skbitmap_operations_unittest.cc | 11 ++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc index c47b89b..d753f93 100644 --- a/ui/gfx/image/image_skia_operations.cc +++ b/ui/gfx/image/image_skia_operations.cc @@ -136,7 +136,7 @@ class TransparentImageSource : public gfx::ImageSkiaSource { static_cast(image_.size().width() * scale), static_cast(image_.size().height() * scale)); alpha.allocPixels(); - alpha.eraseColor(SkColorSetARGB(alpha_ * 256, 0, 0, 0)); + alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( image_rep.sk_bitmap(), alpha), image_rep.scale_factor()); diff --git a/ui/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc index 9f7262d..7e27506 100644 --- a/ui/gfx/skbitmap_operations.cc +++ b/ui/gfx/skbitmap_operations.cc @@ -155,11 +155,14 @@ SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, for (int x = 0; x < masked.width(); ++x) { SkColor rgb_pixel = SkUnPreMultiply::PMColorToColor(rgb_row[x]); SkColor alpha_pixel = SkUnPreMultiply::PMColorToColor(alpha_row[x]); - int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), SkColorGetA(alpha_pixel)); + int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), + SkAlpha255To256(SkColorGetA(alpha_pixel))); + int alpha_256 = SkAlpha255To256(alpha); dst_row[x] = SkColorSetARGB(alpha, - SkAlphaMul(SkColorGetR(rgb_pixel), alpha), - SkAlphaMul(SkColorGetG(rgb_pixel), alpha), - SkAlphaMul(SkColorGetB(rgb_pixel), alpha)); + SkAlphaMul(SkColorGetR(rgb_pixel), alpha_256), + SkAlphaMul(SkColorGetG(rgb_pixel), alpha_256), + SkAlphaMul(SkColorGetB(rgb_pixel), + alpha_256)); } } diff --git a/ui/gfx/skbitmap_operations_unittest.cc b/ui/gfx/skbitmap_operations_unittest.cc index b263a6b..ae1e96c 100644 --- a/ui/gfx/skbitmap_operations_unittest.cc +++ b/ui/gfx/skbitmap_operations_unittest.cc @@ -197,14 +197,15 @@ TEST(SkBitmapOperationsTest, CreateMaskedBitmap) { SkColor masked_pixel = *masked.getAddr32(x, y); int alpha_value = SkAlphaMul(SkColorGetA(src_pixel), - SkColorGetA(alpha_pixel)); + SkAlpha255To256(SkColorGetA(alpha_pixel))); + int alpha_value_256 = SkAlpha255To256(alpha_value); SkColor expected_pixel = SkColorSetARGB( alpha_value, - SkAlphaMul(SkColorGetR(src_pixel), alpha_value), - SkAlphaMul(SkColorGetG(src_pixel), alpha_value), - SkAlphaMul(SkColorGetB(src_pixel), alpha_value)); + SkAlphaMul(SkColorGetR(src_pixel), alpha_value_256), + SkAlphaMul(SkColorGetG(src_pixel), alpha_value_256), + SkAlphaMul(SkColorGetB(src_pixel), alpha_value_256)); - EXPECT_TRUE(ColorsClose(expected_pixel, masked_pixel)); + EXPECT_EQ(expected_pixel, masked_pixel); } } } -- cgit v1.1