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