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

Side by Side 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, 8 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "platform/image-decoders/ImageDecoder.h" 10 #include "platform/image-decoders/ImageDecoder.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return nullptr; 95 return nullptr;
96 ImageFrame* frame = decoder->frameBufferAtIndex(0); 96 ImageFrame* frame = decoder->frameBufferAtIndex(0);
97 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) 97 if (!frame || frame->getStatus() != ImageFrame::FrameComplete)
98 return nullptr; 98 return nullptr;
99 SkBitmap bitmap = frame->bitmap(); 99 SkBitmap bitmap = frame->bitmap();
100 if (!frameIsValid(bitmap)) 100 if (!frameIsValid(bitmap))
101 return nullptr; 101 return nullptr;
102 return adoptRef(SkImage::NewFromBitmap(bitmap)); 102 return adoptRef(SkImage::NewFromBitmap(bitmap));
103 } 103 }
104 104
105 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition alphaOp = DontPremulti plyAlpha) 105 // The parameter imageFormat indicates whether the first parameter "image" is un premultiplied or not.
106 // For example, if the image is already in unpremultiplied format and we want th e created ImageBitmap
107 // in the same format, then we don't need to use the ImageDecoder to decode the image.
108 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = DontPrem ultiplyAlpha, ImageDecoder::GammaAndColorProfileOption colorspaceOp = ImageDecod er::GammaAndColorProfileApplied)
106 { 109 {
107 ASSERT(image); 110 ASSERT(image);
108 111
109 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); 112 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height()));
110 const IntRect srcRect = intersection(imgRect, cropRect); 113 const IntRect srcRect = intersection(imgRect, cropRect);
111 114
112 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image 115 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image
113 // We immediately return a transparent black image with cropRect.size() 116 // We immediately return a transparent black image with cropRect.size()
114 if (srcRect.isEmpty() && !premultiplyAlpha) { 117 if (srcRect.isEmpty() && !premultiplyAlpha) {
115 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType); 118 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType);
116 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[cropRect.width() * cropRect.height() * info.bytesPerPixel()]()); 119 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[cropRect.width() * cropRect.height() * info.bytesPerPixel()]());
117 return StaticBitmapImage::create(newSkImageFromRaster(info, dstPixels.re lease(), cropRect.width() * info.bytesPerPixel())); 120 return StaticBitmapImage::create(newSkImageFromRaster(info, dstPixels.re lease(), cropRect.width() * info.bytesPerPixel()));
118 } 121 }
119 122
120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); 123 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame();
121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied. 124 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied.
122 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && alphaOp == DontPremultiplyAlpha) { 125 if ((((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image- >data() && imageFormat == DontPremultiplyAlpha) || colorspaceOp == ImageDecoder: :GammaAndColorProfileIgnored) {
123 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion 126 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*(image->data()),
124 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( 127 premultiplyAlpha ? ImageDecoder::AlphaPremultiplied : ImageDecoder:: AlphaNotPremultiplied,
125 *(image->data()), ImageDecoder::AlphaNotPremultiplied, 128 colorspaceOp));
126 ImageDecoder::GammaAndColorProfileApplied));
127 if (!decoder) 129 if (!decoder)
128 return nullptr; 130 return nullptr;
129 decoder->setData(image->data(), true); 131 decoder->setData(image->data(), true);
130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); 132 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release());
131 if (!skiaImage) 133 if (!skiaImage)
132 return nullptr; 134 return nullptr;
133 } 135 }
134 136
135 if (cropRect == srcRect) { 137 if (cropRect == srcRect) {
136 if (flipY) 138 if (flipY)
(...skipping 25 matching lines...) Expand all
162 return StaticBitmapImage::create(skiaImage.release()); 164 return StaticBitmapImage::create(skiaImage.release());
163 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); 165 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get()));
164 } 166 }
165 167
166 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) 168 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options)
167 { 169 {
168 bool flipY; 170 bool flipY;
169 bool premultiplyAlpha; 171 bool premultiplyAlpha;
170 parseOptions(options, flipY, premultiplyAlpha); 172 parseOptions(options, flipY, premultiplyAlpha);
171 173
172 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premu ltiplyAlpha); 174 if (options.colorspaceConversion() == "none")
175 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored );
176 else
177 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied );
173 if (!m_image) 178 if (!m_image)
174 return; 179 return;
175 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ())); 180 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ()));
176 m_image->setPremultiplied(premultiplyAlpha); 181 m_image->setPremultiplied(premultiplyAlpha);
177 } 182 }
178 183
179 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) 184 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options)
180 { 185 {
181 IntSize playerSize; 186 IntSize playerSize;
182 if (video->webMediaPlayer()) 187 if (video->webMediaPlayer())
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 FloatSize ImageBitmap::elementSize(const FloatSize&) const 467 FloatSize ImageBitmap::elementSize(const FloatSize&) const
463 { 468 {
464 return FloatSize(width(), height()); 469 return FloatSize(width(), height());
465 } 470 }
466 471
467 DEFINE_TRACE(ImageBitmap) 472 DEFINE_TRACE(ImageBitmap)
468 { 473 {
469 } 474 }
470 475
471 } // namespace blink 476 } // namespace blink
OLDNEW
« 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