Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: Source/core/platform/image-decoders/gif/GIFImageReader.h

Issue 23646005: Improve GIF decoding performance (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: test data moved to Source/core/platform/image-decoders/testing Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 28 matching lines...) Expand all
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 cl ass into this old C decoder,
42 // so we will too. 42 // so we will too.
43 #include "platform/SharedBuffer.h" 43 #include "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_DICTIONARY_ENTRY_BITS 12
50 #define MAX_BYTES 4097 /* 2^MAX_LZW_BITS+1 */ 50 #define MAX_DICTIONARY_ENTRIES 4096 // 2^MAX_DICTIONARY_ENTRY_BITS
51 #define MAX_COLORS 256 51 #define MAX_COLORS 256
52 #define GIF_COLORS 3 52 #define BYTES_PER_COLORMAP_ENTRY 3
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,
(...skipping 25 matching lines...) Expand all
88 , codemask(0) 88 , codemask(0)
89 , clearCode(0) 89 , clearCode(0)
90 , avail(0) 90 , avail(0)
91 , oldcode(0) 91 , oldcode(0)
92 , firstchar(0) 92 , firstchar(0)
93 , bits(0) 93 , bits(0)
94 , datum(0) 94 , datum(0)
95 , ipass(0) 95 , ipass(0)
96 , irow(0) 96 , irow(0)
97 , rowsRemaining(0) 97 , rowsRemaining(0)
98 , stackp(0)
99 , rowIter(0) 98 , rowIter(0)
100 , m_client(client) 99 , m_client(client)
101 , m_frameContext(frameContext) 100 , m_frameContext(frameContext)
102 { } 101 { }
103 102
104 bool prepareToDecode(); 103 bool prepareToDecode();
105 bool outputRow(); 104 bool outputRow(GIFRow::const_iterator rowBegin);
106 bool doLZW(const unsigned char* block, size_t bytesInBlock); 105 bool doLZW(const unsigned char* block, size_t bytesInBlock);
107 bool hasRemainingRows() { return rowsRemaining; } 106 bool hasRemainingRows() { return rowsRemaining; }
108 107
109 private: 108 private:
110 // LZW decoding states and output states. 109 // LZW decoding states and output states.
111 int codesize; 110 int codesize;
112 int codemask; 111 int codemask;
113 int clearCode; // Codeword used to trigger dictionary reset. 112 int clearCode; // Codeword used to trigger dictionary reset.
114 int avail; // Index of next available slot in dictionary. 113 int avail; // Index of next available slot in dictionary.
115 int oldcode; 114 int oldcode;
116 unsigned char firstchar; 115 unsigned char firstchar;
117 int bits; // Number of unread bits in "datum". 116 int bits; // Number of unread bits in "datum".
118 int datum; // 32-bit input buffer. 117 int datum; // 32-bit input buffer.
119 int ipass; // Interlace pass; Ranges 1-4 if interlaced. 118 int ipass; // Interlace pass; Ranges 1-4 if interlaced.
120 size_t irow; // Current output row, starting at zero. 119 size_t irow; // Current output row, starting at zero.
121 size_t rowsRemaining; // Rows remaining to be output. 120 size_t rowsRemaining; // Rows remaining to be output.
122 121
123 unsigned short prefix[MAX_BYTES]; 122 unsigned short prefix[MAX_DICTIONARY_ENTRIES];
124 unsigned char suffix[MAX_BYTES]; 123 unsigned char suffix[MAX_DICTIONARY_ENTRIES];
125 unsigned char stack[MAX_BYTES]; 124 unsigned short suffixLength[MAX_DICTIONARY_ENTRIES];
126 Vector<unsigned char> rowBuffer; // Single scanline temporary buffer. 125 GIFRow rowBuffer; // Single scanline temporary buffer.
127 126 GIFRow::iterator rowIter;
128 size_t stackp; // Current stack pointer.
129 Vector<unsigned char>::iterator rowIter;
130 127
131 // Initialized during construction and read-only. 128 // Initialized during construction and read-only.
132 WebCore::GIFImageDecoder* m_client; 129 WebCore::GIFImageDecoder* m_client;
133 const GIFFrameContext* m_frameContext; 130 const GIFFrameContext* m_frameContext;
134 }; 131 };
135 132
136 // Data structure for one LZW block. 133 // Data structure for one LZW block.
137 struct GIFLZWBlock { 134 struct GIFLZWBlock {
138 WTF_MAKE_FAST_ALLOCATED; 135 WTF_MAKE_FAST_ALLOCATED;
139 public: 136 public:
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 GIFColorMap m_globalColorMap; 355 GIFColorMap m_globalColorMap;
359 int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders. 356 int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders.
360 357
361 Vector<OwnPtr<GIFFrameContext> > m_frames; 358 Vector<OwnPtr<GIFFrameContext> > m_frames;
362 359
363 RefPtr<WebCore::SharedBuffer> m_data; 360 RefPtr<WebCore::SharedBuffer> m_data;
364 bool m_parseCompleted; 361 bool m_parseCompleted;
365 }; 362 };
366 363
367 #endif 364 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698