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

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

Issue 1012873002: Revert "Implementation of image decoding for bmp files, in accordance with the new API." (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « src/codec/SkMasks.cpp ('k') | src/codec/SkSwizzler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 #ifndef SkSwizzler_DEFINED 8 #ifndef SkSwizzler_DEFINED
9 #define SkSwizzler_DEFINED 9 #define SkSwizzler_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 14
15 class SkSwizzler : public SkNoncopyable { 15 class SkSwizzler : public SkNoncopyable {
16 public: 16 public:
17 /** 17 /**
18 * Enum describing the config of the source data. 18 * Enum describing the config of the source data.
19 */ 19 */
20 enum SrcConfig { 20 enum SrcConfig {
21 kGray, 21 kGray, // 1 byte per pixel
22 kIndex1, 22 kIndex, // 1 byte per pixel
23 kIndex2, 23 kRGB, // 3 bytes per pixel
24 kIndex4, 24 kRGBX, // 4 byes per pixel (ignore 4th)
25 kIndex, 25 kRGBA, // 4 bytes per pixel
26 kRGB, 26 kRGB_565 // 2 bytes per pixel
27 kBGR,
28 kRGBX,
29 kBGRX,
30 kRGBA,
31 kBGRA,
32 kRGB_565,
33 }; 27 };
34 28
35 /* 29 static int BytesPerPixel(SrcConfig sc) {
36 *
37 * Result code for the alpha components of a row.
38 *
39 */
40 typedef uint16_t ResultAlpha;
41 static const ResultAlpha kOpaque_ResultAlpha = 0xFFFF;
42 static const ResultAlpha kTransparent_ResultAlpha = 0x0000;
43
44 /*
45 *
46 * Checks if the result of decoding a row indicates that the row was
47 * transparent.
48 *
49 */
50 static bool IsTransparent(ResultAlpha r) {
51 return kTransparent_ResultAlpha == r;
52 }
53
54 /*
55 *
56 * Checks if the result of decoding a row indicates that the row was
57 * opaque.
58 *
59 */
60 static bool IsOpaque(ResultAlpha r) {
61 return kOpaque_ResultAlpha == r;
62 }
63
64 /*
65 *
66 * Constructs the proper result code based on accumulated alpha masks
67 *
68 */
69 static ResultAlpha GetResult(uint8_t zeroAlpha, uint8_t maxAlpha);
70
71 /*
72 *
73 * Returns bits per pixel for source config
74 *
75 */
76 static int BitsPerPixel(SrcConfig sc) {
77 switch (sc) { 30 switch (sc) {
78 case kIndex1:
79 return 1;
80 case kIndex2:
81 return 2;
82 case kIndex4:
83 return 4;
84 case kGray: 31 case kGray:
85 case kIndex: 32 case kIndex:
86 return 8; 33 return 1;
87 case kRGB_565:
88 return 16;
89 case kRGB: 34 case kRGB:
90 case kBGR: 35 return 3;
91 return 24;
92 case kRGBX: 36 case kRGBX:
93 case kRGBA: 37 case kRGBA:
94 case kBGRX: 38 return 4;
95 case kBGRA: 39 case kRGB_565:
96 return 32; 40 return 2;
97 default: 41 default:
98 SkASSERT(false); 42 SkDebugf("invalid source config passed to BytesPerPixel\n");
99 return 0; 43 return -1;
100 } 44 }
101 } 45 }
102 46
103 /*
104 *
105 * Returns bytes per pixel for source config
106 * Raises an error if each pixel is not stored in an even number of bytes
107 *
108 */
109 static int BytesPerPixel(SrcConfig sc) {
110 SkASSERT(SkIsAlign8(BitsPerPixel(sc)));
111 return BitsPerPixel(sc) >> 3;
112 }
113
114 /** 47 /**
115 * Create a new SkSwizzler. 48 * Create a new SkSwizzler.
116 * @param sc SrcConfig 49 * @param sc SrcConfig
117 * @param info dimensions() describe both the src and the dst. 50 * @param info dimensions() describe both the src and the dst.
118 * Other fields describe the dst. 51 * Other fields describe the dst.
119 * @param dst Destination to write pixels. Must match info and dstRowBytes 52 * @param dst Destination to write pixels. Must match info and dstRowBytes
120 * @param dstRowBytes rowBytes for dst. 53 * @param dstRowBytes rowBytes for dst.
121 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 54 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
122 * zero-initialized. The implementation may or may not respect this. 55 * zero-initialized. The implementation may or may not respect this.
123 * @return A new SkSwizzler or NULL on failure. 56 * @return A new SkSwizzler or NULL on failure.
124 */ 57 */
125 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 58 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable,
126 const SkImageInfo& info, void* dst, 59 const SkImageInfo& info, void* dst,
127 size_t dstRowBytes, bool skipZeroes); 60 size_t dstRowBytes, bool skipZeroes);
128
129 /** 61 /**
130 * Swizzle the next line. Call height times, once for each row of source. 62 * Swizzle the next line. Call height times, once for each row of source.
131 * @param src The next row of the source data. 63 * @param src The next row of the source data.
132 * @return A result code describing if the row was fully opaque, fully 64 * @return Whether the row had non-opaque alpha.
133 * transparent, or neither
134 */ 65 */
135 ResultAlpha next(const uint8_t* SK_RESTRICT src); 66 bool next(const uint8_t* SK_RESTRICT src);
136
137 /**
138 *
139 * Alternate version of next that allows the caller to specify the row.
140 * It is very important to only use one version of next. Since the other
141 * version modifies the dst pointer, it will change the behavior of this
142 * function. We will check this in Debug mode.
143 *
144 */
145 ResultAlpha next(const uint8_t* SK_RESTRICT src, int y);
146 private: 67 private:
147
148 #ifdef SK_DEBUG
149 /*
150 *
151 * Keep track of which version of next the caller is using
152 *
153 */
154 enum NextMode {
155 kUninitialized_NextMode,
156 kConsecutive_NextMode,
157 kDesignateRow_NextMode,
158 };
159
160 NextMode fNextMode;
161 #endif
162
163 /** 68 /**
164 * Method for converting raw data to Skia pixels. 69 * Method for converting raw data to Skia pixels.
165 * @param dstRow Row in which to write the resulting pixels. 70 * @param dstRow Row in which to write the resulting pixels.
166 * @param src Row of src data, in format specified by SrcConfig 71 * @param src Row of src data, in format specified by SrcConfig
167 * @param width Width in pixels 72 * @param width Width in pixels
168 * @param deltaSrc if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel 73 * @param bpp bytes per pixel of the source.
169 * else, deltaSrc is bitsPerPixel
170 * @param y Line of source. 74 * @param y Line of source.
171 * @param ctable Colors (used for kIndex source). 75 * @param ctable Colors (used for kIndex source).
172 */ 76 */
173 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, 77 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
174 const uint8_t* SK_RESTRICT src, 78 const uint8_t* SK_RESTRICT src,
175 int width, int deltaSrc, int y, 79 int width, int bpp, int y,
176 const SkPMColor ctable[]); 80 const SkPMColor ctable[]);
177 81
178 const RowProc fRowProc; 82 const RowProc fRowProc;
179 const SkPMColor* fColorTable; // Unowned pointer 83 const SkPMColor* fColorTable; // Unowned pointer
180 const int fDeltaSrc; // if bitsPerPixel % 8 == 0 84 const int fSrcPixelSize;
181 // deltaSrc is bytesPerPixel
182 // else
183 // deltaSrc is bitsPerPixel
184 const SkImageInfo fDstInfo; 85 const SkImageInfo fDstInfo;
185 void* fDstRow; 86 void* fDstRow;
186 const size_t fDstRowBytes; 87 const size_t fDstRowBytes;
187 int fCurrY; 88 int fCurrY;
188 89
189 SkSwizzler(RowProc proc, const SkPMColor* ctable, int deltaSrc, 90 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp,
190 const SkImageInfo& info, void* dst, size_t rowBytes); 91 const SkImageInfo& info, void* dst, size_t rowBytes);
191 92
192 }; 93 };
193 #endif // SkSwizzler_DEFINED 94 #endif // SkSwizzler_DEFINED
OLDNEW
« no previous file with comments | « src/codec/SkMasks.cpp ('k') | src/codec/SkSwizzler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698