| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "public/platform/WebImage.h" | 33 #include "public/platform/WebImage.h" |
| 34 | 34 |
| 35 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
| 36 #include "platform/graphics/Image.h" | 36 #include "platform/graphics/Image.h" |
| 37 #include "platform/graphics/skia/NativeImageSkia.h" | |
| 38 #include "platform/image-decoders/ImageDecoder.h" | 37 #include "platform/image-decoders/ImageDecoder.h" |
| 39 #include "public/platform/WebData.h" | 38 #include "public/platform/WebData.h" |
| 40 #include "public/platform/WebSize.h" | 39 #include "public/platform/WebSize.h" |
| 41 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
| 42 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
| 43 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
| 44 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
| 45 #include <algorithm> | 44 #include <algorithm> |
| 46 | 45 |
| 47 namespace blink { | 46 namespace blink { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 77 if (!i || (frameArea < frameAreaAtIndex)) { | 76 if (!i || (frameArea < frameAreaAtIndex)) { |
| 78 index = i; // Closer to desired area than previous best match. | 77 index = i; // Closer to desired area than previous best match. |
| 79 frameAreaAtIndex = frameArea; | 78 frameAreaAtIndex = frameArea; |
| 80 } | 79 } |
| 81 } | 80 } |
| 82 | 81 |
| 83 ImageFrame* frame = decoder->frameBufferAtIndex(index); | 82 ImageFrame* frame = decoder->frameBufferAtIndex(index); |
| 84 if (!frame) | 83 if (!frame) |
| 85 return WebImage(); | 84 return WebImage(); |
| 86 | 85 |
| 87 RefPtr<NativeImageSkia> image = frame->asNewNativeImage(); | 86 return WebImage(frame->bitmap()); |
| 88 if (!image) | |
| 89 return WebImage(); | |
| 90 | |
| 91 return WebImage(image->bitmap()); | |
| 92 } | 87 } |
| 93 | 88 |
| 94 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 89 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
| 95 { | 90 { |
| 96 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. | 91 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. |
| 97 const size_t maxFrameCount = 8; | 92 const size_t maxFrameCount = 8; |
| 98 | 93 |
| 99 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 94 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 100 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageSource
::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored)); | 95 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageSource
::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored)); |
| 101 if (!decoder) | 96 if (!decoder) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { | 109 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { |
| 115 const IntSize frameSize = decoder->frameSizeAtIndex(i); | 110 const IntSize frameSize = decoder->frameSizeAtIndex(i); |
| 116 if (frameSize == lastSize) | 111 if (frameSize == lastSize) |
| 117 continue; | 112 continue; |
| 118 lastSize = frameSize; | 113 lastSize = frameSize; |
| 119 | 114 |
| 120 ImageFrame* frame = decoder->frameBufferAtIndex(i); | 115 ImageFrame* frame = decoder->frameBufferAtIndex(i); |
| 121 if (!frame) | 116 if (!frame) |
| 122 continue; | 117 continue; |
| 123 | 118 |
| 124 RefPtr<NativeImageSkia> image = frame->asNewNativeImage(); | 119 const SkBitmap& bitmap = frame->bitmap(); |
| 125 if (image && image->isDataComplete()) | 120 if (!bitmap.isNull() && bitmap.isImmutable()) |
| 126 frames.append(WebImage(image->bitmap())); | 121 frames.append(WebImage(bitmap)); |
| 127 } | 122 } |
| 128 | 123 |
| 129 return frames; | 124 return frames; |
| 130 } | 125 } |
| 131 | 126 |
| 132 void WebImage::reset() | 127 void WebImage::reset() |
| 133 { | 128 { |
| 134 m_bitmap.reset(); | 129 m_bitmap.reset(); |
| 135 } | 130 } |
| 136 | 131 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 return WebSize(m_bitmap.width(), m_bitmap.height()); | 144 return WebSize(m_bitmap.width(), m_bitmap.height()); |
| 150 } | 145 } |
| 151 | 146 |
| 152 WebImage::WebImage(const PassRefPtr<Image>& image) | 147 WebImage::WebImage(const PassRefPtr<Image>& image) |
| 153 { | 148 { |
| 154 operator=(image); | 149 operator=(image); |
| 155 } | 150 } |
| 156 | 151 |
| 157 WebImage& WebImage::operator=(const PassRefPtr<Image>& image) | 152 WebImage& WebImage::operator=(const PassRefPtr<Image>& image) |
| 158 { | 153 { |
| 159 RefPtr<NativeImageSkia> p; | 154 SkBitmap p; |
| 160 if (image && (p = image->nativeImageForCurrentFrame())) | 155 if (image && image->bitmapForCurrentFrame(&p)) |
| 161 assign(p->bitmap()); | 156 assign(p); |
| 162 else | 157 else |
| 163 reset(); | 158 reset(); |
| 164 return *this; | 159 return *this; |
| 165 } | 160 } |
| 166 | 161 |
| 167 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |