OLD | NEW |
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 CompuServe Incorporated maintains a mailing list with all those individuals and | 69 CompuServe Incorporated maintains a mailing list with all those individuals and |
70 organizations who wish to receive copies of this document when it is corrected | 70 organizations who wish to receive copies of this document when it is corrected |
71 or revised. This service is offered free of charge; please provide us with your | 71 or revised. This service is offered free of charge; please provide us with your |
72 mailing address. | 72 mailing address. |
73 */ | 73 */ |
74 | 74 |
75 #include "platform/image-decoders/gif/GIFImageReader.h" | 75 #include "platform/image-decoders/gif/GIFImageReader.h" |
76 | 76 |
77 #include "platform/Histogram.h" | 77 #include "platform/Histogram.h" |
78 #include "wtf/PtrUtil.h" | |
79 #include "wtf/Threading.h" | 78 #include "wtf/Threading.h" |
| 79 |
80 #include <string.h> | 80 #include <string.h> |
81 | 81 |
82 using blink::GIFImageDecoder; | 82 using blink::GIFImageDecoder; |
83 | 83 |
84 // GETN(n, s) requests at least 'n' bytes available from 'q', at start of state
's'. | 84 // GETN(n, s) requests at least 'n' bytes available from 'q', at start of state
's'. |
85 // | 85 // |
86 // Note, the hold will never need to be bigger than 256 bytes to gather up in th
e hold, | 86 // Note, the hold will never need to be bigger than 256 bytes to gather up in th
e hold, |
87 // as each GIF block (except colormaps) can never be bigger than 256 bytes. | 87 // as each GIF block (except colormaps) can never be bigger than 256 bytes. |
88 // Colormaps are directly copied in the resp. global_colormap or dynamically all
ocated local_colormap. | 88 // Colormaps are directly copied in the resp. global_colormap or dynamically all
ocated local_colormap. |
89 // So a fixed buffer in GIFImageReader is good enough. | 89 // So a fixed buffer in GIFImageReader is good enough. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 bool GIFFrameContext::decode(blink::FastSharedBufferReader* reader, blink::GIFIm
ageDecoder* client, bool* frameDecoded) | 329 bool GIFFrameContext::decode(blink::FastSharedBufferReader* reader, blink::GIFIm
ageDecoder* client, bool* frameDecoded) |
330 { | 330 { |
331 m_localColorMap.buildTable(reader); | 331 m_localColorMap.buildTable(reader); |
332 | 332 |
333 *frameDecoded = false; | 333 *frameDecoded = false; |
334 if (!m_lzwContext) { | 334 if (!m_lzwContext) { |
335 // Wait for more data to properly initialize GIFLZWContext. | 335 // Wait for more data to properly initialize GIFLZWContext. |
336 if (!isDataSizeDefined() || !isHeaderDefined()) | 336 if (!isDataSizeDefined() || !isHeaderDefined()) |
337 return true; | 337 return true; |
338 | 338 |
339 m_lzwContext = wrapUnique(new GIFLZWContext(client, this)); | 339 m_lzwContext = adoptPtr(new GIFLZWContext(client, this)); |
340 if (!m_lzwContext->prepareToDecode()) { | 340 if (!m_lzwContext->prepareToDecode()) { |
341 m_lzwContext.reset(); | 341 m_lzwContext.reset(); |
342 return false; | 342 return false; |
343 } | 343 } |
344 | 344 |
345 m_currentLzwBlock = 0; | 345 m_currentLzwBlock = 0; |
346 } | 346 } |
347 | 347 |
348 // Some bad GIFs have extra blocks beyond the last row, which we don't want
to decode. | 348 // Some bad GIFs have extra blocks beyond the last row, which we don't want
to decode. |
349 while (m_currentLzwBlock < m_lzwBlocks.size() && m_lzwContext->hasRemainingR
ows()) { | 349 while (m_currentLzwBlock < m_lzwBlocks.size() && m_lzwContext->hasRemainingR
ows()) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 820 |
821 void GIFImageReader::setRemainingBytes(size_t remainingBytes) | 821 void GIFImageReader::setRemainingBytes(size_t remainingBytes) |
822 { | 822 { |
823 ASSERT(remainingBytes <= m_data->size()); | 823 ASSERT(remainingBytes <= m_data->size()); |
824 m_bytesRead = m_data->size() - remainingBytes; | 824 m_bytesRead = m_data->size() - remainingBytes; |
825 } | 825 } |
826 | 826 |
827 void GIFImageReader::addFrameIfNecessary() | 827 void GIFImageReader::addFrameIfNecessary() |
828 { | 828 { |
829 if (m_frames.isEmpty() || m_frames.last()->isComplete()) | 829 if (m_frames.isEmpty() || m_frames.last()->isComplete()) |
830 m_frames.append(wrapUnique(new GIFFrameContext(m_frames.size()))); | 830 m_frames.append(adoptPtr(new GIFFrameContext(m_frames.size()))); |
831 } | 831 } |
832 | 832 |
833 // FIXME: Move this method to close to doLZW(). | 833 // FIXME: Move this method to close to doLZW(). |
834 bool GIFLZWContext::prepareToDecode() | 834 bool GIFLZWContext::prepareToDecode() |
835 { | 835 { |
836 ASSERT(m_frameContext->isDataSizeDefined() && m_frameContext->isHeaderDefine
d()); | 836 ASSERT(m_frameContext->isDataSizeDefined() && m_frameContext->isHeaderDefine
d()); |
837 | 837 |
838 // Since we use a codesize of 1 more than the datasize, we need to ensure | 838 // Since we use a codesize of 1 more than the datasize, we need to ensure |
839 // that our datasize is strictly less than the MAX_DICTIONARY_ENTRY_BITS. | 839 // that our datasize is strictly less than the MAX_DICTIONARY_ENTRY_BITS. |
840 if (m_frameContext->dataSize() >= MAX_DICTIONARY_ENTRY_BITS) | 840 if (m_frameContext->dataSize() >= MAX_DICTIONARY_ENTRY_BITS) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 rowIter = rowBuffer.begin(); | 874 rowIter = rowBuffer.begin(); |
875 rowsRemaining = m_frameContext->height(); | 875 rowsRemaining = m_frameContext->height(); |
876 | 876 |
877 // Clearing the whole suffix table lets us be more tolerant of bad data. | 877 // Clearing the whole suffix table lets us be more tolerant of bad data. |
878 for (int i = 0; i < clearCode; ++i) { | 878 for (int i = 0; i < clearCode; ++i) { |
879 suffix[i] = i; | 879 suffix[i] = i; |
880 suffixLength[i] = 1; | 880 suffixLength[i] = 1; |
881 } | 881 } |
882 return true; | 882 return true; |
883 } | 883 } |
OLD | NEW |