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