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