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

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

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows errors Created 5 years, 8 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/SkCodec_libpng.cpp ('k') | src/codec/SkSwizzler.h » ('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 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkMaskSwizzler.h" 10 #include "SkMaskSwizzler.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 uint8_t red = masks->getRed(p); 56 uint8_t red = masks->getRed(p);
57 uint8_t green = masks->getGreen(p); 57 uint8_t green = masks->getGreen(p);
58 uint8_t blue = masks->getBlue(p); 58 uint8_t blue = masks->getBlue(p);
59 uint8_t alpha = masks->getAlpha(p); 59 uint8_t alpha = masks->getAlpha(p);
60 UPDATE_RESULT_ALPHA(alpha); 60 UPDATE_RESULT_ALPHA(alpha);
61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
62 } 62 }
63 return COMPUTE_RESULT_ALPHA; 63 return COMPUTE_RESULT_ALPHA;
64 } 64 }
65 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( 66 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque(
83 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 67 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
84 68
85 // Use the masks to decode to the destination 69 // Use the masks to decode to the destination
86 SkPMColor* dstPtr = (SkPMColor*) dstRow; 70 SkPMColor* dstPtr = (SkPMColor*) dstRow;
87 for (int i = 0; i < 3*width; i += 3) { 71 for (int i = 0; i < 3*width; i += 3) {
88 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; 72 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16;
89 uint8_t red = masks->getRed(p); 73 uint8_t red = masks->getRed(p);
90 uint8_t green = masks->getGreen(p); 74 uint8_t green = masks->getGreen(p);
91 uint8_t blue = masks->getBlue(p); 75 uint8_t blue = masks->getBlue(p);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 uint8_t red = masks->getRed(p); 107 uint8_t red = masks->getRed(p);
124 uint8_t green = masks->getGreen(p); 108 uint8_t green = masks->getGreen(p);
125 uint8_t blue = masks->getBlue(p); 109 uint8_t blue = masks->getBlue(p);
126 uint8_t alpha = masks->getAlpha(p); 110 uint8_t alpha = masks->getAlpha(p);
127 UPDATE_RESULT_ALPHA(alpha); 111 UPDATE_RESULT_ALPHA(alpha);
128 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue); 112 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue);
129 } 113 }
130 return COMPUTE_RESULT_ALPHA; 114 return COMPUTE_RESULT_ALPHA;
131 } 115 }
132 116
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( 117 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque(
149 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { 118 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) {
150 119
151 // Use the masks to decode to the destination 120 // Use the masks to decode to the destination
152 uint32_t* srcPtr = (uint32_t*) srcRow; 121 uint32_t* srcPtr = (uint32_t*) srcRow;
153 SkPMColor* dstPtr = (SkPMColor*) dstRow; 122 SkPMColor* dstPtr = (SkPMColor*) dstRow;
154 for (int i = 0; i < width; i++) { 123 for (int i = 0; i < width; i++) {
155 uint32_t p = srcPtr[i]; 124 uint32_t p = srcPtr[i];
156 uint8_t red = masks->getRed(p); 125 uint8_t red = masks->getRed(p);
157 uint8_t green = masks->getGreen(p); 126 uint8_t green = masks->getGreen(p);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 uint8_t red = masks->getRed(p); 161 uint8_t red = masks->getRed(p);
193 uint8_t green = masks->getGreen(p); 162 uint8_t green = masks->getGreen(p);
194 uint8_t blue = masks->getBlue(p); 163 uint8_t blue = masks->getBlue(p);
195 uint8_t alpha = masks->getAlpha(p); 164 uint8_t alpha = masks->getAlpha(p);
196 UPDATE_RESULT_ALPHA(alpha); 165 UPDATE_RESULT_ALPHA(alpha);
197 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 166 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
198 } 167 }
199 return COMPUTE_RESULT_ALPHA; 168 return COMPUTE_RESULT_ALPHA;
200 } 169 }
201 170
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
218 /* 171 /*
219 * 172 *
220 * Create a new mask swizzler 173 * Create a new mask swizzler
221 * 174 *
222 */ 175 */
223 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler( 176 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(
224 const SkImageInfo& info, void* dst, size_t dstRowBytes, SkMasks* masks, 177 const SkImageInfo& info, void* dst, size_t dstRowBytes, SkMasks* masks,
225 uint32_t bitsPerPixel) { 178 uint32_t bitsPerPixel) {
226 179
227 // Choose the appropriate row procedure 180 // Choose the appropriate row procedure
228 RowProc proc = NULL; 181 RowProc proc = NULL;
229 switch (bitsPerPixel) { 182 switch (bitsPerPixel) {
230 case 16: 183 case 16:
231 switch (info.colorType()) { 184 switch (info.colorType()) {
232 case kN32_SkColorType: 185 case kN32_SkColorType:
233 switch (info.alphaType()) { 186 switch (info.alphaType()) {
234 case kUnpremul_SkAlphaType: 187 case kUnpremul_SkAlphaType:
235 proc = &swizzle_mask16_to_n32_unpremul; 188 proc = &swizzle_mask16_to_n32_unpremul;
236 break; 189 break;
237 case kPremul_SkAlphaType: 190 case kPremul_SkAlphaType:
238 proc = &swizzle_mask16_to_n32_premul; 191 proc = &swizzle_mask16_to_n32_premul;
239 break; 192 break;
240 case kOpaque_SkAlphaType: 193 case kOpaque_SkAlphaType:
241 proc = &swizzle_mask16_to_n32_opaque; 194 proc = &swizzle_mask16_to_n32_opaque;
242 break; 195 break;
243 default: 196 default:
244 break; 197 break;
245 } 198 }
246 break; 199 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: 200 default:
257 break; 201 break;
258 } 202 }
259 break; 203 break;
260 case 24: 204 case 24:
261 switch (info.colorType()) { 205 switch (info.colorType()) {
262 case kN32_SkColorType: 206 case kN32_SkColorType:
263 switch (info.alphaType()) { 207 switch (info.alphaType()) {
264 case kUnpremul_SkAlphaType: 208 case kUnpremul_SkAlphaType:
265 proc = &swizzle_mask24_to_n32_unpremul; 209 proc = &swizzle_mask24_to_n32_unpremul;
266 break; 210 break;
267 case kPremul_SkAlphaType: 211 case kPremul_SkAlphaType:
268 proc = &swizzle_mask24_to_n32_premul; 212 proc = &swizzle_mask24_to_n32_premul;
269 break; 213 break;
270 case kOpaque_SkAlphaType: 214 case kOpaque_SkAlphaType:
271 proc = &swizzle_mask24_to_n32_opaque; 215 proc = &swizzle_mask24_to_n32_opaque;
272 break; 216 break;
273 default: 217 default:
274 break; 218 break;
275 } 219 }
276 break; 220 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: 221 default:
287 break; 222 break;
288 } 223 }
289 break; 224 break;
290 case 32: 225 case 32:
291 switch (info.colorType()) { 226 switch (info.colorType()) {
292 case kN32_SkColorType: 227 case kN32_SkColorType:
293 switch (info.alphaType()) { 228 switch (info.alphaType()) {
294 case kUnpremul_SkAlphaType: 229 case kUnpremul_SkAlphaType:
295 proc = &swizzle_mask32_to_n32_unpremul; 230 proc = &swizzle_mask32_to_n32_unpremul;
296 break; 231 break;
297 case kPremul_SkAlphaType: 232 case kPremul_SkAlphaType:
298 proc = &swizzle_mask32_to_n32_premul; 233 proc = &swizzle_mask32_to_n32_premul;
299 break; 234 break;
300 case kOpaque_SkAlphaType: 235 case kOpaque_SkAlphaType:
301 proc = &swizzle_mask32_to_n32_opaque; 236 proc = &swizzle_mask32_to_n32_opaque;
302 break; 237 break;
303 default: 238 default:
304 break; 239 break;
305 } 240 }
306 break; 241 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: 242 default:
317 break; 243 break;
318 } 244 }
319 break; 245 break;
320 default: 246 default:
321 SkASSERT(false); 247 SkASSERT(false);
322 return NULL; 248 return NULL;
323 } 249 }
324 return SkNEW_ARGS(SkMaskSwizzler, (info, dst, dstRowBytes, masks, proc)); 250 return SkNEW_ARGS(SkMaskSwizzler, (info, dst, dstRowBytes, masks, proc));
325 } 251 }
(...skipping 18 matching lines...) Expand all
344 * 270 *
345 */ 271 */
346 SkSwizzler::ResultAlpha SkMaskSwizzler::next(const uint8_t* SK_RESTRICT src, 272 SkSwizzler::ResultAlpha SkMaskSwizzler::next(const uint8_t* SK_RESTRICT src,
347 int y) { 273 int y) {
348 // Choose the row 274 // Choose the row
349 void* row = SkTAddOffset<void>(fDst, y*fDstRowBytes); 275 void* row = SkTAddOffset<void>(fDst, y*fDstRowBytes);
350 276
351 // Decode the row 277 // Decode the row
352 return fRowProc(row, src, fDstInfo.width(), fMasks); 278 return fRowProc(row, src, fDstInfo.width(), fMasks);
353 } 279 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libpng.cpp ('k') | src/codec/SkSwizzler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698