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

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

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

Powered by Google App Engine
This is Rietveld 408576698