OLD | NEW |
---|---|
(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 "SkCodecPriv.h" | |
scroggo
2015/03/13 14:06:59
nit: Is anything in SkCodecPriv used by this heade
msarett
2015/03/13 14:57:07
Done.
| |
10 #include "SkImageInfo.h" | |
11 #include "SkMaskSwizzler.h" | |
12 #include "SkStream.h" | |
13 #include "SkSwizzler.h" | |
14 #include "SkTypes.h" | |
15 | |
16 // TODO: rename SkCodec_libbmp files to SkBmpCodec | |
17 // TODO: define a wrapper for SkDebugf that doesn't always print | |
18 /* | |
19 * | |
20 * This class implements the decoding for bmp images | |
21 * | |
22 */ | |
23 class SkBmpCodec : public SkCodec { | |
24 public: | |
25 | |
26 /* | |
27 * | |
28 * Describes if rows of the input start at the top or bottom of the image | |
29 * | |
30 */ | |
31 enum RowOrder { | |
32 kTopDown_RowOrder, | |
33 kBottomUp_RowOrder | |
34 }; | |
35 | |
36 /* | |
37 * | |
38 * Checks the start of the stream to see if the image is a bitmap | |
39 * | |
40 */ | |
41 static bool IsBmp(SkStream*); | |
42 | |
43 /* | |
44 * | |
45 * Assumes IsBmp was called and returned true | |
46 * Creates a bitmap decoder | |
47 * Reads enough of the stream to determine the image format | |
48 * | |
49 */ | |
50 static SkCodec* NewFromStream(SkStream*); | |
51 | |
52 protected: | |
53 | |
54 /* | |
55 * | |
56 * Initiates the bitmap decode | |
57 * | |
58 */ | |
59 virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, | |
60 size_t dstRowBytes, SkPMColor*, | |
61 int*) SK_OVERRIDE; | |
62 | |
63 private: | |
64 | |
65 /* | |
66 * | |
67 * Used to define the input format of the bitmap | |
68 * | |
69 */ | |
70 enum BitmapInputFormat { | |
71 kStandard_BitmapInputFormat, | |
72 kRLE_BitmapInputFormat, | |
73 kBitMask_BitmapInputFormat, | |
74 kUnknown_BitmapInputFormat | |
75 }; | |
76 | |
77 /* | |
78 * | |
79 * Performs the bitmap decoding for bit masks input format | |
80 * | |
81 */ | |
82 Result decodeMask(const SkImageInfo& dstInfo, void* dst, | |
83 uint32_t dstRowBytes); | |
84 | |
85 /* | |
86 * | |
87 * Set an RLE pixel using the color table | |
88 * | |
89 */ | |
90 void setRLEPixel(SkPMColor* dst, uint32_t dstRowBytes, int height, | |
91 uint32_t x, uint32_t y, uint8_t index); | |
92 | |
93 /* | |
94 * | |
95 * Performs the bitmap decoding for RLE input format | |
96 * | |
97 */ | |
98 Result decodeRLE(const SkImageInfo& dstInfo, void* dst, | |
99 uint32_t dstRowBytes); | |
100 | |
101 /* | |
102 * | |
103 * Performs the bitmap decoding for standard input format | |
104 * | |
105 */ | |
106 Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes); | |
107 | |
108 /* | |
109 * | |
110 * Creates an instance of the decoder | |
111 * Called only by NewFromStream | |
112 * | |
113 * @param srcInfo contains the source width and height | |
114 * @param stream the stream of image data | |
115 * @param bitsPerPixel the number of bits used to store each pixel | |
116 * @param format the format of the bmp file | |
117 * @param masks optional color masks for certain bmp formats, passes | |
118 ownership to SkBmpCodec | |
119 * @param colorTable array representing the color table for index-based bmp | |
120 * formats, colors are unpremultiplied, passes ownership | |
121 * to SkBmpCodec | |
122 * @param rowOrder indicates whether rows are ordered top-down or bottom-up | |
123 * @param remainingBytes used only for RLE decodes, as we must decode all | |
124 * of the data at once rather than row by row | |
125 * it indicates the amount of data left in the stream | |
126 * after decoding the headers | |
127 * | |
128 */ | |
129 SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, | |
130 uint16_t bitsPerPixel, BitmapInputFormat format, | |
131 SkMasks* masks, SkPMColor* colorTable, | |
132 RowOrder rowOrder, uint32_t remainingBytes); | |
133 | |
134 // Fields | |
135 const uint16_t fBitsPerPixel; | |
136 const BitmapInputFormat fInputFormat; | |
137 SkAutoTDelete<SkMasks> fMasks; // owned | |
138 const SkAutoTDeleteArray<SkPMColor> fColorTable; // owned, unpremul | |
139 const RowOrder fRowOrder; | |
140 const uint32_t fRemainingBytes; | |
141 | |
142 typedef SkCodec INHERITED; | |
143 }; | |
OLD | NEW |