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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (frameArea < (desiredSize.width * desiredSize.height)) | 68 if (frameArea < (desiredSize.width * desiredSize.height)) |
69 break; // No more frames that are large enough. | 69 break; // No more frames that are large enough. |
70 | 70 |
71 if (!i || (frameArea < frameAreaAtIndex)) { | 71 if (!i || (frameArea < frameAreaAtIndex)) { |
72 index = i; // Closer to desired area than previous best match. | 72 index = i; // Closer to desired area than previous best match. |
73 frameAreaAtIndex = frameArea; | 73 frameAreaAtIndex = frameArea; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 ImageFrame* frame = decoder->frameBufferAtIndex(index); | 77 ImageFrame* frame = decoder->frameBufferAtIndex(index); |
78 if (!frame) | 78 return (frame && !decoder->failed()) ? WebImage(frame->bitmap()) : WebImage(
); |
79 return WebImage(); | |
80 | |
81 return WebImage(frame->bitmap()); | |
82 } | 79 } |
83 | 80 |
84 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 81 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
85 { | 82 { |
86 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. | 83 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. |
87 const size_t maxFrameCount = 8; | 84 const size_t maxFrameCount = 8; |
88 | 85 |
89 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 86 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
90 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(buffer, true, | 87 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(buffer, true, |
91 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red)); | 88 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red)); |
92 if (!decoder || !decoder->isSizeAvailable()) | 89 if (!decoder || !decoder->isSizeAvailable()) |
93 return WebVector<WebImage>(); | 90 return WebVector<WebImage>(); |
94 | 91 |
95 // Frames are arranged by decreasing size, then decreasing bit depth. | 92 // Frames are arranged by decreasing size, then decreasing bit depth. |
96 // Keep the first frame at every size, has the highest bit depth. | 93 // Keep the first frame at every size, has the highest bit depth. |
97 const size_t frameCount = decoder->frameCount(); | 94 const size_t frameCount = decoder->frameCount(); |
98 IntSize lastSize; | 95 IntSize lastSize; |
99 | 96 |
100 Vector<WebImage> frames; | 97 Vector<WebImage> frames; |
101 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { | 98 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { |
102 const IntSize frameSize = decoder->frameSizeAtIndex(i); | 99 const IntSize frameSize = decoder->frameSizeAtIndex(i); |
103 if (frameSize == lastSize) | 100 if (frameSize == lastSize) |
104 continue; | 101 continue; |
105 lastSize = frameSize; | 102 lastSize = frameSize; |
106 | 103 |
107 ImageFrame* frame = decoder->frameBufferAtIndex(i); | 104 ImageFrame* frame = decoder->frameBufferAtIndex(i); |
108 if (!frame) | 105 if (!frame) |
109 continue; | 106 continue; |
110 | 107 |
111 const SkBitmap& bitmap = frame->bitmap(); | 108 SkBitmap bitmap = frame->bitmap(); |
112 if (!bitmap.isNull() && bitmap.isImmutable()) | 109 if (!bitmap.isNull() && frame->getStatus() == ImageFrame::FrameComplete) |
113 frames.append(WebImage(bitmap)); | 110 frames.append(WebImage(bitmap)); |
114 } | 111 } |
115 | 112 |
116 return frames; | 113 return frames; |
117 } | 114 } |
118 | 115 |
119 void WebImage::reset() | 116 void WebImage::reset() |
120 { | 117 { |
121 m_bitmap.reset(); | 118 m_bitmap.reset(); |
122 } | 119 } |
(...skipping 16 matching lines...) Expand all Loading... |
139 WebImage::WebImage(PassRefPtr<Image> image) | 136 WebImage::WebImage(PassRefPtr<Image> image) |
140 { | 137 { |
141 if (!image) | 138 if (!image) |
142 return; | 139 return; |
143 | 140 |
144 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame()) | 141 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame()) |
145 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 142 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
146 } | 143 } |
147 | 144 |
148 } // namespace blink | 145 } // namespace blink |
OLD | NEW |