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 29 matching lines...) Expand all Loading... | |
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 cl ass into this old C decoder, |
42 // so we will too. | 42 // so we will too. |
43 #include "core/platform/SharedBuffer.h" | 43 #include "core/platform/SharedBuffer.h" |
44 #include "core/platform/image-decoders/gif/GIFImageDecoder.h" | 44 #include "core/platform/image-decoders/gif/GIFImageDecoder.h" |
45 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
46 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
47 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
48 | 48 |
49 #define MAX_LZW_BITS 12 | 49 #define MAX_LZW_BITS 12 |
50 #define MAX_BYTES 4097 /* 2^MAX_LZW_BITS+1 */ | 50 #define MAX_BYTES 4097 /* 2^MAX_LZW_BITS+1 */ |
Peter Kasting
2013/08/29 23:46:25
Of the uses of this value in this header, all but
Alpha Left Google
2013/08/30 23:25:36
Done.
| |
51 #define MAX_COLORS 256 | 51 #define MAX_COLORS 256 |
52 #define GIF_COLORS 3 | 52 #define GIF_COLORS 3 |
Peter Kasting
2013/08/29 23:46:25
Nit: While here, can you name this BYTES_PER_COLOR
Alpha Left Google
2013/08/30 23:25:36
Done.
| |
53 | 53 |
54 const int cLoopCountNotSeen = -2; | 54 const int cLoopCountNotSeen = -2; |
55 | 55 |
56 // List of possible parsing states. | 56 // List of possible parsing states. |
57 enum GIFState { | 57 enum GIFState { |
58 GIFType, | 58 GIFType, |
59 GIFGlobalHeader, | 59 GIFGlobalHeader, |
60 GIFGlobalColormap, | 60 GIFGlobalColormap, |
61 GIFImageStart, | 61 GIFImageStart, |
62 GIFImageHeader, | 62 GIFImageHeader, |
63 GIFImageColormap, | 63 GIFImageColormap, |
64 GIFImageBody, | 64 GIFImageBody, |
65 GIFLZWStart, | 65 GIFLZWStart, |
66 GIFLZW, | 66 GIFLZW, |
67 GIFSubBlock, | 67 GIFSubBlock, |
68 GIFExtension, | 68 GIFExtension, |
69 GIFControlExtension, | 69 GIFControlExtension, |
70 GIFConsumeBlock, | 70 GIFConsumeBlock, |
71 GIFSkipBlock, | 71 GIFSkipBlock, |
72 GIFDone, | 72 GIFDone, |
73 GIFCommentExtension, | 73 GIFCommentExtension, |
74 GIFApplicationExtension, | 74 GIFApplicationExtension, |
75 GIFNetscapeExtensionBlock, | 75 GIFNetscapeExtensionBlock, |
76 GIFConsumeNetscapeExtension, | 76 GIFConsumeNetscapeExtension, |
77 GIFConsumeComment | 77 GIFConsumeComment |
78 }; | 78 }; |
79 | 79 |
80 struct GIFFrameContext; | 80 struct GIFFrameContext; |
81 typedef Vector<unsigned char> GIFRow; | |
Peter Kasting
2013/08/29 23:46:25
Nit: Maybe instead of declaring this here we can d
Alpha Left Google
2013/08/30 23:25:36
Done.
| |
81 | 82 |
82 // LZW decoder state machine. | 83 // LZW decoder state machine. |
83 class GIFLZWContext { | 84 class GIFLZWContext { |
84 WTF_MAKE_FAST_ALLOCATED; | 85 WTF_MAKE_FAST_ALLOCATED; |
85 public: | 86 public: |
86 GIFLZWContext(WebCore::GIFImageDecoder* client, const GIFFrameContext* frame Context) | 87 GIFLZWContext(WebCore::GIFImageDecoder* client, const GIFFrameContext* frame Context) |
87 : codesize(0) | 88 : codesize(0) |
88 , codemask(0) | 89 , codemask(0) |
89 , clearCode(0) | 90 , clearCode(0) |
90 , avail(0) | 91 , avail(0) |
91 , oldcode(0) | 92 , oldcode(0) |
92 , firstchar(0) | 93 , firstchar(0) |
93 , bits(0) | 94 , bits(0) |
94 , datum(0) | 95 , datum(0) |
95 , ipass(0) | 96 , ipass(0) |
96 , irow(0) | 97 , irow(0) |
97 , rowsRemaining(0) | 98 , rowsRemaining(0) |
98 , stackp(0) | |
99 , rowIter(0) | 99 , rowIter(0) |
100 , m_client(client) | 100 , m_client(client) |
101 , m_frameContext(frameContext) | 101 , m_frameContext(frameContext) |
102 { } | 102 { } |
103 | 103 |
104 bool prepareToDecode(); | 104 bool prepareToDecode(); |
105 bool outputRow(); | 105 bool outputRow(GIFRow::const_iterator rowBegin); |
106 bool doLZW(const unsigned char* block, size_t bytesInBlock); | 106 bool doLZW(const unsigned char* block, size_t bytesInBlock); |
107 bool hasRemainingRows() { return rowsRemaining; } | 107 bool hasRemainingRows() { return rowsRemaining; } |
108 | 108 |
109 private: | 109 private: |
110 // LZW decoding states and output states. | 110 // LZW decoding states and output states. |
111 int codesize; | 111 int codesize; |
112 int codemask; | 112 int codemask; |
113 int clearCode; // Codeword used to trigger dictionary reset. | 113 int clearCode; // Codeword used to trigger dictionary reset. |
114 int avail; // Index of next available slot in dictionary. | 114 int avail; // Index of next available slot in dictionary. |
115 int oldcode; | 115 int oldcode; |
116 unsigned char firstchar; | 116 unsigned char firstchar; |
117 int bits; // Number of unread bits in "datum". | 117 int bits; // Number of unread bits in "datum". |
118 int datum; // 32-bit input buffer. | 118 int datum; // 32-bit input buffer. |
119 int ipass; // Interlace pass; Ranges 1-4 if interlaced. | 119 int ipass; // Interlace pass; Ranges 1-4 if interlaced. |
120 size_t irow; // Current output row, starting at zero. | 120 size_t irow; // Current output row, starting at zero. |
121 size_t rowsRemaining; // Rows remaining to be output. | 121 size_t rowsRemaining; // Rows remaining to be output. |
122 | 122 |
123 unsigned short prefix[MAX_BYTES]; | 123 unsigned short prefix[MAX_BYTES]; |
Peter Kasting
2013/08/29 23:46:25
These three arrays don't actually need to be MAX_B
Alpha Left Google
2013/08/30 23:25:36
Done.
| |
124 unsigned char suffix[MAX_BYTES]; | 124 unsigned char suffix[MAX_BYTES]; |
125 unsigned char stack[MAX_BYTES]; | 125 unsigned short suffixLength[MAX_BYTES]; |
126 Vector<unsigned char> rowBuffer; // Single scanline temporary buffer. | 126 GIFRow rowBuffer; // Single scanline temporary buffer. |
127 | 127 GIFRow::iterator rowIter; |
128 size_t stackp; // Current stack pointer. | |
129 Vector<unsigned char>::iterator rowIter; | |
130 | 128 |
131 // Initialized during construction and read-only. | 129 // Initialized during construction and read-only. |
132 WebCore::GIFImageDecoder* m_client; | 130 WebCore::GIFImageDecoder* m_client; |
133 const GIFFrameContext* m_frameContext; | 131 const GIFFrameContext* m_frameContext; |
134 }; | 132 }; |
135 | 133 |
136 // Data structure for one LZW block. | 134 // Data structure for one LZW block. |
137 struct GIFLZWBlock { | 135 struct GIFLZWBlock { |
138 WTF_MAKE_FAST_ALLOCATED; | 136 WTF_MAKE_FAST_ALLOCATED; |
139 public: | 137 public: |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 GIFColorMap m_globalColorMap; | 356 GIFColorMap m_globalColorMap; |
359 int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders. | 357 int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders. |
360 | 358 |
361 Vector<OwnPtr<GIFFrameContext> > m_frames; | 359 Vector<OwnPtr<GIFFrameContext> > m_frames; |
362 | 360 |
363 RefPtr<WebCore::SharedBuffer> m_data; | 361 RefPtr<WebCore::SharedBuffer> m_data; |
364 bool m_parseCompleted; | 362 bool m_parseCompleted; |
365 }; | 363 }; |
366 | 364 |
367 #endif | 365 #endif |
OLD | NEW |