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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 bool isComplete() const { return m_isComplete; } | 206 bool isComplete() const { return m_isComplete; } |
207 void setComplete() { m_isComplete = true; } | 207 void setComplete() { m_isComplete = true; } |
208 bool isHeaderDefined() const { return m_isHeaderDefined; } | 208 bool isHeaderDefined() const { return m_isHeaderDefined; } |
209 void setHeaderDefined() { m_isHeaderDefined = true; } | 209 void setHeaderDefined() { m_isHeaderDefined = true; } |
210 bool isDataSizeDefined() const { return m_isDataSizeDefined; } | 210 bool isDataSizeDefined() const { return m_isDataSizeDefined; } |
211 void setDataSize(int size) | 211 void setDataSize(int size) |
212 { | 212 { |
213 datasize = size; | 213 datasize = size; |
214 m_isDataSizeDefined = true; | 214 m_isDataSizeDefined = true; |
215 } | 215 } |
216 | 216 void clearDecodeState() { m_lzwContext.clear(); } |
217 private: | 217 private: |
218 OwnPtr<GIFLZWContext> m_lzwContext; | 218 OwnPtr<GIFLZWContext> m_lzwContext; |
219 Vector<GIFLZWBlock> m_lzwBlocks; // LZW blocks for this frame. | 219 Vector<GIFLZWBlock> m_lzwBlocks; // LZW blocks for this frame. |
220 size_t m_currentLzwBlock; | 220 size_t m_currentLzwBlock; |
221 bool m_isComplete; | 221 bool m_isComplete; |
222 bool m_isHeaderDefined; | 222 bool m_isHeaderDefined; |
223 bool m_isDataSizeDefined; | 223 bool m_isDataSizeDefined; |
224 }; | 224 }; |
225 | 225 |
226 class GIFImageReader { | 226 class GIFImageReader { |
227 WTF_MAKE_FAST_ALLOCATED; | 227 WTF_MAKE_FAST_ALLOCATED; |
228 public: | 228 public: |
229 GIFImageReader(WebCore::GIFImageDecoder* client = 0) | 229 GIFImageReader(WebCore::GIFImageDecoder* client = 0) |
230 : m_client(client) | 230 : m_client(client) |
231 , m_state(GIFType) | 231 , m_state(GIFType) |
232 , m_bytesToConsume(6) // Number of bytes for GIF type, either "GIF87a" o
r "GIF89a". | 232 , m_bytesToConsume(6) // Number of bytes for GIF type, either "GIF87a" o
r "GIF89a". |
233 , m_bytesRead(0) | 233 , m_bytesRead(0) |
234 , m_screenBgcolor(0) | |
235 , m_version(0) | 234 , m_version(0) |
236 , m_screenWidth(0) | 235 , m_screenWidth(0) |
237 , m_screenHeight(0) | 236 , m_screenHeight(0) |
238 , m_isGlobalColormapDefined(false) | 237 , m_isGlobalColormapDefined(false) |
239 , m_globalColormapPosition(0) | 238 , m_globalColormapPosition(0) |
240 , m_globalColormapSize(0) | 239 , m_globalColormapSize(0) |
241 , m_loopCount(cLoopCountNotSeen) | 240 , m_loopCount(cLoopCountNotSeen) |
242 , m_currentDecodingFrame(0) | |
243 , m_parseCompleted(false) | 241 , m_parseCompleted(false) |
244 { | 242 { |
245 } | 243 } |
246 | 244 |
247 ~GIFImageReader() | 245 ~GIFImageReader() |
248 { | 246 { |
249 } | 247 } |
250 | 248 |
251 void setData(PassRefPtr<WebCore::SharedBuffer> data) { m_data = data; } | 249 void setData(PassRefPtr<WebCore::SharedBuffer> data) { m_data = data; } |
252 // FIXME: haltAtFrame should be size_t. | 250 bool parse(WebCore::GIFImageDecoder::GIFParseQuery); |
253 bool decode(WebCore::GIFImageDecoder::GIFQuery, unsigned haltAtFrame); | 251 bool decode(size_t frameIndex); |
254 | 252 |
255 size_t imagesCount() const | 253 size_t imagesCount() const |
256 { | 254 { |
257 if (m_frames.isEmpty()) | 255 if (m_frames.isEmpty()) |
258 return 0; | 256 return 0; |
259 | 257 |
260 // This avoids counting an empty frame when the file is truncated right
after | 258 // This avoids counting an empty frame when the file is truncated right
after |
261 // GIFControlExtension but before GIFImageHeader. | 259 // GIFControlExtension but before GIFImageHeader. |
262 // FIXME: This extra complexity is not necessary and we should just repo
rt m_frames.size(). | 260 // FIXME: This extra complexity is not necessary and we should just repo
rt m_frames.size(). |
263 return m_frames.last()->isHeaderDefined() ? m_frames.size() : m_frames.s
ize() - 1; | 261 return m_frames.last()->isHeaderDefined() ? m_frames.size() : m_frames.s
ize() - 1; |
(...skipping 18 matching lines...) Expand all Loading... |
282 return frame->isLocalColormapDefined ? frame->localColormapSize : 0; | 280 return frame->isLocalColormapDefined ? frame->localColormapSize : 0; |
283 } | 281 } |
284 | 282 |
285 const GIFFrameContext* frameContext(size_t index) const | 283 const GIFFrameContext* frameContext(size_t index) const |
286 { | 284 { |
287 return index < m_frames.size() ? m_frames[index].get() : 0; | 285 return index < m_frames.size() ? m_frames[index].get() : 0; |
288 } | 286 } |
289 | 287 |
290 bool parseCompleted() const { return m_parseCompleted; } | 288 bool parseCompleted() const { return m_parseCompleted; } |
291 | 289 |
| 290 void clearDecodeState(size_t index) { m_frames[index]->clearDecodeState(); } |
| 291 |
292 private: | 292 private: |
293 bool parse(size_t dataPosition, size_t len, bool parseSizeOnly); | 293 bool parseData(size_t dataPosition, size_t len, WebCore::GIFImageDecoder::GI
FParseQuery); |
294 void setRemainingBytes(size_t); | 294 void setRemainingBytes(size_t); |
295 | 295 |
296 const unsigned char* data(size_t dataPosition) const | 296 const unsigned char* data(size_t dataPosition) const |
297 { | 297 { |
298 return reinterpret_cast<const unsigned char*>(m_data->data()) + dataPosi
tion; | 298 return reinterpret_cast<const unsigned char*>(m_data->data()) + dataPosi
tion; |
299 } | 299 } |
300 | 300 |
301 void addFrameIfNecessary(); | 301 void addFrameIfNecessary(); |
302 bool currentFrameIsFirstFrame() const | 302 bool currentFrameIsFirstFrame() const |
303 { | 303 { |
304 return m_frames.isEmpty() || (m_frames.size() == 1u && !m_frames[0]->isC
omplete()); | 304 return m_frames.isEmpty() || (m_frames.size() == 1u && !m_frames[0]->isC
omplete()); |
305 } | 305 } |
306 | 306 |
307 WebCore::GIFImageDecoder* m_client; | 307 WebCore::GIFImageDecoder* m_client; |
308 | 308 |
309 // Parsing state machine. | 309 // Parsing state machine. |
310 GIFState m_state; // Current decoder master state. | 310 GIFState m_state; // Current decoder master state. |
311 size_t m_bytesToConsume; // Number of bytes to consume for next stage of par
sing. | 311 size_t m_bytesToConsume; // Number of bytes to consume for next stage of par
sing. |
312 size_t m_bytesRead; // Number of bytes processed. | 312 size_t m_bytesRead; // Number of bytes processed. |
313 | 313 |
314 // Global (multi-image) state. | 314 // Global (multi-image) state. |
315 int m_screenBgcolor; // Logical screen background color. | |
316 int m_version; // Either 89 for GIF89 or 87 for GIF87. | 315 int m_version; // Either 89 for GIF89 or 87 for GIF87. |
317 unsigned m_screenWidth; // Logical screen width & height. | 316 unsigned m_screenWidth; // Logical screen width & height. |
318 unsigned m_screenHeight; | 317 unsigned m_screenHeight; |
319 bool m_isGlobalColormapDefined; | 318 bool m_isGlobalColormapDefined; |
320 size_t m_globalColormapPosition; // (3* MAX_COLORS in size) Default colormap
if local not supplied, 3 bytes for each color. | 319 size_t m_globalColormapPosition; // (3* MAX_COLORS in size) Default colormap
if local not supplied, 3 bytes for each color. |
321 int m_globalColormapSize; // Size of global colormap array. | 320 int m_globalColormapSize; // Size of global colormap array. |
322 int m_loopCount; // Netscape specific extension block to control the number
of animation loops a GIF renders. | 321 int m_loopCount; // Netscape specific extension block to control the number
of animation loops a GIF renders. |
323 | 322 |
324 Vector<OwnPtr<GIFFrameContext> > m_frames; | 323 Vector<OwnPtr<GIFFrameContext> > m_frames; |
325 size_t m_currentDecodingFrame; | |
326 | 324 |
327 RefPtr<WebCore::SharedBuffer> m_data; | 325 RefPtr<WebCore::SharedBuffer> m_data; |
328 bool m_parseCompleted; | 326 bool m_parseCompleted; |
329 }; | 327 }; |
330 | 328 |
331 #endif | 329 #endif |
OLD | NEW |