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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 2454123002: Refactor image decoders to use 'colorSpace' instead of 'colorProfile' (Closed)
Patch Set: Fix legacy ImageFrame Created 4 years, 1 month 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 | « no previous file | third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp » ('j') | 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/graphics/skia/SkiaUtils.h" 10 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 // The parameter imageFormat indicates whether the first parameter "image" is 270 // The parameter imageFormat indicates whether the first parameter "image" is
271 // unpremultiplied or not. imageFormat = PremultiplyAlpha means the image is in 271 // unpremultiplied or not. imageFormat = PremultiplyAlpha means the image is in
272 // premuliplied format For example, if the image is already in unpremultiplied 272 // premuliplied format For example, if the image is already in unpremultiplied
273 // format and we want the created ImageBitmap in the same format, then we don't 273 // format and we want the created ImageBitmap in the same format, then we don't
274 // need to use the ImageDecoder to decode the image. 274 // need to use the ImageDecoder to decode the image.
275 static PassRefPtr<StaticBitmapImage> cropImage( 275 static PassRefPtr<StaticBitmapImage> cropImage(
276 Image* image, 276 Image* image,
277 const ParsedOptions& parsedOptions, 277 const ParsedOptions& parsedOptions,
278 AlphaDisposition imageFormat = PremultiplyAlpha, 278 AlphaDisposition imageFormat = PremultiplyAlpha,
279 ImageDecoder::GammaAndColorProfileOption colorSpaceOp = 279 ImageDecoder::ColorSpaceOption colorSpaceOp =
280 ImageDecoder::GammaAndColorProfileApplied) { 280 ImageDecoder::ColorSpaceApplied) {
281 ASSERT(image); 281 ASSERT(image);
282 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); 282 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height()));
283 const IntRect srcRect = intersection(imgRect, parsedOptions.cropRect); 283 const IntRect srcRect = intersection(imgRect, parsedOptions.cropRect);
284 284
285 // In the case when cropRect doesn't intersect the source image and it 285 // In the case when cropRect doesn't intersect the source image and it
286 // requires a umpremul image We immediately return a transparent black image 286 // requires a umpremul image We immediately return a transparent black image
287 // with cropRect.size() 287 // with cropRect.size()
288 if (srcRect.isEmpty() && !parsedOptions.premultiplyAlpha) { 288 if (srcRect.isEmpty() && !parsedOptions.premultiplyAlpha) {
289 SkImageInfo info = 289 SkImageInfo info =
290 SkImageInfo::Make(parsedOptions.resizeWidth, parsedOptions.resizeHeight, 290 SkImageInfo::Make(parsedOptions.resizeWidth, parsedOptions.resizeHeight,
291 kN32_SkColorType, kUnpremul_SkAlphaType); 291 kN32_SkColorType, kUnpremul_SkAlphaType);
292 RefPtr<ArrayBuffer> dstBuffer = ArrayBuffer::createOrNull( 292 RefPtr<ArrayBuffer> dstBuffer = ArrayBuffer::createOrNull(
293 static_cast<size_t>(info.width()) * info.height(), 293 static_cast<size_t>(info.width()) * info.height(),
294 info.bytesPerPixel()); 294 info.bytesPerPixel());
295 if (!dstBuffer) 295 if (!dstBuffer)
296 return nullptr; 296 return nullptr;
297 RefPtr<Uint8Array> dstPixels = 297 RefPtr<Uint8Array> dstPixels =
298 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); 298 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength());
299 return StaticBitmapImage::create(newSkImageFromRaster( 299 return StaticBitmapImage::create(newSkImageFromRaster(
300 info, std::move(dstPixels), 300 info, std::move(dstPixels),
301 static_cast<size_t>(info.width()) * info.bytesPerPixel())); 301 static_cast<size_t>(info.width()) * info.bytesPerPixel()));
302 } 302 }
303 303
304 sk_sp<SkImage> skiaImage = image->imageForCurrentFrame(); 304 sk_sp<SkImage> skiaImage = image->imageForCurrentFrame();
305 // Attempt to get raw unpremultiplied image data, executed only when skiaImage 305 // Attempt to get raw unpremultiplied image data, executed only when skiaImage
306 // is premultiplied. 306 // is premultiplied.
307 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) || 307 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) ||
308 !skiaImage) && 308 !skiaImage) &&
309 image->data() && imageFormat == PremultiplyAlpha) || 309 image->data() && imageFormat == PremultiplyAlpha) ||
310 colorSpaceOp == ImageDecoder::GammaAndColorProfileIgnored) { 310 colorSpaceOp == ImageDecoder::ColorSpaceIgnored) {
311 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( 311 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(
312 image->data(), true, 312 image->data(), true,
313 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied 313 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied
314 : ImageDecoder::AlphaNotPremultiplied, 314 : ImageDecoder::AlphaNotPremultiplied,
315 colorSpaceOp)); 315 colorSpaceOp));
316 if (!decoder) 316 if (!decoder)
317 return nullptr; 317 return nullptr;
318 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); 318 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder));
319 if (!skiaImage) 319 if (!skiaImage)
320 return nullptr; 320 return nullptr;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 ImageBitmap::ImageBitmap(HTMLImageElement* image, 381 ImageBitmap::ImageBitmap(HTMLImageElement* image,
382 Optional<IntRect> cropRect, 382 Optional<IntRect> cropRect,
383 Document* document, 383 Document* document,
384 const ImageBitmapOptions& options) { 384 const ImageBitmapOptions& options) {
385 RefPtr<Image> input = image->cachedImage()->getImage(); 385 RefPtr<Image> input = image->cachedImage()->getImage();
386 ParsedOptions parsedOptions = 386 ParsedOptions parsedOptions =
387 parseOptions(options, cropRect, image->bitmapSourceSize()); 387 parseOptions(options, cropRect, image->bitmapSourceSize());
388 if (dstBufferSizeHasOverflow(parsedOptions)) 388 if (dstBufferSizeHasOverflow(parsedOptions))
389 return; 389 return;
390 390
391 if (options.colorSpaceConversion() == "none") 391 if (options.colorSpaceConversion() == "none") {
392 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, 392 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha,
393 ImageDecoder::GammaAndColorProfileIgnored); 393 ImageDecoder::ColorSpaceIgnored);
394 else 394 } else {
395 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, 395 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha,
396 ImageDecoder::GammaAndColorProfileApplied); 396 ImageDecoder::ColorSpaceApplied);
397 }
397 if (!m_image) 398 if (!m_image)
398 return; 399 return;
399 // In the case where the source image is lazy-decoded, m_image may not be in 400 // In the case where the source image is lazy-decoded, m_image may not be in
400 // a decoded state, we trigger it here. 401 // a decoded state, we trigger it here.
401 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); 402 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame();
402 SkPixmap pixmap; 403 SkPixmap pixmap;
403 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { 404 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) {
404 sk_sp<SkSurface> surface = 405 sk_sp<SkSurface> surface =
405 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); 406 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height());
406 surface->getCanvas()->drawImage(skImage, 0, 0); 407 surface->getCanvas()->drawImage(skImage, 0, 0);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, 857 void ImageBitmap::adjustDrawRects(FloatRect* srcRect,
857 FloatRect* dstRect) const {} 858 FloatRect* dstRect) const {}
858 859
859 FloatSize ImageBitmap::elementSize(const FloatSize&) const { 860 FloatSize ImageBitmap::elementSize(const FloatSize&) const {
860 return FloatSize(width(), height()); 861 return FloatSize(width(), height());
861 } 862 }
862 863
863 DEFINE_TRACE(ImageBitmap) {} 864 DEFINE_TRACE(ImageBitmap) {}
864 865
865 } // namespace blink 866 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698