OLD | NEW |
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 info.bytesPerPixel()); | 293 info.bytesPerPixel()); |
294 if (!dstBuffer) | 294 if (!dstBuffer) |
295 return nullptr; | 295 return nullptr; |
296 RefPtr<Uint8Array> dstPixels = | 296 RefPtr<Uint8Array> dstPixels = |
297 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); | 297 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); |
298 return StaticBitmapImage::create(newSkImageFromRaster( | 298 return StaticBitmapImage::create(newSkImageFromRaster( |
299 info, std::move(dstPixels), | 299 info, std::move(dstPixels), |
300 static_cast<unsigned>(info.width()) * info.bytesPerPixel())); | 300 static_cast<unsigned>(info.width()) * info.bytesPerPixel())); |
301 } | 301 } |
302 | 302 |
303 sk_sp<SkImage> skiaImage = image->imageForCurrentFrame(); | 303 // TODO(ccameron): Canvas should operate in sRGB and not display space. |
| 304 // https://crbug.com/667431 |
| 305 sk_sp<SkImage> skiaImage = |
| 306 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
304 // Attempt to get raw unpremultiplied image data, executed only when skiaImage | 307 // Attempt to get raw unpremultiplied image data, executed only when skiaImage |
305 // is premultiplied. | 308 // is premultiplied. |
306 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) || | 309 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) || |
307 !skiaImage) && | 310 !skiaImage) && |
308 image->data() && imageFormat == PremultiplyAlpha) || | 311 image->data() && imageFormat == PremultiplyAlpha) || |
309 colorBehavior.isIgnore()) { | 312 colorBehavior.isIgnore()) { |
310 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( | 313 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( |
311 image->data(), true, | 314 image->data(), true, |
312 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied | 315 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied |
313 : ImageDecoder::AlphaNotPremultiplied, | 316 : ImageDecoder::AlphaNotPremultiplied, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, | 394 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
392 ColorBehavior::ignore()); | 395 ColorBehavior::ignore()); |
393 } else { | 396 } else { |
394 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, | 397 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
395 ColorBehavior::transformToGlobalTarget()); | 398 ColorBehavior::transformToGlobalTarget()); |
396 } | 399 } |
397 if (!m_image) | 400 if (!m_image) |
398 return; | 401 return; |
399 // In the case where the source image is lazy-decoded, m_image may not be in | 402 // In the case where the source image is lazy-decoded, m_image may not be in |
400 // a decoded state, we trigger it here. | 403 // a decoded state, we trigger it here. |
401 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); | 404 // TODO(ccameron): Canvas should operate in sRGB and not display space. |
| 405 // https://crbug.com/667431 |
| 406 sk_sp<SkImage> skImage = |
| 407 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
402 SkPixmap pixmap; | 408 SkPixmap pixmap; |
403 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { | 409 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { |
404 sk_sp<SkSurface> surface = | 410 sk_sp<SkSurface> surface = |
405 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); | 411 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); |
406 surface->getCanvas()->drawImage(skImage, 0, 0); | 412 surface->getCanvas()->drawImage(skImage, 0, 0); |
407 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); | 413 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); |
408 } | 414 } |
409 if (!m_image) | 415 if (!m_image) |
410 return; | 416 return; |
411 m_image->setOriginClean( | 417 m_image->setOriginClean( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 if (!parsedOptions.premultiplyAlpha) { | 488 if (!parsedOptions.premultiplyAlpha) { |
483 parsedOptions.premultiplyAlpha = true; | 489 parsedOptions.premultiplyAlpha = true; |
484 isPremultiplyAlphaReverted = true; | 490 isPremultiplyAlphaReverted = true; |
485 } | 491 } |
486 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, | 492 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
487 ColorBehavior::transformToGlobalTarget()); | 493 ColorBehavior::transformToGlobalTarget()); |
488 if (!m_image) | 494 if (!m_image) |
489 return; | 495 return; |
490 if (isPremultiplyAlphaReverted) { | 496 if (isPremultiplyAlphaReverted) { |
491 parsedOptions.premultiplyAlpha = false; | 497 parsedOptions.premultiplyAlpha = false; |
492 m_image = StaticBitmapImage::create( | 498 // TODO(ccameron): Canvas should operate in sRGB and not display space. |
493 premulSkImageToUnPremul(m_image->imageForCurrentFrame().get())); | 499 // https://crbug.com/667431 |
| 500 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( |
| 501 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
| 502 .get())); |
494 } | 503 } |
495 if (!m_image) | 504 if (!m_image) |
496 return; | 505 return; |
497 m_image->setOriginClean(canvas->originClean()); | 506 m_image->setOriginClean(canvas->originClean()); |
498 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); | 507 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
499 } | 508 } |
500 | 509 |
501 ImageBitmap::ImageBitmap(const void* pixelData, | 510 ImageBitmap::ImageBitmap(const void* pixelData, |
502 uint32_t width, | 511 uint32_t width, |
503 uint32_t height, | 512 uint32_t height, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 return ImageBitmap::create(StaticBitmapImage::create(std::move(image))); | 808 return ImageBitmap::create(StaticBitmapImage::create(std::move(image))); |
800 } | 809 } |
801 | 810 |
802 PassRefPtr<Uint8Array> ImageBitmap::copyBitmapData(AlphaDisposition alphaOp, | 811 PassRefPtr<Uint8Array> ImageBitmap::copyBitmapData(AlphaDisposition alphaOp, |
803 DataColorFormat format) { | 812 DataColorFormat format) { |
804 SkImageInfo info = SkImageInfo::Make( | 813 SkImageInfo info = SkImageInfo::Make( |
805 width(), height(), | 814 width(), height(), |
806 (format == RGBAColorType) ? kRGBA_8888_SkColorType : kN32_SkColorType, | 815 (format == RGBAColorType) ? kRGBA_8888_SkColorType : kN32_SkColorType, |
807 (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType | 816 (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType |
808 : kUnpremul_SkAlphaType); | 817 : kUnpremul_SkAlphaType); |
809 RefPtr<Uint8Array> dstPixels = | 818 // TODO(ccameron): Canvas should operate in sRGB and not display space. |
810 copySkImageData(m_image->imageForCurrentFrame().get(), info); | 819 // https://crbug.com/667431 |
| 820 RefPtr<Uint8Array> dstPixels = copySkImageData( |
| 821 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
| 822 .get(), |
| 823 info); |
811 return dstPixels.release(); | 824 return dstPixels.release(); |
812 } | 825 } |
813 | 826 |
814 unsigned long ImageBitmap::width() const { | 827 unsigned long ImageBitmap::width() const { |
815 if (!m_image) | 828 if (!m_image) |
816 return 0; | 829 return 0; |
817 ASSERT(m_image->width() > 0); | 830 ASSERT(m_image->width() > 0); |
818 return m_image->width(); | 831 return m_image->width(); |
819 } | 832 } |
820 | 833 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 877 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
865 FloatRect* dstRect) const {} | 878 FloatRect* dstRect) const {} |
866 | 879 |
867 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 880 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
868 return FloatSize(width(), height()); | 881 return FloatSize(width(), height()); |
869 } | 882 } |
870 | 883 |
871 DEFINE_TRACE(ImageBitmap) {} | 884 DEFINE_TRACE(ImageBitmap) {} |
872 | 885 |
873 } // namespace blink | 886 } // namespace blink |
OLD | NEW |