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