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

Side by Side Diff: src/codec/SkCodec_libgif.h

Issue 1305123002: Scanline decoding for gifs (Closed) Base URL: https://skia.googlesource.com/skia.git@real-bmp-scan
Patch Set: Compile fix Created 5 years, 3 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
« no previous file with comments | « src/codec/SkCodecPriv.h ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkColorTable.h"
9 #include "SkImageInfo.h" 10 #include "SkImageInfo.h"
11 #include "SkScanlineDecoder.h"
12 #include "SkSwizzler.h"
10 13
11 #include "gif_lib.h" 14 #include "gif_lib.h"
12 15
13 /* 16 /*
14 * 17 *
15 * This class implements the decoding for gif images 18 * This class implements the decoding for gif images
16 * 19 *
17 */ 20 */
18 class SkGifCodec : public SkCodec { 21 class SkGifCodec : public SkCodec {
19 public: 22 public:
20 23
21 /* 24 /*
22 * Checks the start of the stream to see if the image is a gif 25 * Checks the start of the stream to see if the image is a gif
23 */ 26 */
24 static bool IsGif(SkStream*); 27 static bool IsGif(SkStream*);
25 28
26 /* 29 /*
27 * Assumes IsGif was called and returned true 30 * Assumes IsGif was called and returned true
28 * Creates a gif decoder 31 * Creates a gif decoder
29 * Reads enough of the stream to determine the image format 32 * Reads enough of the stream to determine the image format
30 */ 33 */
31 static SkCodec* NewFromStream(SkStream*); 34 static SkCodec* NewFromStream(SkStream*);
32 35
36 static SkScanlineDecoder* NewSDFromStream(SkStream* stream);
33 37
34 protected: 38 protected:
35 39
36 /* 40 /*
37 * Read enough of the stream to initialize the SkGifCodec. 41 * Read enough of the stream to initialize the SkGifCodec.
38 * Returns a bool representing success or failure. 42 * Returns a bool representing success or failure.
39 * 43 *
40 * @param codecOut 44 * @param codecOut
41 * If it returned true, and codecOut was not nullptr, 45 * If it returned true, and codecOut was not nullptr,
42 * codecOut will be set to a new SkGifCodec. 46 * codecOut will be set to a new SkGifCodec.
43 * 47 *
44 * @param gifOut 48 * @param gifOut
45 * If it returned true, and codecOut was nullptr, 49 * If it returned true, and codecOut was nullptr,
46 * gifOut must be non-nullptr and gifOut will be set to a new 50 * gifOut must be non-nullptr and gifOut will be set to a new
47 * GifFileType pointer. 51 * GifFileType pointer.
48 * 52 *
49 * @param stream 53 * @param stream
50 * Deleted on failure. 54 * Deleted on failure.
51 * codecOut will take ownership of it in the case where we created a codec. 55 * codecOut will take ownership of it in the case where we created a codec.
52 * Ownership is unchanged when we returned a gifOut. 56 * Ownership is unchanged when we returned a gifOut.
53 * 57 *
54 */ 58 */
55 static bool ReadHeader(SkStream* stream, SkCodec** codecOut, GifFileType** g ifOut); 59 static bool ReadHeader(SkStream* stream, SkCodec** codecOut,
60 GifFileType** gifOut);
56 61
57 /* 62 /*
58 * Initiates the gif decode 63 * Performs the full gif decode
59 */ 64 */
60 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, 65 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&,
61 SkPMColor*, int32_t*) override; 66 SkPMColor*, int32_t*) override;
62 67
63 SkEncodedFormat onGetEncodedFormat() const override { 68 SkEncodedFormat onGetEncodedFormat() const override {
64 return kGIF_SkEncodedFormat; 69 return kGIF_SkEncodedFormat;
65 } 70 }
66 71
67 bool onRewind() override; 72 bool onRewind() override;
68 73
69 private: 74 private:
70 75
71 /* 76 /*
77 * A gif can contain multiple image frames. We will only decode the first
78 * frame. This function reads up to the first image frame, processing
79 * transparency and/or animation information that comes before the image
80 * data.
81 *
82 * @param gif Pointer to the library type that manages the gif decode
83 * @param transIndex This call will set the transparent index based on the
84 * extension data.
85 */
86 static SkCodec::Result ReadUpToFirstImage(GifFileType* gif, uint32_t* trans Index);
87
88 /*
89 * A gif may contain many image frames, all of different sizes.
90 * This function checks if the frame dimensions are valid and corrects
91 * them if necessary. It then sets fFrameDims to the corrected
92 * dimensions.
93 *
94 * @param desc The image frame descriptor
95 */
96 bool setFrameDimensions(const GifImageDesc& desc);
97
98 /*
99 * Initializes the color table that we will use for decoding.
100 *
101 * @param dstInfo Contains the requested dst color type.
102 * @param inputColorPtr Copies the encoded color table to the client's
103 * input color table if the client requests kIndex8.
104 * @param inputColorCount If the client requests kIndex8, sets
105 * inputColorCount to 256. Since gifs always
106 * contain 8-bit indices, we need a 256 entry color
107 * table to ensure that indexing is always in
108 * bounds.
109 */
110 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr,
111 int* inputColorCount);
112
113 /*
114 * Checks for invalid inputs and calls rewindIfNeeded(), setFramDimensions(), and
115 * initializeColorTable() in the proper sequence.
116 */
117 SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* input ColorPtr,
118 int* inputColorCount, const Options& opts);
119
120 /*
121 * Initializes the swizzler.
122 *
123 * @param dstInfo Output image information. Dimensions may have been
124 * adjusted if the image frame size does not match the size
125 * indicated in the header.
126 * @param zeroInit Indicates if destination memory is zero initialized.
127 */
128 SkCodec::Result initializeSwizzler(const SkImageInfo& dstInfo,
129 ZeroInitialized zeroInit);
130
131 /*
132 * @return kSuccess if the read is successful and kIncompleteInput if the
133 * read fails.
134 */
135 SkCodec::Result readRow();
136
137 /*
72 * This function cleans up the gif object after the decode completes 138 * This function cleans up the gif object after the decode completes
73 * It is used in a SkAutoTCallIProc template 139 * It is used in a SkAutoTCallIProc template
74 */ 140 */
75 static void CloseGif(GifFileType* gif); 141 static void CloseGif(GifFileType* gif);
76 142
77 /* 143 /*
78 * Frees any extension data used in the decode 144 * Frees any extension data used in the decode
79 * Used in a SkAutoTCallVProc 145 * Used in a SkAutoTCallVProc
80 */ 146 */
81 static void FreeExtension(SavedImage* image); 147 static void FreeExtension(SavedImage* image);
82 148
83 /* 149 /*
84 * Creates an instance of the decoder 150 * Creates an instance of the decoder
85 * Called only by NewFromStream 151 * Called only by NewFromStream
86 * 152 *
87 * @param srcInfo contains the source width and height 153 * @param srcInfo contains the source width and height
88 * @param stream the stream of image data 154 * @param stream the stream of image data
89 * @param gif pointer to library type that manages gif decode 155 * @param gif pointer to library type that manages gif decode
90 * takes ownership 156 * takes ownership
157 * @param transIndex The transparent index. An invalid value
158 * indicates that there is no transparent index.
91 */ 159 */
92 SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif); 160 SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif, u int32_t transIndex);
93 161
94 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned 162 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned
163 SkAutoTDeleteArray<uint8_t> fSrcBuffer;
164 SkIRect fFrameDims;
165 const uint32_t fTransIndex;
166 uint32_t fFillIndex;
167 bool fFrameIsSubset;
168 SkAutoTDelete<SkSwizzler> fSwizzler;
169 SkAutoTUnref<SkColorTable> fColorTable;
170
171 friend class SkGifScanlineDecoder;
95 172
96 typedef SkCodec INHERITED; 173 typedef SkCodec INHERITED;
97 }; 174 };
OLDNEW
« no previous file with comments | « src/codec/SkCodecPriv.h ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698