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

Unified Diff: content/common/cursors/webcursor.cc

Issue 1251173003: Fix alpha pre-multiplication error with custom cursor images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows build fix Created 5 years, 5 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 | content/common/cursors/webcursor_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/cursors/webcursor.cc
diff --git a/content/common/cursors/webcursor.cc b/content/common/cursors/webcursor.cc
index 6bc3f3eb98fa7985262f2a056f10d399ccff798a..faa6d703b4f53169468556fe15d596ca0c1ad33e 100644
--- a/content/common/cursors/webcursor.cc
+++ b/content/common/cursors/webcursor.cc
@@ -231,10 +231,12 @@ void WebCursor::SetCustomData(const SkBitmap& bitmap) {
return;
// Fill custom_data_ directly with the NativeImage pixels.
- SkAutoLockPixels bitmap_lock(bitmap);
custom_data_.resize(bitmap.getSize());
- if (!custom_data_.empty())
- memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize());
+ if (!custom_data_.empty()) {
+ //This will divide color values by alpha (un-premultiply) if necessary
+ SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType);
+ bitmap.readPixels(dstInfo, &custom_data_[0], dstInfo.minRowBytes(), 0, 0);
+ }
custom_size_.set_width(bitmap.width());
custom_size_.set_height(bitmap.height());
}
@@ -243,7 +245,10 @@ void WebCursor::ImageFromCustomData(SkBitmap* image) const {
if (custom_data_.empty())
return;
- if (!image->tryAllocN32Pixels(custom_size_.width(), custom_size_.height()))
+ SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(),
+ custom_size_.height(),
+ kUnpremul_SkAlphaType);
+ if (!image->tryAllocPixels(image_info))
return;
memcpy(image->getPixels(), &custom_data_[0], custom_data_.size());
}
« no previous file with comments | « no previous file | content/common/cursors/webcursor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698