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

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

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows errors Created 5 years, 3 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/SkSwizzler.h ('k') | tests/CodexTest.cpp » ('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 "SkScaledCodec.h" 10 #include "SkScaledCodec.h"
11 #include "SkSwizzler.h" 11 #include "SkSwizzler.h"
12 #include "SkTemplates.h" 12 #include "SkTemplates.h"
13 #include "SkUtils.h" 13 #include "SkUtils.h"
14 14
15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, 15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
16 uint8_t maxAlpha) { 16 uint8_t maxAlpha) {
17 // In the transparent case, this returns 0x0000 17 // In the transparent case, this returns 0x0000
18 // In the opaque case, this returns 0xFFFF 18 // In the opaque case, this returns 0xFFFF
19 // If the row is neither transparent nor opaque, returns something else 19 // If the row is neither transparent nor opaque, returns something else
20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; 20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
21 } 21 }
22 22
23 // samples the row. Does not do anything else but sampling 23 // samples the row. Does not do anything else but sampling
24 static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t * SK_RESTRICT src, 24 static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t * SK_RESTRICT src,
25 int width, int deltaSrc, int offset, const SkPMColor ctable[]){ 25 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){
26 26
27 src += offset; 27 src += offset;
28 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; 28 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
29 for (int x = 0; x < width; x++) { 29 for (int x = 0; x < width; x++) {
30 dst[x] = src[1] << 8 | src[0]; 30 dst[x] = src[1] << 8 | src[0];
31 src += deltaSrc; 31 src += deltaSrc;
32 } 32 }
33 // 565 is always opaque 33 // 565 is always opaque
34 return SkSwizzler::kOpaque_ResultAlpha; 34 return SkSwizzler::kOpaque_ResultAlpha;
35 } 35 }
36 36
37 // TODO (msarett): Investigate SIMD optimizations for swizzle routines.
38
37 // kBit 39 // kBit
38 // These routines exclusively choose between white and black 40 // These routines exclusively choose between white and black
39 41
40 #define GRAYSCALE_BLACK 0 42 #define GRAYSCALE_BLACK 0
41 #define GRAYSCALE_WHITE 0xFF 43 #define GRAYSCALE_WHITE 0xFF
42 44
43 45
44 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x] 46 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x]
45 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( 47 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale(
46 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 48 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
47 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 49 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
48 50
49 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 51 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
50 52
51 // increment src by byte offset and bitIndex by bit offset 53 // increment src by byte offset and bitIndex by bit offset
52 src += offset / 8; 54 src += offset / 8;
53 int bitIndex = offset % 8; 55 int bitIndex = offset % 8;
54 uint8_t currByte = *src; 56 uint8_t currByte = *src;
55 57
56 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLAC K; 58 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLAC K;
57 59
58 for (int x = 1; x < dstWidth; x++) { 60 for (int x = 1; x < dstWidth; x++) {
59 int bitOffset = bitIndex + deltaSrc; 61 int bitOffset = bitIndex + deltaSrc;
60 bitIndex = bitOffset % 8; 62 bitIndex = bitOffset % 8;
61 currByte = *(src += bitOffset / 8); 63 currByte = *(src += bitOffset / 8);
62 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_ BLACK; 64 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_ BLACK;
63 } 65 }
64 66
65 return SkSwizzler::kOpaque_ResultAlpha; 67 return SkSwizzler::kOpaque_ResultAlpha;
66 } 68 }
67 69
68 #undef GRAYSCALE_BLACK 70 #undef GRAYSCALE_BLACK
69 #undef GRAYSCALE_WHITE 71 #undef GRAYSCALE_WHITE
70 72
71 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assi gned to dst[x] 73 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assi gned to dst[x]
72 static SkSwizzler::ResultAlpha swizzle_bit_to_index( 74 static SkSwizzler::ResultAlpha swizzle_bit_to_index(
73 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 75 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
74 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 76 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
75 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
76 78
77 // increment src by byte offset and bitIndex by bit offset 79 // increment src by byte offset and bitIndex by bit offset
78 src += offset / 8; 80 src += offset / 8;
79 int bitIndex = offset % 8; 81 int bitIndex = offset % 8;
80 uint8_t currByte = *src; 82 uint8_t currByte = *src;
81 83
82 dst[0] = ((currByte >> (7-bitIndex)) & 1); 84 dst[0] = ((currByte >> (7-bitIndex)) & 1);
83 85
84 for (int x = 1; x < dstWidth; x++) { 86 for (int x = 1; x < dstWidth; x++) {
85 int bitOffset = bitIndex + deltaSrc; 87 int bitOffset = bitIndex + deltaSrc;
86 bitIndex = bitOffset % 8; 88 bitIndex = bitOffset % 8;
87 currByte = *(src += bitOffset / 8); 89 currByte = *(src += bitOffset / 8);
88 dst[x] = ((currByte >> (7-bitIndex)) & 1); 90 dst[x] = ((currByte >> (7-bitIndex)) & 1);
89 } 91 }
90 92
91 return SkSwizzler::kOpaque_ResultAlpha; 93 return SkSwizzler::kOpaque_ResultAlpha;
92 } 94 }
93 95
94 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value as signed to dst[x] 96 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value as signed to dst[x]
95 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( 97 static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
96 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 98 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
97 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 99 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
98 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 100 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
99 101
100 // increment src by byte offset and bitIndex by bit offset 102 // increment src by byte offset and bitIndex by bit offset
101 src += offset / 8; 103 src += offset / 8;
102 int bitIndex = offset % 8; 104 int bitIndex = offset % 8;
103 uint8_t currByte = *src; 105 uint8_t currByte = *src;
104 106
105 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; 107 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
106 108
107 for (int x = 1; x < dstWidth; x++) { 109 for (int x = 1; x < dstWidth; x++) {
108 int bitOffset = bitIndex + deltaSrc; 110 int bitOffset = bitIndex + deltaSrc;
109 bitIndex = bitOffset % 8; 111 bitIndex = bitOffset % 8;
110 currByte = *(src += bitOffset / 8); 112 currByte = *(src += bitOffset / 8);
111 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL ACK; 113 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL ACK;
112 } 114 }
113 115
114 return SkSwizzler::kOpaque_ResultAlpha; 116 return SkSwizzler::kOpaque_ResultAlpha;
115 } 117 }
116 118
117 #define RGB565_BLACK 0 119 #define RGB565_BLACK 0
118 #define RGB565_WHITE 0xFFFF 120 #define RGB565_WHITE 0xFFFF
119 121
120 static SkSwizzler::ResultAlpha swizzle_bit_to_565( 122 static SkSwizzler::ResultAlpha swizzle_bit_to_565(
121 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 123 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
122 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 124 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
123 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; 125 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
124 126
125 // increment src by byte offset and bitIndex by bit offset 127 // increment src by byte offset and bitIndex by bit offset
126 src += offset / 8; 128 src += offset / 8;
127 int bitIndex = offset % 8; 129 int bitIndex = offset % 8;
128 uint8_t currByte = *src; 130 uint8_t currByte = *src;
129 131
130 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK; 132 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
131 133
132 for (int x = 1; x < dstWidth; x++) { 134 for (int x = 1; x < dstWidth; x++) {
133 int bitOffset = bitIndex + deltaSrc; 135 int bitOffset = bitIndex + deltaSrc;
134 bitIndex = bitOffset % 8; 136 bitIndex = bitOffset % 8;
135 currByte = *(src += bitOffset / 8); 137 currByte = *(src += bitOffset / 8);
136 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLAC K; 138 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLAC K;
137 } 139 }
138 140
139 return SkSwizzler::kOpaque_ResultAlpha; 141 return SkSwizzler::kOpaque_ResultAlpha;
140 } 142 }
141 143
142 #undef RGB565_BLACK 144 #undef RGB565_BLACK
143 #undef RGB565_WHITE 145 #undef RGB565_WHITE
144 146
145 // kIndex1, kIndex2, kIndex4 147 // kIndex1, kIndex2, kIndex4
146 148
147 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 149 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
148 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 150 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
149 int bitsPerPixel, int offset, const SkPMColor ctable[]) { 151 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
150 152
151 src += offset; 153 uint8_t* dst = (uint8_t*) dstRow;
152 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
153 INIT_RESULT_ALPHA; 154 INIT_RESULT_ALPHA;
154 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 155 src += offset / 8;
155 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); 156 int bitIndex = offset % 8;
156 const uint8_t mask = (1 << bitsPerPixel) - 1; 157 uint8_t currByte = *src;
157 int x = 0; 158 const uint8_t mask = (1 << bpp) - 1;
158 for (uint32_t byte = 0; byte < rowBytes; byte++) { 159 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
159 uint8_t pixelData = src[byte]; 160 dst[0] = index;
160 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { 161 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
161 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 162
162 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); 163 for (int x = 1; x < dstWidth; x++) {
163 dst[x] = index; 164 int bitOffset = bitIndex + deltaSrc;
164 pixelData <<= bitsPerPixel; 165 bitIndex = bitOffset % 8;
165 x++; 166 currByte = *(src += bitOffset / 8);
166 } 167 index = (currByte >> (8 - bpp - bitIndex)) & mask;
168 dst[x] = index;
169 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
167 } 170 }
168 return COMPUTE_RESULT_ALPHA; 171 return COMPUTE_RESULT_ALPHA;
169 } 172 }
170 173
171 static SkSwizzler::ResultAlpha swizzle_small_index_to_565( 174 static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
172 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 175 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
173 int bitsPerPixel, int offset, const SkPMColor ctable[]) { 176 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
174 177
175 src += offset; 178 uint16_t* dst = (uint16_t*) dstRow;
176 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; 179 src += offset / 8;
177 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 180 int bitIndex = offset % 8;
178 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); 181 uint8_t currByte = *src;
179 const uint8_t mask = (1 << bitsPerPixel) - 1; 182 const uint8_t mask = (1 << bpp) - 1;
180 int x = 0; 183 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
181 for (uint32_t byte = 0; byte < rowBytes; byte++) { 184 dst[0] = SkPixel32ToPixel16(ctable[index]);
182 uint8_t pixelData = src[byte]; 185
183 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { 186 for (int x = 1; x < dstWidth; x++) {
184 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 187 int bitOffset = bitIndex + deltaSrc;
185 uint16_t c = SkPixel32ToPixel16(ctable[index]); 188 bitIndex = bitOffset % 8;
186 dst[x] = c; 189 currByte = *(src += bitOffset / 8);
187 pixelData <<= bitsPerPixel; 190 index = (currByte >> (8 - bpp - bitIndex)) & mask;
188 x++; 191 dst[x] = SkPixel32ToPixel16(ctable[index]);
189 }
190 } 192 }
191 return SkSwizzler::kOpaque_ResultAlpha; 193 return SkAlphaType::kOpaque_SkAlphaType;
192 } 194 }
193 195
194 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 196 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
195 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 197 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
196 int bitsPerPixel, int offset, const SkPMColor ctable[]) { 198 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
197 199
198 src += offset; 200 SkPMColor* dst = (SkPMColor*) dstRow;
199 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
200 INIT_RESULT_ALPHA; 201 INIT_RESULT_ALPHA;
201 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 202 src += offset / 8;
202 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); 203 int bitIndex = offset % 8;
203 const uint8_t mask = (1 << bitsPerPixel) - 1; 204 uint8_t currByte = *src;
204 int x = 0; 205 const uint8_t mask = (1 << bpp) - 1;
205 for (uint32_t byte = 0; byte < rowBytes; byte++) { 206 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
206 uint8_t pixelData = src[byte]; 207 dst[0] = ctable[index];
207 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { 208 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
208 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 209
209 SkPMColor c = ctable[index]; 210 for (int x = 1; x < dstWidth; x++) {
210 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 211 int bitOffset = bitIndex + deltaSrc;
211 dst[x] = c; 212 bitIndex = bitOffset % 8;
212 pixelData <<= bitsPerPixel; 213 currByte = *(src += bitOffset / 8);
213 x++; 214 index = (currByte >> (8 - bpp - bitIndex)) & mask;
214 } 215 dst[x] = ctable[index];
216 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
215 } 217 }
216 return COMPUTE_RESULT_ALPHA; 218 return COMPUTE_RESULT_ALPHA;
217 } 219 }
218 220
219 // kIndex 221 // kIndex
220 222
221 static SkSwizzler::ResultAlpha swizzle_index_to_index( 223 static SkSwizzler::ResultAlpha swizzle_index_to_index(
222 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 224 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
223 int deltaSrc, int offset, const SkPMColor ctable[]) { 225 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
224 226
225 src += offset; 227 src += offset;
226 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 228 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
227 INIT_RESULT_ALPHA; 229 INIT_RESULT_ALPHA;
228 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? 230 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque?
229 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous 231 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous
230 // and probably wrong since gif and bmp (rarely) may have al pha. 232 // and probably wrong since gif and bmp (rarely) may have al pha.
231 if (1 == deltaSrc) { 233 if (1 == deltaSrc) {
232 // A non-zero offset is only used when sampling, meaning that deltaSrc w ill be 234 // A non-zero offset is only used when sampling, meaning that deltaSrc w ill be
233 // greater than 1. The below loop relies on the fact that src remains un changed. 235 // greater than 1. The below loop relies on the fact that src remains un changed.
234 SkASSERT(0 == offset); 236 SkASSERT(0 == offset);
235 memcpy(dst, src, dstWidth); 237 memcpy(dst, src, dstWidth);
236 for (int x = 0; x < dstWidth; x++) { 238 for (int x = 0; x < dstWidth; x++) {
237 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); 239 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
238 } 240 }
239 } else { 241 } else {
240 for (int x = 0; x < dstWidth; x++) { 242 for (int x = 0; x < dstWidth; x++) {
241 dst[x] = *src; 243 dst[x] = *src;
242 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); 244 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT);
243 src += deltaSrc; 245 src += deltaSrc;
244 } 246 }
245 } 247 }
246 return COMPUTE_RESULT_ALPHA; 248 return COMPUTE_RESULT_ALPHA;
247 } 249 }
248 250
249 static SkSwizzler::ResultAlpha swizzle_index_to_n32( 251 static SkSwizzler::ResultAlpha swizzle_index_to_n32(
250 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 252 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
251 int deltaSrc, int offset, const SkPMColor ctable[]) { 253 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
252 254
253 src += offset; 255 src += offset;
254 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 256 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
255 INIT_RESULT_ALPHA; 257 INIT_RESULT_ALPHA;
256 for (int x = 0; x < dstWidth; x++) { 258 for (int x = 0; x < dstWidth; x++) {
257 SkPMColor c = ctable[*src]; 259 SkPMColor c = ctable[*src];
258 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 260 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
259 dst[x] = c; 261 dst[x] = c;
260 src += deltaSrc; 262 src += deltaSrc;
261 } 263 }
262 return COMPUTE_RESULT_ALPHA; 264 return COMPUTE_RESULT_ALPHA;
263 } 265 }
264 266
265 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( 267 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
266 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 268 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
267 int deltaSrc, int offset, const SkPMColor ctable[]) { 269 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
268 270
269 src += offset; 271 src += offset;
270 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 272 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
271 INIT_RESULT_ALPHA; 273 INIT_RESULT_ALPHA;
272 for (int x = 0; x < dstWidth; x++) { 274 for (int x = 0; x < dstWidth; x++) {
273 SkPMColor c = ctable[*src]; 275 SkPMColor c = ctable[*src];
274 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 276 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
275 if (c != 0) { 277 if (c != 0) {
276 dst[x] = c; 278 dst[x] = c;
277 } 279 }
278 src += deltaSrc; 280 src += deltaSrc;
279 } 281 }
280 return COMPUTE_RESULT_ALPHA; 282 return COMPUTE_RESULT_ALPHA;
281 } 283 }
282 284
283 static SkSwizzler::ResultAlpha swizzle_index_to_565( 285 static SkSwizzler::ResultAlpha swizzle_index_to_565(
284 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 286 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
285 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 287 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
286 // FIXME: Support dithering? Requires knowing y, which I think is a bigger 288 // FIXME: Support dithering? Requires knowing y, which I think is a bigger
287 // change. 289 // change.
288 src += offset; 290 src += offset;
289 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 291 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
290 for (int x = 0; x < dstWidth; x++) { 292 for (int x = 0; x < dstWidth; x++) {
291 dst[x] = SkPixel32ToPixel16(ctable[*src]); 293 dst[x] = SkPixel32ToPixel16(ctable[*src]);
292 src += bytesPerPixel; 294 src += deltaSrc;
293 } 295 }
294 return SkSwizzler::kOpaque_ResultAlpha; 296 return SkSwizzler::kOpaque_ResultAlpha;
295 } 297 }
296 298
297 299
298 #undef A32_MASK_IN_PLACE 300 #undef A32_MASK_IN_PLACE
299 301
300 // kGray 302 // kGray
301 303
302 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( 304 static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
303 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 305 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
304 int deltaSrc, int offset, const SkPMColor ctable[]) { 306 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
305 307
306 src += offset; 308 src += offset;
307 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 309 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
308 for (int x = 0; x < dstWidth; x++) { 310 for (int x = 0; x < dstWidth; x++) {
309 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); 311 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src);
310 src += deltaSrc; 312 src += deltaSrc;
311 } 313 }
312 return SkSwizzler::kOpaque_ResultAlpha; 314 return SkSwizzler::kOpaque_ResultAlpha;
313 } 315 }
314 316
315 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( 317 static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
316 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 318 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
317 int deltaSrc, int offset, const SkPMColor ctable[]) { 319 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
318 320
319 src += offset; 321 src += offset;
320 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 322 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
321 if (1 == deltaSrc) { 323 if (1 == deltaSrc) {
322 memcpy(dstRow, src, dstWidth); 324 memcpy(dstRow, src, dstWidth);
323 } else { 325 } else {
324 for (int x = 0; x < dstWidth; x++) { 326 for (int x = 0; x < dstWidth; x++) {
325 dst[x] = src[0]; 327 dst[x] = src[0];
326 src += deltaSrc; 328 src += deltaSrc;
327 } 329 }
328 } 330 }
329 return SkSwizzler::kOpaque_ResultAlpha; 331 return SkSwizzler::kOpaque_ResultAlpha;
330 } 332 }
331 333
332 static SkSwizzler::ResultAlpha swizzle_gray_to_565( 334 static SkSwizzler::ResultAlpha swizzle_gray_to_565(
333 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 335 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
334 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 336 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
335 // FIXME: Support dithering? 337 // FIXME: Support dithering?
336 src += offset; 338 src += offset;
337 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 339 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
338 for (int x = 0; x < dstWidth; x++) { 340 for (int x = 0; x < dstWidth; x++) {
339 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); 341 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
340 src += bytesPerPixel; 342 src += deltaSrc;
341 } 343 }
342 return SkSwizzler::kOpaque_ResultAlpha; 344 return SkSwizzler::kOpaque_ResultAlpha;
343 } 345 }
344 346
345 // kBGRX 347 // kBGRX
346 348
347 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 349 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
348 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 350 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
349 int deltaSrc, int offset, const SkPMColor ctable[]) { 351 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
350 352
351 src += offset; 353 src += offset;
352 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 354 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
353 for (int x = 0; x < dstWidth; x++) { 355 for (int x = 0; x < dstWidth; x++) {
354 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 356 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
355 src += deltaSrc; 357 src += deltaSrc;
356 } 358 }
357 return SkSwizzler::kOpaque_ResultAlpha; 359 return SkSwizzler::kOpaque_ResultAlpha;
358 } 360 }
359 361
360 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( 362 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
361 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 363 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
362 int deltaSrc, int offset, const SkPMColor ctable[]) { 364 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
363 // FIXME: Support dithering? 365 // FIXME: Support dithering?
364 src += offset; 366 src += offset;
365 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 367 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
366 for (int x = 0; x < dstWidth; x++) { 368 for (int x = 0; x < dstWidth; x++) {
367 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); 369 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
368 src += deltaSrc; 370 src += deltaSrc;
369 } 371 }
370 return SkSwizzler::kOpaque_ResultAlpha; 372 return SkSwizzler::kOpaque_ResultAlpha;
371 } 373 }
372 374
373 // kBGRA 375 // kBGRA
374 376
375 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 377 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
376 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 378 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
377 int deltaSrc, int offset, const SkPMColor ctable[]) { 379 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
378 380
379 src += offset; 381 src += offset;
380 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 382 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
381 INIT_RESULT_ALPHA; 383 INIT_RESULT_ALPHA;
382 for (int x = 0; x < dstWidth; x++) { 384 for (int x = 0; x < dstWidth; x++) {
383 uint8_t alpha = src[3]; 385 uint8_t alpha = src[3];
384 UPDATE_RESULT_ALPHA(alpha); 386 UPDATE_RESULT_ALPHA(alpha);
385 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); 387 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
386 src += deltaSrc; 388 src += deltaSrc;
387 } 389 }
388 return COMPUTE_RESULT_ALPHA; 390 return COMPUTE_RESULT_ALPHA;
389 } 391 }
390 392
391 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( 393 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
392 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 394 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
393 int deltaSrc, int offset, const SkPMColor ctable[]) { 395 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
394 396
395 src += offset; 397 src += offset;
396 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 398 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
397 INIT_RESULT_ALPHA; 399 INIT_RESULT_ALPHA;
398 for (int x = 0; x < dstWidth; x++) { 400 for (int x = 0; x < dstWidth; x++) {
399 uint8_t alpha = src[3]; 401 uint8_t alpha = src[3];
400 UPDATE_RESULT_ALPHA(alpha); 402 UPDATE_RESULT_ALPHA(alpha);
401 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); 403 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]);
402 src += deltaSrc; 404 src += deltaSrc;
403 } 405 }
404 return COMPUTE_RESULT_ALPHA; 406 return COMPUTE_RESULT_ALPHA;
405 } 407 }
406 408
407 // kRGBX 409 // kRGBX
408 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( 410 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
409 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 411 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
410 int deltaSrc, int offset, const SkPMColor ctable[]) { 412 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
411 413
412 src += offset; 414 src += offset;
413 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 415 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
414 for (int x = 0; x < dstWidth; x++) { 416 for (int x = 0; x < dstWidth; x++) {
415 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 417 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
416 src += deltaSrc; 418 src += deltaSrc;
417 } 419 }
418 return SkSwizzler::kOpaque_ResultAlpha; 420 return SkSwizzler::kOpaque_ResultAlpha;
419 } 421 }
420 422
421 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( 423 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565(
422 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 424 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
423 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 425 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
424 // FIXME: Support dithering? 426 // FIXME: Support dithering?
425 src += offset; 427 src += offset;
426 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 428 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
427 for (int x = 0; x < dstWidth; x++) { 429 for (int x = 0; x < dstWidth; x++) {
428 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 430 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
429 src += bytesPerPixel; 431 src += deltaSrc;
430 } 432 }
431 return SkSwizzler::kOpaque_ResultAlpha; 433 return SkSwizzler::kOpaque_ResultAlpha;
432 } 434 }
433 435
434 436
435 // kRGBA 437 // kRGBA
436 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( 438 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
437 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 439 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
438 int deltaSrc, int offset, const SkPMColor ctable[]) { 440 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
439 441
440 src += offset; 442 src += offset;
441 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 443 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
442 INIT_RESULT_ALPHA; 444 INIT_RESULT_ALPHA;
443 for (int x = 0; x < dstWidth; x++) { 445 for (int x = 0; x < dstWidth; x++) {
444 unsigned alpha = src[3]; 446 unsigned alpha = src[3];
445 UPDATE_RESULT_ALPHA(alpha); 447 UPDATE_RESULT_ALPHA(alpha);
446 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 448 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
447 src += deltaSrc; 449 src += deltaSrc;
448 } 450 }
449 return COMPUTE_RESULT_ALPHA; 451 return COMPUTE_RESULT_ALPHA;
450 } 452 }
451 453
452 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( 454 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
453 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 455 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
454 int deltaSrc, int offset, const SkPMColor ctable[]) { 456 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
455 457
456 src += offset; 458 src += offset;
457 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 459 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
458 INIT_RESULT_ALPHA; 460 INIT_RESULT_ALPHA;
459 for (int x = 0; x < dstWidth; x++) { 461 for (int x = 0; x < dstWidth; x++) {
460 unsigned alpha = src[3]; 462 unsigned alpha = src[3];
461 UPDATE_RESULT_ALPHA(alpha); 463 UPDATE_RESULT_ALPHA(alpha);
462 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 464 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
463 src += deltaSrc; 465 src += deltaSrc;
464 } 466 }
465 return COMPUTE_RESULT_ALPHA; 467 return COMPUTE_RESULT_ALPHA;
466 } 468 }
467 469
468 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( 470 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
469 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 471 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
470 int deltaSrc, int offset, const SkPMColor ctable[]) { 472 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
471 473
472 src += offset; 474 src += offset;
473 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 475 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
474 INIT_RESULT_ALPHA; 476 INIT_RESULT_ALPHA;
475 for (int x = 0; x < dstWidth; x++) { 477 for (int x = 0; x < dstWidth; x++) {
476 unsigned alpha = src[3]; 478 unsigned alpha = src[3];
477 UPDATE_RESULT_ALPHA(alpha); 479 UPDATE_RESULT_ALPHA(alpha);
478 if (0 != alpha) { 480 if (0 != alpha) {
479 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 481 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
480 } 482 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); 695 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX);
694 } 696 }
695 697
696 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 698 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
697 int deltaSrc, const SkImageInfo& info, int sampleX) 699 int deltaSrc, const SkImageInfo& info, int sampleX)
698 : fRowProc(proc) 700 : fRowProc(proc)
699 , fColorTable(ctable) 701 , fColorTable(ctable)
700 , fDeltaSrc(deltaSrc) 702 , fDeltaSrc(deltaSrc)
701 , fDstInfo(info) 703 , fDstInfo(info)
702 , fSampleX(sampleX) 704 , fSampleX(sampleX)
703 , fX0(sampleX == 1 ? 0 : sampleX >> 1) 705 , fX0(get_start_coord(sampleX))
704 { 706 {
705 // check that fX0 is less than original width 707 // check that fX0 is less than original width
706 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); 708 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX);
707 } 709 }
708 710
709 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { 711 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
710 SkASSERT(nullptr != dst && nullptr != src); 712 SkASSERT(nullptr != dst && nullptr != src);
711 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel taSrc, fColorTable); 713 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc,
714 fX0 * fDeltaSrc, fColorTable);
712 } 715 }
713 716
714 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, 717 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
715 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { 718 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable,
719 SkCodec::ZeroInitialized zeroInit) {
716 SkASSERT(dstStartRow != nullptr); 720 SkASSERT(dstStartRow != nullptr);
717 SkASSERT(numRows <= (uint32_t) dstInfo.height()); 721 SkASSERT(numRows <= (uint32_t) dstInfo.height());
718 722
719 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. 723 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded.
720 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); 724 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes);
721 725
722 // Use the proper memset routine to fill the remaining bytes 726 // Use the proper memset routine to fill the remaining bytes
723 switch(dstInfo.colorType()) { 727 switch(dstInfo.colorType()) {
724 case kN32_SkColorType: 728 case kN32_SkColorType:
725 // Assume input is an index if we have a color table 729 // Assume input is an index if we have a color table
726 uint32_t color; 730 uint32_t color;
727 if (nullptr != colorTable) { 731 if (nullptr != colorTable) {
728 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); 732 color = colorTable[(uint8_t) colorOrIndex];
729 color = colorTable[colorOrIndex];
730 // Otherwise, assume the input is a color 733 // Otherwise, assume the input is a color
731 } else { 734 } else {
732 color = colorOrIndex; 735 color = colorOrIndex;
733 } 736 }
734 737
738 // If memory is zero initialized, we may not need to fill
739 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) {
740 return;
741 }
742
735 // We must fill row by row in the case of unaligned row bytes 743 // We must fill row by row in the case of unaligned row bytes
736 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { 744 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) {
737 sk_memset32((uint32_t*) dstStartRow, color, 745 sk_memset32((uint32_t*) dstStartRow, color,
738 (uint32_t) bytesToFill / sizeof(SkPMColor)); 746 (uint32_t) bytesToFill / sizeof(SkPMColor));
739 } else { 747 } else {
740 // This is an unlikely, slow case 748 // This is an unlikely, slow case
741 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n"); 749 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n");
742 uint32_t* dstRow = (uint32_t*) dstStartRow; 750 uint32_t* dstRow = (uint32_t*) dstStartRow;
743 for (uint32_t row = 0; row < numRows; row++) { 751 for (uint32_t row = 0; row < numRows; row++) {
744 for (int32_t col = 0; col < dstInfo.width(); col++) { 752 for (int32_t col = 0; col < dstInfo.width(); col++) {
745 dstRow[col] = color; 753 dstRow[col] = color;
746 } 754 }
747 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); 755 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes);
748 } 756 }
749 } 757 }
750 break; 758 break;
751 // On an index destination color type, always assume the input is an ind ex
752 case kIndex_8_SkColorType:
753 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex);
754 memset(dstStartRow, colorOrIndex, bytesToFill);
755 break;
756 case kGray_8_SkColorType:
757 // If the destination is kGray, the caller passes in an 8-bit color.
758 // We will not assert that the high bits of colorOrIndex must be zer oed.
759 // This allows us to take advantage of the fact that the low 8 bits of an
760 // SKPMColor may be a valid a grayscale color. For example, the low 8
761 // bits of SK_ColorBLACK are identical to the grayscale representati on
762 // for black.
763 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
764 break;
765 case kRGB_565_SkColorType: 759 case kRGB_565_SkColorType:
766 // If the destination is k565, the caller passes in a 16-bit color. 760 // If the destination is k565, the caller passes in a 16-bit color.
767 // We will not assert that the high bits of colorOrIndex must be zer oed. 761 // We will not assert that the high bits of colorOrIndex must be zer oed.
768 // This allows us to take advantage of the fact that the low 16 bits of an 762 // This allows us to take advantage of the fact that the low 16 bits of an
769 // SKPMColor may be a valid a 565 color. For example, the low 16 763 // SKPMColor may be a valid a 565 color. For example, the low 16
770 // bits of SK_ColorBLACK are identical to the 565 representation 764 // bits of SK_ColorBLACK are identical to the 565 representation
771 // for black. 765 // for black.
772 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 766 // If we ever want to fill with colorOrIndex != 0, we will probably need
767 // to implement this with sk_memset16().
768 SkASSERT((uint16_t) colorOrIndex == (uint8_t) colorOrIndex);
769 // Fall through
770 case kIndex_8_SkColorType:
771 // On an index destination color type, always assume the input is an index.
772 // Fall through
773 case kGray_8_SkColorType:
774 // If the destination is kGray, the caller passes in an 8-bit color.
775 // We will not assert that the high bits of colorOrIndex must be zer oed.
776 // This allows us to take advantage of the fact that the low 8 bits of an
777 // SKPMColor may be a valid a grayscale color. For example, the low 8
778 // bits of SK_ColorBLACK are identical to the grayscale representati on
779 // for black.
780
781 // If memory is zero initialized, we may not need to fill
782 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == (uint8_t) colo rOrIndex) {
783 return;
784 }
785
786 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
773 break; 787 break;
774 default: 788 default:
775 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 789 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
776 SkASSERT(false); 790 SkASSERT(false);
777 break; 791 break;
778 } 792 }
779 } 793 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698