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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 // The following two functions are helpers used in cropImage | 39 // The following two functions are helpers used in cropImage |
40 static inline IntRect normalizeRect(const IntRect& rect) | 40 static inline IntRect normalizeRect(const IntRect& rect) |
41 { | 41 { |
42 return IntRect(std::min(rect.x(), rect.maxX()), | 42 return IntRect(std::min(rect.x(), rect.maxX()), |
43 std::min(rect.y(), rect.maxY()), | 43 std::min(rect.y(), rect.maxY()), |
44 std::max(rect.width(), -rect.width()), | 44 std::max(rect.width(), -rect.width()), |
45 std::max(rect.height(), -rect.height())); | 45 std::max(rect.height(), -rect.height())); |
46 } | 46 } |
47 | 47 |
48 static bool frameIsValid(const SkBitmap& frameBitmap) | |
49 { | |
50 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty() && frameBitmap.isImmuta ble()); | |
51 return frameBitmap.colorType() == kN32_SkColorType; | |
52 } | |
53 | |
54 ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize) | 48 ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize) |
55 { | 49 { |
56 ParsedOptions parsedOptions; | 50 ParsedOptions parsedOptions; |
57 if (options.imageOrientation() == imageOrientationFlipY) { | 51 if (options.imageOrientation() == imageOrientationFlipY) { |
58 parsedOptions.flipY = true; | 52 parsedOptions.flipY = true; |
59 } else { | 53 } else { |
60 parsedOptions.flipY = false; | 54 parsedOptions.flipY = false; |
61 DCHECK(options.imageOrientation() == imageBitmapOptionNone); | 55 DCHECK(options.imageOrientation() == imageBitmapOptionNone); |
62 } | 56 } |
63 if (options.premultiplyAlpha() == imageBitmapOptionNone) { | 57 if (options.premultiplyAlpha() == imageBitmapOptionNone) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 return newSkImageFromRaster(info, std::move(dstPixels), static_cast<size_t>( input->width()) * info.bytesPerPixel()); | 202 return newSkImageFromRaster(info, std::move(dstPixels), static_cast<size_t>( input->width()) * info.bytesPerPixel()); |
209 } | 203 } |
210 | 204 |
211 sk_sp<SkImage> ImageBitmap::getSkImageFromDecoder(std::unique_ptr<ImageDecoder> decoder) | 205 sk_sp<SkImage> ImageBitmap::getSkImageFromDecoder(std::unique_ptr<ImageDecoder> decoder) |
212 { | 206 { |
213 if (!decoder->frameCount()) | 207 if (!decoder->frameCount()) |
214 return nullptr; | 208 return nullptr; |
215 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 209 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
216 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) | 210 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) |
217 return nullptr; | 211 return nullptr; |
218 SkBitmap bitmap = frame->bitmap(); | 212 DCHECK(!frame->bitmap().isNull() && !frame->bitmap().empty()); |
219 if (!frameIsValid(bitmap)) | 213 return (frame->bitmap().colorType() == kN32_SkColorType) ? frame->finalizePi xelsAndGetImage() : nullptr; |
dcheng
2016/09/27 22:44:15
Just curious: what does that mean if we get here a
aleksandar.stojiljkovic
2016/09/28 18:51:24
kUnknown_SkColorType:
In initial state, SkBitmap h
dcheng
2016/09/28 21:16:52
I understand that this is a refactoring only chang
aleksandar.stojiljkovic
2016/09/28 22:10:22
Yes, given the explanation I provided above, there
| |
220 return nullptr; | |
221 return SkImage::MakeFromBitmap(bitmap); | |
222 } | 214 } |
223 | 215 |
224 bool ImageBitmap::isResizeOptionValid(const ImageBitmapOptions& options, Excepti onState& exceptionState) | 216 bool ImageBitmap::isResizeOptionValid(const ImageBitmapOptions& options, Excepti onState& exceptionState) |
225 { | 217 { |
226 if ((options.hasResizeWidth() && options.resizeWidth() == 0) || (options.has ResizeHeight() && options.resizeHeight() == 0)) { | 218 if ((options.hasResizeWidth() && options.resizeWidth() == 0) || (options.has ResizeHeight() && options.resizeHeight() == 0)) { |
227 exceptionState.throwDOMException(InvalidStateError, "The resizeWidth or/ and resizeHeight is equal to 0."); | 219 exceptionState.throwDOMException(InvalidStateError, "The resizeWidth or/ and resizeHeight is equal to 0."); |
228 return false; | 220 return false; |
229 } | 221 } |
230 return true; | 222 return true; |
231 } | 223 } |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 701 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
710 { | 702 { |
711 return FloatSize(width(), height()); | 703 return FloatSize(width(), height()); |
712 } | 704 } |
713 | 705 |
714 DEFINE_TRACE(ImageBitmap) | 706 DEFINE_TRACE(ImageBitmap) |
715 { | 707 { |
716 } | 708 } |
717 | 709 |
718 } // namespace blink | 710 } // namespace blink |
OLD | NEW |