OLD | NEW |
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 INIT_RESULT_ALPHA; |
177 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 180 src += offset / 8; |
178 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 181 int bitIndex = offset % 8; |
179 const uint8_t mask = (1 << bitsPerPixel) - 1; | 182 uint8_t currByte = *src; |
180 int x = 0; | 183 const uint8_t mask = (1 << bpp) - 1; |
181 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 184 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; |
182 uint8_t pixelData = src[byte]; | 185 dst[0] = SkPixel32ToPixel16(ctable[index]); |
183 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | 186 |
184 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 187 for (int x = 1; x < dstWidth; x++) { |
185 uint16_t c = SkPixel32ToPixel16(ctable[index]); | 188 int bitOffset = bitIndex + deltaSrc; |
186 dst[x] = c; | 189 bitIndex = bitOffset % 8; |
187 pixelData <<= bitsPerPixel; | 190 currByte = *(src += bitOffset / 8); |
188 x++; | 191 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
189 } | 192 dst[x] = SkPixel32ToPixel16(ctable[index]); |
190 } | 193 } |
191 return SkSwizzler::kOpaque_ResultAlpha; | 194 return SkAlphaType::kOpaque_SkAlphaType; |
192 } | 195 } |
193 | 196 |
194 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( | 197 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
195 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 198 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
196 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | 199 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
197 | 200 |
198 src += offset; | 201 SkPMColor* dst = (SkPMColor*) dstRow; |
199 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | |
200 INIT_RESULT_ALPHA; | 202 INIT_RESULT_ALPHA; |
201 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 203 src += offset / 8; |
202 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 204 int bitIndex = offset % 8; |
203 const uint8_t mask = (1 << bitsPerPixel) - 1; | 205 uint8_t currByte = *src; |
204 int x = 0; | 206 const uint8_t mask = (1 << bpp) - 1; |
205 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 207 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask; |
206 uint8_t pixelData = src[byte]; | 208 dst[0] = ctable[index]; |
207 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | 209 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); |
208 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 210 |
209 SkPMColor c = ctable[index]; | 211 for (int x = 1; x < dstWidth; x++) { |
210 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 212 int bitOffset = bitIndex + deltaSrc; |
211 dst[x] = c; | 213 bitIndex = bitOffset % 8; |
212 pixelData <<= bitsPerPixel; | 214 currByte = *(src += bitOffset / 8); |
213 x++; | 215 index = (currByte >> (8 - bpp - bitIndex)) & mask; |
214 } | 216 dst[x] = ctable[index]; |
| 217 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); |
215 } | 218 } |
216 return COMPUTE_RESULT_ALPHA; | 219 return COMPUTE_RESULT_ALPHA; |
217 } | 220 } |
218 | 221 |
219 // kIndex | 222 // kIndex |
220 | 223 |
221 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 224 static SkSwizzler::ResultAlpha swizzle_index_to_index( |
222 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 225 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
223 int deltaSrc, int offset, const SkPMColor ctable[]) { | 226 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
224 | 227 |
225 src += offset; | 228 src += offset; |
226 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 229 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
227 INIT_RESULT_ALPHA; | 230 INIT_RESULT_ALPHA; |
228 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? | 231 // 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 | 232 // 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. | 233 // and probably wrong since gif and bmp (rarely) may have al
pha. |
231 if (1 == deltaSrc) { | 234 if (1 == deltaSrc) { |
232 // A non-zero offset is only used when sampling, meaning that deltaSrc w
ill be | 235 // 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. | 236 // greater than 1. The below loop relies on the fact that src remains un
changed. |
234 SkASSERT(0 == offset); | 237 SkASSERT(0 == offset); |
235 memcpy(dst, src, dstWidth); | 238 memcpy(dst, src, dstWidth); |
236 for (int x = 0; x < dstWidth; x++) { | 239 for (int x = 0; x < dstWidth; x++) { |
237 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 240 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
238 } | 241 } |
239 } else { | 242 } else { |
240 for (int x = 0; x < dstWidth; x++) { | 243 for (int x = 0; x < dstWidth; x++) { |
241 dst[x] = *src; | 244 dst[x] = *src; |
242 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); | 245 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); |
243 src += deltaSrc; | 246 src += deltaSrc; |
244 } | 247 } |
245 } | 248 } |
246 return COMPUTE_RESULT_ALPHA; | 249 return COMPUTE_RESULT_ALPHA; |
247 } | 250 } |
248 | 251 |
249 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 252 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
250 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 253 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
251 int deltaSrc, int offset, const SkPMColor ctable[]) { | 254 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
252 | 255 |
253 src += offset; | 256 src += offset; |
254 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 257 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
255 INIT_RESULT_ALPHA; | 258 INIT_RESULT_ALPHA; |
256 for (int x = 0; x < dstWidth; x++) { | 259 for (int x = 0; x < dstWidth; x++) { |
257 SkPMColor c = ctable[*src]; | 260 SkPMColor c = ctable[*src]; |
258 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 261 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
259 dst[x] = c; | 262 dst[x] = c; |
260 src += deltaSrc; | 263 src += deltaSrc; |
261 } | 264 } |
262 return COMPUTE_RESULT_ALPHA; | 265 return COMPUTE_RESULT_ALPHA; |
263 } | 266 } |
264 | 267 |
265 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( | 268 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
266 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 269 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
267 int deltaSrc, int offset, const SkPMColor ctable[]) { | 270 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
268 | 271 |
269 src += offset; | 272 src += offset; |
270 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 273 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
271 INIT_RESULT_ALPHA; | 274 INIT_RESULT_ALPHA; |
272 for (int x = 0; x < dstWidth; x++) { | 275 for (int x = 0; x < dstWidth; x++) { |
273 SkPMColor c = ctable[*src]; | 276 SkPMColor c = ctable[*src]; |
274 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 277 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
275 if (c != 0) { | 278 if (c != 0) { |
276 dst[x] = c; | 279 dst[x] = c; |
277 } | 280 } |
278 src += deltaSrc; | 281 src += deltaSrc; |
279 } | 282 } |
280 return COMPUTE_RESULT_ALPHA; | 283 return COMPUTE_RESULT_ALPHA; |
281 } | 284 } |
282 | 285 |
283 static SkSwizzler::ResultAlpha swizzle_index_to_565( | 286 static SkSwizzler::ResultAlpha swizzle_index_to_565( |
284 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 287 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
285 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 288 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
286 // FIXME: Support dithering? Requires knowing y, which I think is a bigger | 289 // FIXME: Support dithering? Requires knowing y, which I think is a bigger |
287 // change. | 290 // change. |
288 src += offset; | 291 src += offset; |
289 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 292 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
290 for (int x = 0; x < dstWidth; x++) { | 293 for (int x = 0; x < dstWidth; x++) { |
291 dst[x] = SkPixel32ToPixel16(ctable[*src]); | 294 dst[x] = SkPixel32ToPixel16(ctable[*src]); |
292 src += bytesPerPixel; | 295 src += deltaSrc; |
293 } | 296 } |
294 return SkSwizzler::kOpaque_ResultAlpha; | 297 return SkSwizzler::kOpaque_ResultAlpha; |
295 } | 298 } |
296 | 299 |
297 | 300 |
298 #undef A32_MASK_IN_PLACE | 301 #undef A32_MASK_IN_PLACE |
299 | 302 |
300 // kGray | 303 // kGray |
301 | 304 |
302 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | 305 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
303 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 306 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
304 int deltaSrc, int offset, const SkPMColor ctable[]) { | 307 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
305 | 308 |
306 src += offset; | 309 src += offset; |
307 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 310 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
308 for (int x = 0; x < dstWidth; x++) { | 311 for (int x = 0; x < dstWidth; x++) { |
309 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); | 312 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
310 src += deltaSrc; | 313 src += deltaSrc; |
311 } | 314 } |
312 return SkSwizzler::kOpaque_ResultAlpha; | 315 return SkSwizzler::kOpaque_ResultAlpha; |
313 } | 316 } |
314 | 317 |
315 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | 318 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
316 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 319 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
317 int deltaSrc, int offset, const SkPMColor ctable[]) { | 320 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
318 | 321 |
319 src += offset; | 322 src += offset; |
320 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 323 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
321 if (1 == deltaSrc) { | 324 if (1 == deltaSrc) { |
322 memcpy(dstRow, src, dstWidth); | 325 memcpy(dstRow, src, dstWidth); |
323 } else { | 326 } else { |
324 for (int x = 0; x < dstWidth; x++) { | 327 for (int x = 0; x < dstWidth; x++) { |
325 dst[x] = src[0]; | 328 dst[x] = src[0]; |
326 src += deltaSrc; | 329 src += deltaSrc; |
327 } | 330 } |
328 } | 331 } |
329 return SkSwizzler::kOpaque_ResultAlpha; | 332 return SkSwizzler::kOpaque_ResultAlpha; |
330 } | 333 } |
331 | 334 |
332 static SkSwizzler::ResultAlpha swizzle_gray_to_565( | 335 static SkSwizzler::ResultAlpha swizzle_gray_to_565( |
333 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 336 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
334 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 337 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
335 // FIXME: Support dithering? | 338 // FIXME: Support dithering? |
336 src += offset; | 339 src += offset; |
337 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 340 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
338 for (int x = 0; x < dstWidth; x++) { | 341 for (int x = 0; x < dstWidth; x++) { |
339 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 342 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
340 src += bytesPerPixel; | 343 src += deltaSrc; |
341 } | 344 } |
342 return SkSwizzler::kOpaque_ResultAlpha; | 345 return SkSwizzler::kOpaque_ResultAlpha; |
343 } | 346 } |
344 | 347 |
345 // kBGRX | 348 // kBGRX |
346 | 349 |
347 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 350 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
348 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 351 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
349 int deltaSrc, int offset, const SkPMColor ctable[]) { | 352 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
350 | 353 |
351 src += offset; | 354 src += offset; |
352 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 355 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
353 for (int x = 0; x < dstWidth; x++) { | 356 for (int x = 0; x < dstWidth; x++) { |
354 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 357 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
355 src += deltaSrc; | 358 src += deltaSrc; |
356 } | 359 } |
357 return SkSwizzler::kOpaque_ResultAlpha; | 360 return SkSwizzler::kOpaque_ResultAlpha; |
358 } | 361 } |
359 | 362 |
360 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( | 363 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( |
361 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 364 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
362 int deltaSrc, int offset, const SkPMColor ctable[]) { | 365 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
363 // FIXME: Support dithering? | 366 // FIXME: Support dithering? |
364 src += offset; | 367 src += offset; |
365 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 368 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
366 for (int x = 0; x < dstWidth; x++) { | 369 for (int x = 0; x < dstWidth; x++) { |
367 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 370 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
368 src += deltaSrc; | 371 src += deltaSrc; |
369 } | 372 } |
370 return SkSwizzler::kOpaque_ResultAlpha; | 373 return SkSwizzler::kOpaque_ResultAlpha; |
371 } | 374 } |
372 | 375 |
373 // kBGRA | 376 // kBGRA |
374 | 377 |
375 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 378 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
376 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 379 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
377 int deltaSrc, int offset, const SkPMColor ctable[]) { | 380 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
378 | 381 |
379 src += offset; | 382 src += offset; |
380 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 383 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
381 INIT_RESULT_ALPHA; | 384 INIT_RESULT_ALPHA; |
382 for (int x = 0; x < dstWidth; x++) { | 385 for (int x = 0; x < dstWidth; x++) { |
383 uint8_t alpha = src[3]; | 386 uint8_t alpha = src[3]; |
384 UPDATE_RESULT_ALPHA(alpha); | 387 UPDATE_RESULT_ALPHA(alpha); |
385 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 388 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
386 src += deltaSrc; | 389 src += deltaSrc; |
387 } | 390 } |
388 return COMPUTE_RESULT_ALPHA; | 391 return COMPUTE_RESULT_ALPHA; |
389 } | 392 } |
390 | 393 |
391 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | 394 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
392 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 395 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
393 int deltaSrc, int offset, const SkPMColor ctable[]) { | 396 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
394 | 397 |
395 src += offset; | 398 src += offset; |
396 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 399 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
397 INIT_RESULT_ALPHA; | 400 INIT_RESULT_ALPHA; |
398 for (int x = 0; x < dstWidth; x++) { | 401 for (int x = 0; x < dstWidth; x++) { |
399 uint8_t alpha = src[3]; | 402 uint8_t alpha = src[3]; |
400 UPDATE_RESULT_ALPHA(alpha); | 403 UPDATE_RESULT_ALPHA(alpha); |
401 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); | 404 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
402 src += deltaSrc; | 405 src += deltaSrc; |
403 } | 406 } |
404 return COMPUTE_RESULT_ALPHA; | 407 return COMPUTE_RESULT_ALPHA; |
405 } | 408 } |
406 | 409 |
407 // kRGBX | 410 // kRGBX |
408 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 411 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
409 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 412 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
410 int deltaSrc, int offset, const SkPMColor ctable[]) { | 413 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
411 | 414 |
412 src += offset; | 415 src += offset; |
413 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 416 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
414 for (int x = 0; x < dstWidth; x++) { | 417 for (int x = 0; x < dstWidth; x++) { |
415 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 418 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
416 src += deltaSrc; | 419 src += deltaSrc; |
417 } | 420 } |
418 return SkSwizzler::kOpaque_ResultAlpha; | 421 return SkSwizzler::kOpaque_ResultAlpha; |
419 } | 422 } |
420 | 423 |
421 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( | 424 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( |
422 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 425 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
423 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 426 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
424 // FIXME: Support dithering? | 427 // FIXME: Support dithering? |
425 src += offset; | 428 src += offset; |
426 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 429 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
427 for (int x = 0; x < dstWidth; x++) { | 430 for (int x = 0; x < dstWidth; x++) { |
428 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 431 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
429 src += bytesPerPixel; | 432 src += deltaSrc; |
430 } | 433 } |
431 return SkSwizzler::kOpaque_ResultAlpha; | 434 return SkSwizzler::kOpaque_ResultAlpha; |
432 } | 435 } |
433 | 436 |
434 | 437 |
435 // kRGBA | 438 // kRGBA |
436 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( | 439 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
437 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 440 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
438 int deltaSrc, int offset, const SkPMColor ctable[]) { | 441 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
439 | 442 |
440 src += offset; | 443 src += offset; |
441 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 444 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
442 INIT_RESULT_ALPHA; | 445 INIT_RESULT_ALPHA; |
443 for (int x = 0; x < dstWidth; x++) { | 446 for (int x = 0; x < dstWidth; x++) { |
444 unsigned alpha = src[3]; | 447 unsigned alpha = src[3]; |
445 UPDATE_RESULT_ALPHA(alpha); | 448 UPDATE_RESULT_ALPHA(alpha); |
446 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 449 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
447 src += deltaSrc; | 450 src += deltaSrc; |
448 } | 451 } |
449 return COMPUTE_RESULT_ALPHA; | 452 return COMPUTE_RESULT_ALPHA; |
450 } | 453 } |
451 | 454 |
452 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( | 455 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
453 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 456 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
454 int deltaSrc, int offset, const SkPMColor ctable[]) { | 457 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
455 | 458 |
456 src += offset; | 459 src += offset; |
457 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 460 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
458 INIT_RESULT_ALPHA; | 461 INIT_RESULT_ALPHA; |
459 for (int x = 0; x < dstWidth; x++) { | 462 for (int x = 0; x < dstWidth; x++) { |
460 unsigned alpha = src[3]; | 463 unsigned alpha = src[3]; |
461 UPDATE_RESULT_ALPHA(alpha); | 464 UPDATE_RESULT_ALPHA(alpha); |
462 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 465 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
463 src += deltaSrc; | 466 src += deltaSrc; |
464 } | 467 } |
465 return COMPUTE_RESULT_ALPHA; | 468 return COMPUTE_RESULT_ALPHA; |
466 } | 469 } |
467 | 470 |
468 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( | 471 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
469 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 472 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
470 int deltaSrc, int offset, const SkPMColor ctable[]) { | 473 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
471 | 474 |
472 src += offset; | 475 src += offset; |
473 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 476 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
474 INIT_RESULT_ALPHA; | 477 INIT_RESULT_ALPHA; |
475 for (int x = 0; x < dstWidth; x++) { | 478 for (int x = 0; x < dstWidth; x++) { |
476 unsigned alpha = src[3]; | 479 unsigned alpha = src[3]; |
477 UPDATE_RESULT_ALPHA(alpha); | 480 UPDATE_RESULT_ALPHA(alpha); |
478 if (0 != alpha) { | 481 if (0 != alpha) { |
479 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 482 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
480 } | 483 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); | 696 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); |
694 } | 697 } |
695 | 698 |
696 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 699 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
697 int deltaSrc, const SkImageInfo& info, int sampleX) | 700 int deltaSrc, const SkImageInfo& info, int sampleX) |
698 : fRowProc(proc) | 701 : fRowProc(proc) |
699 , fColorTable(ctable) | 702 , fColorTable(ctable) |
700 , fDeltaSrc(deltaSrc) | 703 , fDeltaSrc(deltaSrc) |
701 , fDstInfo(info) | 704 , fDstInfo(info) |
702 , fSampleX(sampleX) | 705 , fSampleX(sampleX) |
703 , fX0(sampleX == 1 ? 0 : sampleX >> 1) | 706 , fX0(SkScaledCodec::GetStartCoord(sampleX)) |
704 { | 707 { |
705 // check that fX0 is less than original width | 708 // check that fX0 is less than original width |
706 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | 709 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
707 } | 710 } |
708 | 711 |
709 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { | 712 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { |
710 SkASSERT(nullptr != dst && nullptr != src); | 713 SkASSERT(nullptr != dst && nullptr != src); |
711 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel
taSrc, fColorTable); | 714 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc, |
| 715 fX0 * fDeltaSrc, fColorTable); |
712 } | 716 } |
713 | 717 |
714 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, | 718 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, |
715 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { | 719 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable, |
| 720 SkCodec::ZeroInitialized zeroInit) { |
716 SkASSERT(dstStartRow != nullptr); | 721 SkASSERT(dstStartRow != nullptr); |
717 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | 722 SkASSERT(numRows <= (uint32_t) dstInfo.height()); |
718 | 723 |
719 // Calculate bytes to fill. We use getSafeSize since the last row may not b
e padded. | 724 // 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); | 725 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS
ize(dstRowBytes); |
721 | 726 |
722 // Use the proper memset routine to fill the remaining bytes | 727 // Use the proper memset routine to fill the remaining bytes |
723 switch(dstInfo.colorType()) { | 728 switch(dstInfo.colorType()) { |
724 case kN32_SkColorType: | 729 case kN32_SkColorType: |
725 // Assume input is an index if we have a color table | 730 // Assume input is an index if we have a color table |
726 uint32_t color; | 731 uint32_t color; |
727 if (nullptr != colorTable) { | 732 if (nullptr != colorTable) { |
728 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); | 733 color = colorTable[(uint8_t) colorOrIndex]; |
729 color = colorTable[colorOrIndex]; | |
730 // Otherwise, assume the input is a color | 734 // Otherwise, assume the input is a color |
731 } else { | 735 } else { |
732 color = colorOrIndex; | 736 color = colorOrIndex; |
733 } | 737 } |
734 | 738 |
| 739 // If memory is zero initialized, we may not need to fill |
| 740 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) { |
| 741 return; |
| 742 } |
| 743 |
735 // We must fill row by row in the case of unaligned row bytes | 744 // We must fill row by row in the case of unaligned row bytes |
736 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { | 745 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { |
737 sk_memset32((uint32_t*) dstStartRow, color, | 746 sk_memset32((uint32_t*) dstStartRow, color, |
738 (uint32_t) bytesToFill / sizeof(SkPMColor)); | 747 (uint32_t) bytesToFill / sizeof(SkPMColor)); |
739 } else { | 748 } else { |
740 // This is an unlikely, slow case | 749 // This is an unlikely, slow case |
741 SkCodecPrintf("Warning: Strange number of row bytes, fill will b
e slow.\n"); | 750 SkCodecPrintf("Warning: Strange number of row bytes, fill will b
e slow.\n"); |
742 uint32_t* dstRow = (uint32_t*) dstStartRow; | 751 uint32_t* dstRow = (uint32_t*) dstStartRow; |
743 for (uint32_t row = 0; row < numRows; row++) { | 752 for (uint32_t row = 0; row < numRows; row++) { |
744 for (int32_t col = 0; col < dstInfo.width(); col++) { | 753 for (int32_t col = 0; col < dstInfo.width(); col++) { |
745 dstRow[col] = color; | 754 dstRow[col] = color; |
746 } | 755 } |
747 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); | 756 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); |
748 } | 757 } |
749 } | 758 } |
750 break; | 759 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: | 760 case kRGB_565_SkColorType: |
766 // If the destination is k565, the caller passes in a 16-bit color. | 761 // 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. | 762 // 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 | 763 // 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 | 764 // SKPMColor may be a valid a 565 color. For example, the low 16 |
770 // bits of SK_ColorBLACK are identical to the 565 representation | 765 // bits of SK_ColorBLACK are identical to the 565 representation |
771 // for black. | 766 // for black. |
772 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 767 // If we ever want to fill with colorOrIndex != 0, we will probably
need |
| 768 // to implement this with sk_memset16(). |
| 769 SkASSERT((uint16_t) colorOrIndex == (uint8_t) colorOrIndex); |
| 770 // Fall through |
| 771 case kIndex_8_SkColorType: |
| 772 // On an index destination color type, always assume the input is an
index. |
| 773 // Fall through |
| 774 case kGray_8_SkColorType: |
| 775 // If the destination is kGray, the caller passes in an 8-bit color. |
| 776 // We will not assert that the high bits of colorOrIndex must be zer
oed. |
| 777 // This allows us to take advantage of the fact that the low 8 bits
of an |
| 778 // SKPMColor may be a valid a grayscale color. For example, the low
8 |
| 779 // bits of SK_ColorBLACK are identical to the grayscale representati
on |
| 780 // for black. |
| 781 |
| 782 // If memory is zero initialized, we may not need to fill |
| 783 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == (uint8_t) colo
rOrIndex) { |
| 784 return; |
| 785 } |
| 786 |
| 787 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); |
773 break; | 788 break; |
774 default: | 789 default: |
775 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); | 790 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); |
776 SkASSERT(false); | 791 SkASSERT(false); |
777 break; | 792 break; |
778 } | 793 } |
779 } | 794 } |
OLD | NEW |