Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1824)

Unified Diff: ui/gfx/skbitmap_operations.cc

Issue 2079413002: CreateButtonBackground() has been creating unpremultiplied bitmaps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: further note Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698