Chromium Code Reviews| 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/image-decoders/ImageDecoder.h" | 10 #include "platform/image-decoders/ImageDecoder.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition alphaOp = DontPremulti plyAlpha, ImageDecoder::GammaAndColorProfileOption colorspaceOp = ImageDecoder:: GammaAndColorProfileApplied) |
| 106 { | 106 { |
| 107 ASSERT(image); | 107 ASSERT(image); |
| 108 | 108 |
| 109 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); | 109 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); |
| 110 const IntRect srcRect = intersection(imgRect, cropRect); | 110 const IntRect srcRect = intersection(imgRect, cropRect); |
| 111 | 111 |
| 112 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image | 112 // 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() | 113 // We immediately return a transparent black image with cropRect.size() |
| 114 if (srcRect.isEmpty() && !premultiplyAlpha) { | 114 if (srcRect.isEmpty() && !premultiplyAlpha) { |
| 115 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType); | 115 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()]()); | 116 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())); | 117 return StaticBitmapImage::create(newSkImageFromRaster(info, dstPixels.re lease(), cropRect.width() * info.bytesPerPixel())); |
| 118 } | 118 } |
| 119 | 119 |
| 120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); | 120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); |
| 121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied. | 121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied. |
| 122 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && alphaOp == DontPremultiplyAlpha) { | 122 if ((((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image- >data() && alphaOp == DontPremultiplyAlpha) || colorspaceOp == ImageDecoder::Gam maAndColorProfileIgnored) { |
| 123 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion | 123 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*(image->data()), |
| 124 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( | 124 premultiplyAlpha ? ImageDecoder::AlphaPremultiplied : ImageDecoder:: AlphaNotPremultiplied, |
|
Justin Novosad
2016/03/30 16:03:20
Not new to this CL, but could you clarify the diff
xidachen
2016/03/30 17:36:03
The parameter "premultiplyAlpha" indicates whether
xidachen
2016/03/30 17:45:30
Maybe change the "alphaOp" to "imageFormat" to ind
| |
| 125 *(image->data()), ImageDecoder::AlphaNotPremultiplied, | 125 colorspaceOp)); |
| 126 ImageDecoder::GammaAndColorProfileApplied)); | |
| 127 if (!decoder) | 126 if (!decoder) |
| 128 return nullptr; | 127 return nullptr; |
| 129 decoder->setData(image->data(), true); | 128 decoder->setData(image->data(), true); |
| 130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); | 129 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); |
| 131 if (!skiaImage) | 130 if (!skiaImage) |
| 132 return nullptr; | 131 return nullptr; |
| 133 } | 132 } |
| 134 | 133 |
| 135 if (cropRect == srcRect) { | 134 if (cropRect == srcRect) { |
| 136 if (flipY) | 135 if (flipY) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 162 return StaticBitmapImage::create(skiaImage.release()); | 161 return StaticBitmapImage::create(skiaImage.release()); |
| 163 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); | 162 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); |
| 164 } | 163 } |
| 165 | 164 |
| 166 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) | 165 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) |
| 167 { | 166 { |
| 168 bool flipY; | 167 bool flipY; |
| 169 bool premultiplyAlpha; | 168 bool premultiplyAlpha; |
| 170 parseOptions(options, flipY, premultiplyAlpha); | 169 parseOptions(options, flipY, premultiplyAlpha); |
| 171 | 170 |
| 172 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premu ltiplyAlpha); | 171 if (options.colorspaceConversion() == "none") |
| 172 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored ); | |
| 173 else | |
| 174 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied ); | |
| 173 if (!m_image) | 175 if (!m_image) |
| 174 return; | 176 return; |
| 175 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ())); | 177 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ())); |
| 176 m_image->setPremultiplied(premultiplyAlpha); | 178 m_image->setPremultiplied(premultiplyAlpha); |
| 177 } | 179 } |
| 178 | 180 |
| 179 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) | 181 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) |
| 180 { | 182 { |
| 181 IntSize playerSize; | 183 IntSize playerSize; |
| 182 if (video->webMediaPlayer()) | 184 if (video->webMediaPlayer()) |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 464 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 463 { | 465 { |
| 464 return FloatSize(width(), height()); | 466 return FloatSize(width(), height()); |
| 465 } | 467 } |
| 466 | 468 |
| 467 DEFINE_TRACE(ImageBitmap) | 469 DEFINE_TRACE(ImageBitmap) |
| 468 { | 470 { |
| 469 } | 471 } |
| 470 | 472 |
| 471 } // namespace blink | 473 } // namespace blink |
| OLD | NEW |