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 "SkMaskSwizzler.h" | 10 #include "SkMaskSwizzler.h" |
| 11 #include "SkScaledCodec.h" |
11 | 12 |
12 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_opaque( | 13 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_opaque( |
13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 14 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 15 uint32_t startX, uint32_t sampleX) { |
14 | 16 |
15 // Use the masks to decode to the destination | 17 // Use the masks to decode to the destination |
16 uint16_t* srcPtr = (uint16_t*) srcRow; | 18 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
17 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 19 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
18 for (int i = 0; i < width; i++) { | 20 for (int i = 0; i < width; i++) { |
19 uint16_t p = srcPtr[i]; | 21 uint16_t p = srcPtr[0]; |
20 uint8_t red = masks->getRed(p); | 22 uint8_t red = masks->getRed(p); |
21 uint8_t green = masks->getGreen(p); | 23 uint8_t green = masks->getGreen(p); |
22 uint8_t blue = masks->getBlue(p); | 24 uint8_t blue = masks->getBlue(p); |
23 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); | 25 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 26 srcPtr += sampleX; |
24 } | 27 } |
25 return SkSwizzler::kOpaque_ResultAlpha; | 28 return SkSwizzler::kOpaque_ResultAlpha; |
26 } | 29 } |
27 | 30 |
28 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_unpremul( | 31 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_unpremul( |
29 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 32 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 33 uint32_t startX, uint32_t sampleX) { |
30 | 34 |
31 // Use the masks to decode to the destination | 35 // Use the masks to decode to the destination |
32 uint16_t* srcPtr = (uint16_t*) srcRow; | 36 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
33 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 37 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
34 INIT_RESULT_ALPHA; | 38 INIT_RESULT_ALPHA; |
35 for (int i = 0; i < width; i++) { | 39 for (int i = 0; i < width; i++) { |
36 uint16_t p = srcPtr[i]; | 40 uint16_t p = srcPtr[0]; |
37 uint8_t red = masks->getRed(p); | 41 uint8_t red = masks->getRed(p); |
38 uint8_t green = masks->getGreen(p); | 42 uint8_t green = masks->getGreen(p); |
39 uint8_t blue = masks->getBlue(p); | 43 uint8_t blue = masks->getBlue(p); |
40 uint8_t alpha = masks->getAlpha(p); | 44 uint8_t alpha = masks->getAlpha(p); |
41 UPDATE_RESULT_ALPHA(alpha); | 45 UPDATE_RESULT_ALPHA(alpha); |
42 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); | 46 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
| 47 srcPtr += sampleX; |
43 } | 48 } |
44 return COMPUTE_RESULT_ALPHA; | 49 return COMPUTE_RESULT_ALPHA; |
45 } | 50 } |
46 | 51 |
47 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_premul( | 52 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_premul( |
48 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 53 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 54 uint32_t startX, uint32_t sampleX) { |
49 | 55 |
50 // Use the masks to decode to the destination | 56 // Use the masks to decode to the destination |
51 uint16_t* srcPtr = (uint16_t*) srcRow; | 57 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
52 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 58 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
53 INIT_RESULT_ALPHA; | 59 INIT_RESULT_ALPHA; |
54 for (int i = 0; i < width; i++) { | 60 for (int i = 0; i < width; i++) { |
55 uint16_t p = srcPtr[i]; | 61 uint16_t p = srcPtr[0]; |
56 uint8_t red = masks->getRed(p); | 62 uint8_t red = masks->getRed(p); |
57 uint8_t green = masks->getGreen(p); | 63 uint8_t green = masks->getGreen(p); |
58 uint8_t blue = masks->getBlue(p); | 64 uint8_t blue = masks->getBlue(p); |
59 uint8_t alpha = masks->getAlpha(p); | 65 uint8_t alpha = masks->getAlpha(p); |
60 UPDATE_RESULT_ALPHA(alpha); | 66 UPDATE_RESULT_ALPHA(alpha); |
61 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); | 67 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
| 68 srcPtr += sampleX; |
62 } | 69 } |
63 return COMPUTE_RESULT_ALPHA; | 70 return COMPUTE_RESULT_ALPHA; |
64 } | 71 } |
65 | 72 |
66 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to | 73 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to |
67 // convert it back to 565. Instead, we should swizzle to 565 directly. | 74 // convert it back to 565. Instead, we should swizzle to 565 directly. |
68 static SkSwizzler::ResultAlpha swizzle_mask16_to_565( | 75 static SkSwizzler::ResultAlpha swizzle_mask16_to_565( |
69 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 76 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 77 uint32_t startX, uint32_t sampleX) { |
70 | 78 |
71 // Use the masks to decode to the destination | 79 // Use the masks to decode to the destination |
72 uint16_t* srcPtr = (uint16_t*) srcRow; | 80 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; |
73 uint16_t* dstPtr = (uint16_t*) dstRow; | 81 uint16_t* dstPtr = (uint16_t*) dstRow; |
74 for (int i = 0; i < width; i++) { | 82 for (int i = 0; i < width; i++) { |
75 uint16_t p = srcPtr[i]; | 83 uint16_t p = srcPtr[0]; |
76 uint8_t red = masks->getRed(p); | 84 uint8_t red = masks->getRed(p); |
77 uint8_t green = masks->getGreen(p); | 85 uint8_t green = masks->getGreen(p); |
78 uint8_t blue = masks->getBlue(p); | 86 uint8_t blue = masks->getBlue(p); |
79 dstPtr[i] = SkPack888ToRGB16(red, green, blue); | 87 dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
| 88 srcPtr += sampleX; |
80 } | 89 } |
81 return SkSwizzler::kOpaque_ResultAlpha; | 90 return SkSwizzler::kOpaque_ResultAlpha; |
82 } | 91 } |
83 | 92 |
84 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque( | 93 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque( |
85 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 94 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 95 uint32_t startX, uint32_t sampleX) { |
86 | 96 |
87 // Use the masks to decode to the destination | 97 // Use the masks to decode to the destination |
| 98 srcRow += 3 * startX; |
88 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 99 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
89 for (int i = 0; i < 3*width; i += 3) { | 100 for (int i = 0; i < width; i++) { |
90 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; | 101 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
91 uint8_t red = masks->getRed(p); | 102 uint8_t red = masks->getRed(p); |
92 uint8_t green = masks->getGreen(p); | 103 uint8_t green = masks->getGreen(p); |
93 uint8_t blue = masks->getBlue(p); | 104 uint8_t blue = masks->getBlue(p); |
94 dstPtr[i/3] = SkPackARGB32NoCheck(0xFF, red, green, blue); | 105 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 106 srcRow += 3 * sampleX; |
95 } | 107 } |
96 return SkSwizzler::kOpaque_ResultAlpha; | 108 return SkSwizzler::kOpaque_ResultAlpha; |
97 } | 109 } |
98 | 110 |
99 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_unpremul( | 111 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_unpremul( |
100 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 112 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 113 uint32_t startX, uint32_t sampleX) { |
101 | 114 |
102 // Use the masks to decode to the destination | 115 // Use the masks to decode to the destination |
103 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 116 srcRow += 3 * startX; |
104 INIT_RESULT_ALPHA; | |
105 for (int i = 0; i < 3*width; i += 3) { | |
106 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; | |
107 uint8_t red = masks->getRed(p); | |
108 uint8_t green = masks->getGreen(p); | |
109 uint8_t blue = masks->getBlue(p); | |
110 uint8_t alpha = masks->getAlpha(p); | |
111 UPDATE_RESULT_ALPHA(alpha); | |
112 dstPtr[i/3] = SkPackARGB32NoCheck(alpha, red, green, blue); | |
113 } | |
114 return COMPUTE_RESULT_ALPHA; | |
115 } | |
116 | |
117 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_premul( | |
118 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | |
119 | |
120 // Use the masks to decode to the destination | |
121 SkPMColor* dstPtr = (SkPMColor*) dstRow; | |
122 INIT_RESULT_ALPHA; | |
123 for (int i = 0; i < 3*width; i += 3) { | |
124 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; | |
125 uint8_t red = masks->getRed(p); | |
126 uint8_t green = masks->getGreen(p); | |
127 uint8_t blue = masks->getBlue(p); | |
128 uint8_t alpha = masks->getAlpha(p); | |
129 UPDATE_RESULT_ALPHA(alpha); | |
130 dstPtr[i/3] = SkPreMultiplyARGB(alpha, red, green, blue); | |
131 } | |
132 return COMPUTE_RESULT_ALPHA; | |
133 } | |
134 | |
135 static SkSwizzler::ResultAlpha swizzle_mask24_to_565( | |
136 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | |
137 | |
138 // Use the masks to decode to the destination | |
139 uint16_t* dstPtr = (uint16_t*) dstRow; | |
140 for (int i = 0; i < 3*width; i += 3) { | |
141 uint32_t p = srcRow[i] | (srcRow[i + 1] << 8) | srcRow[i + 2] << 16; | |
142 uint8_t red = masks->getRed(p); | |
143 uint8_t green = masks->getGreen(p); | |
144 uint8_t blue = masks->getBlue(p); | |
145 dstPtr[i/3] = SkPack888ToRGB16(red, green, blue); | |
146 } | |
147 return SkSwizzler::kOpaque_ResultAlpha; | |
148 } | |
149 | |
150 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque( | |
151 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | |
152 | |
153 // Use the masks to decode to the destination | |
154 uint32_t* srcPtr = (uint32_t*) srcRow; | |
155 SkPMColor* dstPtr = (SkPMColor*) dstRow; | |
156 for (int i = 0; i < width; i++) { | |
157 uint32_t p = srcPtr[i]; | |
158 uint8_t red = masks->getRed(p); | |
159 uint8_t green = masks->getGreen(p); | |
160 uint8_t blue = masks->getBlue(p); | |
161 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); | |
162 } | |
163 return SkSwizzler::kOpaque_ResultAlpha; | |
164 } | |
165 | |
166 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_unpremul( | |
167 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | |
168 | |
169 // Use the masks to decode to the destination | |
170 uint32_t* srcPtr = (uint32_t*) srcRow; | |
171 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 117 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
172 INIT_RESULT_ALPHA; | 118 INIT_RESULT_ALPHA; |
173 for (int i = 0; i < width; i++) { | 119 for (int i = 0; i < width; i++) { |
174 uint32_t p = srcPtr[i]; | 120 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
175 uint8_t red = masks->getRed(p); | 121 uint8_t red = masks->getRed(p); |
176 uint8_t green = masks->getGreen(p); | 122 uint8_t green = masks->getGreen(p); |
177 uint8_t blue = masks->getBlue(p); | 123 uint8_t blue = masks->getBlue(p); |
178 uint8_t alpha = masks->getAlpha(p); | 124 uint8_t alpha = masks->getAlpha(p); |
179 UPDATE_RESULT_ALPHA(alpha); | 125 UPDATE_RESULT_ALPHA(alpha); |
180 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); | 126 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
| 127 srcRow += 3 * sampleX; |
181 } | 128 } |
182 return COMPUTE_RESULT_ALPHA; | 129 return COMPUTE_RESULT_ALPHA; |
183 } | 130 } |
184 | 131 |
185 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_premul( | 132 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_premul( |
186 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 133 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 134 uint32_t startX, uint32_t sampleX) { |
187 | 135 |
188 // Use the masks to decode to the destination | 136 // Use the masks to decode to the destination |
189 uint32_t* srcPtr = (uint32_t*) srcRow; | 137 srcRow += 3 * startX; |
190 SkPMColor* dstPtr = (SkPMColor*) dstRow; | 138 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
191 INIT_RESULT_ALPHA; | 139 INIT_RESULT_ALPHA; |
192 for (int i = 0; i < width; i++) { | 140 for (int i = 0; i < width; i++) { |
193 uint32_t p = srcPtr[i]; | 141 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
194 uint8_t red = masks->getRed(p); | 142 uint8_t red = masks->getRed(p); |
195 uint8_t green = masks->getGreen(p); | 143 uint8_t green = masks->getGreen(p); |
196 uint8_t blue = masks->getBlue(p); | 144 uint8_t blue = masks->getBlue(p); |
197 uint8_t alpha = masks->getAlpha(p); | 145 uint8_t alpha = masks->getAlpha(p); |
198 UPDATE_RESULT_ALPHA(alpha); | 146 UPDATE_RESULT_ALPHA(alpha); |
199 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); | 147 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
| 148 srcRow += 3 * sampleX; |
| 149 } |
| 150 return COMPUTE_RESULT_ALPHA; |
| 151 } |
| 152 |
| 153 static SkSwizzler::ResultAlpha swizzle_mask24_to_565( |
| 154 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 155 uint32_t startX, uint32_t sampleX) { |
| 156 |
| 157 // Use the masks to decode to the destination |
| 158 srcRow += 3 * startX; |
| 159 uint16_t* dstPtr = (uint16_t*) dstRow; |
| 160 for (int i = 0; i < width; i++) { |
| 161 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; |
| 162 uint8_t red = masks->getRed(p); |
| 163 uint8_t green = masks->getGreen(p); |
| 164 uint8_t blue = masks->getBlue(p); |
| 165 dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
| 166 srcRow += 3 * sampleX; |
| 167 } |
| 168 return SkSwizzler::kOpaque_ResultAlpha; |
| 169 } |
| 170 |
| 171 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque( |
| 172 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 173 uint32_t startX, uint32_t sampleX) { |
| 174 |
| 175 // Use the masks to decode to the destination |
| 176 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 177 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
| 178 for (int i = 0; i < width; i++) { |
| 179 uint32_t p = srcPtr[0]; |
| 180 uint8_t red = masks->getRed(p); |
| 181 uint8_t green = masks->getGreen(p); |
| 182 uint8_t blue = masks->getBlue(p); |
| 183 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 184 srcPtr += sampleX; |
| 185 } |
| 186 return SkSwizzler::kOpaque_ResultAlpha; |
| 187 } |
| 188 |
| 189 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_unpremul( |
| 190 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 191 uint32_t startX, uint32_t sampleX) { |
| 192 |
| 193 // Use the masks to decode to the destination |
| 194 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 195 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
| 196 INIT_RESULT_ALPHA; |
| 197 for (int i = 0; i < width; i++) { |
| 198 uint32_t p = srcPtr[0]; |
| 199 uint8_t red = masks->getRed(p); |
| 200 uint8_t green = masks->getGreen(p); |
| 201 uint8_t blue = masks->getBlue(p); |
| 202 uint8_t alpha = masks->getAlpha(p); |
| 203 UPDATE_RESULT_ALPHA(alpha); |
| 204 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); |
| 205 srcPtr += sampleX; |
| 206 } |
| 207 return COMPUTE_RESULT_ALPHA; |
| 208 } |
| 209 |
| 210 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_premul( |
| 211 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 212 uint32_t startX, uint32_t sampleX) { |
| 213 |
| 214 // Use the masks to decode to the destination |
| 215 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
| 216 SkPMColor* dstPtr = (SkPMColor*) dstRow; |
| 217 INIT_RESULT_ALPHA; |
| 218 for (int i = 0; i < width; i++) { |
| 219 uint32_t p = srcPtr[0]; |
| 220 uint8_t red = masks->getRed(p); |
| 221 uint8_t green = masks->getGreen(p); |
| 222 uint8_t blue = masks->getBlue(p); |
| 223 uint8_t alpha = masks->getAlpha(p); |
| 224 UPDATE_RESULT_ALPHA(alpha); |
| 225 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); |
| 226 srcPtr += sampleX; |
200 } | 227 } |
201 return COMPUTE_RESULT_ALPHA; | 228 return COMPUTE_RESULT_ALPHA; |
202 } | 229 } |
203 | 230 |
204 static SkSwizzler::ResultAlpha swizzle_mask32_to_565( | 231 static SkSwizzler::ResultAlpha swizzle_mask32_to_565( |
205 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks) { | 232 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, |
| 233 uint32_t startX, uint32_t sampleX) { |
206 // Use the masks to decode to the destination | 234 // Use the masks to decode to the destination |
207 uint32_t* srcPtr = (uint32_t*) srcRow; | 235 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; |
208 uint16_t* dstPtr = (uint16_t*) dstRow; | 236 uint16_t* dstPtr = (uint16_t*) dstRow; |
209 for (int i = 0; i < width; i++) { | 237 for (int i = 0; i < width; i++) { |
210 uint32_t p = srcPtr[i]; | 238 uint32_t p = srcPtr[0]; |
211 uint8_t red = masks->getRed(p); | 239 uint8_t red = masks->getRed(p); |
212 uint8_t green = masks->getGreen(p); | 240 uint8_t green = masks->getGreen(p); |
213 uint8_t blue = masks->getBlue(p); | 241 uint8_t blue = masks->getBlue(p); |
214 dstPtr[i] = SkPack888ToRGB16(red, green, blue); | 242 dstPtr[i] = SkPack888ToRGB16(red, green, blue); |
| 243 srcPtr += sampleX; |
215 } | 244 } |
216 return SkSwizzler::kOpaque_ResultAlpha; | 245 return SkSwizzler::kOpaque_ResultAlpha; |
217 } | 246 } |
218 | 247 |
219 /* | 248 /* |
220 * | 249 * |
221 * Create a new mask swizzler | 250 * Create a new mask swizzler |
222 * | 251 * |
223 */ | 252 */ |
224 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler( | 253 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler( |
225 const SkImageInfo& info, SkMasks* masks, uint32_t bitsPerPixel) { | 254 const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, SkMasks* masks, |
| 255 uint32_t bitsPerPixel) { |
226 | 256 |
227 // Choose the appropriate row procedure | 257 // Choose the appropriate row procedure |
228 RowProc proc = nullptr; | 258 RowProc proc = nullptr; |
229 switch (bitsPerPixel) { | 259 switch (bitsPerPixel) { |
230 case 16: | 260 case 16: |
231 switch (info.colorType()) { | 261 switch (dstInfo.colorType()) { |
232 case kN32_SkColorType: | 262 case kN32_SkColorType: |
233 switch (info.alphaType()) { | 263 switch (dstInfo.alphaType()) { |
234 case kUnpremul_SkAlphaType: | 264 case kUnpremul_SkAlphaType: |
235 proc = &swizzle_mask16_to_n32_unpremul; | 265 proc = &swizzle_mask16_to_n32_unpremul; |
236 break; | 266 break; |
237 case kPremul_SkAlphaType: | 267 case kPremul_SkAlphaType: |
238 proc = &swizzle_mask16_to_n32_premul; | 268 proc = &swizzle_mask16_to_n32_premul; |
239 break; | 269 break; |
240 case kOpaque_SkAlphaType: | 270 case kOpaque_SkAlphaType: |
241 proc = &swizzle_mask16_to_n32_opaque; | 271 proc = &swizzle_mask16_to_n32_opaque; |
242 break; | 272 break; |
243 default: | 273 default: |
244 break; | 274 break; |
245 } | 275 } |
246 break; | 276 break; |
247 case kRGB_565_SkColorType: | 277 case kRGB_565_SkColorType: |
248 switch (info.alphaType()) { | 278 switch (dstInfo.alphaType()) { |
249 case kOpaque_SkAlphaType: | 279 case kOpaque_SkAlphaType: |
250 proc = &swizzle_mask16_to_565; | 280 proc = &swizzle_mask16_to_565; |
251 break; | 281 break; |
252 default: | 282 default: |
253 break; | 283 break; |
254 } | 284 } |
255 break; | 285 break; |
256 default: | 286 default: |
257 break; | 287 break; |
258 } | 288 } |
259 break; | 289 break; |
260 case 24: | 290 case 24: |
261 switch (info.colorType()) { | 291 switch (dstInfo.colorType()) { |
262 case kN32_SkColorType: | 292 case kN32_SkColorType: |
263 switch (info.alphaType()) { | 293 switch (dstInfo.alphaType()) { |
264 case kUnpremul_SkAlphaType: | 294 case kUnpremul_SkAlphaType: |
265 proc = &swizzle_mask24_to_n32_unpremul; | 295 proc = &swizzle_mask24_to_n32_unpremul; |
266 break; | 296 break; |
267 case kPremul_SkAlphaType: | 297 case kPremul_SkAlphaType: |
268 proc = &swizzle_mask24_to_n32_premul; | 298 proc = &swizzle_mask24_to_n32_premul; |
269 break; | 299 break; |
270 case kOpaque_SkAlphaType: | 300 case kOpaque_SkAlphaType: |
271 proc = &swizzle_mask24_to_n32_opaque; | 301 proc = &swizzle_mask24_to_n32_opaque; |
272 break; | 302 break; |
273 default: | 303 default: |
274 break; | 304 break; |
275 } | 305 } |
276 break; | 306 break; |
277 case kRGB_565_SkColorType: | 307 case kRGB_565_SkColorType: |
278 switch (info.alphaType()) { | 308 switch (dstInfo.alphaType()) { |
279 case kOpaque_SkAlphaType: | 309 case kOpaque_SkAlphaType: |
280 proc = &swizzle_mask24_to_565; | 310 proc = &swizzle_mask24_to_565; |
281 break; | 311 break; |
282 default: | 312 default: |
283 break; | 313 break; |
284 } | 314 } |
285 break; | 315 break; |
286 default: | 316 default: |
287 break; | 317 break; |
288 } | 318 } |
289 break; | 319 break; |
290 case 32: | 320 case 32: |
291 switch (info.colorType()) { | 321 switch (dstInfo.colorType()) { |
292 case kN32_SkColorType: | 322 case kN32_SkColorType: |
293 switch (info.alphaType()) { | 323 switch (dstInfo.alphaType()) { |
294 case kUnpremul_SkAlphaType: | 324 case kUnpremul_SkAlphaType: |
295 proc = &swizzle_mask32_to_n32_unpremul; | 325 proc = &swizzle_mask32_to_n32_unpremul; |
296 break; | 326 break; |
297 case kPremul_SkAlphaType: | 327 case kPremul_SkAlphaType: |
298 proc = &swizzle_mask32_to_n32_premul; | 328 proc = &swizzle_mask32_to_n32_premul; |
299 break; | 329 break; |
300 case kOpaque_SkAlphaType: | 330 case kOpaque_SkAlphaType: |
301 proc = &swizzle_mask32_to_n32_opaque; | 331 proc = &swizzle_mask32_to_n32_opaque; |
302 break; | 332 break; |
303 default: | 333 default: |
304 break; | 334 break; |
305 } | 335 } |
306 break; | 336 break; |
307 case kRGB_565_SkColorType: | 337 case kRGB_565_SkColorType: |
308 switch (info.alphaType()) { | 338 switch (dstInfo.alphaType()) { |
309 case kOpaque_SkAlphaType: | 339 case kOpaque_SkAlphaType: |
310 proc = &swizzle_mask32_to_565; | 340 proc = &swizzle_mask32_to_565; |
311 break; | 341 break; |
312 default: | 342 default: |
313 break; | 343 break; |
314 } | 344 } |
315 break; | 345 break; |
316 default: | 346 default: |
317 break; | 347 break; |
318 } | 348 } |
319 break; | 349 break; |
320 default: | 350 default: |
321 SkASSERT(false); | 351 SkASSERT(false); |
322 return nullptr; | 352 return nullptr; |
323 } | 353 } |
324 return new SkMaskSwizzler(info, masks, proc); | 354 |
| 355 // Get the sample size |
| 356 int sampleX; |
| 357 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL); |
| 358 |
| 359 return new SkMaskSwizzler(dstInfo, masks, proc, sampleX); |
325 } | 360 } |
326 | 361 |
327 /* | 362 /* |
328 * | 363 * |
329 * Constructor for mask swizzler | 364 * Constructor for mask swizzler |
330 * | 365 * |
331 */ | 366 */ |
332 SkMaskSwizzler::SkMaskSwizzler(const SkImageInfo& dstInfo, SkMasks* masks, | 367 SkMaskSwizzler::SkMaskSwizzler(const SkImageInfo& dstInfo, SkMasks* masks, |
333 RowProc proc) | 368 RowProc proc, uint32_t sampleX) |
334 : fDstInfo(dstInfo) | 369 : fDstInfo(dstInfo) |
335 , fMasks(masks) | 370 , fMasks(masks) |
336 , fRowProc(proc) | 371 , fRowProc(proc) |
| 372 , fSampleX(sampleX) |
| 373 , fStartX(get_start_coord(sampleX)) |
337 {} | 374 {} |
338 | 375 |
339 /* | 376 /* |
340 * | 377 * |
341 * Swizzle the specified row | 378 * Swizzle the specified row |
342 * | 379 * |
343 */ | 380 */ |
344 SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RES
TRICT src) { | 381 SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RES
TRICT src) { |
345 SkASSERT(nullptr != dst && nullptr != src); | 382 SkASSERT(nullptr != dst && nullptr != src); |
346 return fRowProc(dst, src, fDstInfo.width(), fMasks); | 383 return fRowProc(dst, src, fDstInfo.width(), fMasks, fStartX, fSampleX); |
347 } | 384 } |
OLD | NEW |