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

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: Various fixes from Leon's comments 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 enum ResultAlpha {
41 kOpaque_ResultAlpha, // All pixels in a row have max alpha
42 kTransparent_ResultAlpha, // All pixels in a row have zero alpha
43 kNeither_ResultAlpha // Alpha is not completely maxed or zeroed
44 };
45
46 /*
47 *
48 * Checks if the result of decoding a row indicates that the row was
49 * transprent.
scroggo 2015/03/12 15:19:57 transparent*
msarett 2015/03/12 18:37:47 Done.
50 *
51 */
52 static bool IsTransparent(ResultAlpha r) {
53 return SkSwizzler::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 SkSwizzler::kOpaque_ResultAlpha == r;
64 }
65
66 static int BitsPerPixel(SrcConfig sc) {
30 switch (sc) { 67 switch (sc) {
68 case kIndex1:
69 return 1;
70 case kIndex2:
71 return 2;
72 case kIndex4:
73 return 4;
31 case kGray: 74 case kGray:
32 case kIndex: 75 case kIndex:
33 return 1; 76 return 8;
77 case kRGB_565:
78 return 16;
34 case kRGB: 79 case kRGB:
35 return 3; 80 case kBGR:
81 return 24;
36 case kRGBX: 82 case kRGBX:
37 case kRGBA: 83 case kRGBA:
38 return 4; 84 case kBGRX:
39 case kRGB_565: 85 case kBGRA:
40 return 2; 86 return 32;
41 default: 87 default:
42 SkDebugf("invalid source config passed to BytesPerPixel\n"); 88 SkASSERT(false);
43 return -1; 89 return 0;
44 } 90 }
45 } 91 }
46 92
93 static int BytesPerPixel(SrcConfig sc) {
94 SkASSERT(SkIsAlign4(BitsPerPixel(sc)));
95 return (BitsPerPixel(sc)) >> 3;
96 }
97
47 /** 98 /**
48 * Create a new SkSwizzler. 99 * Create a new SkSwizzler.
49 * @param sc SrcConfig 100 * @param sc SrcConfig
50 * @param info dimensions() describe both the src and the dst. 101 * @param info dimensions() describe both the src and the dst.
51 * Other fields describe the dst. 102 * Other fields describe the dst.
52 * @param dst Destination to write pixels. Must match info and dstRowBytes 103 * @param dst Destination to write pixels. Must match info and dstRowBytes
53 * @param dstRowBytes rowBytes for dst. 104 * @param dstRowBytes rowBytes for dst.
54 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 105 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
55 * zero-initialized. The implementation may or may not respect this. 106 * zero-initialized. The implementation may or may not respect this.
56 * @return A new SkSwizzler or NULL on failure. 107 * @return A new SkSwizzler or NULL on failure.
57 */ 108 */
58 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 109 static SkSwizzler* CreateSwizzler(
59 const SkImageInfo& info, void* dst, 110 SrcConfig sc, const SkPMColor* ctable, const SkImageInfo& info,
scroggo 2015/03/12 15:19:58 Why did this change? It looks like you just change
msarett 2015/03/12 18:37:47 I believe I added parameters, which prompted me to
60 size_t dstRowBytes, bool skipZeroes); 111 void* dst, size_t dstRowBytes, bool skipZeroes);
112
113 /**
114 *
115 * Chooses the proper result alpha enum based on accumulated alpha masks
116 *
117 */
118 static ResultAlpha GetResult(uint8_t zeroAlpha, uint8_t maxAlpha);
119
61 /** 120 /**
62 * Swizzle the next line. Call height times, once for each row of source. 121 * Swizzle the next line. Call height times, once for each row of source.
63 * @param src The next row of the source data. 122 * @param src The next row of the source data.
64 * @return Whether the row had non-opaque alpha. 123 * @return Whether the row had non-opaque alpha.
scroggo 2015/03/12 15:19:58 Please update this comment.
msarett 2015/03/12 18:37:47 Sorry I'm not too good at remembering to do that.
65 */ 124 */
66 bool next(const uint8_t* SK_RESTRICT src); 125 ResultAlpha next(const uint8_t* SK_RESTRICT src);
126
127 /**
128 *
129 * Alternate version of next that allows the caller to specify the row.
130 * It is very important to only use one version of next. Since the other
131 * version modifies the dst pointer, it will change the behavior of this
132 * function. We will check this in Debug mode.
133 *
134 */
135 ResultAlpha next(const uint8_t* SK_RESTRICT src, int y);
67 private: 136 private:
137
138 #ifdef SK_DEBUG
139 /*
140 *
141 * Keep track of which version of next the caller is using
142 *
143 */
144 enum NextMode {
145 kUninitialized_NextMode,
146 kConsecutive_NextMode,
147 kDesignateRow_NextMode,
148 };
149
150 NextMode fNextMode;
151 #endif
152
68 /** 153 /**
69 * Method for converting raw data to Skia pixels. 154 * Method for converting raw data to Skia pixels.
70 * @param dstRow Row in which to write the resulting pixels. 155 * @param dstRow Row in which to write the resulting pixels.
71 * @param src Row of src data, in format specified by SrcConfig 156 * @param src Row of src data, in format specified by SrcConfig
72 * @param width Width in pixels 157 * @param width Width in pixels
73 * @param bpp bytes per pixel of the source. 158 * @param bpp bits per pixel of the source.
74 * @param y Line of source. 159 * @param y Line of source.
75 * @param ctable Colors (used for kIndex source). 160 * @param ctable Colors (used for kIndex source).
76 */ 161 */
77 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 162 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow,
78 const uint8_t* SK_RESTRICT src, 163 const uint8_t* SK_RESTRICT src,
79 int width, int bpp, int y, 164 int width, int bitsPerPixel, int y,
80 const SkPMColor ctable[]); 165 const SkPMColor ctable[]);
81 166
82 const RowProc fRowProc; 167 const RowProc fRowProc;
83 const SkPMColor* fColorTable; // Unowned pointer 168 const SkPMColor* fColorTable; // Unowned pointer
84 const int fSrcPixelSize; 169 const int fSrcBitsPerPixel;
85 const SkImageInfo fDstInfo; 170 const SkImageInfo fDstInfo;
86 void* fDstRow; 171 void* fDstRow;
87 const size_t fDstRowBytes; 172 const size_t fDstRowBytes;
88 int fCurrY; 173 int fCurrY;
89 174
90 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, 175 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP,
91 const SkImageInfo& info, void* dst, size_t rowBytes); 176 const SkImageInfo& info, void* dst, size_t rowBytes);
92 177
93 }; 178 };
94 #endif // SkSwizzler_DEFINED 179 #endif // SkSwizzler_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698