OLD | NEW |
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C; tab-width: 4; 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 20 matching lines...) Expand all Loading... |
31 * decision by deleting the provisions above and replace them with the notice | 31 * decision by deleting the provisions above and replace them with the notice |
32 * and other provisions required by the GPL or the LGPL. If you do not delete | 32 * and other provisions required by the GPL or the LGPL. If you do not delete |
33 * the provisions above, a recipient may use your version of this file under | 33 * the provisions above, a recipient may use your version of this file under |
34 * the terms of any one of the MPL, the GPL or the LGPL. | 34 * the terms of any one of the MPL, the GPL or the LGPL. |
35 * | 35 * |
36 * ***** END LICENSE BLOCK ***** */ | 36 * ***** END LICENSE BLOCK ***** */ |
37 | 37 |
38 #ifndef GIFImageReader_h | 38 #ifndef GIFImageReader_h |
39 #define GIFImageReader_h | 39 #define GIFImageReader_h |
40 | 40 |
41 // Define ourselves as the clientPtr. Mozilla just hacked their C++ callback cl
ass into this old C decoder, | 41 // Define ourselves as the clientPtr. Mozilla just hacked their C++ callback |
42 // so we will too. | 42 // class into this old C decoder, so we will too. |
43 #include "platform/image-decoders/FastSharedBufferReader.h" | 43 #include "platform/image-decoders/FastSharedBufferReader.h" |
44 #include "platform/image-decoders/gif/GIFImageDecoder.h" | 44 #include "platform/image-decoders/gif/GIFImageDecoder.h" |
45 #include "wtf/Allocator.h" | 45 #include "wtf/Allocator.h" |
46 #include "wtf/Noncopyable.h" | 46 #include "wtf/Noncopyable.h" |
47 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
48 #include <memory> | 48 #include <memory> |
49 | 49 |
50 #define MAX_DICTIONARY_ENTRY_BITS 12 | 50 #define MAX_DICTIONARY_ENTRY_BITS 12 |
51 #define MAX_DICTIONARY_ENTRIES 4096 // 2^MAX_DICTIONARY_ENTRY_BITS | 51 #define MAX_DICTIONARY_ENTRIES 4096 // 2^MAX_DICTIONARY_ENTRY_BITS |
52 #define MAX_COLORS 256 | 52 #define MAX_COLORS 256 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void clearDecodeState() { m_lzwContext.reset(); } | 249 void clearDecodeState() { m_lzwContext.reset(); } |
250 const GIFColorMap& localColorMap() const { return m_localColorMap; } | 250 const GIFColorMap& localColorMap() const { return m_localColorMap; } |
251 GIFColorMap& localColorMap() { return m_localColorMap; } | 251 GIFColorMap& localColorMap() { return m_localColorMap; } |
252 | 252 |
253 private: | 253 private: |
254 int m_frameId; | 254 int m_frameId; |
255 unsigned m_xOffset; | 255 unsigned m_xOffset; |
256 unsigned m_yOffset; // With respect to "screen" origin. | 256 unsigned m_yOffset; // With respect to "screen" origin. |
257 unsigned m_width; | 257 unsigned m_width; |
258 unsigned m_height; | 258 unsigned m_height; |
259 size_t | 259 size_t m_transparentPixel; // Index of transparent pixel. Value is kNotFound |
260 m_transparentPixel; // Index of transparent pixel. Value is kNotFound if
there is no transparent pixel. | 260 // if there is no transparent pixel. |
261 blink::ImageFrame::DisposalMethod | 261 blink::ImageFrame::DisposalMethod |
262 m_disposalMethod; // Restore to background, leave in place, etc. | 262 m_disposalMethod; // Restore to background, leave in place, etc. |
263 int m_dataSize; | 263 int m_dataSize; |
264 | 264 |
265 bool m_progressiveDisplay; // If true, do Haeberli interlace hack. | 265 bool m_progressiveDisplay; // If true, do Haeberli interlace hack. |
266 bool m_interlaced; // True, if scanlines arrive interlaced order. | 266 bool m_interlaced; // True, if scanlines arrive interlaced order. |
267 | 267 |
268 unsigned | 268 unsigned m_delayTime; // Display time, in milliseconds, for this image in a |
269 m_delayTime; // Display time, in milliseconds, for this image in a multi-
image GIF. | 269 // multi-image GIF. |
270 | 270 |
271 std::unique_ptr<GIFLZWContext> m_lzwContext; | 271 std::unique_ptr<GIFLZWContext> m_lzwContext; |
272 Vector<GIFLZWBlock> m_lzwBlocks; // LZW blocks for this frame. | 272 Vector<GIFLZWBlock> m_lzwBlocks; // LZW blocks for this frame. |
273 GIFColorMap m_localColorMap; | 273 GIFColorMap m_localColorMap; |
274 | 274 |
275 size_t m_currentLzwBlock; | 275 size_t m_currentLzwBlock; |
276 bool m_isComplete; | 276 bool m_isComplete; |
277 bool m_isHeaderDefined; | 277 bool m_isHeaderDefined; |
278 bool m_isDataSizeDefined; | 278 bool m_isDataSizeDefined; |
279 }; | 279 }; |
(...skipping 20 matching lines...) Expand all Loading... |
300 ~GIFImageReader() {} | 300 ~GIFImageReader() {} |
301 | 301 |
302 void setData(PassRefPtr<blink::SegmentReader> data) { m_data = data; } | 302 void setData(PassRefPtr<blink::SegmentReader> data) { m_data = data; } |
303 bool parse(blink::GIFImageDecoder::GIFParseQuery); | 303 bool parse(blink::GIFImageDecoder::GIFParseQuery); |
304 bool decode(size_t frameIndex); | 304 bool decode(size_t frameIndex); |
305 | 305 |
306 size_t imagesCount() const { | 306 size_t imagesCount() const { |
307 if (m_frames.isEmpty()) | 307 if (m_frames.isEmpty()) |
308 return 0; | 308 return 0; |
309 | 309 |
310 // This avoids counting an empty frame when the file is truncated right afte
r | 310 // This avoids counting an empty frame when the file is truncated right |
311 // GIFControlExtension but before GIFImageHeader. | 311 // after GIFControlExtension but before GIFImageHeader. |
312 // FIXME: This extra complexity is not necessary and we should just report m
_frames.size(). | 312 // FIXME: This extra complexity is not necessary and we should just report |
| 313 // m_frames.size(). |
313 return m_frames.last()->isHeaderDefined() ? m_frames.size() | 314 return m_frames.last()->isHeaderDefined() ? m_frames.size() |
314 : m_frames.size() - 1; | 315 : m_frames.size() - 1; |
315 } | 316 } |
316 int loopCount() const { return m_loopCount; } | 317 int loopCount() const { return m_loopCount; } |
317 | 318 |
318 const GIFColorMap& globalColorMap() const { return m_globalColorMap; } | 319 const GIFColorMap& globalColorMap() const { return m_globalColorMap; } |
319 | 320 |
320 const GIFFrameContext* frameContext(size_t index) const { | 321 const GIFFrameContext* frameContext(size_t index) const { |
321 return index < m_frames.size() ? m_frames[index].get() : 0; | 322 return index < m_frames.size() ? m_frames[index].get() : 0; |
322 } | 323 } |
(...skipping 10 matching lines...) Expand all Loading... |
333 | 334 |
334 void addFrameIfNecessary(); | 335 void addFrameIfNecessary(); |
335 bool currentFrameIsFirstFrame() const { | 336 bool currentFrameIsFirstFrame() const { |
336 return m_frames.isEmpty() || | 337 return m_frames.isEmpty() || |
337 (m_frames.size() == 1u && !m_frames[0]->isComplete()); | 338 (m_frames.size() == 1u && !m_frames[0]->isComplete()); |
338 } | 339 } |
339 | 340 |
340 blink::GIFImageDecoder* m_client; | 341 blink::GIFImageDecoder* m_client; |
341 | 342 |
342 // Parsing state machine. | 343 // Parsing state machine. |
343 GIFState m_state; // Current decoder master state. | 344 GIFState m_state; // Current decoder master state. |
344 size_t | 345 size_t m_bytesToConsume; // Number of bytes to consume for next stage of |
345 m_bytesToConsume; // Number of bytes to consume for next stage of parsing
. | 346 // parsing. |
346 size_t m_bytesRead; // Number of bytes processed. | 347 size_t m_bytesRead; // Number of bytes processed. |
347 | 348 |
348 // Global (multi-image) state. | 349 // Global (multi-image) state. |
349 int m_version; // Either 89 for GIF89 or 87 for GIF87. | 350 int m_version; // Either 89 for GIF89 or 87 for GIF87. |
350 unsigned m_screenWidth; // Logical screen width & height. | 351 unsigned m_screenWidth; // Logical screen width & height. |
351 unsigned m_screenHeight; | 352 unsigned m_screenHeight; |
352 bool m_sentSizeToClient; | 353 bool m_sentSizeToClient; |
353 GIFColorMap m_globalColorMap; | 354 GIFColorMap m_globalColorMap; |
354 int m_loopCount; // Netscape specific extension block to control the number o
f animation loops a GIF renders. | 355 int m_loopCount; // Netscape specific extension block to control the number |
| 356 // of animation loops a GIF renders. |
355 | 357 |
356 Vector<std::unique_ptr<GIFFrameContext>> m_frames; | 358 Vector<std::unique_ptr<GIFFrameContext>> m_frames; |
357 | 359 |
358 RefPtr<blink::SegmentReader> m_data; | 360 RefPtr<blink::SegmentReader> m_data; |
359 bool m_parseCompleted; | 361 bool m_parseCompleted; |
360 }; | 362 }; |
361 | 363 |
362 #endif | 364 #endif |
OLD | NEW |