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