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

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: Make kScanline_Mode test kOutOfOrder correctly in dm 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
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 transIndex This call will set the transparent index based on the
83 * extension data.
84 */
85 SkCodec::Result readUpToFirstImage(uint32_t* transIndex);
86
87 /*
88 * A gif may contain many image frames, all of different sizes.
89 * This function checks if the frame dimensions are valid and corrects
90 * them if necessary. It then sets fFrameDims to the corrected
91 * dimensions.
92 *
93 * @param desc The image frame descriptor
94 */
95 bool setFrameDimensions(const GifImageDesc& desc);
96
97 /*
98 * Initializes the color table that we will use for decoding.
99 *
100 * @param dstInfo Contains the requested dst color type.
101 * @param inputColorPtr Copies the encoded color table to the client's
102 * input color table if the client requests kIndex8.
103 * @param inputColorCount If the client requests kIndex8, sets
104 * inputColorCount to 256. Since gifs always
105 * contain 8-bit indices, we need a 256 entry color
106 * table to ensure that indexing is always in
107 * bounds.
108 * @param transIndex The transparent index. This is set in
109 * readUpToFirstImage(). An invalid value indicates
110 * that there is no transparent index.
111 */
112 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr,
113 int* inputColorCount, uint32_t transIndex);
114
115 /*
116 * Initializes the swizzler.
117 *
118 * @param dstInfo Output image information. Dimensions may have been
119 * adjusted if the image frame size does not match the size
120 * indicated in the header.
121 * @param zeroInit Indicates if destination memory is zero initialized.
122 */
123 SkCodec::Result initializeSwizzler(const SkImageInfo& dstInfo,
124 ZeroInitialized zeroInit);
125
126 /*
127 * @return kSuccess if the read is successful and kIncompleteInput if the
128 * read fails.
129 */
130 SkCodec::Result readRow();
131
132 /*
72 * This function cleans up the gif object after the decode completes 133 * This function cleans up the gif object after the decode completes
73 * It is used in a SkAutoTCallIProc template 134 * It is used in a SkAutoTCallIProc template
74 */ 135 */
75 static void CloseGif(GifFileType* gif); 136 static void CloseGif(GifFileType* gif);
76 137
77 /* 138 /*
78 * Frees any extension data used in the decode 139 * Frees any extension data used in the decode
79 * Used in a SkAutoTCallVProc 140 * Used in a SkAutoTCallVProc
80 */ 141 */
81 static void FreeExtension(SavedImage* image); 142 static void FreeExtension(SavedImage* image);
82 143
83 /* 144 /*
84 * Creates an instance of the decoder 145 * Creates an instance of the decoder
85 * Called only by NewFromStream 146 * Called only by NewFromStream
86 * 147 *
87 * @param srcInfo contains the source width and height 148 * @param srcInfo contains the source width and height
88 * @param stream the stream of image data 149 * @param stream the stream of image data
89 * @param gif pointer to library type that manages gif decode 150 * @param gif pointer to library type that manages gif decode
90 * takes ownership 151 * takes ownership
91 */ 152 */
92 SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif); 153 SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif);
93 154
94 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned 155 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned
156 SkAutoTDeleteArray<uint8_t> fSrcBuffer;
157 SkIRect fFrameDims;
158 uint32_t fFillIndex;
159 bool fFrameIsSubset;
160 SkAutoTDelete<SkSwizzler> fSwizzler;
161 SkAutoTUnref<SkColorTable> fColorTable;
162
163 friend class SkGifScanlineDecoder;
95 164
96 typedef SkCodec INHERITED; 165 typedef SkCodec INHERITED;
97 }; 166 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698