-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
2016 lines (1709 loc) · 80.4 KB
/
tests.c
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
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma warning( disable : 6011 ) // dereferencing NULL pointer (from malloc)
#endif
#include "src/skcms_public.h"
#include "src/skcms_internals.h"
#include "test_only.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER)
#define DEBUGBREAK __debugbreak
#elif defined(__clang__)
#define DEBUGBREAK __builtin_debugtrap
#else
#define DEBUGBREAK __builtin_trap
#endif
#define expect(cond) \
do { \
if (!(cond)) { \
fprintf(stderr, "expect(" #cond ") failed at %s:%d\n",__FILE__,__LINE__); \
fflush(stderr); /* stderr is buffered on Windows. */ \
DEBUGBREAK(); \
} \
} while(false)
#define expect_close(x,y) \
do { \
double X = (double)(x), \
Y = (double)(y); \
if (X == (double)(int)X && \
Y == (double)(int)Y && \
(X == Y-1 || Y == X-1)) { \
/* These are ints and off by one. Sounds close to me. */ \
} else { \
double ratio = (X < Y) ? X / Y \
: (Y < X) ? Y / X \
: 1.0; \
if (ratio < 1.0) { \
fprintf(stderr, "expect_close(" #x "==%g, " #y "==%g) failed at %s:%d\n", \
X,Y, __FILE__,__LINE__); \
fflush(stderr); /* stderr is buffered on Windows. */ \
DEBUGBREAK(); \
} \
} \
} while(false)
static void test_ICCProfile(void) {
// Nothing works yet. :)
skcms_ICCProfile profile;
const uint8_t buf[] = { 0x42 };
expect(!skcms_Parse(buf, sizeof(buf), &profile));
}
static void test_FormatConversions(void) {
// We can interpret src as 85 RGB_888 pixels or 64 RGB_8888 pixels.
uint8_t src[256],
dst[85*4];
for (int i = 0; i < 256; i++) {
src[i] = (uint8_t)i;
}
// This should basically be a really complicated memcpy().
expect(skcms_Transform(src, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 256; i++) {
expect(dst[i] == i);
}
// We can do RGBA -> BGRA swaps two ways:
expect(skcms_Transform(src, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 64; i++) {
expect(dst[4*i+0] == 4*i+2);
expect(dst[4*i+1] == 4*i+1);
expect(dst[4*i+2] == 4*i+0);
expect(dst[4*i+3] == 4*i+3);
}
expect(skcms_Transform(src, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 64; i++) {
expect(dst[4*i+0] == 4*i+2);
expect(dst[4*i+1] == 4*i+1);
expect(dst[4*i+2] == 4*i+0);
expect(dst[4*i+3] == 4*i+3);
}
// Let's convert RGB_888 to RGBA_8888...
expect(skcms_Transform(src, skcms_PixelFormat_RGB_888 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
85));
for (int i = 0; i < 85; i++) {
expect(dst[4*i+0] == 3*i+0);
expect(dst[4*i+1] == 3*i+1);
expect(dst[4*i+2] == 3*i+2);
expect(dst[4*i+3] == 255);
}
// ... and now all the variants of R-B swaps.
expect(skcms_Transform(src, skcms_PixelFormat_BGR_888 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
85));
for (int i = 0; i < 85; i++) {
expect(dst[4*i+0] == 3*i+0);
expect(dst[4*i+1] == 3*i+1);
expect(dst[4*i+2] == 3*i+2);
expect(dst[4*i+3] == 255);
}
expect(skcms_Transform(src, skcms_PixelFormat_BGR_888 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
85));
for (int i = 0; i < 85; i++) {
expect(dst[4*i+0] == 3*i+2);
expect(dst[4*i+1] == 3*i+1);
expect(dst[4*i+2] == 3*i+0);
expect(dst[4*i+3] == 255);
}
expect(skcms_Transform(src, skcms_PixelFormat_RGB_888 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
85));
for (int i = 0; i < 85; i++) {
expect(dst[4*i+0] == 3*i+2);
expect(dst[4*i+1] == 3*i+1);
expect(dst[4*i+2] == 3*i+0);
expect(dst[4*i+3] == 255);
}
// Let's test in-place transforms.
// RGBA_8888 and RGB_888 aren't the same size, so we shouldn't allow this call.
expect(!skcms_Transform(src, skcms_PixelFormat_RGB_888 , skcms_AlphaFormat_Unpremul, NULL,
src, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
85));
// These two should work fine.
expect(skcms_Transform(src, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
src, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 64; i++) {
expect(src[4*i+0] == 4*i+2);
expect(src[4*i+1] == 4*i+1);
expect(src[4*i+2] == 4*i+0);
expect(src[4*i+3] == 4*i+3);
}
expect(skcms_Transform(src, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
src, skcms_PixelFormat_BGRA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 64; i++) {
expect(src[4*i+0] == 4*i+0);
expect(src[4*i+1] == 4*i+1);
expect(src[4*i+2] == 4*i+2);
expect(src[4*i+3] == 4*i+3);
}
uint32_t _8888[3] = { 0x03020100, 0x07060504, 0x0b0a0908 };
uint8_t _888[9];
expect(skcms_Transform(_8888, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
_888 , skcms_PixelFormat_RGB_888 , skcms_AlphaFormat_Unpremul, NULL,
3));
expect(_888[0] == 0 && _888[1] == 1 && _888[2] == 2);
expect(_888[3] == 4 && _888[4] == 5 && _888[5] == 6);
expect(_888[6] == 8 && _888[7] == 9 && _888[8] == 10);
}
static void test_FormatConversions_565(void) {
// This should hit all the unique values of each lane of 565.
uint16_t src[64];
for (int i = 0; i < 64; i++) {
src[i] = (uint16_t)( (i/2) << 0 )
| (uint16_t)( (i/1) << 5 )
| (uint16_t)( (i/2) << 11 );
}
expect(src[ 0] == 0x0000);
expect(src[31] == 0x7bef);
expect(src[63] == 0xffff);
uint32_t dst[64];
expect(skcms_Transform(src, skcms_PixelFormat_RGB_565 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
64));
// We'll just spot check these results a bit.
for (int i = 0; i < 64; i++) {
expect((dst[i] >> 24) == 255); // All opaque.
}
expect(dst[ 0] == 0xff000000); // 0 -> 0
expect(dst[20] == 0xff525152); // (10/31) ≈ (82/255) and (20/63) ≈ (81/255)
expect(dst[62] == 0xfffffbff); // (31/31) == (255/255) and (62/63) ≈ (251/255)
expect(dst[63] == 0xffffffff); // 1 -> 1
// Let's convert back the other way.
uint16_t back[64];
expect(skcms_Transform(dst , skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_RGB_565 , skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 64; i++) {
expect(src[i] == back[i]);
}
}
static void test_FormatConversions_16161616LE(void) {
// We want to hit each 16-bit value, 4 per each of 16384 pixels.
uint64_t* src = malloc(8 * 16384);
for (int i = 0; i < 16384; i++) {
src[i] = (uint64_t)(4*i + 0) << 0
| (uint64_t)(4*i + 1) << 16
| (uint64_t)(4*i + 2) << 32
| (uint64_t)(4*i + 3) << 48;
}
expect(src[ 0] == 0x0003000200010000);
expect(src[ 32] == 0x0083008200810080); // just on the cusp of rounding to 0x00 or 0x01
expect(src[16383] == 0xfffffffefffdfffc);
uint32_t* dst = malloc(4 * 16384);
expect(skcms_Transform(src, skcms_PixelFormat_RGBA_16161616LE, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
16384));
// skcms_Transform() will treat src as holding little-endian 16-bit values.
expect(dst[ 0] == 0x00000000); // 0x0003 rounds to 0x00, etc.
expect(dst[ 32] == 0x01010100); // 0x80 -> 0.9980544747081712, 0x81 -> 1.0019455252918288
expect(dst[16383] == 0xffffffff); // 0xfffc rounds to 0xff, etc.
// We've lost precision when transforming to 8-bit, so these won't quite round-trip.
// Instead we should see the 8-bit dst value byte-doubled, as 65535/255 = 257 = 0x0101.
uint64_t* back = malloc(8 * 16384);
expect(skcms_Transform(dst , skcms_PixelFormat_RGBA_8888 ,skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_RGBA_16161616LE,skcms_AlphaFormat_Unpremul, NULL,
16384));
for (int i = 0; i < 16384; i++) {
expect_close( ((back[i] >> 0) & 0xffff) , ((dst[i] >> 0) & 0xff) * 0x0101);
expect_close( ((back[i] >> 16) & 0xffff) , ((dst[i] >> 8) & 0xff) * 0x0101);
expect_close( ((back[i] >> 32) & 0xffff) , ((dst[i] >> 16) & 0xff) * 0x0101);
expect_close( ((back[i] >> 48) & 0xffff) , ((dst[i] >> 24) & 0xff) * 0x0101);
}
free(src);
free(dst);
free(back);
}
static void test_FormatConversions_161616LE(void) {
// We'll test the same cases as the _16161616LE() test, as if they were 4 RGB pixels.
uint16_t src[] = { 0x0000, 0x0001, 0x0002,
0x0003, 0x0080, 0x0081,
0x0082, 0x0083, 0xfffc,
0xfffd, 0xfffe, 0xffff };
uint32_t dst[4];
expect(skcms_Transform(src, skcms_PixelFormat_RGB_161616LE, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
4));
expect(dst[0] == 0xff000000);
expect(dst[1] == 0xff010000);
expect(dst[2] == 0xffff0101);
expect(dst[3] == 0xffffffff);
// We've lost precision when transforming to 8-bit, so these won't quite round-trip.
// Instead we should see the 8-bit dst value byte-doubled, as 65535/255 = 257 = 0x0101.
uint16_t back[12];
expect(skcms_Transform(dst , skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_RGB_161616LE, skcms_AlphaFormat_Unpremul, NULL,
4));
uint16_t expected[] = { 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0101,
0x0101, 0x0101, 0xffff,
0xffff, 0xffff, 0xffff };
for (int i = 0; i < 12; i++) {
expect_close(back[i], expected[i]);
}
}
static int bswap16(int x) {
return (x & 0x00ff) << 8
| (x & 0xff00) >> 8;
}
static void test_FormatConversions_16161616BE(void) {
// We want to hit each 16-bit value, 4 per each of 16384 pixels.
uint64_t* src = malloc(8 * 16384);
for (int i = 0; i < 16384; i++) {
src[i] = (uint64_t)(4*i + 0) << 0
| (uint64_t)(4*i + 1) << 16
| (uint64_t)(4*i + 2) << 32
| (uint64_t)(4*i + 3) << 48;
}
expect(src[ 0] == 0x0003000200010000);
expect(src[ 8127] == 0x7eff7efe7efd7efc); // This should demonstrate interesting rounding.
expect(src[16383] == 0xfffffffefffdfffc);
uint32_t* dst = malloc(4 * 16384);
expect(skcms_Transform(src, skcms_PixelFormat_RGBA_16161616BE, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
16384));
// skcms_Transform() will treat src as holding big-endian 16-bit values,
// so the low lanes are actually the most significant byte, and the high least.
expect(dst[ 0] == 0x03020100);
expect(dst[ 8127] == 0xfefefdfc);
expect(dst[16383] == 0xfffefdfc);
// We've lost precision when transforming to 8-bit, so these won't quite round-trip.
// Instead we should see the 8-bit dst value byte-doubled, as 65535/255 = 257 = 0x0101.
uint64_t* back = malloc(8 * 16384);
expect(skcms_Transform(dst , skcms_PixelFormat_RGBA_8888 ,skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_RGBA_16161616BE,skcms_AlphaFormat_Unpremul, NULL,
16384));
for (int i = 0; i < 16384; i++) {
expect_close(bswap16((back[i] >> 0) & 0xffff), ((dst[i] >> 0) & 0xff) * 0x0101);
expect_close(bswap16((back[i] >> 16) & 0xffff), ((dst[i] >> 8) & 0xff) * 0x0101);
expect_close(bswap16((back[i] >> 32) & 0xffff), ((dst[i] >> 16) & 0xff) * 0x0101);
expect_close(bswap16((back[i] >> 48) & 0xffff), ((dst[i] >> 24) & 0xff) * 0x0101);
}
free(src);
free(dst);
free(back);
}
static void test_FormatConversions_161616BE(void) {
// We'll test the same cases as the _16161616BE() test, as if they were 4 RGB pixels.
uint16_t src[] = { 0x0000, 0x0001, 0x0002,
0x0003, 0x7efc, 0x7efd,
0x7efe, 0x7eff, 0xfffc,
0xfffd, 0xfffe, 0xffff };
uint32_t dst[4];
expect(skcms_Transform(src, skcms_PixelFormat_RGB_161616BE, skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
4));
expect(dst[0] == 0xff020100);
expect(dst[1] == 0xfffdfc03);
expect(dst[2] == 0xfffcfefe);
expect(dst[3] == 0xfffffefd);
// We've lost precision when transforming to 8-bit, so these won't quite round-trip.
// Instead we should see the 8-bit dst value byte doubled, as 65535/255 = 257 = 0x0101.
uint16_t back[12];
expect(skcms_Transform(dst , skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_RGB_161616BE, skcms_AlphaFormat_Unpremul, NULL,
4));
uint16_t expected[] = { 0x0000, 0x0101, 0x0202,
0x0303, 0xfcfc, 0xfdfd,
0xfefe, 0xfefe, 0xfcfc,
0xfdfd, 0xfefe, 0xffff };
for (int i = 0; i < 12; i++) {
expect_close(bswap16(back[i]), expected[i]);
}
}
static void test_FormatConversions_101010(void) {
uint32_t src = (uint32_t)1023 << 0 // 1.0.
| (uint32_t) 511 << 10 // About 1/2.
| (uint32_t) 4 << 20 // Smallest 10-bit channel that's non-zero in 8-bit.
| (uint32_t) 1 << 30; // 1/3, smallest non-zero alpha.
uint32_t dst;
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
1));
expect(dst == 0x55017fff);
// Same as above, but we'll ignore the 1/3 alpha and fill in 1.0.
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Opaque , NULL,
&dst, skcms_PixelFormat_RGBA_8888 , skcms_AlphaFormat_Unpremul, NULL,
1));
expect(dst == 0xff017fff);
// Converting 101010x <-> 1010102 will force opaque in either direction.
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Opaque , NULL,
1));
expect(dst == ( (uint32_t)1023 << 0
| (uint32_t) 511 << 10
| (uint32_t) 4 << 20
| (uint32_t) 3 << 30));
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Opaque , NULL,
&dst, skcms_PixelFormat_RGBA_1010102, skcms_AlphaFormat_Unpremul, NULL,
1));
expect(dst == ( (uint32_t)1023 << 0
| (uint32_t) 511 << 10
| (uint32_t) 4 << 20
| (uint32_t) 3 << 30));
}
static void test_FormatConversions_101010_xr(void) {
uint32_t src = 0xff007fff;
uint32_t dst = 0;
expect(skcms_Transform(&src, skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, &dst,
skcms_PixelFormat_BGR_101010x_XR,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(((dst >> 0) & 0x3ff) == 894);
expect(((dst >> 10) & 0x3ff) == 638);
expect(((dst >> 20) & 0x3ff) == 384);
uint32_t dst2 = 0;
expect(skcms_Transform(&dst, skcms_PixelFormat_BGR_101010x_XR,
skcms_AlphaFormat_Unpremul, NULL, &dst2,
skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(((dst2 >> 0) & 0xff) == 255);
expect(((dst2 >> 8) & 0xff) == 127);
expect(((dst2 >> 16) & 0xff) == 0);
// 384 maps to a zero channel value in the BGR_101010x_XR format.
const uint32_t bgr10_xr_zero = 384;
src = (bgr10_xr_zero << 0) |
(bgr10_xr_zero << 10) |
(bgr10_xr_zero << 20);
expect(skcms_Transform(&src, skcms_PixelFormat_BGR_101010x_XR,
skcms_AlphaFormat_Unpremul, NULL, &dst,
skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(dst == 0xff000000);
}
static void test_FormatConversions_10101010_xr(void) {
uint32_t src = 0xff007fff;
uint64_t dst = 0;
expect(skcms_Transform(&src, skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, &dst,
skcms_PixelFormat_BGRA_10101010_XR,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(((dst >> ( 0+6)) & 0x3ff) == 894);
expect(((dst >> (16+6)) & 0x3ff) == 638);
expect(((dst >> (32+6)) & 0x3ff) == 384);
expect(((dst >> (48+6)) & 0x3ff) == 894);
uint32_t dst2;
expect(skcms_Transform(&dst, skcms_PixelFormat_BGRA_10101010_XR,
skcms_AlphaFormat_Unpremul, NULL, &dst2,
skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(((dst2 >> 0) & 0xff) == 255);
expect(((dst2 >> 8) & 0xff) == 127);
expect(((dst2 >> 16) & 0xff) == 0);
// Convert a transparent black pixel with premultiplied alpha.
// 384 maps to a zero channel value in the BGRA_10101010_XR format.
const uint64_t bgra10_xr_zero = 384;
uint64_t src2 = (bgra10_xr_zero << (0+6)) |
(bgra10_xr_zero << (16+6)) |
(bgra10_xr_zero << (32+6)) |
(bgra10_xr_zero << (48+6));
expect(skcms_Transform(&src2, skcms_PixelFormat_BGRA_10101010_XR,
skcms_AlphaFormat_PremulAsEncoded, NULL, &dst2,
skcms_PixelFormat_BGRA_8888,
skcms_AlphaFormat_Unpremul, NULL, 1));
expect(dst2 == 0);
}
static void test_FormatConversions_G8(void) {
uint8_t src[1 * 256] = {0};
for (int i = 0; i < 256; i++) {
src[i] = (uint8_t)i;
}
uint8_t dst[4 * 256] = {0};
expect(skcms_Transform(src, skcms_PixelFormat_G_8 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
256));
for (int i = 0; i < 256; i++) {
expect(dst[i * 4 + 0] == (uint8_t)i); // red = gray
expect(dst[i * 4 + 1] == (uint8_t)i); // green = gray
expect(dst[i * 4 + 2] == (uint8_t)i); // blue = gray
expect(dst[i * 4 + 3] == 0xFF); // opaque
}
// Let's convert back the other way.
uint8_t back[1 * 256] = {0};
expect(skcms_Transform(dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_G_8 , skcms_AlphaFormat_Unpremul, NULL,
256));
for (int i = 0; i < 256; i++) {
expect(src[i] == back[i]);
}
}
static void test_FormatConversions_GA88(void) {
uint8_t src[2 * 256] = {0};
for (int i = 0; i < 256; i++) {
// Using a different "gray" and "alpha" value will hopefully catch most
// potential LE-vs-BE confusion bugs.
src[i * 2 + 0] = (uint8_t)i;
src[i * 2 + 1] = (uint8_t)((i * 7) % 256);
}
uint8_t dst[4 * 256] = {0};
expect(skcms_Transform(src, skcms_PixelFormat_GA_88 , skcms_AlphaFormat_Unpremul, NULL,
dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
256));
for (int i = 0; i < 256; i++) {
expect(dst[i * 4 + 0] == (uint8_t)i); // red = gray
expect(dst[i * 4 + 1] == (uint8_t)i); // green = gray
expect(dst[i * 4 + 2] == (uint8_t)i); // blue = gray
expect(dst[i * 4 + 3] == src[i * 2 + 1]);
}
// Let's convert back the other way.
uint8_t back[2 * 256] = {0};
expect(skcms_Transform(dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
back, skcms_PixelFormat_GA_88 , skcms_AlphaFormat_Unpremul, NULL,
256));
for (int i = 0; i < 256; i++) {
expect(src[i * 2 + 0] == back[i * 2 + 0]);
expect(src[i * 2 + 1] == back[i * 2 + 1]);
}
}
static void test_FormatConversions_half(void) {
uint16_t src[] = {
0x3c00, // 1.0
0x3800, // 0.5
0x1805, // Should round up to 0x01
0x1803, // Should round down to 0x00 (0x1804 may go up or down depending on precision)
0x4000, // 2.0
0x03ff, // A denorm, may be flushed to zero.
0x83ff, // A negative denorm, may be flushed to zero.
0xbc00, // -1.0
};
uint32_t dst[2];
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_hhhh, skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
2));
expect(dst[0] == 0x000180ff);
expect(dst[1] == 0x000000ff); // Notice we've clamped 2.0 to 0xff and -1.0 to 0x00.
expect(skcms_Transform(&src, skcms_PixelFormat_RGB_hhh , skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
2));
expect(dst[0] == 0xff0180ff);
expect(dst[1] == 0xff00ff00); // Remember, this corresponds to src[3-5].
float fdst[8];
expect(skcms_Transform( &src, skcms_PixelFormat_RGBA_hhhh, skcms_AlphaFormat_Unpremul, NULL,
&fdst, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
2));
expect(fdst[0] == 1.0f);
expect(fdst[1] == 0.5f);
expect(fdst[2] > 1/510.0f);
expect(fdst[3] < 1/510.0f);
expect(fdst[4] == 2.0f);
expect(fdst[5] == +0.00006097555f || fdst[5] == 0.0f); // may have been flushed to zero
expect(fdst[6] == -0.00006097555f || fdst[6] == 0.0f);
expect(fdst[7] == -1.0f);
// Now convert back, first to RGBA halfs, then RGB halfs.
uint16_t back[8];
expect(skcms_Transform(&fdst, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
&back, skcms_PixelFormat_RGBA_hhhh, skcms_AlphaFormat_Unpremul, NULL,
2));
expect(back[0] == src[0]);
expect(back[1] == src[1]);
expect(back[2] == src[2]);
expect(back[3] == src[3]);
expect(back[4] == src[4]);
expect(back[5] == src[5] || back[5] == 0x0000);
expect(back[6] == src[6] || back[6] == 0x0000);
expect(back[7] == src[7]);
expect(skcms_Transform(&fdst, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
&back, skcms_PixelFormat_RGB_hhh , skcms_AlphaFormat_Unpremul, NULL,
2));
expect(back[0] == src[0]);
expect(back[1] == src[1]);
expect(back[2] == src[2]);
expect(back[3] == src[4]);
expect(back[4] == src[5] || back[4] == 0x0000);
expect(back[5] == src[6] || back[5] == 0x0000);
}
static void test_FormatConversions_half_norm(void) {
const uint16_t src[] = {
0x3800, // 0.5
0x3c00, // 1.0
0xbc00, // -1.0
0x4000, // 2.0
};
uint16_t dst[ARRAY_COUNT(src)];
const skcms_AlphaFormat upm = skcms_AlphaFormat_Unpremul;
// No-op, no clamp, should preserve all values.
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_hhhh, upm, NULL,
&dst, skcms_PixelFormat_RGBA_hhhh, upm, NULL, 1));
expect(dst[0] == src[0]);
expect(dst[1] == src[1]);
expect(dst[2] == src[2]);
expect(dst[3] == src[3]);
// Clamp on read.
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_hhhh_Norm, upm, NULL,
&dst, skcms_PixelFormat_RGBA_hhhh , upm, NULL, 1));
expect(dst[0] == src[0]);
expect(dst[1] == src[1]);
expect(dst[2] == 0x0000);
expect(dst[3] == src[1]);
// Clamp on write.
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_hhhh , upm, NULL,
&dst, skcms_PixelFormat_RGBA_hhhh_Norm, upm, NULL, 1));
expect(dst[0] == src[0]);
expect(dst[1] == src[1]);
expect(dst[2] == 0x0000);
expect(dst[3] == src[1]);
}
static void test_FormatConversions_float(void) {
float src[] = { 1.0f, 0.5f, 1/255.0f, 1/512.0f };
uint32_t dst;
expect(skcms_Transform(&src, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
1));
expect(dst == 0x000180ff);
// Same as above, but we'll ignore the 1/512 alpha and fill in 1.0.
expect(skcms_Transform(&src, skcms_PixelFormat_RGB_fff , skcms_AlphaFormat_Unpremul, NULL,
&dst, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
1));
expect(dst == 0xff0180ff);
// Let's make sure each byte converts to the float we expect.
uint32_t bytes[64];
float fdst[4*64];
for (int i = 0; i < 64; i++) {
bytes[i] = 0x03020100 + 0x04040404 * (uint32_t)i;
}
expect(skcms_Transform(&bytes, skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul, NULL,
&fdst, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
64));
for (int i = 0; i < 256; i++) {
expect_close(fdst[i], (float)i*(1/255.0f));
if (i == 0 || i == 255) {
expect(fdst[i] == (float)i*(1/255.0f));
}
}
float ffff[16] = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 };
float fff[12] = { 0,0,0, 0,0,0, 0,0,0, 0,0,0};
expect(skcms_Transform(ffff, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
fff , skcms_PixelFormat_RGB_fff , skcms_AlphaFormat_Unpremul, NULL,
1));
expect(fff[0] == 0); expect(fff[1] == 1); expect(fff[2] == 2);
expect(skcms_Transform(ffff, skcms_PixelFormat_RGBA_ffff, skcms_AlphaFormat_Unpremul, NULL,
fff , skcms_PixelFormat_RGB_fff , skcms_AlphaFormat_Unpremul, NULL,
4));
expect(fff[0] == 0); expect(fff[ 1] == 1); expect(fff[ 2] == 2);
expect(fff[3] == 4); expect(fff[ 4] == 5); expect(fff[ 5] == 6);
expect(fff[6] == 8); expect(fff[ 7] == 9); expect(fff[ 8] == 10);
expect(fff[9] == 12); expect(fff[10] == 13); expect(fff[11] == 14);
}
static const char* profile_test_cases[] = {
// iccMAX profiles that we can't parse at all
"profiles/color.org/sRGB_D65_colorimetric.icc",
"profiles/color.org/sRGB_D65_MAT.icc",
"profiles/color.org/sRGB_ISO22028.icc",
// V2 or V4 profiles that only include A2B/B2A tags (no TRC or XYZ)
"profiles/color.org/sRGB_ICC_v4_Appearance.icc",
"profiles/color.org/sRGB_v4_ICC_preference.icc",
"profiles/color.org/Upper_Left.icc",
"profiles/color.org/Upper_Right.icc",
"profiles/misc/Apple_Wide_Color.icc",
"profiles/misc/Coated_FOGRA27_CMYK.icc",
"profiles/misc/Coated_FOGRA39_CMYK.icc",
"profiles/misc/ColorLogic_ISO_Coated_CMYK.icc", // Has kTRC.
"profiles/misc/Japan_Color_2001_Coated.icc",
"profiles/misc/Lexmark_X110.icc",
"profiles/misc/MartiMaria_browsertest_A2B.icc",
"profiles/misc/PrintOpen_ISO_Coated_CMYK.icc", // Has kTRC.
"profiles/misc/sRGB_ICC_v4_beta.icc",
"profiles/misc/SWOP_Coated_20_GCR_CMYK.icc",
"profiles/misc/US_Web_Coated_SWOP_CMYK.icc",
"profiles/misc/XRite_GRACol7_340_CMYK.icc",
// V2 monochrome output profiles that include kTRC but no A2B
"profiles/misc/Dot_Gain_20_Grayscale.icc", // kTRC table
"profiles/misc/Gray_Gamma_22.icc", // kTRC gamma
// V4 profiles with parametric TRC curves and XYZ
"profiles/mobile/Display_P3_parametric.icc",
"profiles/mobile/sRGB_parametric.icc",
"profiles/mobile/iPhone7p.icc",
"profiles/misc/sRGB_lcms.icc",
// V4 profiles with LUT TRC curves and XYZ
"profiles/mobile/Display_P3_LUT.icc",
"profiles/mobile/sRGB_LUT.icc",
// V2 profiles with gamma TRC and XYZ
"profiles/color.org/Lower_Left.icc",
"profiles/color.org/Lower_Right.icc",
"profiles/misc/AdobeRGB.icc",
"profiles/misc/AdobeColorSpin.icc",
"profiles/misc/Color_Spin_Gamma_18.icc",
"profiles/misc/Generic_RGB_Gamma_18.icc",
// V2 profiles with LUT TRC and XYZ
"profiles/color.org/sRGB2014.icc",
"profiles/sRGB_Facebook.icc",
"profiles/misc/Apple_Color_LCD.icc",
"profiles/misc/HD_709.icc",
"profiles/misc/sRGB_black_scaled.icc",
"profiles/misc/sRGB_HP.icc",
"profiles/misc/sRGB_HP_2.icc",
// Calibrated monitor profile with identical sRGB-ish tables.
"profiles/misc/sRGB_Calibrated_Homogeneous.icc",
// Calibrated monitor profile with slightly different sRGB-like tables for each channel.
"profiles/misc/sRGB_Calibrated_Heterogeneous.icc",
// Calibrated monitor profile with non-monotonic TRC tables. We approximate, but badly.
"profiles/misc/DisplayCal_ASUS_NonMonotonic.icc",
// Hard test profile. Non-invertible XYZ, three separate tables that fail to approximate
"profiles/misc/MartiMaria_browsertest_HARD.icc",
// Camera profile with three separate tables that fail to approximate
"profiles/misc/Phase_One_P25.icc",
// Profile claims to be sRGB, but seems quite different
"profiles/misc/Kodak_sRGB.icc",
// Bad profiles found inn the wild
"profiles/misc/ColorGATE_Sihl_PhotoPaper.icc", // Broken tag table, and A2B0 fails to parse
"profiles/misc/bad_pcs.icc", // PCS is 'RGB '
// Unsure what the bug here is, chromium:875650.
"profiles/misc/ThinkpadX1YogaV2.icc",
"profiles/misc/XPS13_9360.icc",
// Calibrated profile where A2B/B2A and XYZ+TRC produce very different gamut mappings.
// User was (rightly) confused & convinced that profile was being ignored.
"profiles/misc/Calibrated_A2B_XYZ_Mismatch.icc", // chromium:1055154
// HDR profiles that include the new 'cicp' tag (from ICC 4.4.0)
"profiles/misc/P3_PQ_cicp.icc",
"profiles/misc/Rec2020_HLG_cicp.icc",
"profiles/misc/Rec2020_PQ_cicp.icc",
// fuzzer generated profiles that found parsing bugs
// Bad tag table data - these should not parse
"profiles/fuzz/last_tag_too_small.icc", // skia:7592
"profiles/fuzz/named_tag_too_small.icc", // skia:7592
// Bad tag data - these should not parse
"profiles/fuzz/curv_size_overflow.icc", // skia:7593
"profiles/fuzz/truncated_curv_tag.icc", // oss-fuzz:6103
"profiles/fuzz/zero_a.icc", // oss-fuzz:????
"profiles/fuzz/a2b_too_many_input_channels.icc", // oss-fuzz:6521
"profiles/fuzz/a2b_too_many_input_channels2.icc", // oss-fuzz:32765
"profiles/fuzz/mangled_trc_tags.icc", // chromium:835666
"profiles/fuzz/negative_g_para.icc", // chromium:836634
"profiles/fuzz/b2a_too_few_output_channels.icc", // oss-fuzz:33281
// A B2A profile with no CLUT.
"profiles/fuzz/b2a_no_clut.icc", // oss-fuzz:33396
// Caused skcms_PolyTF fit to round trip indices outside the range of int.
"profiles/fuzz/infinite_roundtrip.icc", // oss-fuzz:8101
"profiles/fuzz/polytf_big_float_to_int_cast.icc", // oss-fuzz:8142
// Caused skcms_ApproximateCurve to violate the a*d+b >= 0 constraint.
"profiles/fuzz/inverse_tf_adb_negative.icc", // oss-fuzz:8130
// Caused skcms_PolyTF fit to send P to NaN due to very large inverse lhs
"profiles/fuzz/polytf_nan_after_update.icc", // oss-fuzz:8165
// Table is approximated by an inverse TF whose inverse is not invertible.
"profiles/fuzz/inverse_tf_not_invertible.icc", // chromium:841210
// Table is approximated by a TF whose inverse has g > 16M (timeout in approx_pow)
"profiles/fuzz/inverse_tf_huge_g.icc", // chromium:842374
// mAB has a CLUT with 1 input channel
"profiles/fuzz/one_d_clut.icc", // chromium:874433
// Non-D50 profiles.
"profiles/misc/SM245B.icc",
"profiles/misc/BenQ_GL2450.icc",
// This profile is fine, but has really small TRC tables (5 points).
"profiles/misc/BenQ_RL2455.icc", // chromium:869115
// This calibrated profile has a non-zero black.
"profiles/misc/calibrated_nonzero_black.icc",
// A zero g term causes a divide by zero when inverting.
"profiles/fuzz/zero_g.icc", // oss-fuzz:12430
// Reasonable table, but gets approximated very badly
"profiles/misc/crbug_976551.icc", // chromium:976551
// The a term goes negative when inverting.
"profiles/fuzz/negative_a_when_inverted.icc", // oss-fuzz:16581
// a + b is negative when inverting, because d>0
"profiles/fuzz/negative_a_plus_b.icc", // oss-fuzz:16584
"profiles/fuzz/nan_s.icc", // oss-fuzz:16674
"profiles/fuzz/inf_a.icc", // oss-fuzz:16675
"profiles/fuzz/fit_pq.icc", // oss-fuzz:18249
// Reasonable table, bad approximation (converges very slowly)
"profiles/misc/MR2416GSDF.icc", // chromium:869115
// Three different tables w/shoulders, bad approximation (slow convergence)
"profiles/misc/crbug_1017960_19.icc", // chromium:1017960
"profiles/fuzz/direct_fit_not_invertible.icc", // oss-fuzz:19341
"profiles/fuzz/direct_fit_negative_a.icc", // oss-fuzz:19467
// g = 1027 -> -nan from exp2f_, sign-strip doesn't work, leading to powf_ assert
"profiles/fuzz/large_g.icc", // chromium:996795
};
static void test_Parse(bool regen) {
for (int i = 0; i < ARRAY_COUNT(profile_test_cases); ++i) {
const char* filename = profile_test_cases[i];
void* buf = NULL;
size_t len = 0;
expect(load_file(filename, &buf, &len));
skcms_ICCProfile profile;
bool parsed = skcms_Parse(buf, len, &profile);
FILE* dump = tmpfile();
expect(dump);
if (parsed) {
dump_profile(&profile, dump);
} else {
fprintf(dump, "Unable to parse ICC profile\n");
}
// MakeUsable functions should leave input unchanged when returning false
skcms_ICCProfile as_dst = profile;
if (!skcms_MakeUsableAsDestination(&as_dst)) {
expect(memcmp(&as_dst, &profile, sizeof(profile)) == 0);
}
as_dst = profile;
if (!skcms_MakeUsableAsDestinationWithSingleCurve(&as_dst)) {
expect(memcmp(&as_dst, &profile, sizeof(profile)) == 0);
}
void* dump_buf = NULL;
size_t dump_len = 0;
expect(load_file_fp(dump, &dump_buf, &dump_len));
fclose(dump);
char ref_filename[256];
if (snprintf(ref_filename, sizeof(ref_filename), "%s.txt", filename) < 0) {
expect(false);
}
if (regen) {
// Just write out new test data if in regen mode
expect(write_file(ref_filename, dump_buf, dump_len));
} else {
// Read in existing test data
void* ref_buf = NULL;
size_t ref_len = 0;
expect(load_file(ref_filename, &ref_buf, &ref_len));
if (dump_len != ref_len || memcmp(dump_buf, ref_buf, dump_len) != 0) {
const char* cur = dump_buf;
const char* ref = ref_buf;
while (*cur == *ref) { cur++; ref++; }
size_t off = (size_t)(cur - (const char*)dump_buf);
// Write out the new data on a mismatch
fprintf(stderr, "Parse mismatch for %s:\n", filename);
fwrite(dump_buf, 1, dump_len, stderr);
fprintf(stderr, "\n");
fprintf(stderr, "Mismatch begins at offset %zu, expected '%c', got,\n", off, *ref);
fwrite(cur, 1, dump_len - off, stderr);
fprintf(stderr, "\n");
expect(false);
}
free(ref_buf);
}
free(buf);
free(dump_buf);
}
}
static void test_ApproximateCurve_clamped(void) {
// These data represent a transfer function that is clamped at the high
// end of its domain. It comes from the color profile attached to
// https://crbug.com/750459
float t[256] = {
0.000000f, 0.000305f, 0.000610f, 0.000916f, 0.001221f, 0.001511f,
0.001816f, 0.002121f, 0.002426f, 0.002731f, 0.003037f, 0.003601f,
0.003937f, 0.004303f, 0.004685f, 0.005081f, 0.005509f, 0.005951f,
0.006409f, 0.006882f, 0.007385f, 0.007904f, 0.008438f, 0.009003f,
0.009583f, 0.010193f, 0.010819f, 0.011460f, 0.012131f, 0.012818f,
0.013535f, 0.014267f, 0.015030f, 0.015808f, 0.016617f, 0.017456f,
0.018296f, 0.019181f, 0.020081f, 0.021012f, 0.021958f, 0.022934f,
0.023926f, 0.024949f, 0.026001f, 0.027070f, 0.028168f, 0.029297f,
0.030442f, 0.031617f, 0.032822f, 0.034058f, 0.035309f, 0.036591f,
0.037903f, 0.039231f, 0.040604f, 0.041993f, 0.043412f, 0.044846f,
0.046326f, 0.047822f, 0.049348f, 0.050904f, 0.052491f, 0.054108f,
0.055756f, 0.057420f, 0.059113f, 0.060853f, 0.062608f, 0.064393f,
0.066209f, 0.068055f, 0.069932f, 0.071839f, 0.073762f, 0.075731f,
0.077729f, 0.079759f, 0.081804f, 0.083894f, 0.086015f, 0.088167f,
0.090333f, 0.092546f, 0.094789f, 0.097063f, 0.099367f, 0.101701f,
0.104067f, 0.106477f, 0.108904f, 0.111360f, 0.113863f, 0.116381f,
0.118944f, 0.121538f, 0.124163f, 0.126818f, 0.129519f, 0.132235f,
0.134997f, 0.137789f, 0.140612f, 0.143465f, 0.146365f, 0.149279f,
0.152239f, 0.155230f, 0.158267f, 0.161318f, 0.164416f, 0.167544f,
0.170718f, 0.173907f, 0.177142f, 0.180407f, 0.183719f, 0.187045f,
0.190433f, 0.193835f, 0.197284f, 0.200763f, 0.204273f, 0.207813f,
0.211398f, 0.215030f, 0.218692f, 0.222385f, 0.226108f, 0.229877f,
0.233677f, 0.237522f, 0.241382f, 0.245304f, 0.249256f, 0.253239f,
0.257252f, 0.261311f, 0.265415f, 0.269551f, 0.273716f, 0.277928f,
0.282170f, 0.286458f, 0.290776f, 0.295140f, 0.299535f, 0.303975f,
0.308446f, 0.312947f, 0.317494f, 0.322087f, 0.326711f, 0.331380f,
0.336080f, 0.340826f, 0.345602f, 0.350423f, 0.355291f, 0.360174f,
0.365118f, 0.370092f, 0.375113f, 0.380163f, 0.385260f, 0.390387f,
0.395560f, 0.400778f, 0.406027f, 0.411322f, 0.416663f, 0.422034f,
0.427451f, 0.432898f, 0.438392f, 0.443931f, 0.449500f, 0.455116f,
0.460777f, 0.466468f, 0.472221f, 0.477989f, 0.483818f, 0.489677f,
0.495583f, 0.501518f, 0.507500f, 0.513527f, 0.519600f, 0.525719f,
0.531868f, 0.538064f, 0.544289f, 0.550576f, 0.556893f, 0.563256f,
0.569650f, 0.576104f, 0.582589f, 0.589120f, 0.595697f, 0.602304f,
0.608972f, 0.615671f, 0.622415f, 0.629206f, 0.636027f, 0.642908f,
0.649821f, 0.656779f, 0.663783f, 0.670832f, 0.677913f, 0.685054f,
0.692226f, 0.699443f, 0.706706f, 0.714015f, 0.721370f, 0.728771f,
0.736202f, 0.743694f, 0.751217f, 0.758785f, 0.766400f, 0.774060f,
0.781765f, 0.789517f, 0.797314f, 0.805158f, 0.813031f, 0.820966f,
0.828946f, 0.836957f, 0.845029f, 0.853132f, 0.861280f, 0.869490f,
0.877729f, 0.886015f, 0.894362f, 0.902739f, 0.911162f, 0.919631f,
0.928161f, 0.936721f, 0.945327f, 0.953994f, 0.962692f, 0.971435f,
0.980240f, 0.989075f, 0.997955f, 1.000000f,
};
uint8_t table_8[ARRAY_COUNT(t)];
for (int i = 0; i < ARRAY_COUNT(t); i++) {
table_8[i] = (uint8_t)(t[i] * 255.0f + 0.5f);
}
skcms_Curve curve;
curve.table_entries = (uint32_t)ARRAY_COUNT(t);
curve.table_8 = table_8;
skcms_TransferFunction tf;
float max_error;
expect(skcms_ApproximateCurve(&curve, &tf, &max_error));
// The approximation isn't very good.
expect(max_error < 1 / 40.0f);
}
static void expect_eq_Matrix3x3(skcms_Matrix3x3 a, skcms_Matrix3x3 b) {
for (int r = 0; r < 3; r++)
for (int c = 0; c < 3; c++) {
expect(a.vals[r][c] == b.vals[r][c]);
}
}
static void test_Matrix3x3_invert(void) {
skcms_Matrix3x3 inv;
skcms_Matrix3x3 I = {{
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
}};
inv = (skcms_Matrix3x3){{ {0,0,0}, {0,0,0}, {0,0,0} }};
expect(skcms_Matrix3x3_invert(&I, &inv));
expect_eq_Matrix3x3(inv, I);
skcms_Matrix3x3 T = {{