Chromium Code Reviews| 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> | 28 #include <limits> |
| 29 #include "platform/image-decoders/gif/GIFImageReader.h" | 29 #include "platform/image-decoders/gif/GIFImageReader.h" |
| 30 #include "public/platform/Platform.h" | |
| 30 #include "wtf/NotFound.h" | 31 #include "wtf/NotFound.h" |
| 31 #include "wtf/PassOwnPtr.h" | 32 #include "wtf/PassOwnPtr.h" |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes) | 36 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes) |
| 36 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) | 37 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) |
| 37 , m_repetitionCount(cAnimationLoopOnce) | 38 , m_repetitionCount(cAnimationLoopOnce), m_sizeOffset(0), m_sizeOffsetOptimi zed(0) |
| 38 { | 39 { |
| 39 } | 40 } |
| 40 | 41 |
| 41 GIFImageDecoder::~GIFImageDecoder() | 42 GIFImageDecoder::~GIFImageDecoder() |
| 42 { | 43 { |
| 43 } | 44 } |
| 44 | 45 |
| 45 void GIFImageDecoder::onSetData(SharedBuffer* data) | 46 void GIFImageDecoder::onSetData(SharedBuffer* data) |
| 46 { | 47 { |
| 47 if (m_reader) | 48 if (m_reader) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 | 172 |
| 172 buffer.setPixelsChanged(true); | 173 buffer.setPixelsChanged(true); |
| 173 return true; | 174 return true; |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool GIFImageDecoder::parseCompleted() const | 177 bool GIFImageDecoder::parseCompleted() const |
| 177 { | 178 { |
| 178 return m_reader && m_reader->parseCompleted(); | 179 return m_reader && m_reader->parseCompleted(); |
| 179 } | 180 } |
| 180 | 181 |
| 182 void GIFImageDecoder::setSizeOffset(size_t sizeOffset) | |
| 183 { | |
| 184 m_sizeOffset = sizeOffset; | |
| 185 } | |
| 186 | |
| 187 void GIFImageDecoder::setSizeOffsetOptimized(size_t sizeOffsetOptimized) | |
| 188 { | |
| 189 m_sizeOffsetOptimized = sizeOffsetOptimized; | |
| 190 } | |
| 191 | |
| 181 bool GIFImageDecoder::frameComplete(size_t frameIndex) | 192 bool GIFImageDecoder::frameComplete(size_t frameIndex) |
| 182 { | 193 { |
| 183 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, | 194 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, |
| 184 // in which case we never reach haveDecodedRow() before getting here. | 195 // in which case we never reach haveDecodedRow() before getting here. |
| 185 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 196 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
| 186 if ((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameInd ex)) | 197 if ((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameInd ex)) |
| 187 return false; // initFrameBuffer() has already called setFailed(). | 198 return false; // initFrameBuffer() has already called setFailed(). |
| 188 | 199 |
| 189 buffer.setStatus(ImageFrame::FrameComplete); | 200 buffer.setStatus(ImageFrame::FrameComplete); |
| 190 | 201 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 return; | 325 return; |
| 315 } | 326 } |
| 316 | 327 |
| 317 // We need more data to continue decoding. | 328 // We need more data to continue decoding. |
| 318 if (m_frameBufferCache[*i].status() != ImageFrame::FrameComplete) | 329 if (m_frameBufferCache[*i].status() != ImageFrame::FrameComplete) |
| 319 break; | 330 break; |
| 320 } | 331 } |
| 321 | 332 |
| 322 // It is also a fatal error if all data is received and we have decoded all | 333 // It is also a fatal error if all data is received and we have decoded all |
| 323 // frames available but the file is truncated. | 334 // frames available but the file is truncated. |
| 324 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_reade r && !m_reader->parseCompleted()) | 335 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_reade r && !m_reader->parseCompleted()) { |
| 325 setFailed(); | 336 setFailed(); |
| 337 return; | |
| 338 } | |
| 339 Platform::current()->histogramCustomCounts( | |
| 340 "Blink.Images.SizeOffsetOptimized_GIF", m_sizeOffsetOptimized, 1, 100000 0, 50); | |
|
Alexei Svitkine (slow)
2016/02/01 20:51:11
If you prefer, you can use . instead of _ and spec
| |
| 341 Platform::current()->histogramCustomCounts( | |
| 342 "Blink.Images.SizeOffset_GIF", m_sizeOffset, 1, 1000000, 50); | |
| 326 } | 343 } |
| 327 | 344 |
| 328 void GIFImageDecoder::parse(GIFParseQuery query) | 345 void GIFImageDecoder::parse(GIFParseQuery query) |
| 329 { | 346 { |
| 330 if (failed()) | 347 if (failed()) |
| 331 return; | 348 return; |
| 332 | 349 |
| 333 if (!m_reader) { | 350 if (!m_reader) { |
| 334 m_reader = adoptPtr(new GIFImageReader(this)); | 351 m_reader = adoptPtr(new GIFImageReader(this)); |
| 335 m_reader->setData(m_data); | 352 m_reader->setData(m_data); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 385 |
| 369 // Update our status to be partially complete. | 386 // Update our status to be partially complete. |
| 370 buffer->setStatus(ImageFrame::FramePartial); | 387 buffer->setStatus(ImageFrame::FramePartial); |
| 371 | 388 |
| 372 // Reset the alpha pixel tracker for this frame. | 389 // Reset the alpha pixel tracker for this frame. |
| 373 m_currentBufferSawAlpha = false; | 390 m_currentBufferSawAlpha = false; |
| 374 return true; | 391 return true; |
| 375 } | 392 } |
| 376 | 393 |
| 377 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |