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" | |
11 #include "SkSwizzler.h" | 10 #include "SkSwizzler.h" |
12 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
13 #include "SkUtils.h" | 12 #include "SkUtils.h" |
14 | 13 |
15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, | 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
16 uint8_t maxAlpha) { | 15 uint8_t maxAlpha) { |
17 // In the transparent case, this returns 0x0000 | 16 // In the transparent case, this returns 0x0000 |
18 // In the opaque case, this returns 0xFFFF | 17 // In the opaque case, this returns 0xFFFF |
19 // If the row is neither transparent nor opaque, returns something else | 18 // If the row is neither transparent nor opaque, returns something else |
20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; | 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; |
21 } | 20 } |
22 | 21 |
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, | |
25 int width, int deltaSrc, int offset, const SkPMColor ctable[]){ | |
26 | |
27 src += offset; | |
28 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
29 for (int x = 0; x < width; x++) { | |
30 dst[x] = src[1] << 8 | src[0]; | |
31 src += deltaSrc; | |
32 } | |
33 // 565 is always opaque | |
34 return SkSwizzler::kOpaque_ResultAlpha; | |
35 } | |
36 | |
37 // kBit | 22 // kBit |
38 // These routines exclusively choose between white and black | 23 // These routines exclusively choose between white and black |
39 | 24 |
40 #define GRAYSCALE_BLACK 0 | 25 #define GRAYSCALE_BLACK 0 |
41 #define GRAYSCALE_WHITE 0xFF | 26 #define GRAYSCALE_WHITE 0xFF |
42 | 27 |
43 | |
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( | 28 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( |
46 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
47 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 30 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
48 | |
49 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 31 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
50 | 32 |
51 // increment src by byte offset and bitIndex by bit offset | 33 // Determine how many full bytes are in the row |
52 src += offset / 8; | 34 int bytesInRow = width >> 3; |
53 int bitIndex = offset % 8; | 35 int i; |
54 uint8_t currByte = *src; | 36 for (i = 0; i < bytesInRow; i++) { |
55 | 37 U8CPU currByte = src[i]; |
56 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLAC
K; | 38 for (int j = 0; j < 8; j++) { |
57 | 39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B
LACK; |
58 for (int x = 1; x < dstWidth; x++) { | 40 } |
59 int bitOffset = bitIndex + deltaSrc; | 41 dst += 8; |
60 bitIndex = bitOffset % 8; | |
61 currByte = *(src += bitOffset / 8); | |
62 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_
BLACK; | |
63 } | 42 } |
64 | 43 |
| 44 // Finish the remaining bits |
| 45 width &= 7; |
| 46 if (width > 0) { |
| 47 U8CPU currByte = src[i]; |
| 48 for (int j = 0; j < width; j++) { |
| 49 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; |
| 50 currByte <<= 1; |
| 51 } |
| 52 } |
65 return SkSwizzler::kOpaque_ResultAlpha; | 53 return SkSwizzler::kOpaque_ResultAlpha; |
66 } | 54 } |
67 | 55 |
68 #undef GRAYSCALE_BLACK | 56 #undef GRAYSCALE_BLACK |
69 #undef GRAYSCALE_WHITE | 57 #undef GRAYSCALE_WHITE |
70 | 58 |
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( | 59 static SkSwizzler::ResultAlpha swizzle_bit_to_index( |
73 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 60 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
74 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 61 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
75 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 62 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
76 | 63 |
77 // increment src by byte offset and bitIndex by bit offset | 64 // Determine how many full bytes are in the row |
78 src += offset / 8; | 65 int bytesInRow = width >> 3; |
79 int bitIndex = offset % 8; | 66 int i; |
80 uint8_t currByte = *src; | 67 for (i = 0; i < bytesInRow; i++) { |
81 | 68 U8CPU currByte = src[i]; |
82 dst[0] = ((currByte >> (7-bitIndex)) & 1); | 69 for (int j = 0; j < 8; j++) { |
83 | 70 dst[j] = (currByte >> (7 - j)) & 1; |
84 for (int x = 1; x < dstWidth; x++) { | 71 } |
85 int bitOffset = bitIndex + deltaSrc; | 72 dst += 8; |
86 bitIndex = bitOffset % 8; | |
87 currByte = *(src += bitOffset / 8); | |
88 dst[x] = ((currByte >> (7-bitIndex)) & 1); | |
89 } | 73 } |
90 | 74 |
| 75 // Finish the remaining bits |
| 76 width &= 7; |
| 77 if (width > 0) { |
| 78 U8CPU currByte = src[i]; |
| 79 for (int j = 0; j < width; j++) { |
| 80 dst[j] = ((currByte >> 7) & 1); |
| 81 currByte <<= 1; |
| 82 } |
| 83 } |
91 return SkSwizzler::kOpaque_ResultAlpha; | 84 return SkSwizzler::kOpaque_ResultAlpha; |
92 } | 85 } |
93 | 86 |
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( | 87 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( |
96 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 88 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
97 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | 89 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
98 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 90 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
99 | 91 |
100 // increment src by byte offset and bitIndex by bit offset | 92 // Determine how many full bytes are in the row |
101 src += offset / 8; | 93 int bytesInRow = width >> 3; |
102 int bitIndex = offset % 8; | 94 int i; |
103 uint8_t currByte = *src; | 95 for (i = 0; i < bytesInRow; i++) { |
104 | 96 U8CPU currByte = src[i]; |
105 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | 97 for (int j = 0; j < 8; j++) { |
106 | 98 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK
; |
107 for (int x = 1; x < dstWidth; x++) { | 99 } |
108 int bitOffset = bitIndex + deltaSrc; | 100 dst += 8; |
109 bitIndex = bitOffset % 8; | |
110 currByte = *(src += bitOffset / 8); | |
111 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL
ACK; | |
112 } | 101 } |
113 | 102 |
| 103 // Finish the remaining bits |
| 104 width &= 7; |
| 105 if (width > 0) { |
| 106 U8CPU currByte = src[i]; |
| 107 for (int j = 0; j < width; j++) { |
| 108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| 109 currByte <<= 1; |
| 110 } |
| 111 } |
114 return SkSwizzler::kOpaque_ResultAlpha; | 112 return SkSwizzler::kOpaque_ResultAlpha; |
115 } | 113 } |
116 | 114 |
117 // kIndex1, kIndex2, kIndex4 | 115 // kIndex1, kIndex2, kIndex4 |
118 | 116 |
119 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 117 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
120 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
121 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | 119 int bitsPerPixel, const SkPMColor ctable[]) { |
122 | 120 |
123 src += offset; | |
124 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 121 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
125 INIT_RESULT_ALPHA; | 122 INIT_RESULT_ALPHA; |
126 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 123 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
127 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 124 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
128 const uint8_t mask = (1 << bitsPerPixel) - 1; | 125 const uint8_t mask = (1 << bitsPerPixel) - 1; |
129 int x = 0; | 126 int x = 0; |
130 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 127 for (uint32_t byte = 0; byte < rowBytes; byte++) { |
131 uint8_t pixelData = src[byte]; | 128 uint8_t pixelData = src[byte]; |
132 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | 129 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { |
133 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
134 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | 131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); |
135 dst[x] = index; | 132 dst[x] = index; |
136 pixelData <<= bitsPerPixel; | 133 pixelData <<= bitsPerPixel; |
137 x++; | 134 x++; |
138 } | 135 } |
139 } | 136 } |
140 return COMPUTE_RESULT_ALPHA; | 137 return COMPUTE_RESULT_ALPHA; |
141 } | 138 } |
142 | 139 |
143 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( | 140 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
145 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | 142 int bitsPerPixel, const SkPMColor ctable[]) { |
146 | 143 |
147 src += offset; | |
148 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 144 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
149 INIT_RESULT_ALPHA; | 145 INIT_RESULT_ALPHA; |
150 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 146 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
151 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 147 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
152 const uint8_t mask = (1 << bitsPerPixel) - 1; | 148 const uint8_t mask = (1 << bitsPerPixel) - 1; |
153 int x = 0; | 149 int x = 0; |
154 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 150 for (uint32_t byte = 0; byte < rowBytes; byte++) { |
155 uint8_t pixelData = src[byte]; | 151 uint8_t pixelData = src[byte]; |
156 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | 152 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { |
157 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 153 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
158 SkPMColor c = ctable[index]; | 154 SkPMColor c = ctable[index]; |
159 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 155 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
160 dst[x] = c; | 156 dst[x] = c; |
161 pixelData <<= bitsPerPixel; | 157 pixelData <<= bitsPerPixel; |
162 x++; | 158 x++; |
163 } | 159 } |
164 } | 160 } |
165 return COMPUTE_RESULT_ALPHA; | 161 return COMPUTE_RESULT_ALPHA; |
166 } | 162 } |
167 | 163 |
168 // kIndex | 164 // kIndex |
169 | 165 |
170 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 166 static SkSwizzler::ResultAlpha swizzle_index_to_index( |
171 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 167 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
172 int deltaSrc, int offset, const SkPMColor ctable[]) { | 168 int bytesPerPixel, const SkPMColor ctable[]) { |
173 | 169 |
174 src += offset; | |
175 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 170 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
176 INIT_RESULT_ALPHA; | 171 memcpy(dst, src, width); |
177 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? | 172 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? |
178 // SkScaledBitmap sampler just guesses that it is opaque. T
his is dangerous | 173 // SkScaledBitmap sampler just guesses that it is opaque. T
his is dangerous |
179 // and probably wrong since gif and bmp (rarely) may have al
pha. | 174 // and probably wrong since gif and bmp (rarely) may have al
pha. |
180 if (1 == deltaSrc) { | 175 INIT_RESULT_ALPHA; |
181 // A non-zero offset is only used when sampling, meaning that deltaSrc w
ill be | 176 for (int x = 0; x < width; x++) { |
182 // greater than 1. The below loop relies on the fact that src remains un
changed. | 177 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
183 SkASSERT(0 == offset); | 178 } |
184 memcpy(dst, src, dstWidth); | 179 return COMPUTE_RESULT_ALPHA; |
185 for (int x = 0; x < dstWidth; x++) { | 180 } |
186 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 181 |
187 } | 182 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
188 } else { | 183 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
189 for (int x = 0; x < dstWidth; x++) { | 184 int bytesPerPixel, const SkPMColor ctable[]) { |
190 dst[x] = *src; | 185 |
191 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); | 186 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
192 src += deltaSrc; | 187 INIT_RESULT_ALPHA; |
| 188 for (int x = 0; x < width; x++) { |
| 189 SkPMColor c = ctable[src[x]]; |
| 190 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
| 191 dst[x] = c; |
| 192 } |
| 193 return COMPUTE_RESULT_ALPHA; |
| 194 } |
| 195 |
| 196 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
| 197 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 198 int bytesPerPixel, const SkPMColor ctable[]) { |
| 199 |
| 200 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 201 INIT_RESULT_ALPHA; |
| 202 for (int x = 0; x < width; x++) { |
| 203 SkPMColor c = ctable[src[x]]; |
| 204 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
| 205 if (c != 0) { |
| 206 dst[x] = c; |
193 } | 207 } |
194 } | 208 } |
195 return COMPUTE_RESULT_ALPHA; | 209 return COMPUTE_RESULT_ALPHA; |
196 } | 210 } |
197 | 211 |
198 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | |
199 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
200 int deltaSrc, int offset, const SkPMColor ctable[]) { | |
201 | |
202 src += offset; | |
203 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
204 INIT_RESULT_ALPHA; | |
205 for (int x = 0; x < dstWidth; x++) { | |
206 SkPMColor c = ctable[*src]; | |
207 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | |
208 dst[x] = c; | |
209 src += deltaSrc; | |
210 } | |
211 return COMPUTE_RESULT_ALPHA; | |
212 } | |
213 | |
214 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( | |
215 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
216 int deltaSrc, int offset, const SkPMColor ctable[]) { | |
217 | |
218 src += offset; | |
219 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
220 INIT_RESULT_ALPHA; | |
221 for (int x = 0; x < dstWidth; x++) { | |
222 SkPMColor c = ctable[*src]; | |
223 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | |
224 if (c != 0) { | |
225 dst[x] = c; | |
226 } | |
227 src += deltaSrc; | |
228 } | |
229 return COMPUTE_RESULT_ALPHA; | |
230 } | |
231 | |
232 static SkSwizzler::ResultAlpha swizzle_index_to_565( | 212 static SkSwizzler::ResultAlpha swizzle_index_to_565( |
233 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 213 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
234 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 214 int bytesPerPixel, const SkPMColor ctable[]) { |
235 // FIXME: Support dithering? Requires knowing y, which I think is a bigger | 215 // FIXME: Support dithering? Requires knowing y, which I think is a bigger |
236 // change. | 216 // change. |
237 src += offset; | |
238 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 217 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
239 for (int x = 0; x < dstWidth; x++) { | 218 for (int x = 0; x < width; x++) { |
240 dst[x] = SkPixel32ToPixel16(ctable[*src]); | 219 dst[x] = SkPixel32ToPixel16(ctable[*src]); |
241 src += bytesPerPixel; | 220 src += bytesPerPixel; |
242 } | 221 } |
243 return SkSwizzler::kOpaque_ResultAlpha; | 222 return SkSwizzler::kOpaque_ResultAlpha; |
244 } | 223 } |
245 | 224 |
246 | 225 |
247 #undef A32_MASK_IN_PLACE | 226 #undef A32_MASK_IN_PLACE |
248 | 227 |
249 // kGray | 228 // kGray |
250 | 229 |
251 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | 230 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
252 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
253 int deltaSrc, int offset, const SkPMColor ctable[]) { | 232 int bytesPerPixel, const SkPMColor ctable[]) { |
254 | 233 |
255 src += offset; | |
256 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
257 for (int x = 0; x < dstWidth; x++) { | 235 for (int x = 0; x < width; x++) { |
258 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); | 236 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); |
259 src += deltaSrc; | |
260 } | 237 } |
261 return SkSwizzler::kOpaque_ResultAlpha; | 238 return SkSwizzler::kOpaque_ResultAlpha; |
262 } | 239 } |
263 | 240 |
264 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | 241 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
265 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 242 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
266 int deltaSrc, int offset, const SkPMColor ctable[]) { | 243 int bytesPerPixel, const SkPMColor ctable[]) { |
267 | 244 memcpy(dstRow, src, width); |
268 src += offset; | |
269 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
270 if (1 == deltaSrc) { | |
271 memcpy(dstRow, src, dstWidth); | |
272 } else { | |
273 for (int x = 0; x < dstWidth; x++) { | |
274 dst[x] = src[0]; | |
275 src += deltaSrc; | |
276 } | |
277 } | |
278 return SkSwizzler::kOpaque_ResultAlpha; | 245 return SkSwizzler::kOpaque_ResultAlpha; |
279 } | 246 } |
280 | 247 |
281 static SkSwizzler::ResultAlpha swizzle_gray_to_565( | 248 static SkSwizzler::ResultAlpha swizzle_gray_to_565( |
282 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 249 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
283 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 250 int bytesPerPixel, const SkPMColor ctable[]) { |
284 // FIXME: Support dithering? | 251 // FIXME: Support dithering? |
285 src += offset; | |
286 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 252 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
287 for (int x = 0; x < dstWidth; x++) { | 253 for (int x = 0; x < width; x++) { |
288 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 254 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
289 src += bytesPerPixel; | 255 src += bytesPerPixel; |
290 } | 256 } |
291 return SkSwizzler::kOpaque_ResultAlpha; | 257 return SkSwizzler::kOpaque_ResultAlpha; |
292 } | 258 } |
293 | 259 |
294 // kBGRX | 260 // kBGRX |
295 | 261 |
296 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 262 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
297 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 263 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
298 int deltaSrc, int offset, const SkPMColor ctable[]) { | 264 int bytesPerPixel, const SkPMColor ctable[]) { |
299 | 265 |
300 src += offset; | |
301 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
302 for (int x = 0; x < dstWidth; x++) { | 267 for (int x = 0; x < width; x++) { |
303 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 268 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
304 src += deltaSrc; | 269 src += bytesPerPixel; |
305 } | 270 } |
306 return SkSwizzler::kOpaque_ResultAlpha; | 271 return SkSwizzler::kOpaque_ResultAlpha; |
307 } | 272 } |
308 | 273 |
309 // kBGRA | 274 // kBGRA |
310 | 275 |
311 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 276 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
312 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 277 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
313 int deltaSrc, int offset, const SkPMColor ctable[]) { | 278 int bytesPerPixel, const SkPMColor ctable[]) { |
314 | 279 |
315 src += offset; | |
316 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 280 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
317 INIT_RESULT_ALPHA; | 281 INIT_RESULT_ALPHA; |
318 for (int x = 0; x < dstWidth; x++) { | 282 for (int x = 0; x < width; x++) { |
319 uint8_t alpha = src[3]; | 283 uint8_t alpha = src[3]; |
320 UPDATE_RESULT_ALPHA(alpha); | 284 UPDATE_RESULT_ALPHA(alpha); |
321 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 285 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
322 src += deltaSrc; | 286 src += bytesPerPixel; |
323 } | 287 } |
324 return COMPUTE_RESULT_ALPHA; | 288 return COMPUTE_RESULT_ALPHA; |
325 } | 289 } |
326 | 290 |
327 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | 291 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
328 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 292 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
329 int deltaSrc, int offset, const SkPMColor ctable[]) { | 293 int bytesPerPixel, const SkPMColor ctable[]) { |
330 | 294 |
331 src += offset; | |
332 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 295 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
333 INIT_RESULT_ALPHA; | 296 INIT_RESULT_ALPHA; |
334 for (int x = 0; x < dstWidth; x++) { | 297 for (int x = 0; x < width; x++) { |
335 uint8_t alpha = src[3]; | 298 uint8_t alpha = src[3]; |
336 UPDATE_RESULT_ALPHA(alpha); | 299 UPDATE_RESULT_ALPHA(alpha); |
337 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); | 300 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
338 src += deltaSrc; | 301 src += bytesPerPixel; |
339 } | 302 } |
340 return COMPUTE_RESULT_ALPHA; | 303 return COMPUTE_RESULT_ALPHA; |
341 } | 304 } |
342 | 305 |
343 // kRGBX | 306 // kRGBX |
344 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 307 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
345 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 308 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
346 int deltaSrc, int offset, const SkPMColor ctable[]) { | 309 int bytesPerPixel, const SkPMColor ctable[]) { |
347 | 310 |
348 src += offset; | |
349 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 311 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
350 for (int x = 0; x < dstWidth; x++) { | 312 for (int x = 0; x < width; x++) { |
351 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 313 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
352 src += deltaSrc; | 314 src += bytesPerPixel; |
353 } | 315 } |
354 return SkSwizzler::kOpaque_ResultAlpha; | 316 return SkSwizzler::kOpaque_ResultAlpha; |
355 } | 317 } |
356 | 318 |
357 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( | 319 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( |
358 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 320 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
359 int bytesPerPixel, int offset, const SkPMColor ctable[]) { | 321 int bytesPerPixel, const SkPMColor ctable[]) { |
360 // FIXME: Support dithering? | 322 // FIXME: Support dithering? |
361 src += offset; | |
362 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 323 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
363 for (int x = 0; x < dstWidth; x++) { | 324 for (int x = 0; x < width; x++) { |
364 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 325 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
365 src += bytesPerPixel; | 326 src += bytesPerPixel; |
366 } | 327 } |
367 return SkSwizzler::kOpaque_ResultAlpha; | 328 return SkSwizzler::kOpaque_ResultAlpha; |
368 } | 329 } |
369 | 330 |
370 | 331 |
371 // kRGBA | 332 // kRGBA |
372 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( | 333 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 334 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
374 int deltaSrc, int offset, const SkPMColor ctable[]) { | 335 int bytesPerPixel, const SkPMColor ctable[]) { |
375 | 336 |
376 src += offset; | |
377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 337 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
378 INIT_RESULT_ALPHA; | 338 INIT_RESULT_ALPHA; |
379 for (int x = 0; x < dstWidth; x++) { | 339 for (int x = 0; x < width; x++) { |
380 unsigned alpha = src[3]; | 340 unsigned alpha = src[3]; |
381 UPDATE_RESULT_ALPHA(alpha); | 341 UPDATE_RESULT_ALPHA(alpha); |
382 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 342 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
383 src += deltaSrc; | 343 src += bytesPerPixel; |
384 } | 344 } |
385 return COMPUTE_RESULT_ALPHA; | 345 return COMPUTE_RESULT_ALPHA; |
386 } | 346 } |
387 | 347 |
388 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( | 348 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
389 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 349 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
390 int deltaSrc, int offset, const SkPMColor ctable[]) { | 350 int bytesPerPixel, const SkPMColor ctable[]) { |
391 | 351 |
392 src += offset; | |
393 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 352 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
394 INIT_RESULT_ALPHA; | 353 INIT_RESULT_ALPHA; |
395 for (int x = 0; x < dstWidth; x++) { | 354 for (int x = 0; x < width; x++) { |
396 unsigned alpha = src[3]; | 355 unsigned alpha = src[3]; |
397 UPDATE_RESULT_ALPHA(alpha); | 356 UPDATE_RESULT_ALPHA(alpha); |
398 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 357 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
399 src += deltaSrc; | 358 src += bytesPerPixel; |
400 } | 359 } |
401 return COMPUTE_RESULT_ALPHA; | 360 return COMPUTE_RESULT_ALPHA; |
402 } | 361 } |
403 | 362 |
404 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( | 363 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
405 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 364 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
406 int deltaSrc, int offset, const SkPMColor ctable[]) { | 365 int bytesPerPixel, const SkPMColor ctable[]) { |
407 | 366 |
408 src += offset; | |
409 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 367 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
410 INIT_RESULT_ALPHA; | 368 INIT_RESULT_ALPHA; |
411 for (int x = 0; x < dstWidth; x++) { | 369 for (int x = 0; x < width; x++) { |
412 unsigned alpha = src[3]; | 370 unsigned alpha = src[3]; |
413 UPDATE_RESULT_ALPHA(alpha); | 371 UPDATE_RESULT_ALPHA(alpha); |
414 if (0 != alpha) { | 372 if (0 != alpha) { |
415 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 373 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
416 } | 374 } |
417 src += deltaSrc; | 375 src += bytesPerPixel; |
418 } | 376 } |
419 return COMPUTE_RESULT_ALPHA; | 377 return COMPUTE_RESULT_ALPHA; |
420 } | 378 } |
421 | 379 |
422 /** | 380 /** |
423 FIXME: This was my idea to cheat in order to continue taking advantage of sk
ipping zeroes. | 381 FIXME: This was my idea to cheat in order to continue taking advantage of sk
ipping zeroes. |
424 This would be fine for drawing normally, but not for drawing with transfer m
odes. Being | 382 This would be fine for drawing normally, but not for drawing with transfer m
odes. Being |
425 honest means we can draw correctly with transfer modes, with the cost of not
being able | 383 honest means we can draw correctly with transfer modes, with the cost of not
being able |
426 to take advantage of Android's free unwritten pages. Something to keep in mi
nd when we | 384 to take advantage of Android's free unwritten pages. Something to keep in mi
nd when we |
427 decide whether to switch to unpremul default. | 385 decide whether to switch to unpremul default. |
428 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, | 386 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, |
429 const uint8_t* SK_RESTRICT src, | 387 const uint8_t* SK_RESTRICT src, |
430 int dstWidth, int bitsPerPixel, i
nt offset, | 388 int width, int bitsPerPixel, |
431 const SkPMColor[]) { | 389 const SkPMColor[]) { |
432 src += offset; | |
433 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 390 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
434 unsigned alphaMask = 0xFF; | 391 unsigned alphaMask = 0xFF; |
435 for (int x = 0; x < dstWidth; x++) { | 392 for (int x = 0; x < width; x++) { |
436 unsigned alpha = src[3]; | 393 unsigned alpha = src[3]; |
437 // NOTE: We cheat here. The caller requested unpremul and skip zeroes. I
t's possible | 394 // NOTE: We cheat here. The caller requested unpremul and skip zeroes. I
t's possible |
438 // the color components are not zero, but we skip them anyway, meaning t
hey'll remain | 395 // the color components are not zero, but we skip them anyway, meaning t
hey'll remain |
439 // zero (implied by the request to skip zeroes). | 396 // zero (implied by the request to skip zeroes). |
440 if (0 != alpha) { | 397 if (0 != alpha) { |
441 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 398 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
442 } | 399 } |
443 src += deltaSrc; | 400 src += deltaSrc; |
444 alphaMask &= alpha; | 401 alphaMask &= alpha; |
445 } | 402 } |
446 return alphaMask != 0xFF; | 403 return alphaMask != 0xFF; |
447 } | 404 } |
448 */ | 405 */ |
449 | 406 |
450 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 407 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
451 const SkPMColor* ctable, | 408 const SkPMColor* ctable, |
452 const SkImageInfo& dstInfo, | 409 const SkImageInfo& info, |
453 SkCodec::ZeroInitialized zeroInit, | 410 SkCodec::ZeroInitialized zeroInit) { |
454 const SkImageInfo& srcInfo) { | 411 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
455 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | |
456 return NULL; | 412 return NULL; |
457 } | 413 } |
458 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 414 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
459 && NULL == ctable) { | 415 && NULL == ctable) { |
460 return NULL; | 416 return NULL; |
461 } | 417 } |
462 RowProc proc = NULL; | 418 RowProc proc = NULL; |
463 | |
464 switch (sc) { | 419 switch (sc) { |
465 case kBit: | 420 case kBit: |
466 switch (dstInfo.colorType()) { | 421 switch (info.colorType()) { |
467 case kN32_SkColorType: | 422 case kN32_SkColorType: |
468 proc = &swizzle_bit_to_n32; | 423 proc = &swizzle_bit_to_n32; |
469 break; | 424 break; |
470 case kIndex_8_SkColorType: | 425 case kIndex_8_SkColorType: |
471 proc = &swizzle_bit_to_index; | 426 proc = &swizzle_bit_to_index; |
472 break; | 427 break; |
473 case kGray_8_SkColorType: | 428 case kGray_8_SkColorType: |
474 proc = &swizzle_bit_to_grayscale; | 429 proc = &swizzle_bit_to_grayscale; |
475 break; | 430 break; |
476 default: | 431 default: |
477 break; | 432 break; |
478 } | 433 } |
479 break; | 434 break; |
480 case kIndex1: | 435 case kIndex1: |
481 case kIndex2: | 436 case kIndex2: |
482 case kIndex4: | 437 case kIndex4: |
483 switch (dstInfo.colorType()) { | 438 switch (info.colorType()) { |
484 case kN32_SkColorType: | 439 case kN32_SkColorType: |
485 proc = &swizzle_small_index_to_n32; | 440 proc = &swizzle_small_index_to_n32; |
486 break; | 441 break; |
487 case kIndex_8_SkColorType: | 442 case kIndex_8_SkColorType: |
488 proc = &swizzle_small_index_to_index; | 443 proc = &swizzle_small_index_to_index; |
489 break; | 444 break; |
490 default: | 445 default: |
491 break; | 446 break; |
492 } | 447 } |
493 break; | 448 break; |
494 case kIndex: | 449 case kIndex: |
495 switch (dstInfo.colorType()) { | 450 switch (info.colorType()) { |
496 case kN32_SkColorType: | 451 case kN32_SkColorType: |
497 // We assume the color premultiplied ctable (or not) as desi
red. | 452 // We assume the color premultiplied ctable (or not) as desi
red. |
498 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 453 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
499 proc = &swizzle_index_to_n32_skipZ; | 454 proc = &swizzle_index_to_n32_skipZ; |
500 break; | 455 break; |
501 } else { | 456 } else { |
502 proc = &swizzle_index_to_n32; | 457 proc = &swizzle_index_to_n32; |
503 break; | 458 break; |
504 } | 459 } |
505 break; | 460 break; |
506 case kRGB_565_SkColorType: | 461 case kRGB_565_SkColorType: |
507 proc = &swizzle_index_to_565; | 462 proc = &swizzle_index_to_565; |
508 break; | 463 break; |
509 case kIndex_8_SkColorType: | 464 case kIndex_8_SkColorType: |
510 proc = &swizzle_index_to_index; | 465 proc = &swizzle_index_to_index; |
511 break; | 466 break; |
512 default: | 467 default: |
513 break; | 468 break; |
514 } | 469 } |
515 break; | 470 break; |
516 case kGray: | 471 case kGray: |
517 switch (dstInfo.colorType()) { | 472 switch (info.colorType()) { |
518 case kN32_SkColorType: | 473 case kN32_SkColorType: |
519 proc = &swizzle_gray_to_n32; | 474 proc = &swizzle_gray_to_n32; |
520 break; | 475 break; |
521 case kGray_8_SkColorType: | 476 case kGray_8_SkColorType: |
522 proc = &swizzle_gray_to_gray; | 477 proc = &swizzle_gray_to_gray; |
523 break; | 478 break; |
524 case kRGB_565_SkColorType: | 479 case kRGB_565_SkColorType: |
525 proc = &swizzle_gray_to_565; | 480 proc = &swizzle_gray_to_565; |
526 break; | 481 break; |
527 default: | 482 default: |
528 break; | 483 break; |
529 } | 484 } |
530 break; | 485 break; |
531 case kBGR: | 486 case kBGR: |
532 case kBGRX: | 487 case kBGRX: |
533 switch (dstInfo.colorType()) { | 488 switch (info.colorType()) { |
534 case kN32_SkColorType: | 489 case kN32_SkColorType: |
535 proc = &swizzle_bgrx_to_n32; | 490 proc = &swizzle_bgrx_to_n32; |
536 break; | 491 break; |
537 default: | 492 default: |
538 break; | 493 break; |
539 } | 494 } |
540 break; | 495 break; |
541 case kBGRA: | 496 case kBGRA: |
542 switch (dstInfo.colorType()) { | 497 switch (info.colorType()) { |
543 case kN32_SkColorType: | 498 case kN32_SkColorType: |
544 switch (dstInfo.alphaType()) { | 499 switch (info.alphaType()) { |
545 case kUnpremul_SkAlphaType: | 500 case kUnpremul_SkAlphaType: |
546 proc = &swizzle_bgra_to_n32_unpremul; | 501 proc = &swizzle_bgra_to_n32_unpremul; |
547 break; | 502 break; |
548 case kPremul_SkAlphaType: | 503 case kPremul_SkAlphaType: |
549 proc = &swizzle_bgra_to_n32_premul; | 504 proc = &swizzle_bgra_to_n32_premul; |
550 break; | 505 break; |
551 default: | 506 default: |
552 break; | 507 break; |
553 } | 508 } |
554 break; | 509 break; |
555 default: | 510 default: |
556 break; | 511 break; |
557 } | 512 } |
558 break; | 513 break; |
559 case kRGBX: | 514 case kRGBX: |
560 // TODO: Support other swizzles. | 515 // TODO: Support other swizzles. |
561 switch (dstInfo.colorType()) { | 516 switch (info.colorType()) { |
562 case kN32_SkColorType: | 517 case kN32_SkColorType: |
563 proc = &swizzle_rgbx_to_n32; | 518 proc = &swizzle_rgbx_to_n32; |
564 break; | 519 break; |
565 case kRGB_565_SkColorType: | 520 case kRGB_565_SkColorType: |
566 proc = &swizzle_rgbx_to_565; | 521 proc = &swizzle_rgbx_to_565; |
567 default: | 522 default: |
568 break; | 523 break; |
569 } | 524 } |
570 break; | 525 break; |
571 case kRGBA: | 526 case kRGBA: |
572 switch (dstInfo.colorType()) { | 527 switch (info.colorType()) { |
573 case kN32_SkColorType: | 528 case kN32_SkColorType: |
574 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 529 if (info.alphaType() == kUnpremul_SkAlphaType) { |
575 // Respect zeroInit? | 530 // Respect zeroInit? |
576 proc = &swizzle_rgba_to_n32_unpremul; | 531 proc = &swizzle_rgba_to_n32_unpremul; |
577 } else { | 532 } else { |
578 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 533 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
579 proc = &swizzle_rgba_to_n32_premul_skipZ; | 534 proc = &swizzle_rgba_to_n32_premul_skipZ; |
580 } else { | 535 } else { |
581 proc = &swizzle_rgba_to_n32_premul; | 536 proc = &swizzle_rgba_to_n32_premul; |
582 } | 537 } |
583 } | 538 } |
584 break; | 539 break; |
585 default: | 540 default: |
586 break; | 541 break; |
587 } | 542 } |
588 break; | 543 break; |
589 case kRGB: | 544 case kRGB: |
590 switch (dstInfo.colorType()) { | 545 switch (info.colorType()) { |
591 case kN32_SkColorType: | 546 case kN32_SkColorType: |
592 proc = &swizzle_rgbx_to_n32; | 547 proc = &swizzle_rgbx_to_n32; |
593 break; | 548 break; |
594 default: | 549 default: |
595 break; | 550 break; |
596 } | 551 } |
597 break; | 552 break; |
598 case kRGB_565: | |
599 switch (dstInfo.colorType()) { | |
600 case kRGB_565_SkColorType: | |
601 proc = &sample565; | |
602 break; | |
603 default: | |
604 break; | |
605 } | |
606 default: | 553 default: |
607 break; | 554 break; |
608 } | 555 } |
609 if (NULL == proc) { | 556 if (NULL == proc) { |
610 return NULL; | 557 return NULL; |
611 } | 558 } |
612 | 559 |
613 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 560 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits |
614 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix
el(sc); | 561 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : |
615 | 562 BitsPerPixel(sc); |
616 // get sampleX based on srcInfo and dstInfo dimensions | 563 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info)); |
617 int sampleX; | |
618 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL); | |
619 | |
620 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX)); | |
621 } | 564 } |
622 | 565 |
623 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 566 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
624 int deltaSrc, const SkImageInfo& info, int sampleX) | 567 int deltaSrc, const SkImageInfo& info) |
625 : fRowProc(proc) | 568 : fRowProc(proc) |
626 , fColorTable(ctable) | 569 , fColorTable(ctable) |
627 , fDeltaSrc(deltaSrc) | 570 , fDeltaSrc(deltaSrc) |
628 , fDstInfo(info) | 571 , fDstInfo(info) |
629 , fSampleX(sampleX) | 572 {} |
630 , fX0(sampleX == 1 ? 0 : sampleX >> 1) | |
631 { | |
632 // check that fX0 is less than original width | |
633 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | |
634 } | |
635 | 573 |
636 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { | 574 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { |
637 SkASSERT(NULL != dst && NULL != src); | 575 SkASSERT(NULL != dst && NULL != src); |
638 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel
taSrc, fColorTable); | 576 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable); |
639 } | 577 } |
640 | 578 |
641 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, | 579 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, |
642 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { | 580 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { |
643 SkASSERT(dstStartRow != NULL); | 581 SkASSERT(dstStartRow != NULL); |
644 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | 582 SkASSERT(numRows <= (uint32_t) dstInfo.height()); |
645 | 583 |
646 // Calculate bytes to fill. We use getSafeSize since the last row may not b
e padded. | 584 // Calculate bytes to fill. We use getSafeSize since the last row may not b
e padded. |
647 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS
ize(dstRowBytes); | 585 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS
ize(dstRowBytes); |
648 | 586 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // bits of SK_ColorBLACK are identical to the 565 representation | 635 // bits of SK_ColorBLACK are identical to the 565 representation |
698 // for black. | 636 // for black. |
699 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 637 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
700 break; | 638 break; |
701 default: | 639 default: |
702 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); | 640 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); |
703 SkASSERT(false); | 641 SkASSERT(false); |
704 break; | 642 break; |
705 } | 643 } |
706 } | 644 } |
OLD | NEW |