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

Unified Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 1843953003: Add ColorspaceConversion to createImageBitmap(HTMLImageElement) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change parameter name "alphaOp" to "imageFormat" Created 4 years, 9 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 | « third_party/WebKit/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-image-bitmap-from-image.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/ImageBitmap.cpp
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
index 694ed0c58b08b296d90b7ee82202a9e2a2c93849..2327de1ccefab0f9c98ff73bbfd07cfb7ef3ffd5 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
@@ -102,7 +102,10 @@ PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(PassOwnPtr<ImageDecoder>
return adoptRef(SkImage::NewFromBitmap(bitmap));
}
-static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& cropRect, bool flipY, bool premultiplyAlpha, AlphaDisposition alphaOp = DontPremultiplyAlpha)
+// The parameter imageFormat indicates whether the first parameter "image" is unpremultiplied or not.
+// For example, if the image is already in unpremultiplied format and we want the created ImageBitmap
+// in the same format, then we don't need to use the ImageDecoder to decode the image.
+static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& cropRect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileOption colorspaceOp = ImageDecoder::GammaAndColorProfileApplied)
{
ASSERT(image);
@@ -119,11 +122,10 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
RefPtr<SkImage> skiaImage = image->imageForCurrentFrame();
// Attempt to get raw unpremultiplied image data, executed only when skiaImage is premultiplied.
- if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image->data() && alphaOp == DontPremultiplyAlpha) {
- // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion
- OwnPtr<ImageDecoder> decoder(ImageDecoder::create(
- *(image->data()), ImageDecoder::AlphaNotPremultiplied,
- ImageDecoder::GammaAndColorProfileApplied));
+ if ((((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image->data() && imageFormat == DontPremultiplyAlpha) || colorspaceOp == ImageDecoder::GammaAndColorProfileIgnored) {
+ OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*(image->data()),
+ premultiplyAlpha ? ImageDecoder::AlphaPremultiplied : ImageDecoder::AlphaNotPremultiplied,
+ colorspaceOp));
if (!decoder)
return nullptr;
decoder->setData(image->data(), true);
@@ -169,7 +171,10 @@ ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum
bool premultiplyAlpha;
parseOptions(options, flipY, premultiplyAlpha);
- m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premultiplyAlpha);
+ if (options.colorspaceConversion() == "none")
+ m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored);
+ else
+ m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied);
if (!m_image)
return;
m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin()));
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-image-bitmap-from-image.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698