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 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 ? frameContext->localColorMap().getTable() | 125 ? frameContext->localColorMap().getTable() |
126 : m_reader->globalColorMap().getTable(); | 126 : m_reader->globalColorMap().getTable(); |
127 | 127 |
128 if (colorTable.isEmpty()) | 128 if (colorTable.isEmpty()) |
129 return true; | 129 return true; |
130 | 130 |
131 GIFColorMap::Table::const_iterator colorTableIter = colorTable.begin(); | 131 GIFColorMap::Table::const_iterator colorTableIter = colorTable.begin(); |
132 | 132 |
133 // Initialize the frame if necessary. | 133 // Initialize the frame if necessary. |
134 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 134 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
135 if ((buffer.getStatus() == ImageFrame::FrameEmpty) && | 135 if (!initFrameBuffer(frameIndex)) |
136 !initFrameBuffer(frameIndex)) | |
137 return false; | 136 return false; |
138 | 137 |
139 const size_t transparentPixel = frameContext->transparentPixel(); | 138 const size_t transparentPixel = frameContext->transparentPixel(); |
140 GIFRow::const_iterator rowEnd = rowBegin + (xEnd - xBegin); | 139 GIFRow::const_iterator rowEnd = rowBegin + (xEnd - xBegin); |
141 ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin); | 140 ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin); |
142 | 141 |
143 // We may or may not need to write transparent pixels to the buffer. | 142 // We may or may not need to write transparent pixels to the buffer. |
144 // If we're compositing against a previous image, it's wrong, and if | 143 // If we're compositing against a previous image, it's wrong, and if |
145 // we're writing atop a cleared, fully transparent buffer, it's | 144 // we're writing atop a cleared, fully transparent buffer, it's |
146 // unnecessary; but if we're decoding an interlaced gif and | 145 // unnecessary; but if we're decoding an interlaced gif and |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 } | 182 } |
184 | 183 |
185 bool GIFImageDecoder::parseCompleted() const { | 184 bool GIFImageDecoder::parseCompleted() const { |
186 return m_reader && m_reader->parseCompleted(); | 185 return m_reader && m_reader->parseCompleted(); |
187 } | 186 } |
188 | 187 |
189 bool GIFImageDecoder::frameComplete(size_t frameIndex) { | 188 bool GIFImageDecoder::frameComplete(size_t frameIndex) { |
190 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, | 189 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, |
191 // in which case we never reach haveDecodedRow() before getting here. | 190 // in which case we never reach haveDecodedRow() before getting here. |
192 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 191 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
193 if ((buffer.getStatus() == ImageFrame::FrameEmpty) && | 192 if (!initFrameBuffer(frameIndex)) |
194 !initFrameBuffer(frameIndex)) | |
195 return false; // initFrameBuffer() has already called setFailed(). | 193 return false; // initFrameBuffer() has already called setFailed(). |
196 | 194 |
197 buffer.setStatus(ImageFrame::FrameComplete); | 195 buffer.setStatus(ImageFrame::FrameComplete); |
198 | 196 |
199 if (!m_currentBufferSawAlpha) { | 197 if (!m_currentBufferSawAlpha) { |
200 // The whole frame was non-transparent, so it's possible that the entire | 198 // The whole frame was non-transparent, so it's possible that the entire |
201 // resulting buffer was non-transparent, and we can setHasAlpha(false). | 199 // resulting buffer was non-transparent, and we can setHasAlpha(false). |
202 if (buffer.originalFrameRect().contains(IntRect(IntPoint(), size()))) { | 200 if (buffer.originalFrameRect().contains(IntRect(IntPoint(), size()))) { |
203 buffer.setHasAlpha(false); | 201 buffer.setHasAlpha(false); |
204 buffer.setRequiredPreviousFrameIndex(kNotFound); | 202 buffer.setRequiredPreviousFrameIndex(kNotFound); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 if (!m_reader) { | 354 if (!m_reader) { |
357 m_reader = wrapUnique(new GIFImageReader(this)); | 355 m_reader = wrapUnique(new GIFImageReader(this)); |
358 m_reader->setData(m_data); | 356 m_reader->setData(m_data); |
359 } | 357 } |
360 | 358 |
361 if (!m_reader->parse(query)) | 359 if (!m_reader->parse(query)) |
362 setFailed(); | 360 setFailed(); |
363 } | 361 } |
364 | 362 |
365 bool GIFImageDecoder::initFrameBuffer(size_t frameIndex) { | 363 bool GIFImageDecoder::initFrameBuffer(size_t frameIndex) { |
366 // Initialize the frame rect in our buffer. | 364 // ImageDecoder::initFrameBuffer does a DCHECK if |frameIndex| exists. |
367 ImageFrame* const buffer = &m_frameBufferCache[frameIndex]; | 365 if (!ImageDecoder::initFrameBuffer(frameIndex)) |
scroggo_chromium
2016/11/14 13:51:46
Since all of the overrides first call ImageDecoder
joostouwerling
2016/11/14 16:25:10
Good suggestion! Done.
| |
366 return false; | |
368 | 367 |
369 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); | |
370 if (requiredPreviousFrameIndex == kNotFound) { | |
371 // This frame doesn't rely on any previous data. | |
372 if (!buffer->setSizeAndColorSpace(size().width(), size().height(), | |
373 colorSpace())) { | |
374 return setFailed(); | |
375 } | |
376 } else { | |
377 ImageFrame* prevBuffer = &m_frameBufferCache[requiredPreviousFrameIndex]; | |
378 ASSERT(prevBuffer->getStatus() == ImageFrame::FrameComplete); | |
379 | |
380 // We try to reuse |prevBuffer| as starting state to avoid copying. | |
381 // For DisposeOverwritePrevious, the next frame will also use | |
382 // |prevBuffer| as its starting state, so we can't take over its image | |
383 // data using takeBitmapDataIfWritable. Copy the data instead. | |
384 if ((buffer->getDisposalMethod() == ImageFrame::DisposeOverwritePrevious || | |
385 !buffer->takeBitmapDataIfWritable(prevBuffer)) && | |
386 !buffer->copyBitmapData(*prevBuffer)) | |
387 return setFailed(); | |
388 | |
389 if (prevBuffer->getDisposalMethod() == | |
390 ImageFrame::DisposeOverwriteBgcolor) { | |
391 // We want to clear the previous frame to transparent, without | |
392 // affecting pixels in the image outside of the frame. | |
393 const IntRect& prevRect = prevBuffer->originalFrameRect(); | |
394 ASSERT(!prevRect.contains(IntRect(IntPoint(), size()))); | |
395 buffer->zeroFillFrameRect(prevRect); | |
396 } | |
397 } | |
398 | |
399 // Update our status to be partially complete. | |
400 buffer->setStatus(ImageFrame::FramePartial); | |
401 | |
402 // Reset the alpha pixel tracker for this frame. | |
403 m_currentBufferSawAlpha = false; | 368 m_currentBufferSawAlpha = false; |
404 return true; | 369 return true; |
405 } | 370 } |
371 | |
372 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | |
373 DCHECK(frameIndex < m_frameBufferCache.size()); | |
374 return m_frameBufferCache[frameIndex].getDisposalMethod() != | |
375 ImageFrame::DisposeOverwritePrevious; | |
376 } | |
377 | |
406 } // namespace blink | 378 } // namespace blink |
OLD | NEW |