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 "SkSwizzler.h" | 11 #include "SkSwizzler.h" |
11 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
12 #include "SkUtils.h" | 13 #include "SkUtils.h" |
13 | 14 |
14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, | 15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
15 uint8_t maxAlpha) { | 16 uint8_t maxAlpha) { |
16 // In the transparent case, this returns 0x0000 | 17 // In the transparent case, this returns 0x0000 |
17 // In the opaque case, this returns 0xFFFF | 18 // In the opaque case, this returns 0xFFFF |
18 // If the row is neither transparent nor opaque, returns something else | 19 // If the row is neither transparent nor opaque, returns something else |
19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; | 20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; |
20 } | 21 } |
21 | 22 |
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, const SkPMColor c table[]){ | |
26 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
27 for (int x = 0; x < width; x++) { | |
28 dst[x] = src[1] << 8 | src[0]; | |
29 src += deltaSrc; | |
30 } | |
31 return 0xFFFF; | |
scroggo
2015/07/31 19:31:58
// 565 is always opaque.
emmaleer
2015/07/31 20:43:10
Acknowledged.
| |
32 } | |
22 // kIndex1, kIndex2, kIndex4 | 33 // kIndex1, kIndex2, kIndex4 |
23 | 34 |
24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 35 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 36 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
26 int bitsPerPixel, const SkPMColor ctable[]) { | 37 int bitsPerPixel, const SkPMColor ctable[]) { |
27 | 38 |
28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 39 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
29 INIT_RESULT_ALPHA; | 40 INIT_RESULT_ALPHA; |
30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 41 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | 42 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 x++; | 76 x++; |
66 } | 77 } |
67 } | 78 } |
68 return COMPUTE_RESULT_ALPHA; | 79 return COMPUTE_RESULT_ALPHA; |
69 } | 80 } |
70 | 81 |
71 // kIndex | 82 // kIndex |
72 | 83 |
73 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 84 static SkSwizzler::ResultAlpha swizzle_index_to_index( |
74 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 85 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
75 int bytesPerPixel, const SkPMColor ctable[]) { | 86 int deltaSrc, const SkPMColor ctable[]) { |
76 | 87 |
77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 88 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
78 memcpy(dst, src, width); | 89 if (1 == deltaSrc) { |
90 memcpy(dst, src, width); | |
91 } else { | |
92 for (int x = 0; x < width; x++) { | |
93 dst[x] = src[0]; | |
94 src += deltaSrc; | |
95 } | |
96 } | |
79 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? | 97 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? |
80 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous | 98 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous |
81 // and probably wrong since gif and bmp (rarely) may have al pha. | 99 // and probably wrong since gif and bmp (rarely) may have al pha. |
82 INIT_RESULT_ALPHA; | 100 INIT_RESULT_ALPHA; |
83 for (int x = 0; x < width; x++) { | 101 for (int x = 0; x < width; x++) { |
84 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 102 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
85 } | 103 } |
86 return COMPUTE_RESULT_ALPHA; | 104 return COMPUTE_RESULT_ALPHA; |
87 } | 105 } |
88 | 106 |
89 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 107 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 108 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
91 int bytesPerPixel, const SkPMColor ctable[]) { | 109 int deltaSrc, const SkPMColor ctable[]) { |
92 | 110 |
93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 111 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
94 INIT_RESULT_ALPHA; | 112 INIT_RESULT_ALPHA; |
95 for (int x = 0; x < width; x++) { | 113 for (int x = 0; x < width; x++) { |
96 SkPMColor c = ctable[src[x]]; | 114 SkPMColor c = ctable[*src]; |
97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 115 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
98 dst[x] = c; | 116 dst[x] = c; |
117 src += deltaSrc; | |
99 } | 118 } |
100 return COMPUTE_RESULT_ALPHA; | 119 return COMPUTE_RESULT_ALPHA; |
101 } | 120 } |
102 | 121 |
103 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( | 122 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
104 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 123 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
105 int bytesPerPixel, const SkPMColor ctable[]) { | 124 int deltaSrc, const SkPMColor ctable[]) { |
106 | 125 |
107 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 126 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
108 INIT_RESULT_ALPHA; | 127 INIT_RESULT_ALPHA; |
109 for (int x = 0; x < width; x++) { | 128 for (int x = 0; x < width; x++) { |
110 SkPMColor c = ctable[src[x]]; | 129 SkPMColor c = ctable[*src]; |
111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 130 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
112 if (c != 0) { | 131 if (c != 0) { |
113 dst[x] = c; | 132 dst[x] = c; |
114 } | 133 } |
134 src += deltaSrc; | |
115 } | 135 } |
116 return COMPUTE_RESULT_ALPHA; | 136 return COMPUTE_RESULT_ALPHA; |
117 } | 137 } |
118 | 138 |
119 #undef A32_MASK_IN_PLACE | 139 #undef A32_MASK_IN_PLACE |
120 | 140 |
121 // kGray | 141 // kGray |
122 | 142 |
123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | 143 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
125 int bytesPerPixel, const SkPMColor ctable[]) { | 145 int deltaSrc, const SkPMColor ctable[]) { |
126 | 146 |
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
128 for (int x = 0; x < width; x++) { | 148 for (int x = 0; x < width; x++) { |
129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); | 149 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
150 src += deltaSrc; | |
130 } | 151 } |
131 return SkSwizzler::kOpaque_ResultAlpha; | 152 return SkSwizzler::kOpaque_ResultAlpha; |
132 } | 153 } |
133 | 154 |
134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | 155 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 156 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
136 int bytesPerPixel, const SkPMColor ctable[]) { | 157 int deltaSrc, const SkPMColor ctable[]) { |
137 memcpy(dstRow, src, width); | 158 |
159 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
160 if (1 == deltaSrc) { | |
161 memcpy(dstRow, src, width); | |
162 } else { | |
163 for (int x = 0; x < width; x++) { | |
164 dst[x] = src[0]; | |
165 src += deltaSrc; | |
166 } | |
167 } | |
138 return SkSwizzler::kOpaque_ResultAlpha; | 168 return SkSwizzler::kOpaque_ResultAlpha; |
139 } | 169 } |
140 | 170 |
141 // kBGRX | 171 // kBGRX |
142 | 172 |
143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 173 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 174 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
145 int bytesPerPixel, const SkPMColor ctable[]) { | 175 int deltaSrc, const SkPMColor ctable[]) { |
146 | 176 |
147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 177 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
148 for (int x = 0; x < width; x++) { | 178 for (int x = 0; x < width; x++) { |
149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 179 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
150 src += bytesPerPixel; | 180 src += deltaSrc; |
151 } | 181 } |
152 return SkSwizzler::kOpaque_ResultAlpha; | 182 return SkSwizzler::kOpaque_ResultAlpha; |
153 } | 183 } |
154 | 184 |
155 // kBGRA | 185 // kBGRA |
156 | 186 |
157 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 187 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
158 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 188 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
159 int bytesPerPixel, const SkPMColor ctable[]) { | 189 int deltaSrc, const SkPMColor ctable[]) { |
160 | 190 |
161 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 191 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
162 INIT_RESULT_ALPHA; | 192 INIT_RESULT_ALPHA; |
163 for (int x = 0; x < width; x++) { | 193 for (int x = 0; x < width; x++) { |
164 uint8_t alpha = src[3]; | 194 uint8_t alpha = src[3]; |
165 UPDATE_RESULT_ALPHA(alpha); | 195 UPDATE_RESULT_ALPHA(alpha); |
166 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 196 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
167 src += bytesPerPixel; | 197 src += deltaSrc; |
168 } | 198 } |
169 return COMPUTE_RESULT_ALPHA; | 199 return COMPUTE_RESULT_ALPHA; |
170 } | 200 } |
171 | 201 |
172 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | 202 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
173 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 203 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
174 int bytesPerPixel, const SkPMColor ctable[]) { | 204 int deltaSrc, const SkPMColor ctable[]) { |
175 | 205 |
176 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 206 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
177 INIT_RESULT_ALPHA; | 207 INIT_RESULT_ALPHA; |
178 for (int x = 0; x < width; x++) { | 208 for (int x = 0; x < width; x++) { |
179 uint8_t alpha = src[3]; | 209 uint8_t alpha = src[3]; |
180 UPDATE_RESULT_ALPHA(alpha); | 210 UPDATE_RESULT_ALPHA(alpha); |
181 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); | 211 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
182 src += bytesPerPixel; | 212 src += deltaSrc; |
183 } | 213 } |
184 return COMPUTE_RESULT_ALPHA; | 214 return COMPUTE_RESULT_ALPHA; |
185 } | 215 } |
186 | 216 |
187 // n32 | 217 // n32 |
188 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 218 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
189 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 219 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
190 int bytesPerPixel, const SkPMColor ctable[]) { | 220 int deltaSrc, const SkPMColor ctable[]) { |
191 | 221 |
192 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 222 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
193 for (int x = 0; x < width; x++) { | 223 for (int x = 0; x < width; x++) { |
194 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 224 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
195 src += bytesPerPixel; | 225 src += deltaSrc; |
196 } | 226 } |
197 return SkSwizzler::kOpaque_ResultAlpha; | 227 return SkSwizzler::kOpaque_ResultAlpha; |
198 } | 228 } |
199 | 229 |
200 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( | 230 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
201 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
202 int bytesPerPixel, const SkPMColor ctable[]) { | 232 int deltaSrc, const SkPMColor ctable[]) { |
203 | 233 |
204 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
205 INIT_RESULT_ALPHA; | 235 INIT_RESULT_ALPHA; |
206 for (int x = 0; x < width; x++) { | 236 for (int x = 0; x < width; x++) { |
207 unsigned alpha = src[3]; | 237 unsigned alpha = src[3]; |
208 UPDATE_RESULT_ALPHA(alpha); | 238 UPDATE_RESULT_ALPHA(alpha); |
209 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 239 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
210 src += bytesPerPixel; | 240 src += deltaSrc; |
211 } | 241 } |
212 return COMPUTE_RESULT_ALPHA; | 242 return COMPUTE_RESULT_ALPHA; |
213 } | 243 } |
214 | 244 |
215 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( | 245 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
216 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 246 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
217 int bytesPerPixel, const SkPMColor ctable[]) { | 247 int deltaSrc, const SkPMColor ctable[]) { |
218 | 248 |
219 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 249 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
220 INIT_RESULT_ALPHA; | 250 INIT_RESULT_ALPHA; |
221 for (int x = 0; x < width; x++) { | 251 for (int x = 0; x < width; x++) { |
222 unsigned alpha = src[3]; | 252 unsigned alpha = src[3]; |
223 UPDATE_RESULT_ALPHA(alpha); | 253 UPDATE_RESULT_ALPHA(alpha); |
224 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 254 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
225 src += bytesPerPixel; | 255 src += deltaSrc; |
226 } | 256 } |
227 return COMPUTE_RESULT_ALPHA; | 257 return COMPUTE_RESULT_ALPHA; |
228 } | 258 } |
229 | 259 |
230 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( | 260 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 261 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
232 int bytesPerPixel, const SkPMColor ctable[]) { | 262 int deltaSrc, const SkPMColor ctable[]) { |
233 | 263 |
234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 264 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
235 INIT_RESULT_ALPHA; | 265 INIT_RESULT_ALPHA; |
236 for (int x = 0; x < width; x++) { | 266 for (int x = 0; x < width; x++) { |
237 unsigned alpha = src[3]; | 267 unsigned alpha = src[3]; |
238 UPDATE_RESULT_ALPHA(alpha); | 268 UPDATE_RESULT_ALPHA(alpha); |
239 if (0 != alpha) { | 269 if (0 != alpha) { |
240 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); | 270 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
241 } | 271 } |
242 src += bytesPerPixel; | 272 src += deltaSrc; |
243 } | 273 } |
244 return COMPUTE_RESULT_ALPHA; | 274 return COMPUTE_RESULT_ALPHA; |
245 } | 275 } |
246 | 276 |
247 /** | 277 /** |
248 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. | 278 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. |
249 This would be fine for drawing normally, but not for drawing with transfer m odes. Being | 279 This would be fine for drawing normally, but not for drawing with transfer m odes. Being |
250 honest means we can draw correctly with transfer modes, with the cost of not being able | 280 honest means we can draw correctly with transfer modes, with the cost of not being able |
251 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we | 281 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we |
252 decide whether to switch to unpremul default. | 282 decide whether to switch to unpremul default. |
(...skipping 13 matching lines...) Expand all Loading... | |
266 } | 296 } |
267 src += deltaSrc; | 297 src += deltaSrc; |
268 alphaMask &= alpha; | 298 alphaMask &= alpha; |
269 } | 299 } |
270 return alphaMask != 0xFF; | 300 return alphaMask != 0xFF; |
271 } | 301 } |
272 */ | 302 */ |
273 | 303 |
274 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 304 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
275 const SkPMColor* ctable, | 305 const SkPMColor* ctable, |
276 const SkImageInfo& info, | 306 const SkImageInfo& dstInfo, |
277 SkCodec::ZeroInitialized zeroInit) { | 307 SkCodec::ZeroInitialized zeroInit, |
278 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 308 int srcWidth) { |
309 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | |
279 return NULL; | 310 return NULL; |
280 } | 311 } |
281 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 312 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
282 && NULL == ctable) { | 313 && NULL == ctable) { |
283 return NULL; | 314 return NULL; |
284 } | 315 } |
285 RowProc proc = NULL; | 316 RowProc proc = NULL; |
317 | |
286 switch (sc) { | 318 switch (sc) { |
287 case kIndex1: | 319 case kIndex1: |
288 case kIndex2: | 320 case kIndex2: |
289 case kIndex4: | 321 case kIndex4: |
290 switch (info.colorType()) { | 322 switch (dstInfo.colorType()) { |
291 case kN32_SkColorType: | 323 case kN32_SkColorType: |
292 proc = &swizzle_small_index_to_n32; | 324 proc = &swizzle_small_index_to_n32; |
293 break; | 325 break; |
294 case kIndex_8_SkColorType: | 326 case kIndex_8_SkColorType: |
295 proc = &swizzle_small_index_to_index; | 327 proc = &swizzle_small_index_to_index; |
296 break; | 328 break; |
297 default: | 329 default: |
298 break; | 330 break; |
299 } | 331 } |
300 break; | 332 break; |
301 case kIndex: | 333 case kIndex: |
302 switch (info.colorType()) { | 334 switch (dstInfo.colorType()) { |
303 case kN32_SkColorType: | 335 case kN32_SkColorType: |
304 // We assume the color premultiplied ctable (or not) as desi red. | 336 // We assume the color premultiplied ctable (or not) as desi red. |
305 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 337 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
306 proc = &swizzle_index_to_n32_skipZ; | 338 proc = &swizzle_index_to_n32_skipZ; |
307 break; | 339 break; |
308 } else { | 340 } else { |
309 proc = &swizzle_index_to_n32; | 341 proc = &swizzle_index_to_n32; |
310 break; | 342 break; |
311 } | 343 } |
312 break; | 344 break; |
313 case kIndex_8_SkColorType: | 345 case kIndex_8_SkColorType: |
314 proc = &swizzle_index_to_index; | 346 proc = &swizzle_index_to_index; |
315 break; | 347 break; |
316 default: | 348 default: |
317 break; | 349 break; |
318 } | 350 } |
319 break; | 351 break; |
320 case kGray: | 352 case kGray: |
321 switch (info.colorType()) { | 353 switch (dstInfo.colorType()) { |
322 case kN32_SkColorType: | 354 case kN32_SkColorType: |
323 proc = &swizzle_gray_to_n32; | 355 proc = &swizzle_gray_to_n32; |
324 break; | 356 break; |
325 case kGray_8_SkColorType: | 357 case kGray_8_SkColorType: |
326 proc = &swizzle_gray_to_gray; | 358 proc = &swizzle_gray_to_gray; |
327 default: | 359 default: |
328 break; | 360 break; |
329 } | 361 } |
330 break; | 362 break; |
331 case kBGR: | 363 case kBGR: |
332 case kBGRX: | 364 case kBGRX: |
333 switch (info.colorType()) { | 365 switch (dstInfo.colorType()) { |
334 case kN32_SkColorType: | 366 case kN32_SkColorType: |
335 proc = &swizzle_bgrx_to_n32; | 367 proc = &swizzle_bgrx_to_n32; |
336 break; | 368 break; |
337 default: | 369 default: |
338 break; | 370 break; |
339 } | 371 } |
340 break; | 372 break; |
341 case kBGRA: | 373 case kBGRA: |
342 switch (info.colorType()) { | 374 switch (dstInfo.colorType()) { |
343 case kN32_SkColorType: | 375 case kN32_SkColorType: |
344 switch (info.alphaType()) { | 376 switch (dstInfo.alphaType()) { |
345 case kUnpremul_SkAlphaType: | 377 case kUnpremul_SkAlphaType: |
346 proc = &swizzle_bgra_to_n32_unpremul; | 378 proc = &swizzle_bgra_to_n32_unpremul; |
347 break; | 379 break; |
348 case kPremul_SkAlphaType: | 380 case kPremul_SkAlphaType: |
349 proc = &swizzle_bgra_to_n32_premul; | 381 proc = &swizzle_bgra_to_n32_premul; |
350 break; | 382 break; |
351 default: | 383 default: |
352 break; | 384 break; |
353 } | 385 } |
354 break; | 386 break; |
355 default: | 387 default: |
356 break; | 388 break; |
357 } | 389 } |
358 break; | 390 break; |
359 case kRGBX: | 391 case kRGBX: |
360 // TODO: Support other swizzles. | 392 // TODO: Support other swizzles. |
361 switch (info.colorType()) { | 393 switch (dstInfo.colorType()) { |
362 case kN32_SkColorType: | 394 case kN32_SkColorType: |
363 proc = &swizzle_rgbx_to_n32; | 395 proc = &swizzle_rgbx_to_n32; |
364 break; | 396 break; |
365 default: | 397 default: |
366 break; | 398 break; |
367 } | 399 } |
368 break; | 400 break; |
369 case kRGBA: | 401 case kRGBA: |
370 switch (info.colorType()) { | 402 switch (dstInfo.colorType()) { |
371 case kN32_SkColorType: | 403 case kN32_SkColorType: |
372 if (info.alphaType() == kUnpremul_SkAlphaType) { | 404 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
373 // Respect zeroInit? | 405 // Respect zeroInit? |
374 proc = &swizzle_rgba_to_n32_unpremul; | 406 proc = &swizzle_rgba_to_n32_unpremul; |
375 } else { | 407 } else { |
376 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 408 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
377 proc = &swizzle_rgba_to_n32_premul_skipZ; | 409 proc = &swizzle_rgba_to_n32_premul_skipZ; |
378 } else { | 410 } else { |
379 proc = &swizzle_rgba_to_n32_premul; | 411 proc = &swizzle_rgba_to_n32_premul; |
380 } | 412 } |
381 } | 413 } |
382 break; | 414 break; |
383 default: | 415 default: |
384 break; | 416 break; |
385 } | 417 } |
386 break; | 418 break; |
387 case kRGB: | 419 case kRGB: |
388 switch (info.colorType()) { | 420 switch (dstInfo.colorType()) { |
389 case kN32_SkColorType: | 421 case kN32_SkColorType: |
390 proc = &swizzle_rgbx_to_n32; | 422 proc = &swizzle_rgbx_to_n32; |
391 break; | 423 break; |
392 default: | 424 default: |
393 break; | 425 break; |
394 } | 426 } |
395 break; | 427 break; |
428 case kRGB_565: | |
429 switch (dstInfo.colorType()) { | |
430 case kRGB_565_SkColorType: | |
431 proc = &sample565; | |
432 break; | |
433 default: | |
434 break; | |
435 } | |
396 default: | 436 default: |
397 break; | 437 break; |
398 } | 438 } |
399 if (NULL == proc) { | 439 if (NULL == proc) { |
400 return NULL; | 440 return NULL; |
401 } | 441 } |
402 | 442 |
403 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 443 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits |
404 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : | 444 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); |
405 BitsPerPixel(sc); | 445 |
406 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info)); | 446 int sampleX = SkScaledCodec::GetSampleSize(srcWidth, dstInfo.width()); |
447 | |
448 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX)); | |
407 } | 449 } |
408 | 450 |
409 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 451 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
410 int deltaSrc, const SkImageInfo& info) | 452 int deltaSrc, const SkImageInfo& info, int sampleX) |
411 : fRowProc(proc) | 453 : fRowProc(proc) |
412 , fColorTable(ctable) | 454 , fColorTable(ctable) |
413 , fDeltaSrc(deltaSrc) | 455 , fDeltaSrc(deltaSrc) |
414 , fDstInfo(info) | 456 , fDstInfo(info) |
415 {} | 457 , fSampleX(sampleX) |
458 , fX0(sampleX == 1 ? 0 : sampleX >> 1) | |
459 { | |
460 // check that fX0 is less than original width | |
461 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | |
462 } | |
416 | 463 |
417 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { | 464 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { |
418 SkASSERT(NULL != dst && NULL != src); | 465 SkASSERT(NULL != dst && NULL != src); |
419 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable); | 466 return fRowProc(dst, src + fX0 * fDeltaSrc, fDstInfo.width(), fSampleX * fDe ltaSrc, |
467 fColorTable); | |
420 } | 468 } |
421 | 469 |
422 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, | 470 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, |
423 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { | 471 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { |
424 SkASSERT(dstStartRow != NULL); | 472 SkASSERT(dstStartRow != NULL); |
425 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | 473 SkASSERT(numRows <= (uint32_t) dstInfo.height()); |
426 | 474 |
427 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. | 475 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. |
428 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); | 476 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); |
429 | 477 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 // bits of SK_ColorBLACK are identical to the 565 representation | 526 // bits of SK_ColorBLACK are identical to the 565 representation |
479 // for black. | 527 // for black. |
480 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 528 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
481 break; | 529 break; |
482 default: | 530 default: |
483 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 531 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
484 SkASSERT(false); | 532 SkASSERT(false); |
485 break; | 533 break; |
486 } | 534 } |
487 } | 535 } |
OLD | NEW |