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