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

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

Issue 1254483004: Scanline decoding for wbmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More minor fixes 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
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"
11 #include "SkTemplates.h" 11 #include "SkTemplates.h"
12 #include "SkUtils.h" 12 #include "SkUtils.h"
13 13
14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
15 uint8_t maxAlpha) { 15 uint8_t maxAlpha) {
16 // In the transparent case, this returns 0x0000 16 // In the transparent case, this returns 0x0000
17 // In the opaque case, this returns 0xFFFF 17 // In the opaque case, this returns 0xFFFF
18 // If the row is neither transparent nor opaque, returns something else 18 // If the row is neither transparent nor opaque, returns something else
19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
20 } 20 }
21 21
22 // kBit
23 // These routines exclusively choose between white and black
24
25 #define GRAYSCALE_BLACK 0
26 #define GRAYSCALE_WHITE 0xFF
27
28 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale(
29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
30 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
31 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
32
33 // Determine how many full bytes are in the row
34 int bytesInRow = width >> 3;
35 int i;
36 for (i = 0; i < bytesInRow; i++) {
37 U8CPU currByte = src[i];
38 for (int j = 0; j < 8; j++) {
39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B LACK;
40 }
41 dst += 8;
42 }
43
44 // Finish the remaining bits
45 width &= 7;
46 U8CPU currByte = src[i];
47 for (int j = 0; j < width; j++) {
48 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
49 currByte <<= 1;
50 }
51 return SkSwizzler::kOpaque_ResultAlpha;
52 }
53
54 #undef GRAYSCALE_BLACK
55 #undef GRAYSCALE_WHITE
56
57 static SkSwizzler::ResultAlpha swizzle_bit_to_index(
58 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
59 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
60 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
61
62 // Determine how many full bytes are in the row
63 int bytesInRow = width >> 3;
64 int i;
65 for (i = 0; i < bytesInRow; i++) {
66 U8CPU currByte = src[i];
67 for (int j = 0; j < 8; j++) {
68 dst[j] = (currByte >> (7 - j)) & 1;
69 }
70 dst += 8;
71 }
72
73 // Finish the remaining bits
74 width &= 7;
75 U8CPU currByte = src[i];
76 for (int j = 0; j < width; j++) {
77 dst[j] = ((currByte >> 7) & 1);
78 currByte <<= 1;
79 }
80 return SkSwizzler::kOpaque_ResultAlpha;
81 }
82
83 static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
84 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
85 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
86 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
87
88 // Determine how many full bytes are in the row
89 int bytesInRow = width >> 3;
90 int i;
91 for (i = 0; i < bytesInRow; i++) {
92 U8CPU currByte = src[i];
93 for (int j = 0; j < 8; j++) {
94 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK ;
95 }
96 dst += 8;
97 }
98
99 // Finish the remaining bits
100 width &= 7;
101 U8CPU currByte = src[i];
102 for (int j = 0; j < width; j++) {
103 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
104 currByte <<= 1;
105 }
106 return SkSwizzler::kOpaque_ResultAlpha;
107 }
108
22 // kIndex1, kIndex2, kIndex4 109 // kIndex1, kIndex2, kIndex4
23 110
24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 111 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 112 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
26 int bitsPerPixel, const SkPMColor ctable[]) { 113 int bitsPerPixel, const SkPMColor ctable[]) {
27 114
28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 115 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
29 INIT_RESULT_ALPHA; 116 INIT_RESULT_ALPHA;
30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 117 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 118 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 SkCodec::ZeroInitialized zeroInit) { 364 SkCodec::ZeroInitialized zeroInit) {
278 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { 365 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
279 return NULL; 366 return NULL;
280 } 367 }
281 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 368 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
282 && NULL == ctable) { 369 && NULL == ctable) {
283 return NULL; 370 return NULL;
284 } 371 }
285 RowProc proc = NULL; 372 RowProc proc = NULL;
286 switch (sc) { 373 switch (sc) {
374 case kBit:
375 switch (info.colorType()) {
376 case kN32_SkColorType:
377 proc = &swizzle_bit_to_n32;
378 break;
379 case kIndex_8_SkColorType:
380 proc = &swizzle_bit_to_index;
381 break;
382 case kGray_8_SkColorType:
383 proc = &swizzle_bit_to_grayscale;
384 break;
385 default:
386 break;
387 }
388 break;
287 case kIndex1: 389 case kIndex1:
288 case kIndex2: 390 case kIndex2:
289 case kIndex4: 391 case kIndex4:
290 switch (info.colorType()) { 392 switch (info.colorType()) {
291 case kN32_SkColorType: 393 case kN32_SkColorType:
292 proc = &swizzle_small_index_to_n32; 394 proc = &swizzle_small_index_to_n32;
293 break; 395 break;
294 case kIndex_8_SkColorType: 396 case kIndex_8_SkColorType:
295 proc = &swizzle_small_index_to_index; 397 proc = &swizzle_small_index_to_index;
296 break; 398 break;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // bits of SK_ColorBLACK are identical to the 565 representation 580 // bits of SK_ColorBLACK are identical to the 565 representation
479 // for black. 581 // for black.
480 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 582 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill);
481 break; 583 break;
482 default: 584 default:
483 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 585 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
484 SkASSERT(false); 586 SkASSERT(false);
485 break; 587 break;
486 } 588 }
487 } 589 }
OLDNEW
« src/codec/SkCodec_wbmp.cpp ('K') | « src/codec/SkSwizzler.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698