summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 22:47:38 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 22:47:38 +0000
commit6479f85bcd6d6e7347fe84c270fdc0e6f762863c (patch)
treeaea12c51888b0d9aaa5c01335fbd8c8e7ebbe3d3 /ui
parent5f016bf70dec4824289d421db62039051fe98546 (diff)
downloadchromium_src-6479f85bcd6d6e7347fe84c270fdc0e6f762863c.zip
chromium_src-6479f85bcd6d6e7347fe84c270fdc0e6f762863c.tar.gz
chromium_src-6479f85bcd6d6e7347fe84c270fdc0e6f762863c.tar.bz2
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
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/image/image_skia_operations.cc2
-rw-r--r--ui/gfx/skbitmap_operations.cc11
-rw-r--r--ui/gfx/skbitmap_operations_unittest.cc11
3 files changed, 14 insertions, 10 deletions
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<int>(image_.size().width() * scale),
static_cast<int>(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);
}
}
}