Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: src/codec/SkSwizzler.cpp

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

Powered by Google App Engine
This is Rietveld 408576698