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

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

Powered by Google App Engine
This is Rietveld 408576698