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

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

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Moved bmp specific code out of the swizzler Created 5 years, 9 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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCodec.h"
9 #include "SkImageInfo.h"
10 #include "SkStream.h"
11 #include "SkSwizzler.h"
12 #include "SkTypes.h"
13
14 // TODO: rename SkCodec_libbmp files to SkBmpCodec
15 // TODO: define a wrapper for SkDebugf that doesn't always print
16 /*
17 *
18 * This class implements the decoding for bmp images
19 *
20 */
21 class SkBmpCodec : public SkCodec {
22 public:
23
24 /*
25 *
26 * Bit masks used for color components in mask compression modes
27 *
28 */
29 struct BitMasks {
30 uint32_t redMask;
31 uint32_t greenMask;
32 uint32_t blueMask;
33 uint32_t alphaMask;
34 };
35
36 /*
37 *
38 * Number of trailing zeros on bit masks used in mask compression modes
39 *
40 */
41 struct BitMaskShifts {
42 uint32_t redShift;
43 uint32_t greenShift;
44 uint32_t blueShift;
45 uint32_t alphaShift;
46 };
47
48 /*
49 *
50 * Size of bit masks used in mask compression modes
51 *
52 */
53 struct BitMaskSizes {
54 uint32_t redSize;
55 uint32_t greenSize;
56 uint32_t blueSize;
57 uint32_t alphaSize;
58 };
59
60 /*
61 *
62 * Describes if rows of the input start at the top or bottom of the image
63 *
64 */
65 enum RowOrder {
66 kTopDown_RowOrder,
67 kBottomUp_RowOrder
68 };
69
70 /*
71 *
72 * Checks the start of the stream to see if the image is a bitmap
73 *
74 */
75 static bool IsBmp(SkStream*);
76
77 /*
78 *
79 * Assumes IsBmp was called and returned true
80 * Creates a bitmap decoder
81 * Reads enough of the stream to determine the image format
82 *
83 */
84 static SkCodec* NewFromStream(SkStream*);
85
86 protected:
87
88 /*
89 *
90 * Initiates the bitmap decode
91 *
92 */
93 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
94 size_t dstRowBytes, SkColor*,
scroggo 2015/03/06 18:56:13 I think this happens to compile because SkColor an
95 int*) SK_OVERRIDE;
96
97 private:
98
99 /*
100 *
101 * Used to define the input format of the bitmap
102 *
103 */
104 enum BitmapInputFormat {
105 kStandard_BitmapInputFormat,
106 kRLE_BitmapInputFormat,
107 kBitMask_BitmapInputFormat,
108 kUnknown_BitmapInputFormat
109 };
110
111 /*
112 *
113 * For a continuous bit mask (ex: 0011100), retrieves the size of the mask
114 * and the number of bits to shift the mask
115 *
116 */
117 void processMasks();
118
119 /*
120 *
121 * Performs the bitmap decoding for bit masks input format
122 *
123 */
124 Result decodeMask(const SkImageInfo& dstInfo, void* dst,
125 uint32_t dstRowBytes);
126
127 /*
128 *
129 * Set an RLE pixel using the color table
130 *
131 */
132 void setRLEPixel(SkColor* dst, uint32_t dstRowBytes, int height,
scroggo 2015/03/06 18:56:14 SkPMColor (I think)
133 uint32_t x, uint32_t y, uint8_t index);
134
135 /*
136 *
137 * Performs the bitmap decoding for RLE input format
138 *
139 */
140 Result decodeRLE(const SkImageInfo& dstInfo, void* dst,
141 uint32_t dstRowBytes);
142
143 /*
144 *
145 * Performs the bitmap decoding for standard input format
146 *
147 */
148 Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes);
149
150 /*
151 *
152 * Creates an instance of the decoder
153 * Called only by NewFromStream
154 *
155 * @param srcInfo contains the source width and height
156 * @param stream the stream of image data
157 * @param bitsPerPixel the number of bits used to store each pixel
158 * @param format the format of the bmp file
159 * @param bitMasks optional color masks for certain bmp formats
160 * @param colorTable array representing the color table for index-based bmp
161 * formats, passes ownership to SkBmpCodec
162 * @param rowOrder indicates whether rows are ordered top-down or bottom-up
163 * @param remainingBytes used only for RLE decodes, as we must decode all
164 * of the data at once rather than row by row
165 * it indicates the amount of data left in the stream
166 * after decoding the headers
167 *
168 */
169 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream,
170 uint16_t bitsPerPixel, BitmapInputFormat format,
171 BitMasks bitMasks, SkColor* colorTable,
172 RowOrder rowOrder, uint32_t remainingBytes);
173
174 // Fields
175 const uint16_t fBitsPerPixel;
176 const BitmapInputFormat fInputFormat;
177 BitMasks fBitMasks;
178 BitMaskShifts fMaskShifts;
179 BitMaskSizes fMaskSizes;
180 const SkAutoTDeleteArray<SkColor> fColorTable; // owned
181 const RowOrder fRowOrder;
182 const uint32_t fRemainingBytes;
183
184 typedef SkCodec INHERITED;
185 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698