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

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

Issue 1277593002: Support decoding PNG to 565. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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') | no next file » | 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 "SkSwizzler.h" 10 #include "SkSwizzler.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 for (int x = 0; x < width; x++) { 109 for (int x = 0; x < width; x++) {
110 SkPMColor c = ctable[src[x]]; 110 SkPMColor c = ctable[src[x]];
111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
112 if (c != 0) { 112 if (c != 0) {
113 dst[x] = c; 113 dst[x] = c;
114 } 114 }
115 } 115 }
116 return COMPUTE_RESULT_ALPHA; 116 return COMPUTE_RESULT_ALPHA;
117 } 117 }
118 118
119 static SkSwizzler::ResultAlpha swizzle_index_to_565(
120 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
121 int bytesPerPixel, const SkPMColor ctable[]) {
122 // FIXME: Support dithering? Requires knowing y, which I think is a bigger
123 // change.
124 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
125 for (int x = 0; x < width; x++) {
126 dst[x] = SkPixel32ToPixel16(ctable[*src]);
127 src += bytesPerPixel;
128 }
129 return SkSwizzler::kOpaque_ResultAlpha;
130 }
131
132
119 #undef A32_MASK_IN_PLACE 133 #undef A32_MASK_IN_PLACE
120 134
121 // kGray 135 // kGray
122 136
123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( 137 static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 138 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
125 int bytesPerPixel, const SkPMColor ctable[]) { 139 int bytesPerPixel, const SkPMColor ctable[]) {
126 140
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 141 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
128 for (int x = 0; x < width; x++) { 142 for (int x = 0; x < width; x++) {
129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); 143 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]);
130 } 144 }
131 return SkSwizzler::kOpaque_ResultAlpha; 145 return SkSwizzler::kOpaque_ResultAlpha;
132 } 146 }
133 147
134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( 148 static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 149 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
136 int bytesPerPixel, const SkPMColor ctable[]) { 150 int bytesPerPixel, const SkPMColor ctable[]) {
137 memcpy(dstRow, src, width); 151 memcpy(dstRow, src, width);
138 return SkSwizzler::kOpaque_ResultAlpha; 152 return SkSwizzler::kOpaque_ResultAlpha;
139 } 153 }
140 154
155 static SkSwizzler::ResultAlpha swizzle_gray_to_565(
156 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
157 int bytesPerPixel, const SkPMColor ctable[]) {
158 // FIXME: Support dithering?
159 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
160 for (int x = 0; x < width; x++) {
161 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
162 src += bytesPerPixel;
163 }
164 return SkSwizzler::kOpaque_ResultAlpha;
165 }
166
141 // kBGRX 167 // kBGRX
142 168
143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 169 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 170 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
145 int bytesPerPixel, const SkPMColor ctable[]) { 171 int bytesPerPixel, const SkPMColor ctable[]) {
146 172
147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 173 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
148 for (int x = 0; x < width; x++) { 174 for (int x = 0; x < width; x++) {
149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 175 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
150 src += bytesPerPixel; 176 src += bytesPerPixel;
(...skipping 26 matching lines...) Expand all
177 INIT_RESULT_ALPHA; 203 INIT_RESULT_ALPHA;
178 for (int x = 0; x < width; x++) { 204 for (int x = 0; x < width; x++) {
179 uint8_t alpha = src[3]; 205 uint8_t alpha = src[3];
180 UPDATE_RESULT_ALPHA(alpha); 206 UPDATE_RESULT_ALPHA(alpha);
181 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); 207 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]);
182 src += bytesPerPixel; 208 src += bytesPerPixel;
183 } 209 }
184 return COMPUTE_RESULT_ALPHA; 210 return COMPUTE_RESULT_ALPHA;
185 } 211 }
186 212
187 // n32 213 // kRGBX
188 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( 214 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
189 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 215 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
190 int bytesPerPixel, const SkPMColor ctable[]) { 216 int bytesPerPixel, const SkPMColor ctable[]) {
191 217
192 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 218 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
193 for (int x = 0; x < width; x++) { 219 for (int x = 0; x < width; x++) {
194 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 220 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
195 src += bytesPerPixel; 221 src += bytesPerPixel;
196 } 222 }
197 return SkSwizzler::kOpaque_ResultAlpha; 223 return SkSwizzler::kOpaque_ResultAlpha;
198 } 224 }
199 225
226 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565(
227 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
228 int bytesPerPixel, const SkPMColor ctable[]) {
229 // FIXME: Support dithering?
230 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
231 for (int x = 0; x < width; x++) {
232 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
233 src += bytesPerPixel;
234 }
235 return SkSwizzler::kOpaque_ResultAlpha;
236 }
237
238
239 // kRGBA
200 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( 240 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
201 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 241 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
202 int bytesPerPixel, const SkPMColor ctable[]) { 242 int bytesPerPixel, const SkPMColor ctable[]) {
203 243
204 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 244 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
205 INIT_RESULT_ALPHA; 245 INIT_RESULT_ALPHA;
206 for (int x = 0; x < width; x++) { 246 for (int x = 0; x < width; x++) {
207 unsigned alpha = src[3]; 247 unsigned alpha = src[3];
208 UPDATE_RESULT_ALPHA(alpha); 248 UPDATE_RESULT_ALPHA(alpha);
209 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 249 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 case kN32_SkColorType: 343 case kN32_SkColorType:
304 // We assume the color premultiplied ctable (or not) as desi red. 344 // We assume the color premultiplied ctable (or not) as desi red.
305 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 345 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
306 proc = &swizzle_index_to_n32_skipZ; 346 proc = &swizzle_index_to_n32_skipZ;
307 break; 347 break;
308 } else { 348 } else {
309 proc = &swizzle_index_to_n32; 349 proc = &swizzle_index_to_n32;
310 break; 350 break;
311 } 351 }
312 break; 352 break;
353 case kRGB_565_SkColorType:
354 proc = &swizzle_index_to_565;
355 break;
313 case kIndex_8_SkColorType: 356 case kIndex_8_SkColorType:
314 proc = &swizzle_index_to_index; 357 proc = &swizzle_index_to_index;
315 break; 358 break;
316 default: 359 default:
317 break; 360 break;
318 } 361 }
319 break; 362 break;
320 case kGray: 363 case kGray:
321 switch (info.colorType()) { 364 switch (info.colorType()) {
322 case kN32_SkColorType: 365 case kN32_SkColorType:
323 proc = &swizzle_gray_to_n32; 366 proc = &swizzle_gray_to_n32;
324 break; 367 break;
325 case kGray_8_SkColorType: 368 case kGray_8_SkColorType:
326 proc = &swizzle_gray_to_gray; 369 proc = &swizzle_gray_to_gray;
370 break;
371 case kRGB_565_SkColorType:
372 proc = &swizzle_gray_to_565;
373 break;
327 default: 374 default:
328 break; 375 break;
329 } 376 }
330 break; 377 break;
331 case kBGR: 378 case kBGR:
332 case kBGRX: 379 case kBGRX:
333 switch (info.colorType()) { 380 switch (info.colorType()) {
334 case kN32_SkColorType: 381 case kN32_SkColorType:
335 proc = &swizzle_bgrx_to_n32; 382 proc = &swizzle_bgrx_to_n32;
336 break; 383 break;
(...skipping 18 matching lines...) Expand all
355 default: 402 default:
356 break; 403 break;
357 } 404 }
358 break; 405 break;
359 case kRGBX: 406 case kRGBX:
360 // TODO: Support other swizzles. 407 // TODO: Support other swizzles.
361 switch (info.colorType()) { 408 switch (info.colorType()) {
362 case kN32_SkColorType: 409 case kN32_SkColorType:
363 proc = &swizzle_rgbx_to_n32; 410 proc = &swizzle_rgbx_to_n32;
364 break; 411 break;
412 case kRGB_565_SkColorType:
413 proc = &swizzle_rgbx_to_565;
365 default: 414 default:
366 break; 415 break;
367 } 416 }
368 break; 417 break;
369 case kRGBA: 418 case kRGBA:
370 switch (info.colorType()) { 419 switch (info.colorType()) {
371 case kN32_SkColorType: 420 case kN32_SkColorType:
372 if (info.alphaType() == kUnpremul_SkAlphaType) { 421 if (info.alphaType() == kUnpremul_SkAlphaType) {
373 // Respect zeroInit? 422 // Respect zeroInit?
374 proc = &swizzle_rgba_to_n32_unpremul; 423 proc = &swizzle_rgba_to_n32_unpremul;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // bits of SK_ColorBLACK are identical to the 565 representation 527 // bits of SK_ColorBLACK are identical to the 565 representation
479 // for black. 528 // for black.
480 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 529 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill);
481 break; 530 break;
482 default: 531 default:
483 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 532 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
484 SkASSERT(false); 533 SkASSERT(false);
485 break; 534 break;
486 } 535 }
487 } 536 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libpng.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698