OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "platform/image-decoders/gif/GIFImageDecoder.h" | 26 #include "platform/image-decoders/gif/GIFImageDecoder.h" |
27 | 27 |
28 #include "platform/image-decoders/gif/GIFImageReader.h" | 28 #include <limits> |
29 #include "third_party/skia/include/core/SkImageInfo.h" | |
29 #include "wtf/NotFound.h" | 30 #include "wtf/NotFound.h" |
30 #include "wtf/PtrUtil.h" | 31 #include "wtf/PtrUtil.h" |
31 #include <limits> | |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, | 35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, |
36 const ColorBehavior& colorBehavior, | 36 const ColorBehavior& colorBehavior, |
37 size_t maxDecodedBytes) | 37 size_t maxDecodedBytes) |
38 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), | 38 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), |
39 m_repetitionCount(cAnimationLoopOnce) {} | 39 m_codec(), |
40 | 40 m_segmentStream(nullptr) {} |
41 GIFImageDecoder::~GIFImageDecoder() {} | 41 |
42 GIFImageDecoder::~GIFImageDecoder() { | |
43 if (!m_codec) { | |
44 // if we did not create m_codec and thus did not pass ownership to it | |
45 if (m_segmentStream) | |
46 delete m_segmentStream; | |
47 } | |
48 } | |
42 | 49 |
43 void GIFImageDecoder::onSetData(SegmentReader* data) { | 50 void GIFImageDecoder::onSetData(SegmentReader* data) { |
44 if (m_reader) | 51 if (!data) { |
45 m_reader->setData(data); | 52 if (m_segmentStream) |
53 m_segmentStream->setReader(nullptr, false); | |
54 return; | |
55 } | |
56 | |
57 if (!m_segmentStream) | |
58 m_segmentStream = new SegmentStream(); | |
59 | |
60 m_segmentStream->setReader(data, isAllDataReceived()); | |
61 | |
62 // If we don't have a SkCodec yet, create one from the stream | |
63 if (!m_codec) { | |
64 SkCodec* codec = SkCodec::NewFromStream(m_segmentStream); | |
65 if (codec) { | |
66 m_codec.reset(codec); | |
67 } else { | |
68 // m_segmentStream's ownership is passed. It is deleted if SkCodec | |
69 // creation fails. In this case, release our reference so we can create a | |
70 // new SegmentStream later. | |
71 m_segmentStream = nullptr; | |
72 return; | |
73 } | |
74 | |
75 // SkCodec::NewFromStream will read enough of the image to get the image | |
76 // size. | |
77 SkImageInfo imageInfo = m_codec->getInfo(); | |
78 setSize(imageInfo.width(), imageInfo.height()); | |
79 } | |
46 } | 80 } |
47 | 81 |
48 int GIFImageDecoder::repetitionCount() const { | 82 int GIFImageDecoder::repetitionCount() const { |
83 if (!m_codec) | |
84 return cAnimationLoopOnce; | |
85 | |
49 // This value can arrive at any point in the image data stream. Most GIFs | 86 // This value can arrive at any point in the image data stream. Most GIFs |
50 // in the wild declare it near the beginning of the file, so it usually is | 87 // in the wild declare it near the beginning of the file, so it usually is |
51 // set by the time we've decoded the size, but (depending on the GIF and the | 88 // set by the time we've decoded the size, but (depending on the GIF and the |
52 // packets sent back by the webserver) not always. If the reader hasn't | 89 // packets sent back by the webserver) not always. |
53 // seen a loop count yet, it will return cLoopCountNotSeen, in which case we | |
54 // should default to looping once (the initial value for | |
55 // |m_repetitionCount|). | |
56 // | 90 // |
57 // There are some additional wrinkles here. First, ImageSource::clear() | 91 // SkCodec will parse forward in the file if the repetition count has not been |
58 // may destroy the reader, making the result from the reader _less_ | 92 // seen yet. |
59 // authoritative on future calls if the recreated reader hasn't seen the | 93 |
60 // loop count. We don't need to special-case this because in this case the | 94 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
61 // new reader will once again return cLoopCountNotSeen, and we won't | 95 if (isAllDataReceived() && frameInfos.size() == 1) |
62 // overwrite the cached correct value. | 96 return cAnimationNone; |
63 // | 97 if (failed()) |
64 // Second, a GIF might never set a loop count at all, in which case we | 98 return cAnimationLoopOnce; |
65 // should continue to treat it as a "loop once" animation. We don't need | 99 |
66 // special code here either, because in this case we'll never change | 100 int repetitionCount = m_codec->getRepetitionCount(); |
67 // |m_repetitionCount| from its default value. | 101 switch (repetitionCount) { |
68 // | 102 case 0: |
69 // Third, we use the same GIFImageReader for counting frames and we might | 103 return cAnimationLoopOnce; |
70 // see the loop count and then encounter a decoding error which happens | 104 case SkCodec::kRepetitionCountInfinite: |
71 // later in the stream. It is also possible that no frames are in the | 105 return cAnimationLoopInfinite; |
72 // stream. In these cases we should just loop once. | 106 default: |
73 if (isAllDataReceived() && parseCompleted() && m_reader->imagesCount() == 1) | 107 return repetitionCount; |
74 m_repetitionCount = cAnimationNone; | 108 } |
75 else if (failed() || (m_reader && (!m_reader->imagesCount()))) | |
76 m_repetitionCount = cAnimationLoopOnce; | |
77 else if (m_reader && m_reader->loopCount() != cLoopCountNotSeen) | |
78 m_repetitionCount = m_reader->loopCount(); | |
79 return m_repetitionCount; | |
80 } | 109 } |
81 | 110 |
82 bool GIFImageDecoder::frameIsCompleteAtIndex(size_t index) const { | 111 bool GIFImageDecoder::frameIsCompleteAtIndex(size_t index) const { |
83 return m_reader && (index < m_reader->imagesCount()) && | 112 if (!m_codec) |
84 m_reader->frameContext(index)->isComplete(); | 113 return false; |
114 | |
115 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); | |
116 if (frameInfos.size() <= index) | |
117 return false; | |
118 | |
119 return frameInfos[index].fFullyReceived; | |
85 } | 120 } |
86 | 121 |
87 float GIFImageDecoder::frameDurationAtIndex(size_t index) const { | 122 float GIFImageDecoder::frameDurationAtIndex(size_t index) const { |
88 return (m_reader && (index < m_reader->imagesCount()) && | 123 if (index < m_frameBufferCache.size()) |
89 m_reader->frameContext(index)->isHeaderDefined()) | 124 return m_frameBufferCache[index].duration(); |
90 ? m_reader->frameContext(index)->delayTime() | 125 return 0; |
91 : 0; | 126 } |
92 } | 127 |
93 | 128 size_t GIFImageDecoder::decodeFrameCount() { |
94 bool GIFImageDecoder::setFailed() { | 129 if (!m_codec) |
95 m_reader.reset(); | 130 return 0; |
96 return ImageDecoder::setFailed(); | 131 |
97 } | 132 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
98 | 133 return frameInfos.size(); |
99 bool GIFImageDecoder::haveDecodedRow(size_t frameIndex, | 134 } |
100 GIFRow::const_iterator rowBegin, | 135 |
101 size_t width, | 136 void GIFImageDecoder::initializeNewFrame(size_t index) { |
102 size_t rowNumber, | 137 DCHECK(m_codec); |
103 unsigned repeatCount, | 138 |
104 bool writeTransparentPixels) { | 139 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
105 const GIFFrameContext* frameContext = m_reader->frameContext(frameIndex); | 140 |
106 // The pixel data and coordinates supplied to us are relative to the frame's | 141 ImageFrame& frame = m_frameBufferCache[index]; |
107 // origin within the entire image size, i.e. | 142 // SkCodec does not inform us if only a portion of the image was updated |
108 // (frameContext->xOffset, frameContext->yOffset). There is no guarantee | 143 // in the current frame. Because of this, rather than correctly filling in |
109 // that width == (size().width() - frameContext->xOffset), so | 144 // the frame rect, we set the frame rect to be the image's full size. |
110 // we must ensure we don't run off the end of either the source data or the | 145 IntSize fullImageSize = size(); |
111 // row's X-coordinates. | 146 frame.setOriginalFrameRect(IntRect(IntPoint(), fullImageSize)); |
112 const int xBegin = frameContext->xOffset(); | 147 frame.setDuration(frameInfos[index].fDuration); |
113 const int yBegin = frameContext->yOffset() + rowNumber; | 148 size_t requiredPreviousFrameIndex = frameInfos[index].fRequiredFrame; |
114 const int xEnd = std::min(static_cast<int>(frameContext->xOffset() + width), | 149 if (requiredPreviousFrameIndex == SkCodec::kNone) |
115 size().width()); | 150 requiredPreviousFrameIndex = WTF::kNotFound; |
116 const int yEnd = std::min( | 151 frame.setRequiredPreviousFrameIndex(requiredPreviousFrameIndex); |
117 static_cast<int>(frameContext->yOffset() + rowNumber + repeatCount), | 152 // The disposal method is not required any more, but is left in place |
118 size().height()); | 153 // for the other image decoders that do not yet rely on SkCodec. |
119 if (!width || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || | 154 // For now, fill it with DisposeKeep. |
120 (yEnd <= yBegin)) | 155 frame.setDisposalMethod(ImageFrame::DisposeKeep); |
121 return true; | 156 } |
122 | 157 |
123 const GIFColorMap::Table& colorTable = | 158 void GIFImageDecoder::decode(size_t index) { |
124 frameContext->localColorMap().isDefined() | 159 if (failed()) |
125 ? frameContext->localColorMap().getTable() | 160 return; |
126 : m_reader->globalColorMap().getTable(); | 161 |
127 | 162 if (!m_codec) |
128 if (colorTable.isEmpty()) | 163 return; |
129 return true; | 164 |
130 | 165 if (m_frameBufferCache.size() <= index) { |
131 GIFColorMap::Table::const_iterator colorTableIter = colorTable.begin(); | 166 // It is a fatal error if all data is received and we have decoded all |
132 | 167 // frames available but the file is truncated. |
133 // Initialize the frame if necessary. | 168 if (isAllDataReceived()) |
134 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 169 setFailed(); |
135 if (!initFrameBuffer(frameIndex)) | 170 |
136 return false; | 171 return; |
137 | 172 } |
138 const size_t transparentPixel = frameContext->transparentPixel(); | 173 |
139 GIFRow::const_iterator rowEnd = rowBegin + (xEnd - xBegin); | 174 updateAggressivePurging(index); |
140 ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin); | 175 |
141 | 176 SkImageInfo imageInfo = m_codec->getInfo().makeColorType(kN32_SkColorType); |
142 // We may or may not need to write transparent pixels to the buffer. | 177 |
143 // If we're compositing against a previous image, it's wrong, and if | 178 SkCodec::Options options; |
144 // we're writing atop a cleared, fully transparent buffer, it's | 179 options.fFrameIndex = index; |
145 // unnecessary; but if we're decoding an interlaced gif and | 180 options.fHasPriorFrame = false; |
146 // displaying it "Haeberli"-style, we must write these for passes | 181 |
147 // beyond the first, or the initial passes will "show through" the | 182 ImageFrame& frame = m_frameBufferCache[index]; |
148 // later ones. | 183 if (frame.getStatus() == ImageFrame::FrameEmpty) { |
149 // | 184 size_t requiredPreviousFrameIndex = frame.requiredPreviousFrameIndex(); |
150 // The loops below are almost identical. One writes a transparent pixel | 185 if (requiredPreviousFrameIndex == WTF::kNotFound) { |
151 // and one doesn't based on the value of |writeTransparentPixels|. | 186 frame.setSizeAndColorSpace(size().width(), size().height(), |
152 // The condition check is taken out of the loop to enhance performance. | 187 colorSpaceForSkImages()); |
153 // This optimization reduces decoding time by about 15% for a 3MB image. | 188 } else { |
154 if (writeTransparentPixels) { | 189 ImageFrame& requiredPreviousFrame = |
155 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 190 m_frameBufferCache[requiredPreviousFrameIndex]; |
156 const size_t sourceValue = *rowBegin; | 191 |
157 if ((sourceValue != transparentPixel) && | 192 if (requiredPreviousFrame.getStatus() != ImageFrame::FrameComplete) |
158 (sourceValue < colorTable.size())) { | 193 decode(requiredPreviousFrameIndex); |
159 *currentAddress = colorTableIter[sourceValue]; | 194 |
160 } else { | 195 // We try to reuse |requiredPreviousFrame| as starting state to avoid |
161 *currentAddress = 0; | 196 // copying. If canReusePreviousFrameBuffer returns false, we must copy |
162 m_currentBufferSawAlpha = true; | 197 // the data since |requiredPreviousFrame| is necessary to decode this |
198 // or later frames. In that case copy the data instead. | |
199 if ((!canReusePreviousFrameBuffer(index) || | |
200 !frame.takeBitmapDataIfWritable(&requiredPreviousFrame)) && | |
201 !frame.copyBitmapData(requiredPreviousFrame)) { | |
202 setFailed(); | |
203 return; | |
163 } | 204 } |
205 | |
206 options.fHasPriorFrame = true; | |
164 } | 207 } |
165 } else { | 208 |
166 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 209 SkCodec::Result startIncrementalDecodeResult = |
167 const size_t sourceValue = *rowBegin; | 210 m_codec->startIncrementalDecode(imageInfo, frame.bitmap().getPixels(), |
168 if ((sourceValue != transparentPixel) && | 211 frame.bitmap().rowBytes(), &options, |
169 (sourceValue < colorTable.size())) | 212 nullptr, nullptr); |
170 *currentAddress = colorTableIter[sourceValue]; | 213 switch (startIncrementalDecodeResult) { |
171 else | 214 case SkCodec::kSuccess: |
172 m_currentBufferSawAlpha = true; | 215 break; |
216 case SkCodec::kIncompleteInput: | |
217 return; | |
218 default: | |
219 setFailed(); | |
220 return; | |
173 } | 221 } |
174 } | 222 frame.setStatus(ImageFrame::FramePartial); |
175 | 223 } |
176 // Tell the frame to copy the row data if need be. | 224 |
177 if (repeatCount > 1) | 225 int rowsDecoded = 0; |
178 buffer.copyRowNTimes(xBegin, xEnd, yBegin, yEnd); | 226 SkCodec::Result incrementalDecodeResult = |
179 | 227 m_codec->incrementalDecode(&rowsDecoded); |
180 buffer.setPixelsChanged(true); | 228 switch (incrementalDecodeResult) { |
181 return true; | 229 case SkCodec::kSuccess: |
182 } | 230 frame.setPixelsChanged(true); |
183 | 231 frame.setStatus(ImageFrame::FrameComplete); |
184 bool GIFImageDecoder::parseCompleted() const { | 232 postDecodeProcessing(index); |
185 return m_reader && m_reader->parseCompleted(); | 233 break; |
186 } | 234 case SkCodec::kIncompleteInput: |
187 | 235 // This decoder will not attempt to decode a frame unless it is complete |
scroggo_chromium
2017/03/08 16:36:10
Come to think of it, although BitmapImage will not
cblume
2017/03/08 19:49:43
Yeah, I think that makes sense.
I also think if (
scroggo_chromium
2017/03/08 21:04:11
I do not have a strong preference here, but noel@
cblume
2017/03/08 23:18:57
Cool. I'll leave it as if (index :)
Noel Gordon
2017/03/09 04:12:28
Yeah, recent addition. Reading
if (index != 0
| |
188 bool GIFImageDecoder::frameComplete(size_t frameIndex) { | 236 // unless it is frame 0. We should only get this value if: |
189 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, | 237 // 1.) we have only part of frame 0, or |
190 // in which case we never reach haveDecodedRow() before getting here. | 238 // 2.) there was an error decoding a frame other than 0 |
191 if (!initFrameBuffer(frameIndex)) | 239 // |
192 return false; // initFrameBuffer() has already called setFailed(). | 240 // If we are on frame 0 but all data is received, that is also an error. |
193 | 241 if (index || isAllDataReceived()) { |
194 m_frameBufferCache[frameIndex].setStatus(ImageFrame::FrameComplete); | 242 setFailed(); |
195 if (!m_currentBufferSawAlpha) | 243 return; |
196 correctAlphaWhenFrameBufferSawNoAlpha(frameIndex); | 244 } |
197 | 245 |
198 return true; | 246 frame.setPixelsChanged(true); |
199 } | 247 break; |
200 | 248 default: |
201 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { | |
202 if (m_reader && | |
203 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | |
204 // Reset the state of the partial frame in the reader so that the frame | |
205 // can be decoded again when requested. | |
206 m_reader->clearDecodeState(frameIndex); | |
207 } | |
208 ImageDecoder::clearFrameBuffer(frameIndex); | |
209 } | |
210 | |
211 size_t GIFImageDecoder::decodeFrameCount() { | |
212 parse(GIFFrameCountQuery); | |
213 // If decoding fails, |m_reader| will have been destroyed. Instead of | |
214 // returning 0 in this case, return the existing number of frames. This way | |
215 // if we get halfway through the image before decoding fails, we won't | |
216 // suddenly start reporting that the image has zero frames. | |
217 return failed() ? m_frameBufferCache.size() : m_reader->imagesCount(); | |
218 } | |
219 | |
220 void GIFImageDecoder::initializeNewFrame(size_t index) { | |
221 ImageFrame* buffer = &m_frameBufferCache[index]; | |
222 const GIFFrameContext* frameContext = m_reader->frameContext(index); | |
223 buffer->setOriginalFrameRect( | |
224 intersection(frameContext->frameRect(), IntRect(IntPoint(), size()))); | |
225 buffer->setDuration(frameContext->delayTime()); | |
226 buffer->setDisposalMethod(frameContext->getDisposalMethod()); | |
227 buffer->setRequiredPreviousFrameIndex( | |
228 findRequiredPreviousFrame(index, false)); | |
229 } | |
230 | |
231 void GIFImageDecoder::decode(size_t index) { | |
232 parse(GIFFrameCountQuery); | |
233 | |
234 if (failed()) | |
235 return; | |
236 | |
237 updateAggressivePurging(index); | |
238 | |
239 Vector<size_t> framesToDecode = findFramesToDecode(index); | |
240 for (auto i = framesToDecode.rbegin(); i != framesToDecode.rend(); ++i) { | |
241 if (!m_reader->decode(*i)) { | |
242 setFailed(); | 249 setFailed(); |
243 return; | 250 return; |
244 } | 251 } |
245 | 252 } |
246 // If this returns false, we need more data to continue decoding. | 253 |
247 if (!postDecodeProcessing(*i)) | 254 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t index) const { |
248 break; | 255 DCHECK(index < m_frameBufferCache.size()); |
249 } | 256 |
250 | 257 // If the current frame and the next frame depend on the same frame, we cannot |
251 // It is also a fatal error if all data is received and we have decoded all | 258 // reuse the old frame. We must preserve it for the next frame. |
252 // frames available but the file is truncated. | 259 // |
253 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && | 260 // However, if the current and next frame depend on different frames then we |
254 m_reader && !m_reader->parseCompleted()) | 261 // know the current frame is the last one to use the frame it depends on. That |
255 setFailed(); | 262 // means the current frame can reuse the previous frame buffer. |
256 } | 263 // |
257 | 264 // If we do not have information about the next frame yet, we cannot assume it |
258 void GIFImageDecoder::parse(GIFParseQuery query) { | 265 // is safe to reuse the previous frame buffer. |
259 if (failed()) | 266 |
260 return; | 267 if (index + 1 >= m_frameBufferCache.size()) |
261 | 268 return false; |
262 if (!m_reader) { | 269 |
263 m_reader = WTF::makeUnique<GIFImageReader>(this); | 270 const ImageFrame& frame = m_frameBufferCache[index]; |
264 m_reader->setData(m_data); | 271 size_t requiredFrameIndex = frame.requiredPreviousFrameIndex(); |
265 } | 272 |
266 | 273 const ImageFrame& nextFrame = m_frameBufferCache[index + 1]; |
267 if (!m_reader->parse(query)) | 274 size_t nextRequiredFrameIndex = nextFrame.requiredPreviousFrameIndex(); |
268 setFailed(); | 275 |
269 } | 276 return requiredFrameIndex != nextRequiredFrameIndex; |
270 | |
271 void GIFImageDecoder::onInitFrameBuffer(size_t frameIndex) { | |
272 m_currentBufferSawAlpha = false; | |
273 } | |
274 | |
275 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | |
276 DCHECK(frameIndex < m_frameBufferCache.size()); | |
277 return m_frameBufferCache[frameIndex].getDisposalMethod() != | |
278 ImageFrame::DisposeOverwritePrevious; | |
279 } | 277 } |
280 | 278 |
281 } // namespace blink | 279 } // namespace blink |
OLD | NEW |