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

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

Issue 2045293002: Add support for multiple frames in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Cache all frames in the GM Created 4 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
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 "SkCodecAnimation.h"
9 #include "SkColorSpace.h" 10 #include "SkColorSpace.h"
10 #include "SkColorTable.h" 11 #include "SkColorTable.h"
11 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
12 #include "SkSwizzler.h" 13 #include "SkSwizzler.h"
14 #include "../private/SkTArray.h"
13 15
14 struct GifFileType; 16 struct GifFileType;
15 struct SavedImage; 17 struct SavedImage;
16 18
17 /* 19 /*
18 * 20 *
19 * This class implements the decoding for gif images 21 * This class implements the decoding for gif images
20 * 22 *
21 */ 23 */
22 class SkGifCodec : public SkCodec { 24 class SkGifCodec : public SkCodec {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 /* 59 /*
58 * Performs the full gif decode 60 * Performs the full gif decode
59 */ 61 */
60 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, 62 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&,
61 SkPMColor*, int*, int*) override; 63 SkPMColor*, int*, int*) override;
62 64
63 SkEncodedFormat onGetEncodedFormat() const override { 65 SkEncodedFormat onGetEncodedFormat() const override {
64 return kGIF_SkEncodedFormat; 66 return kGIF_SkEncodedFormat;
65 } 67 }
66 68
67 bool onRewind() override;
68
69 uint64_t onGetFillValue(const SkImageInfo&) const override; 69 uint64_t onGetFillValue(const SkImageInfo&) const override;
70 70
71 int onOutputScanline(int inputScanline) const override; 71 size_t onGetFrameCount() override {
72 return (size_t) fFrameInfos.count();
73 }
72 74
75 size_t onGetRequiredFrame(size_t) override;
76
77 size_t onGetFrameDuration(size_t) override;
73 private: 78 private:
74 79
75 /*
76 * A gif can contain multiple image frames. We will only decode the first
77 * frame. This function reads up to the first image frame, processing
78 * transparency and/or animation information that comes before the image
79 * data.
80 *
81 * @param gif Pointer to the library type that manages the gif decode
82 * @param transIndex This call will set the transparent index based on the
83 * extension data.
84 */
85 static Result ReadUpToFirstImage(GifFileType* gif, uint32_t* transIndex);
86
87 /* 80 /*
88 * A gif may contain many image frames, all of different sizes. 81 * A gif may contain many image frames, all of different sizes.
89 * This function checks if the gif dimensions are valid, based on the frame 82 * This function checks if the gif dimensions are valid, based on the frame
90 * dimensions, and corrects the gif dimensions if necessary. 83 * dimensions, and corrects the gif dimensions if necessary.
91 * 84 *
92 * @param gif Pointer to the library type that manages the gif decode 85 * @param gif Pointer to the library type that manages the gif decode
93 * @param size Size of the image that we will decode. 86 * @param size Size of the image that we will decode.
94 * Will be set by this function if the return value is tru e. 87 * Will be set by this function if the return value is tru e.
95 * @param frameRect Contains the dimenions and offset of the first image fr ame.
96 * Will be set by this function if the return value is tru e.
97 * 88 *
98 * @return true on success, false otherwise 89 * @return true on success, false otherwise
99 */ 90 */
100 static bool GetDimensions(GifFileType* gif, SkISize* size, SkIRect* frameRe ct); 91 static bool GetDimensions(GifFileType* gif, SkISize* size);
101 92
102 /* 93 /*
103 * Initializes the color table that we will use for decoding. 94 * Initializes the color table that we will use for decoding.
104 * 95 *
105 * @param dstInfo Contains the requested dst color type. 96 * @param dstInfo Contains the requested dst color type.
106 * @param inputColorPtr Copies the encoded color table to the client's 97 * @param inputColorPtr Copies the encoded color table to the client's
107 * input color table if the client requests kIndex8. 98 * input color table if the client requests kIndex8.
108 * @param inputColorCount If the client requests kIndex8, sets 99 * @param inputColorCount If the client requests kIndex8, sets
109 * inputColorCount to 256. Since gifs always 100 * inputColorCount to 256. Since gifs always
110 * contain 8-bit indices, we need a 256 entry color 101 * contain 8-bit indices, we need a 256 entry color
111 * table to ensure that indexing is always in 102 * table to ensure that indexing is always in
112 * bounds. 103 * bounds.
113 */ 104 */
114 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr, 105 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr,
115 int* inputColorCount); 106 int* inputColorCount);
116 107
117 /* 108 /*
118 * Checks for invalid inputs and calls setFrameDimensions(), and 109 * Checks for invalid inputs and calls setFrameDimensions(), and
119 * initializeColorTable() in the proper sequence. 110 * initializeColorTable() in the proper sequence.
120 */ 111 */
121 Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, 112 Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr,
122 int* inputColorCount, const Options& opts); 113 int* inputColorCount, const Options& opts);
123 114
124 /* 115 /*
125 * Initializes the swizzler. 116 * Recursive function to decode a frame.
126 * 117 *
127 * @param dstInfo Output image information. Dimensions may have been 118 * If !opts.fHasPriorFrame, and the frame is not independent, it will first
128 * adjusted if the image frame size does not match the size 119 * decode the frame that it depends on.
129 * indicated in the header.
130 * @param options Informs the swizzler if destination memory is zero initia lized.
131 * Contains subset information.
132 */ 120 */
133 void initializeSwizzler(const SkImageInfo& dstInfo, 121 void decodeFrame(const SkImageInfo& dstInfo, void* pixels, size_t dstRowByte s,
134 const Options& options); 122 const Options& opts);
135 123
136 SkSampler* getSampler(bool createIfNecessary) override { 124 // FIXME: Old patch deletes this. Was that really necessary?
137 SkASSERT(fSwizzler); 125 // void initializeSwizzler(const SkImageInfo& dstInfo,
138 return fSwizzler; 126 // const Options& options);
139 }
140
141 /*
142 * @return true if the read is successful and false if the read fails.
143 */
144 bool readRow();
145
146 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opts ,
147 SkPMColor inputColorPtr[], int* inputColorCount) override;
148
149 int onGetScanlines(void* dst, int count, size_t rowBytes) override;
150
151 bool onSkipScanlines(int count) override;
152
153 /*
154 * For a scanline decode of "count" lines, this function indicates how
155 * many of the "count" lines should be skipped until we reach the top of
156 * the image frame and how many of the "count" lines are actually inside
157 * the image frame.
158 *
159 * @param count The number of scanlines requested.
160 * @param rowsBeforeFrame Output variable. The number of lines before
161 * we reach the top of the image frame.
162 * @param rowsInFrame Output variable. The number of lines to decode
163 * inside the image frame.
164 */
165 void handleScanlineFrame(int count, int* rowsBeforeFrame, int* rowsInFrame);
166
167 SkScanlineOrder onGetScanlineOrder() const override;
168 127
169 /* 128 /*
170 * This function cleans up the gif object after the decode completes 129 * This function cleans up the gif object after the decode completes
171 * It is used in a SkAutoTCallIProc template 130 * It is used in a SkAutoTCallIProc template
172 */ 131 */
173 static void CloseGif(GifFileType* gif); 132 static void CloseGif(GifFileType* gif);
174 133
175 /* 134 /*
176 * Frees any extension data used in the decode 135 * Frees any extension data used in the decode
177 * Used in a SkAutoTCallVProc 136 * Used in a SkAutoTCallVProc
178 */ 137 */
179 static void FreeExtension(SavedImage* image); 138 static void FreeExtension(SavedImage* image);
180 139
181 /* 140 /*
182 * Creates an instance of the decoder 141 * Creates an instance of the decoder
183 * Called only by NewFromStream 142 * Called only by NewFromStream
184 * 143 *
185 * @param info contains properties of the encoded data 144 * @param info contains properties of the encoded data
186 * @param stream the stream of image data 145 * @param stream the stream of image data
187 * @param gif pointer to library type that manages gif decode 146 * @param gif pointer to library type that manages gif decode
188 * takes ownership 147 * takes ownership
189 * @param transIndex The transparent index. An invalid value 148 * @param transIndex The transparent index. An invalid value
190 * indicates that there is no transparent index. 149 * indicates that there is no transparent index.
191 */ 150 */
192 SkGifCodec(int width, int height, const SkEncodedInfo& info, SkStream* strea m, 151 SkGifCodec(int width, int height, const SkEncodedInfo& info, SkStream* strea m,
193 GifFileType* gif, uint32_t transIndex, const SkIRect& frameRect, boo l frameIsSubset); 152 GifFileType* gif, uint32_t transIndex);
153
154
155 struct FrameInfo : public SkCodecAnimation::FrameInfo {
156 uint32_t fTransIndex;
157 };
194 158
195 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned 159 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned
196 SkAutoTDeleteArray<uint8_t> fSrcBuffer; 160 SkAutoTDeleteArray<uint8_t> fSrcBuffer;
197 const SkIRect fFrameRect;
198 const uint32_t fTransIndex;
199 uint32_t fFillIndex; 161 uint32_t fFillIndex;
200 const bool fFrameIsSubset;
201 SkAutoTDelete<SkSwizzler> fSwizzler; 162 SkAutoTDelete<SkSwizzler> fSwizzler;
202 SkAutoTUnref<SkColorTable> fColorTable; 163 SkAutoTUnref<SkColorTable> fColorTable;
164 SkTArray<FrameInfo> fFrameInfos;
203 165
204 typedef SkCodec INHERITED; 166 typedef SkCodec INHERITED;
205 }; 167 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698