Chromium Code Reviews| Index: ui/gfx/skbitmap_operations.cc |
| diff --git a/ui/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc |
| index 1535b7032d390f20ac831ab83fa41938e4cca787..1d810508ca629d109efc041a94bff9c1c0c60b0f 100644 |
| --- a/ui/gfx/skbitmap_operations.cc |
| +++ b/ui/gfx/skbitmap_operations.cc |
| @@ -129,16 +129,24 @@ SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, |
| SkBitmap SkBitmapOperations::CreateButtonBackground(SkColor color, |
| const SkBitmap& image, |
| const SkBitmap& mask) { |
| + // TODO: can we just do this with a couple SkCanvas draw calls? |
|
danakj
2016/06/22 00:51:27
TODO format is:
TODO(chromiumname): text
or
TODO(
mtklein_C
2016/07/28 19:56:04
Gotcha. Good point... no one will probably ever c
|
| + // e.g. drawColor(color) -> drawBitmap(image) -> drawBitmap(mask, kDstIn_Mode) |
| + // This requires we first pin down the premul/unpremul state of each bitmap. |
| + |
| + // TODO: It sure seems like image is actually unpremultiplied. |
| + // The math producing dst_row[x] below is a correct SrcOver when bg is |
|
mtklein_C
2016/06/22 15:19:40
Is this one too far away?
sky
2016/06/22 15:37:43
It wasn't obvious to me that the two relate. Comme
mtklein_C
2016/07/28 19:56:04
Fixed up, I think.
|
| + // premultiplied and img is unpremultiplied. |
| DCHECK(image.colorType() == kN32_SkColorType); |
| DCHECK(mask.colorType() == kN32_SkColorType); |
| SkBitmap background; |
| background.allocN32Pixels(mask.width(), mask.height()); |
| + // We premultiply bg here. |
|
sky
2016/06/22 15:17:40
This comment just documents the code, and isn't ve
mtklein_C
2016/07/28 19:56:04
Gone.
|
| double bg_a = SkColorGetA(color); |
| - double bg_r = SkColorGetR(color); |
| - double bg_g = SkColorGetG(color); |
| - double bg_b = SkColorGetB(color); |
| + double bg_r = SkColorGetR(color) * (bg_a / 255.0); |
| + double bg_g = SkColorGetG(color) * (bg_a / 255.0); |
| + double bg_b = SkColorGetB(color) * (bg_a / 255.0); |
| SkAutoLockPixels lock_mask(mask); |
| SkAutoLockPixels lock_image(image); |
| @@ -157,12 +165,13 @@ SkBitmap SkBitmapOperations::CreateButtonBackground(SkColor color, |
| double img_g = SkColorGetG(image_pixel); |
| double img_b = SkColorGetB(image_pixel); |
| - double img_alpha = static_cast<double>(img_a) / 255.0; |
| + double img_alpha = img_a / 255.0; |
| double img_inv = 1 - img_alpha; |
| double mask_a = static_cast<double>(SkColorGetA(mask_row[x])) / 255.0; |
| dst_row[x] = SkColorSetARGB( |
| + // TODO: why not the usual SrcOver alpha? |
| static_cast<int>(std::min(255.0, bg_a + img_a) * mask_a), |
| static_cast<int>(((bg_r * img_inv) + (img_r * img_alpha)) * mask_a), |
| static_cast<int>(((bg_g * img_inv) + (img_g * img_alpha)) * mask_a), |