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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // In the case when cropRect doesn't intersect the source image and it requi
res a umpremul image | 212 // In the case when cropRect doesn't intersect the source image and it requi
res a umpremul image |
213 // We immediately return a transparent black image with cropRect.size() | 213 // We immediately return a transparent black image with cropRect.size() |
214 if (srcRect.isEmpty() && !parsedOptions.premultiplyAlpha) { | 214 if (srcRect.isEmpty() && !parsedOptions.premultiplyAlpha) { |
215 SkImageInfo info = SkImageInfo::Make(parsedOptions.resizeWidth, parsedOp
tions.resizeHeight, kN32_SkColorType, kUnpremul_SkAlphaType); | 215 SkImageInfo info = SkImageInfo::Make(parsedOptions.resizeWidth, parsedOp
tions.resizeHeight, kN32_SkColorType, kUnpremul_SkAlphaType); |
216 std::unique_ptr<uint8_t[]> dstPixels = wrapArrayUnique(new uint8_t[info.
width() * info.height() * info.bytesPerPixel()]()); | 216 std::unique_ptr<uint8_t[]> dstPixels = wrapArrayUnique(new uint8_t[info.
width() * info.height() * info.bytesPerPixel()]()); |
217 return StaticBitmapImage::create(newSkImageFromRaster(info, std::move(ds
tPixels), info.width() * info.bytesPerPixel())); | 217 return StaticBitmapImage::create(newSkImageFromRaster(info, std::move(ds
tPixels), info.width() * info.bytesPerPixel())); |
218 } | 218 } |
219 | 219 |
220 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); | 220 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); |
221 // Attempt to get raw unpremultiplied image data, executed only when skiaIma
ge is premultiplied. | 221 // Attempt to get raw unpremultiplied image data, executed only when skiaIma
ge is premultiplied. |
222 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) || !skiaIm
age) && image->data() && imageFormat == PremultiplyAlpha) || colorSpaceOp == Ima
geDecoder::GammaAndColorProfileIgnored) { | 222 if ((((!parsedOptions.premultiplyAlpha && !skiaImage->isOpaque()) || !skiaIm
age) && image->data() && imageFormat == PremultiplyAlpha) || colorSpaceOp == Ima
geDecoder::GammaAndColorProfileNotApplied) { |
223 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( | 223 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( |
224 ImageDecoder::determineImageType(*(image->data())), | 224 ImageDecoder::determineImageType(*(image->data())), |
225 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied :
ImageDecoder::AlphaNotPremultiplied, | 225 parsedOptions.premultiplyAlpha ? ImageDecoder::AlphaPremultiplied :
ImageDecoder::AlphaNotPremultiplied, |
226 colorSpaceOp)); | 226 colorSpaceOp)); |
227 if (!decoder) | 227 if (!decoder) |
228 return nullptr; | 228 return nullptr; |
229 decoder->setData(image->data(), true); | 229 decoder->setData(image->data(), true); |
230 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); | 230 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); |
231 if (!skiaImage) | 231 if (!skiaImage) |
232 return nullptr; | 232 return nullptr; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 278 } |
279 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); | 279 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); |
280 } | 280 } |
281 | 281 |
282 ImageBitmap::ImageBitmap(HTMLImageElement* image, Optional<IntRect> cropRect, Do
cument* document, const ImageBitmapOptions& options) | 282 ImageBitmap::ImageBitmap(HTMLImageElement* image, Optional<IntRect> cropRect, Do
cument* document, const ImageBitmapOptions& options) |
283 { | 283 { |
284 RefPtr<Image> input = image->cachedImage()->getImage(); | 284 RefPtr<Image> input = image->cachedImage()->getImage(); |
285 ParsedOptions parsedOptions = parseOptions(options, cropRect, image->bitmapS
ourceSize()); | 285 ParsedOptions parsedOptions = parseOptions(options, cropRect, image->bitmapS
ourceSize()); |
286 | 286 |
287 if (options.colorSpaceConversion() == "none") | 287 if (options.colorSpaceConversion() == "none") |
288 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, ImageD
ecoder::GammaAndColorProfileIgnored); | 288 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, ImageD
ecoder::GammaAndColorProfileNotApplied); |
289 else | 289 else |
290 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, ImageD
ecoder::GammaAndColorProfileApplied); | 290 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, ImageD
ecoder::GammaAndColorProfileApplied); |
291 if (!m_image) | 291 if (!m_image) |
292 return; | 292 return; |
293 // In the case where the source image is lazy-decoded, m_image may not be in | 293 // In the case where the source image is lazy-decoded, m_image may not be in |
294 // a decoded state, we trigger it here. | 294 // a decoded state, we trigger it here. |
295 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); | 295 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); |
296 SkPixmap pixmap; | 296 SkPixmap pixmap; |
297 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { | 297 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { |
298 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width
(), skImage->height()); | 298 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width
(), skImage->height()); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 648 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
649 { | 649 { |
650 return FloatSize(width(), height()); | 650 return FloatSize(width(), height()); |
651 } | 651 } |
652 | 652 |
653 DEFINE_TRACE(ImageBitmap) | 653 DEFINE_TRACE(ImageBitmap) |
654 { | 654 { |
655 } | 655 } |
656 | 656 |
657 } // namespace blink | 657 } // namespace blink |
OLD | NEW |