Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSwizzler.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
14#include "include/core/SkRect.h"
21#include "src/base/SkHalf.h"
24
25#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
27#endif
28
29#include <cstring>
30
31static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
32 const SkPMColor ctable[]) {
33 // This function must not be called if we are sampling. If we are not
34 // sampling, deltaSrc should equal bpp.
35 SkASSERT(deltaSrc == bpp);
36
37 memcpy(dst, src + offset, width * bpp);
38}
39
40static void sample1(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
41 const SkPMColor ctable[]) {
42 src += offset;
43 uint8_t* dst8 = (uint8_t*) dst;
44 for (int x = 0; x < width; x++) {
45 dst8[x] = *src;
46 src += deltaSrc;
47 }
48}
49
50static void sample2(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
51 const SkPMColor ctable[]) {
52 src += offset;
53 uint16_t* dst16 = (uint16_t*) dst;
54 for (int x = 0; x < width; x++) {
55 dst16[x] = *((const uint16_t*) src);
56 src += deltaSrc;
57 }
58}
59
60static void sample4(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
61 const SkPMColor ctable[]) {
62 src += offset;
63 uint32_t* dst32 = (uint32_t*) dst;
64 for (int x = 0; x < width; x++) {
65 dst32[x] = *((const uint32_t*) src);
66 src += deltaSrc;
67 }
68}
69
70static void sample6(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
71 const SkPMColor ctable[]) {
72 src += offset;
73 uint8_t* dst8 = (uint8_t*) dst;
74 for (int x = 0; x < width; x++) {
75 memcpy(dst8, src, 6);
76 dst8 += 6;
77 src += deltaSrc;
78 }
79}
80
81static void sample8(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
82 const SkPMColor ctable[]) {
83 src += offset;
84 uint64_t* dst64 = (uint64_t*) dst;
85 for (int x = 0; x < width; x++) {
86 dst64[x] = *((const uint64_t*) src);
87 src += deltaSrc;
88 }
89}
90
91// kBit
92// These routines exclusively choose between white and black
93
94#define GRAYSCALE_BLACK 0
95#define GRAYSCALE_WHITE 0xFF
96
97
98// same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x]
100 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
101 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
102
103 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
104
105 // increment src by byte offset and bitIndex by bit offset
106 src += offset / 8;
107 int bitIndex = offset % 8;
108 uint8_t currByte = *src;
109
110 dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
111
112 for (int x = 1; x < dstWidth; x++) {
113 int bitOffset = bitIndex + deltaSrc;
114 bitIndex = bitOffset % 8;
115 currByte = *(src += bitOffset / 8);
116 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
117 }
118}
119
120#undef GRAYSCALE_BLACK
121#undef GRAYSCALE_WHITE
122
123// same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value assigned to dst[x]
125 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
126 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
128
129 // increment src by byte offset and bitIndex by bit offset
130 src += offset / 8;
131 int bitIndex = offset % 8;
132 uint8_t currByte = *src;
133
134 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
135
136 for (int x = 1; x < dstWidth; x++) {
137 int bitOffset = bitIndex + deltaSrc;
138 bitIndex = bitOffset % 8;
139 currByte = *(src += bitOffset / 8);
140 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
141 }
142}
143
144#define RGB565_BLACK 0
145#define RGB565_WHITE 0xFFFF
146
148 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
149 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
150 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
151
152 // increment src by byte offset and bitIndex by bit offset
153 src += offset / 8;
154 int bitIndex = offset % 8;
155 uint8_t currByte = *src;
156
157 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
158
159 for (int x = 1; x < dstWidth; x++) {
160 int bitOffset = bitIndex + deltaSrc;
161 bitIndex = bitOffset % 8;
162 currByte = *(src += bitOffset / 8);
163 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
164 }
165}
166
167#undef RGB565_BLACK
168#undef RGB565_WHITE
169
171 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
172 int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
173 constexpr uint64_t kWhite = (((uint64_t) SK_Half1) << 0) |
174 (((uint64_t) SK_Half1) << 16) |
175 (((uint64_t) SK_Half1) << 32) |
176 (((uint64_t) SK_Half1) << 48);
177 constexpr uint64_t kBlack = (((uint64_t) 0) << 0) |
178 (((uint64_t) 0) << 16) |
179 (((uint64_t) 0) << 32) |
180 (((uint64_t) SK_Half1) << 48);
181
182 uint64_t* SK_RESTRICT dst = (uint64_t*) dstRow;
183
184 // increment src by byte offset and bitIndex by bit offset
185 src += offset / 8;
186 int bitIndex = offset % 8;
187 uint8_t currByte = *src;
188
189 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? kWhite : kBlack;
190
191 for (int x = 1; x < dstWidth; x++) {
192 int bitOffset = bitIndex + deltaSrc;
193 bitIndex = bitOffset % 8;
194 currByte = *(src += bitOffset / 8);
195 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? kWhite : kBlack;
196 }
197}
198
199// kIndex1, kIndex2, kIndex4
200
202 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
203 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
204
205 uint16_t* dst = (uint16_t*) dstRow;
206 src += offset / 8;
207 int bitIndex = offset % 8;
208 uint8_t currByte = *src;
209 const uint8_t mask = (1 << bpp) - 1;
210 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
211 dst[0] = SkPixel32ToPixel16(ctable[index]);
212
213 for (int x = 1; x < dstWidth; x++) {
214 int bitOffset = bitIndex + deltaSrc;
215 bitIndex = bitOffset % 8;
216 currByte = *(src += bitOffset / 8);
217 index = (currByte >> (8 - bpp - bitIndex)) & mask;
218 dst[x] = SkPixel32ToPixel16(ctable[index]);
219 }
220}
221
223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
225
226 SkPMColor* dst = (SkPMColor*) dstRow;
227 src += offset / 8;
228 int bitIndex = offset % 8;
229 uint8_t currByte = *src;
230 const uint8_t mask = (1 << bpp) - 1;
231 uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
232 dst[0] = ctable[index];
233
234 for (int x = 1; x < dstWidth; x++) {
235 int bitOffset = bitIndex + deltaSrc;
236 bitIndex = bitOffset % 8;
237 currByte = *(src += bitOffset / 8);
238 index = (currByte >> (8 - bpp - bitIndex)) & mask;
239 dst[x] = ctable[index];
240 }
241}
242
243// kIndex
244
246 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
247 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
248
249 src += offset;
250 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
251 for (int x = 0; x < dstWidth; x++) {
252 SkPMColor c = ctable[*src];
253 dst[x] = c;
254 src += deltaSrc;
255 }
256}
257
259 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
260 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
261
262 src += offset;
263 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
264 for (int x = 0; x < dstWidth; x++) {
265 SkPMColor c = ctable[*src];
266 if (c != 0) {
267 dst[x] = c;
268 }
269 src += deltaSrc;
270 }
271}
272
274 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
275 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
276 src += offset;
277 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
278 for (int x = 0; x < dstWidth; x++) {
279 dst[x] = SkPixel32ToPixel16(ctable[*src]);
280 src += deltaSrc;
281 }
282}
283
284// kGray
285
287 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
288 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
289
290 src += offset;
291 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
292 for (int x = 0; x < dstWidth; x++) {
293 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src);
294 src += deltaSrc;
295 }
296}
297
299 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
300 const SkPMColor ctable[]) {
301
302 // This function must not be called if we are sampling. If we are not
303 // sampling, deltaSrc should equal bpp.
304 SkASSERT(deltaSrc == bpp);
305
306 // Note that there is no need to distinguish between RGB and BGR.
307 // Each color channel will get the same value.
308 SkOpts::gray_to_RGB1((uint32_t*) dst, src + offset, width);
309}
310
312 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
313 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
314
315 src += offset;
316 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
317 for (int x = 0; x < dstWidth; x++) {
318 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
319 src += deltaSrc;
320 }
321}
322
323// kGrayAlpha
324
326 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
327 const SkPMColor ctable[]) {
328
329 src += offset;
330 SkPMColor* dst32 = (SkPMColor*) dst;
331 for (int x = 0; x < width; x++) {
332 dst32[x] = SkPackARGB32NoCheck(src[1], src[0], src[0], src[0]);
333 src += deltaSrc;
334 }
335}
336
338 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
339 const SkPMColor ctable[]) {
340
341 // This function must not be called if we are sampling. If we are not
342 // sampling, deltaSrc should equal bpp.
343 SkASSERT(deltaSrc == bpp);
344
345 // Note that there is no need to distinguish between RGB and BGR.
346 // Each color channel will get the same value.
347 SkOpts::grayA_to_RGBA((uint32_t*) dst, src + offset, width);
348}
349
351 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
352 const SkPMColor ctable[]) {
353
354 src += offset;
355 SkPMColor* dst32 = (SkPMColor*) dst;
356 for (int x = 0; x < width; x++) {
357 uint8_t pmgray = SkMulDiv255Round(src[1], src[0]);
358 dst32[x] = SkPackARGB32NoCheck(src[1], pmgray, pmgray, pmgray);
359 src += deltaSrc;
360 }
361}
362
364 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
365 const SkPMColor ctable[]) {
366
367 // This function must not be called if we are sampling. If we are not
368 // sampling, deltaSrc should equal bpp.
369 SkASSERT(deltaSrc == bpp);
370
371 // Note that there is no need to distinguish between rgb and bgr.
372 // Each color channel will get the same value.
373 SkOpts::grayA_to_rgbA((uint32_t*) dst, src + offset, width);
374}
375
376static void swizzle_grayalpha_to_a8(void* dst, const uint8_t* src, int width, int bpp,
377 int deltaSrc, int offset, const SkPMColor[]) {
378 src += offset;
379 uint8_t* dst8 = (uint8_t*)dst;
380 for (int x = 0; x < width; ++x) {
381 dst8[x] = src[1]; // src[0] is gray, ignored
382 src += deltaSrc;
383 }
384}
385
386// kBGR
387
389 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
390 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
391
392 src += offset;
393 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
394 for (int x = 0; x < dstWidth; x++) {
395 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
396 src += deltaSrc;
397 }
398}
399
400// kRGB
401
403 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
404 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
405
406 src += offset;
407 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
408 for (int x = 0; x < dstWidth; x++) {
409 dst[x] = SkPackARGB_as_RGBA(0xFF, src[0], src[1], src[2]);
410 src += deltaSrc;
411 }
412}
413
415 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
416 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
417
418 src += offset;
419 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
420 for (int x = 0; x < dstWidth; x++) {
421 dst[x] = SkPackARGB_as_BGRA(0xFF, src[0], src[1], src[2]);
422 src += deltaSrc;
423 }
424}
425
427 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
428 int offset, const SkPMColor ctable[]) {
429
430 // This function must not be called if we are sampling. If we are not
431 // sampling, deltaSrc should equal bpp.
432 SkASSERT(deltaSrc == bpp);
433
434 SkOpts::RGB_to_RGB1((uint32_t*) dst, src + offset, width);
435}
436
438 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
439 int offset, const SkPMColor ctable[]) {
440
441 // This function must not be called if we are sampling. If we are not
442 // sampling, deltaSrc should equal bpp.
443 SkASSERT(deltaSrc == bpp);
444
445 SkOpts::RGB_to_BGR1((uint32_t*) dst, src + offset, width);
446}
447
449 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
450 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
451
452 src += offset;
453 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
454 for (int x = 0; x < dstWidth; x++) {
455 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
456 src += deltaSrc;
457 }
458}
459
460// kRGBA
461
463 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
464 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
465
466 src += offset;
467 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
468 for (int x = 0; x < dstWidth; x++) {
469 dst[x] = premultiply_argb_as_rgba(src[3], src[0], src[1], src[2]);
470 src += deltaSrc;
471 }
472}
473
475 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
476 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
477
478 src += offset;
479 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
480 for (int x = 0; x < dstWidth; x++) {
481 dst[x] = premultiply_argb_as_bgra(src[3], src[0], src[1], src[2]);
482 src += deltaSrc;
483 }
484}
485
487 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
488 int offset, const SkPMColor ctable[]) {
489
490 // This function must not be called if we are sampling. If we are not
491 // sampling, deltaSrc should equal bpp.
492 SkASSERT(deltaSrc == bpp);
493
494 SkOpts::RGBA_to_rgbA((uint32_t*) dst, (const uint32_t*)(src + offset), width);
495}
496
498 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
499 int offset, const SkPMColor ctable[]) {
500
501 // This function must not be called if we are sampling. If we are not
502 // sampling, deltaSrc should equal bpp.
503 SkASSERT(deltaSrc == bpp);
504
505 SkOpts::RGBA_to_bgrA((uint32_t*) dst, (const uint32_t*)(src + offset), width);
506}
507
509 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
510 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
511
512 src += offset;
513 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
514 for (int x = 0; x < dstWidth; x++) {
515 unsigned alpha = src[3];
516 dst[x] = SkPackARGB_as_BGRA(alpha, src[0], src[1], src[2]);
517 src += deltaSrc;
518 }
519}
520
522 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
523 const SkPMColor ctable[]) {
524
525 // This function must not be called if we are sampling. If we are not
526 // sampling, deltaSrc should equal bpp.
527 SkASSERT(deltaSrc == bpp);
528
529 SkOpts::RGBA_to_BGRA((uint32_t*) dst, (const uint32_t*)(src + offset), width);
530}
531
532// 16-bits per component kRGB and kRGBA
533
535 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
536 const SkPMColor ctable[]) {
537 auto strip16to8 = [](const uint8_t* ptr) {
538 return 0xFF000000 | (ptr[4] << 16) | (ptr[2] << 8) | ptr[0];
539 };
540
541 src += offset;
542 uint32_t* dst32 = (uint32_t*) dst;
543 for (int x = 0; x < width; x++) {
544 dst32[x] = strip16to8(src);
545 src += deltaSrc;
546 }
547}
548
550 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
551 const SkPMColor ctable[]) {
552 auto strip16to8 = [](const uint8_t* ptr) {
553 return 0xFF000000 | (ptr[0] << 16) | (ptr[2] << 8) | ptr[4];
554 };
555
556 src += offset;
557 uint32_t* dst32 = (uint32_t*) dst;
558 for (int x = 0; x < width; x++) {
559 dst32[x] = strip16to8(src);
560 src += deltaSrc;
561 }
562}
563
565 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
566 const SkPMColor ctable[]) {
567 auto strip16to565 = [](const uint8_t* ptr) {
568 return SkPack888ToRGB16(ptr[0], ptr[2], ptr[4]);
569 };
570
571 src += offset;
572 uint16_t* dst16 = (uint16_t*) dst;
573 for (int x = 0; x < width; x++) {
574 dst16[x] = strip16to565(src);
575 src += deltaSrc;
576 }
577}
578
580 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
581 const SkPMColor ctable[]) {
582 auto strip16to8 = [](const uint8_t* ptr) {
583 return (ptr[6] << 24) | (ptr[4] << 16) | (ptr[2] << 8) | ptr[0];
584 };
585
586 src += offset;
587 uint32_t* dst32 = (uint32_t*) dst;
588 for (int x = 0; x < width; x++) {
589 dst32[x] = strip16to8(src);
590 src += deltaSrc;
591 }
592}
593
595 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
596 const SkPMColor ctable[]) {
597 auto stripAndPremul16to8 = [](const uint8_t* ptr) {
598 return premultiply_argb_as_rgba(ptr[6], ptr[0], ptr[2], ptr[4]);
599 };
600
601 src += offset;
602 uint32_t* dst32 = (uint32_t*) dst;
603 for (int x = 0; x < width; x++) {
604 dst32[x] = stripAndPremul16to8(src);
605 src += deltaSrc;
606 }
607}
608
610 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
611 const SkPMColor ctable[]) {
612 auto strip16to8 = [](const uint8_t* ptr) {
613 return (ptr[6] << 24) | (ptr[0] << 16) | (ptr[2] << 8) | ptr[4];
614 };
615
616 src += offset;
617 uint32_t* dst32 = (uint32_t*) dst;
618 for (int x = 0; x < width; x++) {
619 dst32[x] = strip16to8(src);
620 src += deltaSrc;
621 }
622}
623
625 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
626 const SkPMColor ctable[]) {
627 auto stripAndPremul16to8 = [](const uint8_t* ptr) {
628 return premultiply_argb_as_bgra(ptr[6], ptr[0], ptr[2], ptr[4]);
629 };
630
631 src += offset;
632 uint32_t* dst32 = (uint32_t*) dst;
633 for (int x = 0; x < width; x++) {
634 dst32[x] = stripAndPremul16to8(src);
635 src += deltaSrc;
636 }
637}
638
639// kCMYK
640//
641// CMYK is stored as four bytes per pixel.
642//
643// We will implement a crude conversion from CMYK -> RGB using formulas
644// from easyrgb.com.
645//
646// CMYK -> CMY
647// C = C * (1 - K) + K
648// M = M * (1 - K) + K
649// Y = Y * (1 - K) + K
650//
651// libjpeg actually gives us inverted CMYK, so we must subtract the
652// original terms from 1.
653// CMYK -> CMY
654// C = (1 - C) * (1 - (1 - K)) + (1 - K)
655// M = (1 - M) * (1 - (1 - K)) + (1 - K)
656// Y = (1 - Y) * (1 - (1 - K)) + (1 - K)
657//
658// Simplifying the above expression.
659// CMYK -> CMY
660// C = 1 - CK
661// M = 1 - MK
662// Y = 1 - YK
663//
664// CMY -> RGB
665// R = (1 - C) * 255
666// G = (1 - M) * 255
667// B = (1 - Y) * 255
668//
669// Therefore the full conversion is below. This can be verified at
670// www.rapidtables.com (assuming inverted CMYK).
671// CMYK -> RGB
672// R = C * K * 255
673// G = M * K * 255
674// B = Y * K * 255
675//
676// As a final note, we have treated the CMYK values as if they were on
677// a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255.
678// We must divide each CMYK component by 255 to obtain the true conversion
679// we should perform.
680// CMYK -> RGB
681// R = C * K / 255
682// G = M * K / 255
683// B = Y * K / 255
685 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
686 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
687
688 src += offset;
689 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
690 for (int x = 0; x < dstWidth; x++) {
691 const uint8_t r = SkMulDiv255Round(src[0], src[3]);
692 const uint8_t g = SkMulDiv255Round(src[1], src[3]);
693 const uint8_t b = SkMulDiv255Round(src[2], src[3]);
694
695 dst[x] = SkPackARGB_as_RGBA(0xFF, r, g, b);
696 src += deltaSrc;
697 }
698}
699
701 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
702 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
703
704 src += offset;
705 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
706 for (int x = 0; x < dstWidth; x++) {
707 const uint8_t r = SkMulDiv255Round(src[0], src[3]);
708 const uint8_t g = SkMulDiv255Round(src[1], src[3]);
709 const uint8_t b = SkMulDiv255Round(src[2], src[3]);
710
711 dst[x] = SkPackARGB_as_BGRA(0xFF, r, g, b);
712 src += deltaSrc;
713 }
714}
715
717 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
718 const SkPMColor ctable[]) {
719
720 // This function must not be called if we are sampling. If we are not
721 // sampling, deltaSrc should equal bpp.
722 SkASSERT(deltaSrc == bpp);
723
724 SkOpts::inverted_CMYK_to_RGB1((uint32_t*) dst, (const uint32_t*)(src + offset), width);
725}
726
728 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int offset,
729 const SkPMColor ctable[]) {
730
731 // This function must not be called if we are sampling. If we are not
732 // sampling, deltaSrc should equal bpp.
733 SkASSERT(deltaSrc == bpp);
734
735 SkOpts::inverted_CMYK_to_BGR1((uint32_t*) dst, (const uint32_t*)(src + offset), width);
736}
737
739 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
740 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
741
742 src += offset;
743 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
744 for (int x = 0; x < dstWidth; x++) {
745 const uint8_t r = SkMulDiv255Round(src[0], src[3]);
746 const uint8_t g = SkMulDiv255Round(src[1], src[3]);
747 const uint8_t b = SkMulDiv255Round(src[2], src[3]);
748
749 dst[x] = SkPack888ToRGB16(r, g, b);
750 src += deltaSrc;
751 }
752}
753
754template <SkSwizzler::RowProc proc>
755void SkSwizzler::SkipLeadingGrayAlphaZerosThen(
756 void* dst, const uint8_t* src, int width,
757 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
758 SkASSERT(!ctable);
759
760 const uint16_t* src16 = (const uint16_t*) (src + offset);
761 uint32_t* dst32 = (uint32_t*) dst;
762
763 // This may miss opportunities to skip when the output is premultiplied,
764 // e.g. for a src pixel 0x00FF which is not zero but becomes zero after premultiplication.
765 while (width > 0 && *src16 == 0x0000) {
766 width--;
767 dst32++;
768 src16 += deltaSrc / 2;
769 }
770 proc(dst32, (const uint8_t*)src16, width, bpp, deltaSrc, 0, ctable);
771}
772
773template <SkSwizzler::RowProc proc>
774void SkSwizzler::SkipLeading8888ZerosThen(
775 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
776 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
777 SkASSERT(!ctable);
778
779 auto src32 = (const uint32_t*)(src+offset);
780 auto dst32 = (uint32_t*)dstRow;
781
782 // This may miss opportunities to skip when the output is premultiplied,
783 // e.g. for a src pixel 0x00FFFFFF which is not zero but becomes zero after premultiplication.
784 while (dstWidth > 0 && *src32 == 0x00000000) {
785 dstWidth--;
786 dst32++;
787 src32 += deltaSrc/4;
788 }
789 proc(dst32, (const uint8_t*)src32, dstWidth, bpp, deltaSrc, 0, ctable);
790}
791
792std::unique_ptr<SkSwizzler> SkSwizzler::MakeSimple(int srcBPP, const SkImageInfo& dstInfo,
793 const SkCodec::Options& options) {
794 RowProc proc = nullptr;
795 switch (srcBPP) {
796 case 1: // kGray_8_SkColorType
797 proc = &sample1;
798 break;
799 case 2: // kRGB_565_SkColorType
800 proc = &sample2;
801 break;
802 case 4: // kRGBA_8888_SkColorType
803 // kBGRA_8888_SkColorType
804 // kRGBA_1010102_SkColorType
805 proc = &sample4;
806 break;
807 case 6: // 16 bit PNG no alpha
808 proc = &sample6;
809 break;
810 case 8: // 16 bit PNG with alpha
811 proc = &sample8;
812 break;
813 default:
814 return nullptr;
815 }
816
817 return Make(dstInfo, &copy, proc, nullptr /*ctable*/, srcBPP,
818 dstInfo.bytesPerPixel(), options, nullptr /*frame*/);
819}
820
821std::unique_ptr<SkSwizzler> SkSwizzler::Make(const SkEncodedInfo& encodedInfo,
822 const SkPMColor* ctable,
823 const SkImageInfo& dstInfo,
825 const SkIRect* frame) {
826 if (SkEncodedInfo::kPalette_Color == encodedInfo.color() && nullptr == ctable) {
827 return nullptr;
828 }
829
830 RowProc fastProc = nullptr;
831 RowProc proc = nullptr;
832 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized;
833 const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha()) &&
834 (kPremul_SkAlphaType == dstInfo.alphaType());
835
836 switch (encodedInfo.color()) {
838 switch (encodedInfo.bitsPerComponent()) {
839 case 1:
840 switch (dstInfo.colorType()) {
843 proc = &swizzle_bit_to_n32;
844 break;
846 proc = &swizzle_bit_to_565;
847 break;
850 break;
852 proc = &swizzle_bit_to_f16;
853 break;
854 default:
855 return nullptr;
856 }
857 break;
858 case 8:
859 switch (dstInfo.colorType()) {
862 proc = &swizzle_gray_to_n32;
863 fastProc = &fast_swizzle_gray_to_n32;
864 break;
866 proc = &sample1;
867 fastProc = &copy;
868 break;
870 proc = &swizzle_gray_to_565;
871 break;
872 default:
873 return nullptr;
874 }
875 break;
876 default:
877 return nullptr;
878 }
879 break;
882 switch (dstInfo.colorType()) {
885 if (premultiply) {
886 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
887 proc = &SkipLeadingGrayAlphaZerosThen
889 fastProc = &SkipLeadingGrayAlphaZerosThen
891 } else {
894 }
895 } else {
896 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
897 proc = &SkipLeadingGrayAlphaZerosThen
899 fastProc = &SkipLeadingGrayAlphaZerosThen
901 } else {
904 }
905 }
906 break;
909 break;
910 default:
911 return nullptr;
912 }
913 break;
915 // We assume that the color table is premultiplied and swizzled
916 // as desired.
917 switch (encodedInfo.bitsPerComponent()) {
918 case 1:
919 case 2:
920 case 4:
921 switch (dstInfo.colorType()) {
925 break;
928 break;
929 default:
930 return nullptr;
931 }
932 break;
933 case 8:
934 switch (dstInfo.colorType()) {
938 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
940 } else {
941 proc = &swizzle_index_to_n32;
942 }
943 break;
945 proc = &swizzle_index_to_565;
946 break;
947 default:
948 return nullptr;
949 }
950 break;
951 default:
952 return nullptr;
953 }
954 break;
956 // Treat 565 exactly like RGB (since it's still encoded as 8 bits per component).
957 // We just mark as 565 when we have a hint that there are only 5/6/5 "significant"
958 // bits in each channel.
960 switch (dstInfo.colorType()) {
962 if (16 == encodedInfo.bitsPerComponent()) {
963 proc = &swizzle_rgb16_to_rgba;
964 break;
965 }
966
967 SkASSERT(8 == encodedInfo.bitsPerComponent());
968 proc = &swizzle_rgb_to_rgba;
969 fastProc = &fast_swizzle_rgb_to_rgba;
970 break;
972 if (16 == encodedInfo.bitsPerComponent()) {
973 proc = &swizzle_rgb16_to_bgra;
974 break;
975 }
976
977 SkASSERT(8 == encodedInfo.bitsPerComponent());
978 proc = &swizzle_rgb_to_bgra;
979 fastProc = &fast_swizzle_rgb_to_bgra;
980 break;
982 if (16 == encodedInfo.bitsPerComponent()) {
983 proc = &swizzle_rgb16_to_565;
984 break;
985 }
986
987 proc = &swizzle_rgb_to_565;
988 break;
989 default:
990 return nullptr;
991 }
992 break;
994 switch (dstInfo.colorType()) {
996 if (16 == encodedInfo.bitsPerComponent()) {
997 proc = premultiply ? &swizzle_rgba16_to_rgba_premul :
999 break;
1000 }
1001
1002 SkASSERT(8 == encodedInfo.bitsPerComponent());
1003 if (premultiply) {
1004 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1005 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgba_premul>;
1006 fastProc = &SkipLeading8888ZerosThen
1008 } else {
1011 }
1012 } else {
1013 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1014 proc = &SkipLeading8888ZerosThen<sample4>;
1015 fastProc = &SkipLeading8888ZerosThen<copy>;
1016 } else {
1017 proc = &sample4;
1018 fastProc = &copy;
1019 }
1020 }
1021 break;
1023 if (16 == encodedInfo.bitsPerComponent()) {
1024 proc = premultiply ? &swizzle_rgba16_to_bgra_premul :
1026 break;
1027 }
1028
1029 SkASSERT(8 == encodedInfo.bitsPerComponent());
1030 if (premultiply) {
1031 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1032 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_premul>;
1033 fastProc = &SkipLeading8888ZerosThen
1035 } else {
1038 }
1039 } else {
1040 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1041 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_unpremul>;
1042 fastProc = &SkipLeading8888ZerosThen
1044 } else {
1047 }
1048 }
1049 break;
1050 default:
1051 return nullptr;
1052 }
1053 break;
1055 switch (dstInfo.colorType()) {
1057 proc = &swizzle_rgb_to_rgba;
1058 fastProc = &fast_swizzle_rgb_to_rgba;
1059 break;
1061 proc = &swizzle_rgb_to_bgra;
1062 fastProc = &fast_swizzle_rgb_to_bgra;
1063 break;
1065 proc = &swizzle_bgr_to_565;
1066 break;
1067 default:
1068 return nullptr;
1069 }
1070 break;
1072 switch (dstInfo.colorType()) {
1074 proc = &swizzle_rgb_to_rgba;
1075 break;
1077 proc = &swizzle_rgb_to_bgra;
1078 break;
1080 proc = &swizzle_bgr_to_565;
1081 break;
1082 default:
1083 return nullptr;
1084 }
1085 break;
1087 switch (dstInfo.colorType()) {
1089 if (premultiply) {
1090 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1091 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgba_premul>;
1092 fastProc = &SkipLeading8888ZerosThen
1094 } else {
1097 }
1098 } else {
1099 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1100 proc = &SkipLeading8888ZerosThen<sample4>;
1101 fastProc = &SkipLeading8888ZerosThen<copy>;
1102 } else {
1103 proc = &sample4;
1104 fastProc = &copy;
1105 }
1106 }
1107 break;
1109 if (premultiply) {
1110 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1111 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_premul>;
1112 fastProc = &SkipLeading8888ZerosThen
1114 } else {
1117 }
1118 } else {
1119 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
1120 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgra_unpremul>;
1121 fastProc = &SkipLeading8888ZerosThen
1123 } else {
1126 }
1127 }
1128 break;
1129 default:
1130 return nullptr;
1131 }
1132 break;
1134 switch (dstInfo.colorType()) {
1136 proc = &swizzle_cmyk_to_rgba;
1137 fastProc = &fast_swizzle_cmyk_to_rgba;
1138 break;
1140 proc = &swizzle_cmyk_to_bgra;
1141 fastProc = &fast_swizzle_cmyk_to_bgra;
1142 break;
1144 proc = &swizzle_cmyk_to_565;
1145 break;
1146 default:
1147 return nullptr;
1148 }
1149 break;
1150 default:
1151 return nullptr;
1152 }
1153
1154 // Store bpp in bytes if it is an even multiple, otherwise use bits
1155 uint8_t bitsPerPixel = encodedInfo.bitsPerPixel();
1156 int srcBPP = SkIsAlign8(bitsPerPixel) ? bitsPerPixel / 8 : bitsPerPixel;
1157 int dstBPP = dstInfo.bytesPerPixel();
1158 return Make(dstInfo, fastProc, proc, ctable, srcBPP, dstBPP, options, frame);
1159}
1160
1161std::unique_ptr<SkSwizzler> SkSwizzler::Make(const SkImageInfo& dstInfo,
1162 RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcBPP,
1163 int dstBPP, const SkCodec::Options& options, const SkIRect* frame) {
1164 int srcOffset = 0;
1165 int srcWidth = dstInfo.width();
1166 int dstOffset = 0;
1167 int dstWidth = srcWidth;
1168 if (options.fSubset) {
1169 // We do not currently support subset decodes for image types that may have
1170 // frames (gif).
1171 SkASSERT(!frame);
1172 srcOffset = options.fSubset->left();
1173 srcWidth = options.fSubset->width();
1174 dstWidth = srcWidth;
1175 } else if (frame) {
1176 dstOffset = frame->left();
1177 srcWidth = frame->width();
1178 }
1179
1180 return std::unique_ptr<SkSwizzler>(new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth,
1181 dstOffset, dstWidth, srcBPP, dstBPP));
1182}
1183
1184SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset,
1185 int srcWidth, int dstOffset, int dstWidth, int srcBPP, int dstBPP)
1186 : fFastProc(fastProc)
1187 , fSlowProc(proc)
1188 , fActualProc(fFastProc ? fFastProc : fSlowProc)
1189 , fColorTable(ctable)
1190 , fSrcOffset(srcOffset)
1191 , fDstOffset(dstOffset)
1192 , fSrcOffsetUnits(srcOffset * srcBPP)
1193 , fDstOffsetBytes(dstOffset * dstBPP)
1194 , fSrcWidth(srcWidth)
1195 , fDstWidth(dstWidth)
1196 , fSwizzleWidth(srcWidth)
1197 , fAllocatedWidth(dstWidth)
1198 , fSampleX(1)
1199 , fSrcBPP(srcBPP)
1200 , fDstBPP(dstBPP)
1201{}
1202
1204 SkASSERT(sampleX > 0);
1205
1206 fSampleX = sampleX;
1207 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP;
1208 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX);
1209 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX);
1210
1211 int frameSampleX = sampleX;
1212 if (fSrcWidth < fDstWidth) {
1213 // Although SkSampledCodec adjusted sampleX so that it will never be
1214 // larger than the width of the image (or subset, if applicable), it
1215 // doesn't account for the width of a subset frame (i.e. gif). As a
1216 // result, get_start_coord(sampleX) could result in fSrcOffsetUnits
1217 // being wider than fSrcWidth. Compute a sampling rate based on the
1218 // frame width to ensure that fSrcOffsetUnits is sensible.
1219 frameSampleX = fSrcWidth / fSwizzleWidth;
1220 }
1221 fSrcOffsetUnits = (get_start_coord(frameSampleX) + fSrcOffset) * fSrcBPP;
1222
1223 if (fDstOffsetBytes > 0) {
1224 const size_t dstSwizzleBytes = fSwizzleWidth * fDstBPP;
1225 const size_t dstAllocatedBytes = fAllocatedWidth * fDstBPP;
1226 if (fDstOffsetBytes + dstSwizzleBytes > dstAllocatedBytes) {
1227#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
1228 SkAndroidFrameworkUtils::SafetyNetLog("118143775");
1229#endif
1230 SkASSERT(dstSwizzleBytes <= dstAllocatedBytes);
1231 fDstOffsetBytes = dstAllocatedBytes - dstSwizzleBytes;
1232 }
1233 }
1234
1235 // The optimized swizzler functions do not support sampling. Sampled swizzles
1236 // are already fast because they skip pixels. We haven't seen a situation
1237 // where speeding up sampling has a significant impact on total decode time.
1238 if (1 == fSampleX && fFastProc) {
1239 fActualProc = fFastProc;
1240 } else {
1241 fActualProc = fSlowProc;
1242 }
1243
1244 return fAllocatedWidth;
1245}
1246
1247void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
1248 SkASSERT(nullptr != dst && nullptr != src);
1249 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
1250 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
1251}
const char * options
static constexpr bool SkIsAlign8(T x)
Definition SkAlign.h:21
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
static int get_scaled_dimension(int srcDimension, int sampleSize)
Definition SkCodecPriv.h:44
static SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static int get_start_coord(int sampleFactor)
Definition SkCodecPriv.h:57
static uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColorData.h:65
static U16CPU SkPack888ToRGB16(U8CPU r, U8CPU g, U8CPU b)
static U16CPU SkPixel32ToPixel16(SkPMColor c)
static uint32_t SkPackARGB_as_BGRA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColorData.h:74
static SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition SkColorType.h:31
uint32_t SkPMColor
Definition SkColor.h:205
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
#define SK_RESTRICT
Definition SkFeatures.h:42
static constexpr uint16_t SK_Half1
Definition SkHalf.h:23
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition SkMath.h:73
static void swizzle_cmyk_to_bgra(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample8(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bgr_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_grayalpha_to_n32_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_gray_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_cmyk_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_cmyk_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_bgra_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_565(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
#define RGB565_BLACK
static void swizzle_rgb_to_rgba(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_gray_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgb_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
#define GRAYSCALE_WHITE
static void swizzle_rgba16_to_rgba_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba_to_bgra_unpremul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample1(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void sample6(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba_to_rgba_premul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_n32_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_rgba_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_rgba_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgba16_to_bgra_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_n32_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_rgb16_to_rgba(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_grayalpha_to_n32_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_gray_to_n32(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_bgra_premul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_small_index_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_cmyk_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_f16(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void swizzle_cmyk_to_rgba(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_small_index_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample4(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgb_to_bgra(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_index_to_n32(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_grayalpha_to_a8(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor[])
static void swizzle_rgba_to_bgra_premul(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
#define RGB565_WHITE
static void swizzle_rgb_to_bgra(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_index_to_n32_skipZ(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
#define GRAYSCALE_BLACK
static void swizzle_bit_to_grayscale(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
static void swizzle_index_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[])
static void sample2(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void fast_swizzle_rgba_to_bgra_unpremul(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static void swizzle_bit_to_565(void *SK_RESTRICT dstRow, const uint8_t *SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor *)
ZeroInitialized
Definition SkCodec.h:303
@ kYes_ZeroInitialized
Definition SkCodec.h:308
static std::unique_ptr< SkSwizzler > MakeSimple(int srcBPP, const SkImageInfo &dstInfo, const SkCodec::Options &)
static std::unique_ptr< SkSwizzler > Make(const SkEncodedInfo &encodedInfo, const SkPMColor *ctable, const SkImageInfo &dstInfo, const SkCodec::Options &, const SkIRect *frame=nullptr)
void swizzle(void *dst, const uint8_t *SK_RESTRICT src)
int onSetSampleX(int) override
int sampleX() const
Definition SkSwizzler.h:84
double frame
Definition examples.cpp:31
static bool b
double x
Swizzle_8888_u8 gray_to_RGB1
Swizzle_8888_u32 RGBA_to_rgbA
Swizzle_8888_u8 RGB_to_RGB1
Swizzle_8888_u8 grayA_to_rgbA
Swizzle_8888_u8 RGB_to_BGR1
Swizzle_8888_u8 grayA_to_RGBA
Swizzle_8888_u32 RGBA_to_BGRA
Swizzle_8888_u32 RGBA_to_bgrA
Swizzle_8888_u32 inverted_CMYK_to_BGR1
Swizzle_8888_u32 inverted_CMYK_to_RGB1
Definition copy.py:1
int32_t width
Point offset
Color color() const
uint8_t bitsPerPixel() const
Alpha alpha() const
uint8_t bitsPerComponent() const
int bytesPerPixel() const
int width() const
SkAlphaType alphaType() const
SkColorType colorType() const