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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::ColorSpaceOption colorSpaceOp = | 279 ImageDecoder::ColorSpaceOption colorSpaceOp = |
280 ImageDecoder::ColorSpaceApplied) { | 280 ImageDecoder::ColorSpaceTransformed) { |
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, |
(...skipping 14 matching lines...) Expand all Loading... |
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::ColorSpaceIgnored) { | 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, colorSpaceOp == ImageDecoder::ColorSpaceTransformed |
| 316 ? ImageDecoder::globalTargetColorSpace() |
| 317 : nullptr)); |
316 if (!decoder) | 318 if (!decoder) |
317 return nullptr; | 319 return nullptr; |
318 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); | 320 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); |
319 if (!skiaImage) | 321 if (!skiaImage) |
320 return nullptr; | 322 return nullptr; |
321 } | 323 } |
322 | 324 |
323 if (parsedOptions.cropRect == srcRect && !parsedOptions.shouldScaleInput) { | 325 if (parsedOptions.cropRect == srcRect && !parsedOptions.shouldScaleInput) { |
324 sk_sp<SkImage> croppedSkImage = skiaImage->makeSubset(srcRect); | 326 sk_sp<SkImage> croppedSkImage = skiaImage->makeSubset(srcRect); |
325 if (parsedOptions.flipY) | 327 if (parsedOptions.flipY) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ParsedOptions parsedOptions = | 388 ParsedOptions parsedOptions = |
387 parseOptions(options, cropRect, image->bitmapSourceSize()); | 389 parseOptions(options, cropRect, image->bitmapSourceSize()); |
388 if (dstBufferSizeHasOverflow(parsedOptions)) | 390 if (dstBufferSizeHasOverflow(parsedOptions)) |
389 return; | 391 return; |
390 | 392 |
391 if (options.colorSpaceConversion() == "none") { | 393 if (options.colorSpaceConversion() == "none") { |
392 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, | 394 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
393 ImageDecoder::ColorSpaceIgnored); | 395 ImageDecoder::ColorSpaceIgnored); |
394 } else { | 396 } else { |
395 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, | 397 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
396 ImageDecoder::ColorSpaceApplied); | 398 ImageDecoder::ColorSpaceTransformed); |
397 } | 399 } |
398 if (!m_image) | 400 if (!m_image) |
399 return; | 401 return; |
400 // 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 |
401 // a decoded state, we trigger it here. | 403 // a decoded state, we trigger it here. |
402 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); | 404 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); |
403 SkPixmap pixmap; | 405 SkPixmap pixmap; |
404 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { | 406 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { |
405 sk_sp<SkSurface> surface = | 407 sk_sp<SkSurface> surface = |
406 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); | 408 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 864 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
863 FloatRect* dstRect) const {} | 865 FloatRect* dstRect) const {} |
864 | 866 |
865 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 867 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
866 return FloatSize(width(), height()); | 868 return FloatSize(width(), height()); |
867 } | 869 } |
868 | 870 |
869 DEFINE_TRACE(ImageBitmap) {} | 871 DEFINE_TRACE(ImageBitmap) {} |
870 | 872 |
871 } // namespace blink | 873 } // namespace blink |
OLD | NEW |