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

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

Issue 1258863008: Split SkBmpCodec into three separate classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 #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"
15 17
16 // TODO: rename SkCodec_libbmp files to SkBmpCodec
17 /* 18 /*
18 * 19 * This class enables the creation of specific bmp codecs that subclass SkCodec
19 * This class implements the decoding for bmp images
20 *
21 */ 20 */
22 class SkBmpCodec : public SkCodec { 21 class SkBmpCodec {
23 public: 22 public:
24 23
25 /* 24 /*
26 *
27 * Describes if rows of the input start at the top or bottom of the image 25 * Describes if rows of the input start at the top or bottom of the image
28 *
29 */ 26 */
30 enum RowOrder { 27 enum RowOrder {
31 kTopDown_RowOrder, 28 kTopDown_RowOrder,
32 kBottomUp_RowOrder 29 kBottomUp_RowOrder
33 }; 30 };
34 31
35 /* 32 /*
36 *
37 * Checks the start of the stream to see if the image is a bmp 33 * Checks the start of the stream to see if the image is a bmp
38 *
39 */ 34 */
40 static bool IsBmp(SkStream*); 35 static bool IsBmp(SkStream*);
41 36
42 /* 37 /*
43 *
44 * Assumes IsBmp was called and returned true 38 * Assumes IsBmp was called and returned true
45 * Creates a bmp decoder 39 * Creates a bmp decoder
46 * Reads enough of the stream to determine the image format 40 * Reads enough of the stream to determine the image format
47 *
48 */ 41 */
49 static SkCodec* NewFromStream(SkStream*); 42 static SkCodec* NewFromStream(SkStream*);
50 43
51 /* 44 /*
52 *
53 * Creates a bmp decoder for a bmp embedded in ico 45 * Creates a bmp decoder for a bmp embedded in ico
54 * Reads enough of the stream to determine the image format 46 * Reads enough of the stream to determine the image format
55 *
56 */ 47 */
57 static SkCodec* NewFromIco(SkStream*); 48 static SkCodec* NewFromIco(SkStream*);
58 49
59 protected:
60
61 /*
62 *
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
70 SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedF ormat; }
71
72 private: 50 private:
73 51
74 /* 52 /*
75 *
76 * Used to define the input format of the bmp 53 * Used to define the input format of the bmp
77 *
78 */ 54 */
79 enum BitmapInputFormat { 55 enum BmpInputFormat {
80 kStandard_BitmapInputFormat, 56 kStandard_BmpInputFormat,
81 kRLE_BitmapInputFormat, 57 kRLE_BmpInputFormat,
82 kBitMask_BitmapInputFormat, 58 kBitMask_BmpInputFormat,
83 kUnknown_BitmapInputFormat 59 kUnknown_BmpInputFormat
84 }; 60 };
85 61
86 /* 62 /*
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 63 * Creates a bmp decoder
96 * Reads enough of the stream to determine the image format 64 * Reads enough of the stream to determine the image format
97 *
98 */ 65 */
99 static SkCodec* NewFromStream(SkStream*, bool isIco); 66 static SkCodec* NewFromStream(SkStream*, bool isIco);
100 67
101 /* 68 /*
102 *
103 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool 69 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool
104 * representing success or failure. If it returned true, and codecOut was 70 * representing success or failure. If it returned true, and codecOut was
105 * not NULL, it will be set to a new SkBmpCodec. 71 * not NULL, it will be set to a new SkBmpCodec.
106 * Does *not* take ownership of the passed in SkStream. 72 * Does *not* take ownership of the passed in SkStream.
107 *
108 */ 73 */
109 static bool ReadHeader(SkStream*, bool isIco, SkCodec** codecOut); 74 static bool ReadHeader(SkStream*, bool isIco, SkCodec** codecOut);
110 75
111 /* 76 /*
112 * 77 * Fix the decoded output when a bmp is encoded as fully transparent.
113 * Performs the bitmap decoding for bit masks input format 78 * It was most likely not intended to be opaque.
114 *
115 */ 79 */
116 Result decodeMask(const SkImageInfo& dstInfo, void* dst, 80 static SkCodec::Result FixTransparentDecode(void* dst, size_t dstRowBytes,
117 size_t dstRowBytes, const Options& opts); 81 SkPMColor* colorPtr, int* colorCountPtr, SkStream* stream);
118 82
119 /* 83 friend class SkBmpMaskCodec;
120 * 84 friend class SkBmpRLECodec;
121 * Set an RLE pixel using the color table 85 friend class SkBmpStandardCodec;
122 * 86 };
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 87
136 /* 88 #endif
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
192 typedef SkCodec INHERITED;
193 };
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkBmpCodec.cpp » ('j') | src/codec/SkBmpCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698