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

Side by Side Diff: src/codec/SkMaskSwizzler.cpp

Issue 1013743003: Adding premul and 565 swizzles for bmp: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Trybot fixes 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 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkMaskSwizzler.h" 10 #include "SkMaskSwizzler.h"
11 11
12 /* 12 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_opaque(
13 *
14 * Row procedure for masked color components with 16 bits per pixel
15 *
16 */
17 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32(
18 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
19 14
20 // Use the masks to decode to the destination 15 // Use the masks to decode to the destination
21 uint16_t* srcPtr = (uint16_t*) srcRow; 16 uint16_t* srcPtr = (uint16_t*) srcRow;
22 SkPMColor* dstPtr = (SkPMColor*) dstRow; 17 SkPMColor* dstPtr = (SkPMColor*) dstRow;
23 for (int i = 0; i < width; i++) { 18 for (int i = 0; i < width; i++) {
24 uint16_t p = srcPtr[i]; 19 uint16_t p = srcPtr[i];
25 uint8_t red = masks->getRed(p); 20 uint8_t red = masks->getRed(p);
26 uint8_t green = masks->getGreen(p); 21 uint8_t green = masks->getGreen(p);
27 uint8_t blue = masks->getBlue(p); 22 uint8_t blue = masks->getBlue(p);
28 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 23 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
29 } 24 }
30 return SkSwizzler::kOpaque_ResultAlpha; 25 return SkSwizzler::kOpaque_ResultAlpha;
31 } 26 }
32 27
33 /* 28 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_unpremul(
34 *
35 * Row procedure for masked color components with 16 bits per pixel with alpha
36 *
37 */
38 static SkSwizzler::ResultAlpha swizzle_mask16_alpha_to_n32(
39 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 29 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
40 30
41 // Use the masks to decode to the destination 31 // Use the masks to decode to the destination
42 uint16_t* srcPtr = (uint16_t*) srcRow; 32 uint16_t* srcPtr = (uint16_t*) srcRow;
43 SkPMColor* dstPtr = (SkPMColor*) dstRow; 33 SkPMColor* dstPtr = (SkPMColor*) dstRow;
44 INIT_RESULT_ALPHA; 34 INIT_RESULT_ALPHA;
45 for (int i = 0; i < width; i++) { 35 for (int i = 0; i < width; i++) {
46 uint16_t p = srcPtr[i]; 36 uint16_t p = srcPtr[i];
47 uint8_t red = masks->getRed(p); 37 uint8_t red = masks->getRed(p);
48 uint8_t green = masks->getGreen(p); 38 uint8_t green = masks->getGreen(p);
49 uint8_t blue = masks->getBlue(p); 39 uint8_t blue = masks->getBlue(p);
50 uint8_t alpha = masks->getAlpha(p); 40 uint8_t alpha = masks->getAlpha(p);
51 UPDATE_RESULT_ALPHA(alpha); 41 UPDATE_RESULT_ALPHA(alpha);
52 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 42 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
53 } 43 }
54 return COMPUTE_RESULT_ALPHA; 44 return COMPUTE_RESULT_ALPHA;
55 } 45 }
56 46
57 /* 47 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_premul(
58 *
59 * Row procedure for masked color components with 24 bits per pixel
60 *
61 */
62 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32(
63 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 48 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
64 49
65 // Use the masks to decode to the destination 50 // Use the masks to decode to the destination
51 uint16_t* srcPtr = (uint16_t*) srcRow;
52 SkPMColor* dstPtr = (SkPMColor*) dstRow;
53 INIT_RESULT_ALPHA;
54 for (int i = 0; i < width; i++) {
55 uint16_t p = srcPtr[i];
56 uint8_t red = masks->getRed(p);
57 uint8_t green = masks->getGreen(p);
58 uint8_t blue = masks->getBlue(p);
59 uint8_t alpha = masks->getAlpha(p);
60 UPDATE_RESULT_ALPHA(alpha);
61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
62 }
63 return COMPUTE_RESULT_ALPHA;
64 }
65
66 static SkSwizzler::ResultAlpha swizzle_mask16_to_565(
67 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
68
69 // Use the masks to decode to the destination
70 uint16_t* srcPtr = (uint16_t*) srcRow;
71 uint16_t* dstPtr = (uint16_t*) dstRow;
72 for (int i = 0; i < width; i++) {
73 uint16_t p = srcPtr[i];
74 uint8_t red = masks->getRed(p);
75 uint8_t green = masks->getGreen(p);
76 uint8_t blue = masks->getBlue(p);
77 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
78 }
79 return SkSwizzler::kOpaque_ResultAlpha;
80 }
81
82 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque(
83 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
84
85 // Use the masks to decode to the destination
66 SkPMColor* dstPtr = (SkPMColor*) dstRow; 86 SkPMColor* dstPtr = (SkPMColor*) dstRow;
67 for (int i = 0; i < 3*width; i += 3) { 87 for (int i = 0; i < 3*width; i += 3) {
68 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; 88 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
69 uint8_t red = masks->getRed(p); 89 uint8_t red = masks->getRed(p);
70 uint8_t green = masks->getGreen(p); 90 uint8_t green = masks->getGreen(p);
71 uint8_t blue = masks->getBlue(p); 91 uint8_t blue = masks->getBlue(p);
72 dstPtr[i/3] = SkPackARGB32NoCheck(0xFF, red, green, blue); 92 dstPtr[i/3] = SkPackARGB32NoCheck(0xFF, red, green, blue);
73 } 93 }
74 return SkSwizzler::kOpaque_ResultAlpha; 94 return SkSwizzler::kOpaque_ResultAlpha;
75 } 95 }
76 96
77 /* 97 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_unpremul(
78 *
79 * Row procedure for masked color components with 24 bits per pixel with alpha
80 *
81 */
82 static SkSwizzler::ResultAlpha swizzle_mask24_alpha_to_n32(
83 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 98 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
84 99
85 // Use the masks to decode to the destination 100 // Use the masks to decode to the destination
86 SkPMColor* dstPtr = (SkPMColor*) dstRow; 101 SkPMColor* dstPtr = (SkPMColor*) dstRow;
87 INIT_RESULT_ALPHA; 102 INIT_RESULT_ALPHA;
88 for (int i = 0; i < 3*width; i += 3) { 103 for (int i = 0; i < 3*width; i += 3) {
89 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; 104 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
90 uint8_t red = masks->getRed(p); 105 uint8_t red = masks->getRed(p);
91 uint8_t green = masks->getGreen(p); 106 uint8_t green = masks->getGreen(p);
92 uint8_t blue = masks->getBlue(p); 107 uint8_t blue = masks->getBlue(p);
93 uint8_t alpha = masks->getAlpha(p); 108 uint8_t alpha = masks->getAlpha(p);
94 UPDATE_RESULT_ALPHA(alpha); 109 UPDATE_RESULT_ALPHA(alpha);
95 dstPtr[i/3] = SkPackARGB32NoCheck(alpha, red, green, blue); 110 dstPtr[i/3] = SkPackARGB32NoCheck(alpha, red, green, blue);
96 } 111 }
97 return COMPUTE_RESULT_ALPHA; 112 return COMPUTE_RESULT_ALPHA;
98 } 113 }
99 114
100 /* 115 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_premul(
101 *
102 * Row procedure for masked color components with 32 bits per pixel
103 *
104 */
105 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32(
106 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 116 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
107 117
108 // Use the masks to decode to the destination 118 // Use the masks to decode to the destination
119 SkPMColor* dstPtr = (SkPMColor*) dstRow;
120 INIT_RESULT_ALPHA;
121 for (int i = 0; i < 3*width; i += 3) {
122 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
123 uint8_t red = masks->getRed(p);
124 uint8_t green = masks->getGreen(p);
125 uint8_t blue = masks->getBlue(p);
126 uint8_t alpha = masks->getAlpha(p);
127 UPDATE_RESULT_ALPHA(alpha);
128 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue);
129 }
130 return COMPUTE_RESULT_ALPHA;
131 }
132
133 static SkSwizzler::ResultAlpha swizzle_mask24_to_565(
134 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
135
136 // Use the masks to decode to the destination
137 uint16_t* dstPtr = (uint16_t*) dstRow;
138 for (int i = 0; i < 3*width; i += 3) {
139 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
140 uint8_t red = masks->getRed(p);
141 uint8_t green = masks->getGreen(p);
142 uint8_t blue = masks->getBlue(p);
143 dstPtr[i/3] = SkPack888ToRGB16(red, green, blue);
144 }
145 return SkSwizzler::kOpaque_ResultAlpha;
146 }
147
148 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque(
149 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
150
151 // Use the masks to decode to the destination
109 uint32_t* srcPtr = (uint32_t*) srcRow; 152 uint32_t* srcPtr = (uint32_t*) srcRow;
110 SkPMColor* dstPtr = (SkPMColor*) dstRow; 153 SkPMColor* dstPtr = (SkPMColor*) dstRow;
111 for (int i = 0; i < width; i++) { 154 for (int i = 0; i < width; i++) {
112 uint32_t p = srcPtr[i]; 155 uint32_t p = srcPtr[i];
113 uint8_t red = masks->getRed(p); 156 uint8_t red = masks->getRed(p);
114 uint8_t green = masks->getGreen(p); 157 uint8_t green = masks->getGreen(p);
115 uint8_t blue = masks->getBlue(p); 158 uint8_t blue = masks->getBlue(p);
116 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 159 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
117 } 160 }
118 return SkSwizzler::kOpaque_ResultAlpha; 161 return SkSwizzler::kOpaque_ResultAlpha;
119 } 162 }
120 163
121 /* 164 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_unpremul(
122 *
123 * Row procedure for masked color components with 32 bits per pixel
124 *
125 */
126 static SkSwizzler::ResultAlpha swizzle_mask32_alpha_to_n32(
127 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 165 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
128 166
129 // Use the masks to decode to the destination 167 // Use the masks to decode to the destination
130 uint32_t* srcPtr = (uint32_t*) srcRow; 168 uint32_t* srcPtr = (uint32_t*) srcRow;
131 SkPMColor* dstPtr = (SkPMColor*) dstRow; 169 SkPMColor* dstPtr = (SkPMColor*) dstRow;
132 INIT_RESULT_ALPHA; 170 INIT_RESULT_ALPHA;
133 for (int i = 0; i < width; i++) { 171 for (int i = 0; i < width; i++) {
134 uint32_t p = srcPtr[i]; 172 uint32_t p = srcPtr[i];
135 uint8_t red = masks->getRed(p); 173 uint8_t red = masks->getRed(p);
136 uint8_t green = masks->getGreen(p); 174 uint8_t green = masks->getGreen(p);
137 uint8_t blue = masks->getBlue(p); 175 uint8_t blue = masks->getBlue(p);
138 uint8_t alpha = masks->getAlpha(p); 176 uint8_t alpha = masks->getAlpha(p);
139 UPDATE_RESULT_ALPHA(alpha); 177 UPDATE_RESULT_ALPHA(alpha);
140 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 178 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
141 } 179 }
142 return COMPUTE_RESULT_ALPHA; 180 return COMPUTE_RESULT_ALPHA;
143 } 181 }
144 182
183 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_premul(
184 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
185
186 // Use the masks to decode to the destination
187 uint32_t* srcPtr = (uint32_t*) srcRow;
188 SkPMColor* dstPtr = (SkPMColor*) dstRow;
189 INIT_RESULT_ALPHA;
190 for (int i = 0; i < width; i++) {
191 uint32_t p = srcPtr[i];
192 uint8_t red = masks->getRed(p);
193 uint8_t green = masks->getGreen(p);
194 uint8_t blue = masks->getBlue(p);
195 uint8_t alpha = masks->getAlpha(p);
196 UPDATE_RESULT_ALPHA(alpha);
197 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
198 }
199 return COMPUTE_RESULT_ALPHA;
200 }
201
202 static SkSwizzler::ResultAlpha swizzle_mask32_to_565(
203 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
204
205 // Use the masks to decode to the destination
206 uint32_t* srcPtr = (uint32_t*) srcRow;
207 uint16_t* dstPtr = (uint16_t*) dstRow;
208 for (int i = 0; i < width; i++) {
209 uint32_t p = srcPtr[i];
210 uint8_t red = masks->getRed(p);
211 uint8_t green = masks->getGreen(p);
212 uint8_t blue = masks->getBlue(p);
213 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
214 }
215 return SkSwizzler::kOpaque_ResultAlpha;
216 }
217
145 /* 218 /*
146 * 219 *
147 * Create a new mask swizzler 220 * Create a new mask swizzler
148 * 221 *
149 */ 222 */
150 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler( 223 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(
151 const SkImageInfo& imageInfo, SkMasks* masks, uint32_t bitsPerPixel) { 224 const SkImageInfo& info, void* dst, size_t dstRowBytes, SkMasks* masks,
225 uint32_t bitsPerPixel) {
152 226
153 // Choose the appropriate row procedure 227 // Choose the appropriate row procedure
154 RowProc proc = NULL; 228 RowProc proc = NULL;
155 uint32_t alphaMask = masks->getAlphaMask();
156 switch (bitsPerPixel) { 229 switch (bitsPerPixel) {
157 case 16: 230 case 16:
158 if (0 == alphaMask) { 231 switch (info.colorType()) {
159 proc = &swizzle_mask16_to_n32; 232 case kN32_SkColorType:
160 } else { 233 switch (info.alphaType()) {
161 proc = &swizzle_mask16_alpha_to_n32; 234 case kUnpremul_SkAlphaType:
235 proc = &swizzle_mask16_to_n32_unpremul;
236 break;
237 case kPremul_SkAlphaType:
238 proc = &swizzle_mask16_to_n32_premul;
239 break;
240 case kOpaque_SkAlphaType:
241 proc = &swizzle_mask16_to_n32_opaque;
242 break;
243 default:
244 break;
245 }
246 break;
247 case kRGB_565_SkColorType:
248 switch (info.alphaType()) {
249 case kOpaque_SkAlphaType:
250 proc = &swizzle_mask16_to_565;
251 break;
252 default:
253 break;
254 }
255 break;
256 default:
257 break;
162 } 258 }
163 break; 259 break;
164 case 24: 260 case 24:
165 if (0 == alphaMask) { 261 switch (info.colorType()) {
166 proc = &swizzle_mask24_to_n32; 262 case kN32_SkColorType:
167 } else { 263 switch (info.alphaType()) {
168 proc = &swizzle_mask24_alpha_to_n32; 264 case kUnpremul_SkAlphaType:
265 proc = &swizzle_mask24_to_n32_unpremul;
266 break;
267 case kPremul_SkAlphaType:
268 proc = &swizzle_mask24_to_n32_premul;
269 break;
270 case kOpaque_SkAlphaType:
271 proc = &swizzle_mask24_to_n32_opaque;
272 break;
273 default:
274 break;
275 }
276 break;
277 case kRGB_565_SkColorType:
278 switch (info.alphaType()) {
279 case kOpaque_SkAlphaType:
280 proc = &swizzle_mask24_to_565;
281 break;
282 default:
283 break;
284 }
285 break;
286 default:
287 break;
169 } 288 }
170 break; 289 break;
171 case 32: 290 case 32:
172 if (0 == alphaMask) { 291 switch (info.colorType()) {
173 proc = &swizzle_mask32_to_n32; 292 case kN32_SkColorType:
174 } else { 293 switch (info.alphaType()) {
175 proc = &swizzle_mask32_alpha_to_n32; 294 case kUnpremul_SkAlphaType:
295 proc = &swizzle_mask32_to_n32_unpremul;
296 break;
297 case kPremul_SkAlphaType:
298 proc = &swizzle_mask32_to_n32_premul;
299 break;
300 case kOpaque_SkAlphaType:
301 proc = &swizzle_mask32_to_n32_opaque;
302 break;
303 default:
304 break;
305 }
306 break;
307 case kRGB_565_SkColorType:
308 switch (info.alphaType()) {
309 case kOpaque_SkAlphaType:
310 proc = &swizzle_mask32_to_565;
311 break;
312 default:
313 break;
314 }
315 break;
316 default:
317 break;
176 } 318 }
177 break; 319 break;
178 default: 320 default:
179 SkASSERT(false); 321 SkASSERT(false);
180 return NULL; 322 return NULL;
181 } 323 }
182 return SkNEW_ARGS(SkMaskSwizzler, (imageInfo, masks, proc)); 324 return SkNEW_ARGS(SkMaskSwizzler, (info, dst, dstRowBytes, masks, proc));
183 } 325 }
184 326
185 /* 327 /*
186 * 328 *
187 * Constructor for mask swizzler 329 * Constructor for mask swizzler
188 * 330 *
189 */ 331 */
190 SkMaskSwizzler::SkMaskSwizzler(const SkImageInfo& imageInfo, 332 SkMaskSwizzler::SkMaskSwizzler(const SkImageInfo& dstInfo, void* dst,
191 SkMasks* masks, RowProc proc) 333 size_t dstRowBytes, SkMasks* masks, RowProc proc)
192 : fImageInfo(imageInfo) 334 : fDstInfo(dstInfo)
335 , fDst(dst)
336 , fDstRowBytes(dstRowBytes)
193 , fMasks(masks) 337 , fMasks(masks)
194 , fRowProc(proc) 338 , fRowProc(proc)
195 {} 339 {}
196 340
197 /* 341 /*
198 * 342 *
199 * Swizzle the next row 343 * Swizzle the specified row
200 * 344 *
201 */ 345 */
202 SkSwizzler::ResultAlpha SkMaskSwizzler::next(void* dst, 346 SkSwizzler::ResultAlpha SkMaskSwizzler::next(const uint8_t* SK_RESTRICT src,
203 const uint8_t* src) { 347 int y) {
204 return fRowProc(dst, src, fImageInfo.width(), fMasks); 348 // Choose the row
349 void* row = SkTAddOffset<void>(fDst, y*fDstRowBytes);
350
351 // Decode the row
352 return fRowProc(row, src, fDstInfo.width(), fMasks);
205 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698