| 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 <limits> |
| 29 #include "platform/graphics/BitmapImageMetrics.h" |
| 28 #include "platform/image-decoders/gif/GIFImageReader.h" | 30 #include "platform/image-decoders/gif/GIFImageReader.h" |
| 29 #include "wtf/NotFound.h" | 31 #include "wtf/NotFound.h" |
| 30 #include "wtf/PtrUtil.h" | 32 #include "wtf/PtrUtil.h" |
| 31 #include <limits> | |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, | 36 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, |
| 36 const ColorBehavior& colorBehavior, | 37 const ColorBehavior& colorBehavior, |
| 37 size_t maxDecodedBytes) | 38 size_t maxDecodedBytes) |
| 38 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), | 39 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), |
| 39 m_repetitionCount(cAnimationLoopOnce) {} | 40 m_repetitionCount(cAnimationLoopOnce) {} |
| 40 | 41 |
| 41 GIFImageDecoder::~GIFImageDecoder() {} | 42 GIFImageDecoder::~GIFImageDecoder() {} |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (m_reader && | 204 if (m_reader && |
| 204 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | 205 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { |
| 205 // Reset the state of the partial frame in the reader so that the frame | 206 // Reset the state of the partial frame in the reader so that the frame |
| 206 // can be decoded again when requested. | 207 // can be decoded again when requested. |
| 207 m_reader->clearDecodeState(frameIndex); | 208 m_reader->clearDecodeState(frameIndex); |
| 208 } | 209 } |
| 209 ImageDecoder::clearFrameBuffer(frameIndex); | 210 ImageDecoder::clearFrameBuffer(frameIndex); |
| 210 } | 211 } |
| 211 | 212 |
| 212 size_t GIFImageDecoder::decodeFrameCount() { | 213 size_t GIFImageDecoder::decodeFrameCount() { |
| 214 const bool alreadyParsedFrameTwo = m_reader && m_reader->imagesCount() > 1; |
| 213 parse(GIFFrameCountQuery); | 215 parse(GIFFrameCountQuery); |
| 214 // If decoding fails, |m_reader| will have been destroyed. Instead of | 216 // If decoding fails, |m_reader| will have been destroyed. Instead of |
| 215 // returning 0 in this case, return the existing number of frames. This way | 217 // returning 0 in this case, return the existing number of frames. This way |
| 216 // if we get halfway through the image before decoding fails, we won't | 218 // if we get halfway through the image before decoding fails, we won't |
| 217 // suddenly start reporting that the image has zero frames. | 219 // suddenly start reporting that the image has zero frames. |
| 218 return failed() ? m_frameBufferCache.size() : m_reader->imagesCount(); | 220 if (failed()) |
| 221 return m_frameBufferCache.size(); |
| 222 |
| 223 const size_t newCount = m_reader->imagesCount(); |
| 224 if (!alreadyParsedFrameTwo && newCount > 1) |
| 225 BitmapImageMetrics::countAnimatedImageType(BitmapImageMetrics::AnimatedGIF); |
| 226 return newCount; |
| 219 } | 227 } |
| 220 | 228 |
| 221 void GIFImageDecoder::initializeNewFrame(size_t index) { | 229 void GIFImageDecoder::initializeNewFrame(size_t index) { |
| 222 ImageFrame* buffer = &m_frameBufferCache[index]; | 230 ImageFrame* buffer = &m_frameBufferCache[index]; |
| 223 const GIFFrameContext* frameContext = m_reader->frameContext(index); | 231 const GIFFrameContext* frameContext = m_reader->frameContext(index); |
| 224 buffer->setOriginalFrameRect( | 232 buffer->setOriginalFrameRect( |
| 225 intersection(frameContext->frameRect(), IntRect(IntPoint(), size()))); | 233 intersection(frameContext->frameRect(), IntRect(IntPoint(), size()))); |
| 226 buffer->setDuration(frameContext->delayTime()); | 234 buffer->setDuration(frameContext->delayTime()); |
| 227 buffer->setDisposalMethod(frameContext->getDisposalMethod()); | 235 buffer->setDisposalMethod(frameContext->getDisposalMethod()); |
| 228 buffer->setRequiredPreviousFrameIndex( | 236 buffer->setRequiredPreviousFrameIndex( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 m_currentBufferSawAlpha = false; | 281 m_currentBufferSawAlpha = false; |
| 274 } | 282 } |
| 275 | 283 |
| 276 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | 284 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { |
| 277 DCHECK(frameIndex < m_frameBufferCache.size()); | 285 DCHECK(frameIndex < m_frameBufferCache.size()); |
| 278 return m_frameBufferCache[frameIndex].getDisposalMethod() != | 286 return m_frameBufferCache[frameIndex].getDisposalMethod() != |
| 279 ImageFrame::DisposeOverwritePrevious; | 287 ImageFrame::DisposeOverwritePrevious; |
| 280 } | 288 } |
| 281 | 289 |
| 282 } // namespace blink | 290 } // namespace blink |
| OLD | NEW |