OLD | NEW |
---|---|
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 #ifndef SkBmpCodec_DEFINED | |
8 #define SkBmpCodec_DEFINED | |
7 | 9 |
8 #include "SkCodec.h" | 10 #include "SkCodec.h" |
9 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
10 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
11 #include "SkMaskSwizzler.h" | 13 #include "SkMaskSwizzler.h" |
12 #include "SkStream.h" | 14 #include "SkStream.h" |
13 #include "SkSwizzler.h" | 15 #include "SkSwizzler.h" |
14 #include "SkTypes.h" | 16 #include "SkTypes.h" |
msarett
2015/08/03 22:52:36
Changes:
Deleted functions that relate to specifi
| |
15 | 17 |
16 // TODO: rename SkCodec_libbmp files to SkBmpCodec | |
17 /* | 18 /* |
18 * | 19 * This class enables code sharing between its bmp codec subclasses. It is the |
scroggo
2015/08/04 16:16:46
nit: This second sentence seems unnecessarily word
msarett
2015/08/04 23:14:44
Yep agreed
msarett
2015/08/04 23:14:44
Done.
| |
19 * This class implements the decoding for bmp images | 20 * subclasses which perform the actual decoding. |
20 * | |
21 */ | 21 */ |
22 class SkBmpCodec : public SkCodec { | 22 class SkBmpCodec : public SkCodec { |
23 public: | 23 public: |
24 | 24 |
25 /* | 25 /* |
26 * | |
27 * Describes if rows of the input start at the top or bottom of the image | 26 * Describes if rows of the input start at the top or bottom of the image |
28 * | |
29 */ | 27 */ |
30 enum RowOrder { | 28 enum RowOrder { |
31 kTopDown_RowOrder, | 29 kTopDown_RowOrder, |
32 kBottomUp_RowOrder | 30 kBottomUp_RowOrder |
33 }; | 31 }; |
34 | 32 |
35 /* | 33 /* |
36 * | |
37 * Checks the start of the stream to see if the image is a bmp | 34 * Checks the start of the stream to see if the image is a bmp |
38 * | |
39 */ | 35 */ |
40 static bool IsBmp(SkStream*); | 36 static bool IsBmp(SkStream*); |
41 | 37 |
42 /* | 38 /* |
43 * | |
44 * Assumes IsBmp was called and returned true | 39 * Assumes IsBmp was called and returned true |
45 * Creates a bmp decoder | 40 * Creates a bmp decoder |
46 * Reads enough of the stream to determine the image format | 41 * Reads enough of the stream to determine the image format |
47 * | |
48 */ | 42 */ |
49 static SkCodec* NewFromStream(SkStream*); | 43 static SkCodec* NewFromStream(SkStream*); |
50 | 44 |
51 /* | 45 /* |
52 * | |
53 * Creates a bmp decoder for a bmp embedded in ico | 46 * Creates a bmp decoder for a bmp embedded in ico |
54 * Reads enough of the stream to determine the image format | 47 * Reads enough of the stream to determine the image format |
55 * | |
56 */ | 48 */ |
57 static SkCodec* NewFromIco(SkStream*); | 49 static SkCodec* NewFromIco(SkStream*); |
58 | 50 |
59 protected: | 51 protected: |
60 | 52 |
61 /* | 53 SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, |
62 * | 54 RowOrder rowOrder); |
63 * Initiates the bmp decode | |
64 * | |
65 */ | |
66 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, | |
67 size_t dstRowBytes, const Options&, SkPMColor*, | |
68 int*) override; | |
69 | 55 |
70 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } | 56 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; } |
71 | 57 |
58 /* | |
59 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | |
60 * representing success or failure. If it returned true, and codecOut was | |
61 * not NULL, it will be set to a new SkBmpCodec. | |
62 * Does *not* take ownership of the passed in SkStream. | |
63 */ | |
64 static bool ReadHeader(SkStream*, bool isIco, SkCodec** codecOut); | |
65 | |
66 /* | |
67 * Fix the decoded output when a bmp is encoded as fully transparent. | |
68 * It was most likely not intended to be opaque. | |
69 */ | |
70 static SkCodec::Result FixTransparentDecode(void* dst, size_t dstRowBytes, | |
msarett
2015/08/03 22:52:36
FixTransparentDecode() is new. It is an improveme
scroggo
2015/08/04 16:16:46
We should find those images. Have you checked out
msarett
2015/08/04 23:14:44
I'll chat with you tomorrow, but I checked out src
| |
71 SkPMColor* colorPtr, int* colorCountPtr, SkStream* stream); | |
scroggo
2015/08/04 16:16:46
Can you update the comment that this requires a ca
msarett
2015/08/04 23:14:44
Yeah it's unfortunate. I see the trade off as:
Ra
| |
72 | |
73 /* | |
74 * Rewinds the image stream if necessary | |
75 */ | |
76 bool handleRewind(bool isIco); | |
77 | |
78 /* | |
79 * Get the destination row to start filling from | |
80 * Used to fill the remainder of the image on incomplete input for bmps | |
81 */ | |
82 void* getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const; | |
83 | |
84 /* | |
85 * Accessors used by subclasses | |
86 */ | |
87 const uint16_t bitsPerPixel() const { return fBitsPerPixel; } | |
scroggo
2015/08/04 16:16:46
It seems a little weird to return a const basic da
msarett
2015/08/04 23:14:44
Nope let's just make it a basic data type.
| |
88 const RowOrder rowOrder() const {return fRowOrder; } | |
scroggo
2015/08/04 16:16:46
nit: space between "{" and "return"
msarett
2015/08/04 23:14:45
Done.
| |
89 | |
72 private: | 90 private: |
73 | 91 |
74 /* | 92 /* |
75 * | |
76 * Used to define the input format of the bmp | 93 * Used to define the input format of the bmp |
77 * | |
78 */ | 94 */ |
79 enum BitmapInputFormat { | 95 enum BmpInputFormat { |
scroggo
2015/08/04 16:16:46
It looks like this is no longer used by the header
msarett
2015/08/04 23:14:44
Done.
| |
80 kStandard_BitmapInputFormat, | 96 kStandard_BmpInputFormat, |
81 kRLE_BitmapInputFormat, | 97 kRLE_BmpInputFormat, |
82 kBitMask_BitmapInputFormat, | 98 kBitMask_BmpInputFormat, |
83 kUnknown_BitmapInputFormat | 99 kUnknown_BmpInputFormat |
84 }; | 100 }; |
85 | 101 |
86 /* | 102 /* |
87 * | |
88 * Creates the color table | |
89 * Sets colorCount to the new color count if it is non-NULL | |
90 */ | |
91 bool createColorTable(SkAlphaType alphaType, int* colorCount); | |
92 | |
93 /* | |
94 * | |
95 * Creates a bmp decoder | 103 * Creates a bmp decoder |
96 * Reads enough of the stream to determine the image format | 104 * Reads enough of the stream to determine the image format |
97 * | |
98 */ | 105 */ |
99 static SkCodec* NewFromStream(SkStream*, bool isIco); | 106 static SkCodec* NewFromStream(SkStream*, bool isIco); |
100 | 107 |
101 /* | 108 const uint16_t fBitsPerPixel; |
102 * | 109 const RowOrder fRowOrder; |
103 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | |
104 * representing success or failure. If it returned true, and codecOut was | |
105 * not NULL, it will be set to a new SkBmpCodec. | |
106 * Does *not* take ownership of the passed in SkStream. | |
107 * | |
108 */ | |
109 static bool ReadHeader(SkStream*, bool isIco, SkCodec** codecOut); | |
110 | |
111 /* | |
112 * | |
113 * Performs the bitmap decoding for bit masks input format | |
114 * | |
115 */ | |
116 Result decodeMask(const SkImageInfo& dstInfo, void* dst, | |
117 size_t dstRowBytes, const Options& opts); | |
118 | |
119 /* | |
120 * | |
121 * Set an RLE pixel using the color table | |
122 * | |
123 */ | |
124 void setRLEPixel(void* dst, size_t dstRowBytes, | |
125 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, | |
126 uint8_t index); | |
127 /* | |
128 * | |
129 * Set an RLE24 pixel from R, G, B values | |
130 * | |
131 */ | |
132 void setRLE24Pixel(void* dst, size_t dstRowBytes, | |
133 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, | |
134 uint8_t red, uint8_t green, uint8_t blue); | |
135 | |
136 /* | |
137 * | |
138 * Performs the bitmap decoding for RLE input format | |
139 * | |
140 */ | |
141 Result decodeRLE(const SkImageInfo& dstInfo, void* dst, | |
142 size_t dstRowBytes, const Options& opts); | |
143 | |
144 /* | |
145 * | |
146 * Performs the bitmap decoding for standard input format | |
147 * | |
148 */ | |
149 Result decode(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, con st Options& opts); | |
150 | |
151 /* | |
152 * | |
153 * Creates an instance of the decoder | |
154 * Called only by NewFromStream | |
155 * | |
156 * @param srcInfo contains the source width and height | |
157 * @param stream the stream of image data | |
158 * @param bitsPerPixel the number of bits used to store each pixel | |
159 * @param format the format of the bmp file | |
160 * @param masks optional color masks for certain bmp formats, passes | |
161 ownership to SkBmpCodec | |
162 * @param numColors the number of colors in the color table | |
163 * @param bytesPerColor the number of bytes in the stream used to represent | |
164 each color in the color table | |
165 * @param offset the offset of the image pixel data from the end of the | |
166 * headers | |
167 * @param rowOrder indicates whether rows are ordered top-down or bottom-up | |
168 * @param RLEBytes used only for RLE decodes, as we must decode all | |
169 * of the data at once rather than row by row | |
170 * it indicates the amount of data left in the stream | |
171 * after decoding the headers | |
172 * | |
173 */ | |
174 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, | |
175 uint16_t bitsPerPixel, BitmapInputFormat format, | |
176 SkMasks* masks, uint32_t numColors, uint32_t bytesPerColor, | |
177 uint32_t offset, RowOrder rowOrder, size_t RLEBytes, | |
178 bool isIco); | |
179 | |
180 // Fields | |
181 const uint16_t fBitsPerPixel; | |
182 const BitmapInputFormat fInputFormat; | |
183 SkAutoTDelete<SkMasks> fMasks; // owned | |
184 SkAutoTUnref<SkColorTable> fColorTable; // owned | |
185 uint32_t fNumColors; | |
186 const uint32_t fBytesPerColor; | |
187 const uint32_t fOffset; | |
188 const RowOrder fRowOrder; | |
189 const size_t fRLEBytes; | |
190 const bool fIsIco; | |
191 | 110 |
192 typedef SkCodec INHERITED; | 111 typedef SkCodec INHERITED; |
193 }; | 112 }; |
113 | |
114 #endif | |
OLD | NEW |