-
Notifications
You must be signed in to change notification settings - Fork 16
/
ACES_LIB.h
4101 lines (3829 loc) · 163 KB
/
ACES_LIB.h
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
// ACES 1.3 Function Library
typedef struct {
float x, y, z, w, m;
} float5;
typedef struct {
float2 c0, c1;
} mat2;
typedef struct {
float3 c0, c1, c2;
} mat3;
typedef struct {
float2 red; float2 green; float2 blue; float2 white;
} Chromaticities;
typedef struct {
float x; float y;
} SplineMapPoint;
typedef struct {
float coefsLow[6]; float coefsHigh[6];
SplineMapPoint minPoint; SplineMapPoint midPoint; SplineMapPoint maxPoint;
float slopeLow; float slopeHigh;
} SegmentedSplineParams_c5;
typedef struct {
float coefsLow[10]; float coefsHigh[10];
SplineMapPoint minPoint; SplineMapPoint midPoint; SplineMapPoint maxPoint;
float slopeLow; float slopeHigh;
} SegmentedSplineParams_c9;
typedef struct {
float x; float y; float slope;
} TsPoint;
typedef struct {
TsPoint Min; TsPoint Mid; TsPoint Max;
float coefsLow[6]; float coefsHigh[6];
} TsParams;
#define REF_PT ((7120.0f - 1520.0f) / 8000.0f * (100.0f / 55.0f) - _log10f(0.18f)) * 1.0f
__CONSTANT__ mat3 MM = { {0.5f, -1.0f, 0.5f}, {-1.0f, 1.0f, 0.5f}, {0.5f, 0.0f, 0.0f} };
__CONSTANT__ mat3 M1 = { {0.5f, -1.0f, 0.5f}, {-1.0f, 1.0f, 0.5f}, {0.5f, 0.0f, 0.0f} };
__CONSTANT__ float TINY = 1e-10f;
__CONSTANT__ float DIM_SURROUND_GAMMA = 0.9811f;
__CONSTANT__ float ODT_SAT_FACTOR = 0.93f;
__CONSTANT__ float MIN_STOP_SDR = -6.5f;
__CONSTANT__ float MAX_STOP_SDR = 6.5f;
__CONSTANT__ float MIN_STOP_RRT = -15.0f;
__CONSTANT__ float MAX_STOP_RRT = 18.0f;
__CONSTANT__ float MIN_LUM_SDR = 0.02f;
__CONSTANT__ float MAX_LUM_SDR = 48.0f;
__CONSTANT__ float MIN_LUM_RRT = 0.0001f;
__CONSTANT__ float MAX_LUM_RRT = 10000.0f;
__CONSTANT__ float RRT_GLOW_GAIN = 0.05f;
__CONSTANT__ float RRT_GLOW_MID = 0.08f;
__CONSTANT__ float RRT_RED_SCALE = 0.82f;
__CONSTANT__ float RRT_RED_PIVOT = 0.03f;
__CONSTANT__ float RRT_RED_HUE = 0.0f;
__CONSTANT__ float RRT_RED_WIDTH = 135.0f;
__CONSTANT__ float RRT_SAT_FACTOR = 0.96f;
__CONSTANT__ float X_BRK = 0.0078125f;
__CONSTANT__ float Y_BRK = 0.155251141552511f;
__CONSTANT__ float A = 10.5402377416545f;
__CONSTANT__ float B = 0.0729055341958355f;
__CONSTANT__ float sqrt3over4 = 0.433012701892219f;
__CONSTANT__ float pq_m1 = 0.1593017578125f;
__CONSTANT__ float pq_m2 = 78.84375f;
__CONSTANT__ float pq_c1 = 0.8359375f;
__CONSTANT__ float pq_c2 = 18.8515625f;
__CONSTANT__ float pq_c3 = 18.6875f;
__CONSTANT__ float pq_C = 10000.0f;
__CONSTANT__ mat3 CDD_TO_CID =
{ {0.75573f, 0.05901f, 0.16134f}, {0.22197f, 0.96928f, 0.07406f}, {0.02230f, -0.02829f, 0.76460f} };
__CONSTANT__ mat3 EXP_TO_ACES =
{ {0.72286f, 0.11923f, 0.01427f}, {0.12630f, 0.76418f, 0.08213f}, {0.15084f, 0.11659f, 0.90359f} };
__CONSTANT__ Chromaticities AP0 =
{ {0.7347f, 0.2653f}, {0.0f, 1.0f}, {0.0001f, -0.077f}, {0.32168f, 0.33767f} };
__CONSTANT__ Chromaticities AP1 =
{ {0.713f, 0.293f}, {0.165f, 0.83f}, {0.128f, 0.044f}, {0.32168f, 0.33767f} };
__CONSTANT__ Chromaticities REC709_PRI =
{ {0.64f, 0.33f}, {0.3f, 0.6f}, {0.15f, 0.06f}, {0.3127f, 0.329f} };
__CONSTANT__ Chromaticities P3D60_PRI =
{ {0.68f, 0.32f}, {0.265f, 0.69f}, {0.15f, 0.06f}, {0.32168, 0.33767f} };
__CONSTANT__ Chromaticities P3D65_PRI =
{ {0.68f, 0.32f}, {0.265f, 0.69f}, {0.15f, 0.06f}, {0.3127f, 0.329f} };
__CONSTANT__ Chromaticities P3DCI_PRI =
{ {0.68f, 0.32f}, {0.265f, 0.69f}, {0.15f, 0.06f}, {0.314f, 0.351f} };
__CONSTANT__ Chromaticities ARRI_ALEXA_WG_PRI =
{ {0.684f, 0.313f}, {0.221f, 0.848f}, {0.0861f, -0.102f}, {0.3127f, 0.329f} };
__CONSTANT__ Chromaticities REC2020_PRI =
{ {0.708f, 0.292f}, {0.17f, 0.797f}, {0.131f, 0.046f}, {0.3127f, 0.329f} };
__CONSTANT__ Chromaticities RIMMROMM_PRI =
{ {0.7347f, 0.2653f}, {0.1596f, 0.8404f}, {0.0366f, 0.0001f}, {0.3457f, 0.3585f} };
__CONSTANT__ mat3 CONE_RESP_MATRADFORD =
{ {0.8951f, -0.7502f, 0.0389f}, {0.2664f, 1.7135f, -0.0685f}, {-0.1614f, 0.0367f, 1.0296f} };
__CONSTANT__ mat3 CONE_RESP_MAT_CAT02 =
{ {0.7328f, -0.7036f, 0.003f}, {0.4296f, 1.6975f, 0.0136f}, {-0.1624f, 0.0061f, 0.9834f} };
__CONSTANT__ mat3 AP0_2_XYZ_MAT =
{ {0.9525523959f, 0.3439664498f, 0.0f}, {0.0f, 0.7281660966f, 0.0f}, {0.0000936786f, -0.0721325464f, 1.0088251844f} };
__CONSTANT__ mat3 XYZ_2_AP0_MAT =
{ {1.0498110175f, -0.4959030231f, 0.0f}, {0.0f, 1.3733130458f, 0.0f}, {-0.0000974845f, 0.0982400361f, 0.9912520182f} };
__CONSTANT__ mat3 AP1_2_XYZ_MAT =
{ {0.6624541811f, 0.2722287168f, -0.0055746495f}, {0.1340042065f, 0.6740817658f, 0.0040607335f}, {0.156187687f, 0.0536895174f, 1.0103391003f} };
__CONSTANT__ mat3 XYZ_2_AP1_MAT =
{ {1.6410233797f, -0.6636628587f, 0.0117218943f}, {-0.3248032942f, 1.6153315917f, -0.008284442f}, {-0.2364246952f, 0.0167563477f, 0.9883948585f} };
__CONSTANT__ mat3 AP0_2_AP1_MAT =
{ {1.4514393161f, -0.0765537734f, 0.0083161484f}, {-0.2365107469f, 1.1762296998f, -0.0060324498f}, {-0.2149285693f, -0.0996759264f, 0.9977163014f} };
__CONSTANT__ mat3 AP1_2_AP0_MAT =
{ {0.6954522414f, 0.0447945634f, -0.0055258826f}, {0.1406786965f, 0.8596711185f, 0.0040252103f}, {0.1638690622f, 0.0955343182f, 1.0015006723f} };
__CONSTANT__ mat3 D60_2_D65_CAT =
{ {0.987224f, -0.00759836f, 0.00307257f}, {-0.00611327f, 1.00186f, -0.00509595f}, {0.0159533f, 0.00533002f, 1.08168f} };
__CONSTANT__ mat3 D65_2_D60_CAT =
{ {1.01303f, 0.00769823f, -0.00284131f}, {0.00610531f, 0.998165f, 0.00468516f}, {-0.014971f, -0.00503203f, 0.924507f} };
__CONSTANT__ mat3 LMS_2_AP0_MAT =
{ { 2.2034860017f, -0.5267000086f, -0.0465914122f}, {-1.4028871323f, 1.5838401289f, -0.0457828327f}, { 0.1994183978f, -0.0571107433f, 1.0924829098f} };
__CONSTANT__ mat3 ICtCp_2_LMSp_MAT =
{ { 1.0f, 1.0f, 1.0f}, { 0.0086064753f, -0.0086064753f, 0.5600463058f}, { 0.1110335306f, -0.1110335306f, -0.3206319566f} };
__CONSTANT__ mat3 AP0_2_LMS_MAT =
{ { 0.5729360781f, 0.1916984459f, 0.0324676922f}, { 0.5052187675f, 0.8013733145f, 0.0551294631f}, {-0.0781710859f, 0.0069006377f, 0.9123015294f} };
__CONSTANT__ mat3 LMSp_2_ICtCp_MAT =
{ { 0.5f, 1.6137000085f, 4.378062447f}, { 0.5f, -3.3233961429f, -4.2455397991f}, { 0.0f, 1.7096961344f, -0.1325226479f} };
__CONSTANT__ mat3 SG3_2_AP0_MAT =
{ { 0.7529825954f, 0.0217076974f, -0.0094160528f}, { 0.1433702162f, 1.0153188355f, 0.0033704179f}, { 0.1036471884f, -0.0370265329f, 1.0060456349f} };
__CONSTANT__ mat3 AP0_2_SG3_MAT =
{ { 1.3316572111f, -0.0280131244f, 0.0125574528f}, {-0.1875611006f, 0.9887375645f, -0.0050679052f}, {-0.1440961106f, 0.0392755599f, 0.9925104526f} };
__CONSTANT__ mat3 SG3C_2_AP0_MAT =
{ { 0.6387886672f, -0.0039159061f, -0.0299072021f}, { 0.2723514337f, 1.0880732308f, -0.0264325799f}, { 0.0888598992f, -0.0841573249f, 1.056339782f} };
__CONSTANT__ mat3 AP0_2_SG3C_MAT =
{ { 1.5554591070f, 0.0090216145f, 0.0442640666f}, {-0.3932807985f, 0.9185569566f, 0.0118502607f}, {-0.1621783087f, 0.0724214290f, 0.9438856727f} };
__CONSTANT__ mat3 VSG3_2_AP0_MAT =
{ { 0.7933297411f, 0.0155810585f, -0.0188647478f}, { 0.0890786256f, 1.0327123069f, 0.0127694121f}, { 0.1175916333f, -0.0482933654f, 1.0060953358f} };
__CONSTANT__ mat3 VSG3C_2_AP0_MAT =
{ { 0.6742570921f, -0.0093136061f, -0.0382090673f}, { 0.2205717359f, 1.1059588614f, -0.0179383766f}, { 0.1051711720f, -0.0966452553f, 1.0561474439f} };
__CONSTANT__ mat3 VGAMUT_2_AP0_MAT =
{ { 0.724382758f, 0.166748484f, 0.108497411f}, { 0.021354009f, 0.985138372f, -0.006319092f}, {-0.009234278f, -0.00104295f, 1.010272625f} };
__CONSTANT__ mat3 AWG_2_AP0_MAT =
{ { 0.6802059161f, 0.0854150695f, 0.0020562648f}, { 0.2361367500f, 1.0174707720f, -0.0625622837f}, { 0.0836574074f, -0.1028858550f, 1.0605062481f} };
__CONSTANT__ mat3 AP0_2_AWG_MAT =
{ { 1.5159863829f, -0.1283275799f, -0.0105107561f}, {-0.3613418588f, 1.0193145873f, 0.0608329325f}, {-0.1546444592f, 0.1090123949f, 0.9496764954f} };
__CONSTANT__ mat3 RWG_2_AP0_MAT =
{ { 0.7850585442f, 0.0231738066f, -0.0737605663f}, { 0.0838583156f, 1.0878975877f, -0.3145898729f}, { 0.1310821505f, -0.1110709153f, 1.3883506702f} };
__CONSTANT__ mat3 AP0_2_RWG_MAT =
{ { 1.2655392805f, -0.0205691227f, 0.0625750095f}, {-0.1352322515f, 0.9431709627f, 0.2065308369f}, {-0.1303056816f, 0.0773976700f, 0.7308939479f} };
__CONSTANT__ float3 AP1_RGB2Y = { 0.2722287168f, 0.6740817658f, 0.0536895174f};
__DEVICE__ Chromaticities make_chromaticities( float2 A, float2 B, float2 C, float2 D) {
Chromaticities E;
E.red = A; E.green = B; E.blue = C; E.white = D;
return E;
}
__DEVICE__ mat2 make_mat2( float2 A, float2 B) {
mat2 C;
C.c0 = A; C.c1 = B;
return C;
}
__DEVICE__ mat3 make_mat3( float3 A, float3 B, float3 C) {
mat3 D;
D.c0 = A; D.c1 = B; D.c2 = C;
return D;
}
__DEVICE__ float min_f3( float3 a) {
return _fminf( a.x, _fminf( a.y, a.z));
}
__DEVICE__ float max_f3( float3 a) {
return _fmaxf( a.x, _fmaxf( a.y, a.z));
}
__DEVICE__ float3 max_f3_f( float3 a, float b) {
float3 out;
out.x =_fmaxf(a.x, b); out.y =_fmaxf(a.y, b); out.z =_fmaxf(a.z, b);
return out;
}
__DEVICE__ float clip( float v) {
return _fminf(v, 1.0f);
}
__DEVICE__ float3 clip_f3( float3 in) {
float3 out;
out.x = clip( in.x); out.y = clip( in.y); out.z = clip( in.z);
return out;
}
__DEVICE__ float3 add_f_f3( float a, float3 b) {
float3 out;
out.x = a + b.x; out.y = a + b.y; out.z = a + b.z;
return out;
}
__DEVICE__ float3 pow_f3( float3 a, float b) {
float3 out;
out.x = _powf(a.x, b); out.y = _powf(a.y, b); out.z = _powf(a.z, b);
return out;
}
__DEVICE__ float3 exp10_f3( float3 a) {
float3 out;
out.x = _exp10f(a.x); out.y = _exp10f(a.y); out.z = _exp10f(a.z);
return out;
}
__DEVICE__ float3 log10_f3( float3 a) {
float3 out;
out.x = _log10f(a.x); out.y = _log10f(a.y); out.z = _log10f(a.z);
return out;
}
__DEVICE__ float _sign( float x) {
float y;
if (x < 0.0f) y = -1.0f;
else if (x > 0.0f) y = 1.0f;
else y = 0.0f;
return y;
}
__DEVICE__ float3 mult_f_f3( float f, float3 x) {
float3 r;
r.x = f * x.x; r.y = f * x.y; r.z = f * x.z;
return r;
}
__DEVICE__ float3 add_f3_f3( float3 x, float3 y) {
float3 r;
r.x = x.x + y.x; r.y = x.y + y.y; r.z = x.z + y.z;
return r;
}
__DEVICE__ float3 sub_f3_f3( float3 x, float3 y) {
float3 r;
r.x = x.x - y.x; r.y = x.y - y.y; r.z = x.z - y.z;
return r;
}
__DEVICE__ float3 cross_f3_f3( float3 x, float3 y) {
float3 r;
r.z = x.x * y.y - x.y * y.x; r.x = x.y * y.z - x.z * y.y; r.y = x.z * y.x - x.x * y.z;
return r;
}
__DEVICE__ float3 clamp_f3( float3 A, float mn, float mx) {
float3 out;
out.x = _clampf( A.x, mn, mx); out.y = _clampf( A.y, mn, mx); out.z = _clampf( A.z, mn, mx);
return out;
}
__DEVICE__ float dot_f3_f3( float3 x, float3 y) {
return x.x * y.x + x.y * y.y + x.z * y.z;
}
__DEVICE__ float length_f3( float3 x) {
return _sqrtf( x.x * x.x + x.y * x.y + x.z * x.z );
}
__DEVICE__ mat2 transpose_f22( mat2 A) {
mat2 B;
B.c0 = make_float2(A.c0.x, A.c1.x); B.c1 = make_float2(A.c0.y, A.c1.y);
return B;
}
__DEVICE__ mat3 transpose_f33( mat3 A) {
float r[3][3];
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z}, {A.c1.x, A.c1.y, A.c1.z}, {A.c2.x, A.c2.y, A.c2.z}};
for( int i = 0; i < 3; ++i){
for( int j = 0; j < 3; ++j){
r[i][j] = a[j][i];}}
mat3 R = make_mat3(make_float3(r[0][0], r[0][1], r[0][2]), make_float3(r[1][0], r[1][1], r[1][2]), make_float3(r[2][0], r[2][1], r[2][2]));
return R;
}
__DEVICE__ mat3 mult_f_f33( float f, mat3 A) {
float r[3][3];
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z}, {A.c1.x, A.c1.y, A.c1.z}, {A.c2.x, A.c2.y, A.c2.z}};
for( int i = 0; i < 3; ++i ){
for( int j = 0; j < 3; ++j ){
r[i][j] = f * a[i][j];}}
mat3 R = make_mat3(make_float3(r[0][0], r[0][1], r[0][2]), make_float3(r[1][0], r[1][1], r[1][2]), make_float3(r[2][0], r[2][1], r[2][2]));
return R;
}
__DEVICE__ float3 mult_f3_f33( float3 X, mat3 A) {
float r[3];
float x[3] = {X.x, X.y, X.z};
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z}, {A.c1.x, A.c1.y, A.c1.z}, {A.c2.x, A.c2.y, A.c2.z}};
for( int i = 0; i < 3; ++i){
r[i] = 0.0f;
for( int j = 0; j < 3; ++j){
r[i] = r[i] + x[j] * a[j][i];}}
return make_float3(r[0], r[1], r[2]);
}
__DEVICE__ mat3 mult_f33_f33( mat3 A, mat3 B) {
float r[3][3];
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z},
{A.c1.x, A.c1.y, A.c1.z},
{A.c2.x, A.c2.y, A.c2.z}};
float b[3][3] = {{B.c0.x, B.c0.y, B.c0.z},
{B.c1.x, B.c1.y, B.c1.z},
{B.c2.x, B.c2.y, B.c2.z}};
for( int i = 0; i < 3; ++i){
for( int j = 0; j < 3; ++j){
r[i][j] = 0.0f;
for( int k = 0; k < 3; ++k){
r[i][j] = r[i][j] + a[i][k] * b[k][j];
}}}
mat3 R = make_mat3(make_float3(r[0][0], r[0][1], r[0][2]), make_float3(r[1][0], r[1][1], r[1][2]), make_float3(r[2][0], r[2][1], r[2][2]));
return R;
}
__DEVICE__ mat3 add_f33_f33( mat3 A, mat3 B) {
float r[3][3];
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z}, {A.c1.x, A.c1.y, A.c1.z}, {A.c2.x, A.c2.y, A.c2.z}};
float b[3][3] = {{B.c0.x, B.c0.y, B.c0.z}, {B.c1.x, B.c1.y, B.c1.z}, {B.c2.x, B.c2.y, B.c2.z}};
for( int i = 0; i < 3; ++i ){
for( int j = 0; j < 3; ++j ){
r[i][j] = a[i][j] + b[i][j];}}
mat3 R = make_mat3(make_float3(r[0][0], r[0][1], r[0][2]), make_float3(r[1][0], r[1][1], r[1][2]), make_float3(r[2][0], r[2][1], r[2][2]));
return R;
}
__DEVICE__ mat3 invert_f33( mat3 A) {
mat3 R;
float result[3][3];
float a[3][3] = {{A.c0.x, A.c0.y, A.c0.z}, {A.c1.x, A.c1.y, A.c1.z}, {A.c2.x, A.c2.y, A.c2.z}};
float det = a[0][0] * a[1][1] * a[2][2] + a[0][1] * a[1][2] * a[2][0]
+ a[0][2] * a[1][0] * a[2][1] - a[2][0] * a[1][1] * a[0][2]
- a[2][1] * a[1][2] * a[0][0] - a[2][2] * a[1][0] * a[0][1];
if( det != 0.0f ){
result[0][0] = a[1][1] * a[2][2] - a[1][2] * a[2][1]; result[0][1] = a[2][1] * a[0][2] - a[2][2] * a[0][1];
result[0][2] = a[0][1] * a[1][2] - a[0][2] * a[1][1]; result[1][0] = a[2][0] * a[1][2] - a[1][0] * a[2][2];
result[1][1] = a[0][0] * a[2][2] - a[2][0] * a[0][2]; result[1][2] = a[1][0] * a[0][2] - a[0][0] * a[1][2];
result[2][0] = a[1][0] * a[2][1] - a[2][0] * a[1][1]; result[2][1] = a[2][0] * a[0][1] - a[0][0] * a[2][1];
result[2][2] = a[0][0] * a[1][1] - a[1][0] * a[0][1];
R = make_mat3(make_float3(result[0][0], result[0][1], result[0][2]), make_float3(result[1][0], result[1][1],
result[1][2]), make_float3(result[2][0], result[2][1], result[2][2]));
return mult_f_f33( 1.0f / det, R);
}
R = make_mat3(make_float3(1.0f, 0.0f, 0.0f), make_float3(0.0f, 1.0f, 0.0f), make_float3(0.0f, 0.0f, 1.0f));
return R;
}
__DEVICE__ float interpolate1D( float2 table[], int Size, float p) {
if( p <= table[0].x ) return table[0].y;
if( p >= table[Size - 1].x ) return table[Size - 1].y;
for( int i = 0; i < Size - 1; ++i ){
if( table[i].x <= p && p < table[i + 1].x ){
float s = (p - table[i].x) / (table[i + 1].x - table[i].x);
return table[i].y * ( 1.0f - s ) + table[i+1].y * s;}}
return 0.0f;
}
__DEVICE__ mat3 RGBtoXYZ( Chromaticities N) {
mat3 M = make_mat3(make_float3(N.red.x, N.red.y, 1.0f - (N.red.x + N.red.y)),
make_float3(N.green.x, N.green.y, 1.0f - (N.green.x + N.green.y)), make_float3(N.blue.x, N.blue.y, 1.0f - (N.blue.x + N.blue.y)));
float3 wh = make_float3(N.white.x / N.white.y, 1.0f, (1.0f - (N.white.x + N.white.y)) / N.white.y);
wh = mult_f3_f33(wh, invert_f33(M));
mat3 WH = make_mat3(make_float3(wh.x, 0.0f, 0.0f), make_float3(0.0f, wh.y, 0.0f), make_float3(0.0f, 0.0f, wh.z));
M = mult_f33_f33(WH, M);
return M;
}
__DEVICE__ mat3 XYZtoRGB( Chromaticities N) {
mat3 M = invert_f33(RGBtoXYZ(N));
return M;
}
__DEVICE__ float SLog3_to_lin( float SLog ) {
float out = 0.0f;
if (SLog >= 171.2102946929f / 1023.0f){
out = _exp10f((SLog * 1023.0f - 420.0f) / 261.5f) * (0.18f + 0.01f) - 0.01f;
} else {
out = (SLog * 1023.0f - 95.0f) * 0.01125000f / (171.2102946929f - 95.0f);}
return out;
}
__DEVICE__ float lin_to_SLog3( float in) {
float out;
if (in >= 0.01125f) {
out = (420.0f + _log10f((in + 0.01f) / (0.18f + 0.01f)) * 261.5f) / 1023.0f;
} else {
out = (in * (171.2102946929f - 95.0f) / 0.01125f + 95.0f) / 1023.0f;
}
return out;
}
__DEVICE__ float VLog_to_lin( float x) {
float cutInv = 0.181f;
float b = 0.00873f;
float c = 0.241514f;
float d = 0.598206f;
if (x <= cutInv)
return (x - 0.125f) / 5.6f;
else
return _exp10f((x - d) / c) - b;
}
__DEVICE__ float lin_to_VLog( float x) {
float cut1 = 0.01f;
float b = 0.00873f;
float c = 0.241514f;
float d = 0.598206f;
if (x < cut1 )
return 5.6f * x + 0.125f;
else
return c * _log10f(x + b) + d;
}
__DEVICE__ float SLog1_to_lin( float SLog, float b, float ab, float w) {
float lin = 0.0f;
if (SLog >= ab)
lin = ( _exp10f(( ( ( SLog - b) / ( w - b) - 0.616596f - 0.03f) / 0.432699f)) - 0.037584f) * 0.9f;
else if (SLog < ab)
lin = ( ( ( SLog - b) / ( w - b) - 0.030001222851889303f) / 5.0f) * 0.9f;
return lin;
}
__DEVICE__ float SLog2_to_lin( float SLog, float b, float ab, float w) {
float lin = 0.0f;
if (SLog >= ab)
lin = ( 219.0f * ( _exp10f(( ( ( SLog - b) / ( w - b) - 0.616596f - 0.03f) / 0.432699f)) - 0.037584f) / 155.0f) * 0.9f;
else if (SLog < ab)
lin = ( ( ( SLog - b) / ( w - b) - 0.030001222851889303f) / 3.53881278538813f) * 0.9f;
return lin;
}
__DEVICE__ float CanonLog_to_lin( float clog) {
float out = 0.0f;
if(clog < 0.12512248f)
out = -( _powf( 10.0f, ( 0.12512248f - clog ) / 0.45310179f ) - 1.0f ) / 10.1596f;
else
out = ( _powf( 10.0f, ( clog - 0.12512248f ) / 0.45310179f ) - 1.0f ) / 10.1596f;
return out;
}
__DEVICE__ float CanonLog2_to_lin( float clog2) {
float out = 0.0f;
if(clog2 < 0.092864125f)
out = -( _powf( 10.0f, ( 0.092864125f - clog2 ) / 0.24136077f ) - 1.0f ) / 87.099375f;
else
out = ( _powf( 10.0f, ( clog2 - 0.092864125f ) / 0.24136077f ) - 1.0f ) / 87.099375f;
return out;
}
__DEVICE__ float CanonLog3_to_lin( float clog3) {
float out = 0.0f;
if(clog3 < 0.097465473f)
out = -( _powf( 10.0f, ( 0.12783901f - clog3 ) / 0.36726845f ) - 1.0f ) / 14.98325f;
else if(clog3 <= 0.15277891f)
out = ( clog3 - 0.12512219f ) / 1.9754798f;
else
out = ( _powf( 10.0f, ( clog3 - 0.12240537f ) / 0.36726845f ) - 1.0f ) / 14.98325f;
return out;
}
__DEVICE__ float LogC_to_lin( float in) {
const float midGraySignal = 0.01f;
const float cut = 1.0f / 9.0f;
const float slope = 3.9086503371f;
const float offset = -1.3885369913f;
const float encOffset = 0.3855369987f;
const float gain = 800.0f / 400.0f;
const float encGain = 0.2471896383f;
const float gray = 0.005f;
const float nz = 0.052272275f;
float out = (in - encOffset) / encGain;
float ns = (out - offset) / slope;
if (ns > cut)
ns = _exp10f(out);
ns = (ns - nz) * gray;
return ns * (0.18f * gain / midGraySignal);
}
__DEVICE__ float lin_to_LogC( float in) {
const float midGraySignal = 0.01f;
const float cut = 1.0f / 9.0f;
const float slope = 3.9086503371f;
const float offset = -1.3885369913f;
const float encOffset = 0.3855369987f;
const float gain = 800.0f / 400.0f;
const float encGain = 0.2471896383f;
const float gray = 0.005f;
const float nz = 0.052272275f;
float out;
float ns = in / (0.18f * gain / midGraySignal);
ns = nz + (ns / gray);
if (ns > cut) {
out = _log10f(ns);
} else {
out = offset + (ns * slope);
}
return encOffset + (out * encGain);
}
__DEVICE__ float Log3G10_to_lin( float log3g10) {
const float a = 0.224282f;
const float b = 155.975327f;
const float c = 0.01f;
const float g = 15.1927f;
float linear = log3g10 < 0.0f ? (log3g10 / g) : (_exp10f(log3g10 / a) - 1.0f) / b;
linear = linear - c;
return linear;
}
__DEVICE__ float lin_to_Log3G10( float in) {
const float a = 0.224282f;
const float b = 155.975327f;
const float c = 0.01f;
const float g = 15.1927f;
float out = in + c;
if (out < 0.0f) {
out = out * g;
} else {
out = a * _log10f(out * b + 1.0f);
}
return out;
}
__DEVICE__ float3 XYZ_2_xyY( float3 XYZ) {
float3 xyY;
float divisor = (XYZ.x + XYZ.y + XYZ.z);
if (divisor == 0.0f) divisor = 1e-10f;
xyY.x = XYZ.x / divisor;
xyY.y = XYZ.y / divisor;
xyY.z = XYZ.y;
return xyY;
}
__DEVICE__ float3 xyY_2_XYZ( float3 xyY) {
float3 XYZ;
XYZ.x = xyY.x * xyY.z / _fmaxf( xyY.y, 1e-10f);
XYZ.y = xyY.z;
XYZ.z = (1.0f - xyY.x - xyY.y) * xyY.z / _fmaxf( xyY.y, 1e-10f);
return XYZ;
}
__DEVICE__ float rgb_2_hue( float3 rgb) {
float hue = 0.0f;
if (rgb.x == rgb.y && rgb.y == rgb.z) {
hue = 0.0f;
} else {
hue = (180.0f/3.1415926535897932f) * _atan2f( _sqrtf(3.0f) * (rgb.y - rgb.z), 2.0f * rgb.x - rgb.y - rgb.z);
}
if (hue < 0.0f) hue = hue + 360.0f;
return hue;
}
__DEVICE__ float rgb_2_yc( float3 rgb, float ycRadiusWeight) {
float r = rgb.x;
float g = rgb.y;
float b = rgb.z;
float chroma = _sqrtf(b * (b - g) + g * (g - r) + r * (r - b));
return ( b + g + r + ycRadiusWeight * chroma) / 3.0f;
}
__DEVICE__ mat3 calculate_cat_matrix( float2 src_xy, float2 des_xy) {
mat3 coneRespMat = CONE_RESP_MATRADFORD;
const float3 src_xyY = { src_xy.x, src_xy.y, 1.0f };
const float3 des_xyY = { des_xy.x, des_xy.y, 1.0f };
float3 src_XYZ = xyY_2_XYZ( src_xyY );
float3 des_XYZ = xyY_2_XYZ( des_xyY );
float3 src_coneResp = mult_f3_f33( src_XYZ, coneRespMat);
float3 des_coneResp = mult_f3_f33( des_XYZ, coneRespMat);
mat3 vkMat = {
{ des_coneResp.x / src_coneResp.x, 0.0f, 0.0f },
{ 0.0f, des_coneResp.y / src_coneResp.y, 0.0f },
{ 0.0f, 0.0f, des_coneResp.z / src_coneResp.z }
};
mat3 cat_matrix = mult_f33_f33( coneRespMat, mult_f33_f33( vkMat, invert_f33( coneRespMat ) ) );
return cat_matrix;
}
__DEVICE__ mat3 calc_sat_adjust_matrix( float sat, float3 rgb2Y) {
float M[3][3];
M[0][0] = (1.0f - sat) * rgb2Y.x + sat; M[1][0] = (1.0f - sat) * rgb2Y.x; M[2][0] = (1.0f - sat) * rgb2Y.x;
M[0][1] = (1.0f - sat) * rgb2Y.y; M[1][1] = (1.0f - sat) * rgb2Y.y + sat; M[2][1] = (1.0f - sat) * rgb2Y.y;
M[0][2] = (1.0f - sat) * rgb2Y.z; M[1][2] = (1.0f - sat) * rgb2Y.z; M[2][2] = (1.0f - sat) * rgb2Y.z + sat;
mat3 R = make_mat3(make_float3(M[0][0], M[0][1], M[0][2]),
make_float3(M[1][0], M[1][1], M[1][2]), make_float3(M[2][0], M[2][1], M[2][2]));
R = transpose_f33(R);
return R;
}
__DEVICE__ float moncurve_f( float x, float gamma, float offs ) {
float y;
const float fs = (( gamma - 1.0f) / offs) * _powf( offs * gamma / ( ( gamma - 1.0f) * ( 1.0f + offs)), gamma);
const float xb = offs / ( gamma - 1.0f);
if ( x >= xb)
y = _powf( ( x + offs) / ( 1.0f + offs), gamma);
else
y = x * fs;
return y;
}
__DEVICE__ float moncurve_r( float y, float gamma, float offs ) {
float x;
const float yb = _powf( offs * gamma / ( ( gamma - 1.0f) * ( 1.0f + offs)), gamma);
const float rs = _powf( ( gamma - 1.0f) / offs, gamma - 1.0f) * _powf( ( 1.0f + offs) / gamma, gamma);
if ( y >= yb)
x = ( 1.0f + offs) * _powf( y, 1.0f / gamma) - offs;
else
x = y * rs;
return x;
}
__DEVICE__ float3 moncurve_f_f3( float3 x, float gamma, float offs) {
float3 y;
y.x = moncurve_f( x.x, gamma, offs);
y.y = moncurve_f( x.y, gamma, offs);
y.z = moncurve_f( x.z, gamma, offs);
return y;
}
__DEVICE__ float3 moncurve_r_f3( float3 y, float gamma, float offs) {
float3 x;
x.x = moncurve_r( y.x, gamma, offs);
x.y = moncurve_r( y.y, gamma, offs);
x.z = moncurve_r( y.z, gamma, offs);
return x;
}
__DEVICE__ float bt1886_f( float V, float gamma, float Lw, float Lb) {
float a = _powf( _powf( Lw, 1.0f/gamma) - _powf( Lb, 1.0f/gamma), gamma);
float b = _powf( Lb, 1.0f/gamma) / ( _powf( Lw, 1.0f/gamma) - _powf( Lb, 1.0f/gamma));
float L = a * _powf( _fmaxf( V + b, 0.0f), gamma);
return L;
}
__DEVICE__ float bt1886_r( float L, float gamma, float Lw, float Lb) {
float a = _powf( _powf( Lw, 1.0f/gamma) - _powf( Lb, 1.0f/gamma), gamma);
float b = _powf( Lb, 1.0f/gamma) / ( _powf( Lw, 1.0f/gamma) - _powf( Lb, 1.0f/gamma));
float V = _powf( _fmaxf( L / a, 0.0f), 1.0f/gamma) - b;
return V;
}
__DEVICE__ float3 bt1886_f_f3( float3 V, float gamma, float Lw, float Lb) {
float3 L;
L.x = bt1886_f( V.x, gamma, Lw, Lb); L.y = bt1886_f( V.y, gamma, Lw, Lb); L.z = bt1886_f( V.z, gamma, Lw, Lb);
return L;
}
__DEVICE__ float3 bt1886_r_f3( float3 L, float gamma, float Lw, float Lb) {
float3 V;
V.x = bt1886_r( L.x, gamma, Lw, Lb); V.y = bt1886_r( L.y, gamma, Lw, Lb); V.z = bt1886_r( L.z, gamma, Lw, Lb);
return V;
}
__DEVICE__ float smpteRange_to_fullRange( float in) {
const float REFBLACK = ( 64.0f / 1023.0f);
const float REFWHITE = ( 940.0f / 1023.0f);
return (( in - REFBLACK) / ( REFWHITE - REFBLACK));
}
__DEVICE__ float fullRange_to_smpteRange( float in) {
const float REFBLACK = ( 64.0f / 1023.0f);
const float REFWHITE = ( 940.0f / 1023.0f);
return ( in * ( REFWHITE - REFBLACK) + REFBLACK );
}
__DEVICE__ float3 smpteRange_to_fullRange_f3( float3 rgbIn) {
float3 rgbOut;
rgbOut.x = smpteRange_to_fullRange( rgbIn.x);
rgbOut.y = smpteRange_to_fullRange( rgbIn.y);
rgbOut.z = smpteRange_to_fullRange( rgbIn.z);
return rgbOut;
}
__DEVICE__ float3 fullRange_to_smpteRange_f3( float3 rgbIn) {
float3 rgbOut;
rgbOut.x = fullRange_to_smpteRange( rgbIn.x);
rgbOut.y = fullRange_to_smpteRange( rgbIn.y);
rgbOut.z = fullRange_to_smpteRange( rgbIn.z);
return rgbOut;
}
__DEVICE__ float3 dcdm_decode( float3 XYZp) {
float3 XYZ;
XYZ.x = (52.37f/48.0f) * _powf( XYZp.x, 2.6f);
XYZ.y = (52.37f/48.0f) * _powf( XYZp.y, 2.6f);
XYZ.z = (52.37f/48.0f) * _powf( XYZp.z, 2.6f);
return XYZ;
}
__DEVICE__ float3 dcdm_encode( float3 XYZ) {
float3 XYZp;
XYZp.x = _powf( (48.0f/52.37f) * XYZ.x, 1.0f/2.6f);
XYZp.y = _powf( (48.0f/52.37f) * XYZ.y, 1.0f/2.6f);
XYZp.z = _powf( (48.0f/52.37f) * XYZ.z, 1.0f/2.6f);
return XYZp;
}
__DEVICE__ float ST2084_2_Y( float N ) {
float Np = _powf( N, 1.0f / pq_m2 );
float L = Np - pq_c1;
if ( L < 0.0f )
L = 0.0f;
L = L / ( pq_c2 - pq_c3 * Np );
L = _powf( L, 1.0f / pq_m1 );
return L * pq_C;
}
__DEVICE__ float Y_2_ST2084( float C ) {
float L = C / pq_C;
float Lm = _powf( L, pq_m1 );
float N = ( pq_c1 + pq_c2 * Lm ) / ( 1.0f + pq_c3 * Lm );
N = _powf( N, pq_m2 );
return N;
}
__DEVICE__ float3 Y_2_ST2084_f3( float3 in) {
float3 out;
out.x = Y_2_ST2084( in.x);
out.y = Y_2_ST2084( in.y);
out.z = Y_2_ST2084( in.z);
return out;
}
__DEVICE__ float3 ST2084_2_Y_f3( float3 in) {
float3 out;
out.x = ST2084_2_Y( in.x);
out.y = ST2084_2_Y( in.y);
out.z = ST2084_2_Y( in.z);
return out;
}
__DEVICE__ float3 ST2084_2_HLG_1000nits_f3( float3 PQ) {
float3 displayLinear = ST2084_2_Y_f3( PQ);
float Y_d = 0.2627f * displayLinear.x + 0.6780f * displayLinear.y + 0.0593f * displayLinear.z;
const float L_w = 1000.0f;
const float L_b = 0.0f;
const float alpha = (L_w - L_b);
const float beta = L_b;
const float gamma = 1.2f;
float3 sceneLinear;
if (Y_d == 0.0f) {
sceneLinear.x = 0.0f; sceneLinear.y = 0.0f; sceneLinear.z = 0.0f;
} else {
sceneLinear.x = _powf( (Y_d - beta) / alpha, (1.0f - gamma) / gamma) * ((displayLinear.x - beta) / alpha);
sceneLinear.y = _powf( (Y_d - beta) / alpha, (1.0f - gamma) / gamma) * ((displayLinear.y - beta) / alpha);
sceneLinear.z = _powf( (Y_d - beta) / alpha, (1.0f - gamma) / gamma) * ((displayLinear.z - beta) / alpha);
}
const float a = 0.17883277f;
const float b = 0.28466892f;
const float c = 0.55991073f;
float3 HLG;
if (sceneLinear.x <= 1.0f / 12.0f) {
HLG.x = _sqrtf(3.0f * sceneLinear.x);
} else {
HLG.x = a * _logf(12.0f * sceneLinear.x-b)+c;
}
if (sceneLinear.y <= 1.0f / 12.0f) {
HLG.y = _sqrtf(3.0f * sceneLinear.y);
} else {
HLG.y = a * _logf(12.0f * sceneLinear.y-b)+c;
}
if (sceneLinear.z <= 1.0f / 12.0f) {
HLG.z = _sqrtf(3.0f * sceneLinear.z);
} else {
HLG.z = a * _logf(12.0f * sceneLinear.z - b) + c;
}
return HLG;
}
__DEVICE__ float3 HLG_2_ST2084_1000nits_f3( float3 HLG) {
const float a = 0.17883277f;
const float b = 0.28466892f;
const float c = 0.55991073f;
const float L_w = 1000.0f;
const float L_b = 0.0f;
const float alpha = (L_w - L_b);
const float beta = L_b;
const float gamma = 1.2f;
float3 sceneLinear;
if ( HLG.x >= 0.0f && HLG.x <= 0.5f) {
sceneLinear.x = _powf(HLG.x, 2.0f) / 3.0f;
} else {
sceneLinear.x = (_expf((HLG.x - c) / a) + b) / 12.0f;
}
if ( HLG.y >= 0.0f && HLG.y <= 0.5f) {
sceneLinear.y = _powf(HLG.y, 2.0f) / 3.0f;
} else {
sceneLinear.y = (_expf((HLG.y - c) / a) + b) / 12.0f;
}
if ( HLG.z >= 0.0f && HLG.z <= 0.5f) {
sceneLinear.z = _powf(HLG.z, 2.0f) / 3.0f;
} else {
sceneLinear.z = (_expf((HLG.z - c) / a) + b) / 12.0f;
}
float Y_s = 0.2627f * sceneLinear.x + 0.6780f * sceneLinear.y + 0.0593f * sceneLinear.z;
float3 displayLinear;
displayLinear.x = alpha * _powf( Y_s, gamma - 1.0f) * sceneLinear.x + beta;
displayLinear.y = alpha * _powf( Y_s, gamma - 1.0f) * sceneLinear.y + beta;
displayLinear.z = alpha * _powf( Y_s, gamma - 1.0f) * sceneLinear.z + beta;
float3 PQ = Y_2_ST2084_f3( displayLinear);
return PQ;
}
__DEVICE__ float rgb_2_saturation( float3 rgb) {
return ( _fmaxf( max_f3(rgb), TINY) - _fmaxf( min_f3(rgb), TINY)) / _fmaxf( max_f3(rgb), 1e-2f);
}
__DEVICE__ SegmentedSplineParams_c5 RRT_PARAMS() {
SegmentedSplineParams_c5 A = {{ -4.0f, -4.0f, -3.1573765773f, -0.4852499958f, 1.8477324706f, 1.8477324706f},
{ -0.7185482425f, 2.0810307172f, 3.6681241237f, 4.0f, 4.0f, 4.0f}, {0.18f * _exp2f(-15.0f), 0.0001f},
{0.18f, 4.8f}, {0.18f * _exp2f(18.0f), 10000.0f}, 0.0f, 0.0f};
return A;
};
__DEVICE__ float segmented_spline_c5_fwd( float x) {
SegmentedSplineParams_c5 C = RRT_PARAMS();
const int N_KNOTS_LOW = 4;
const int N_KNOTS_HIGH = 4;
float logx = _log10f( _fmaxf(x, 0.0f));
float logy = 0.0f;
if ( logx <= _log10f(C.minPoint.x) ) {
logy = logx * C.slopeLow + ( _log10f(C.minPoint.y) - C.slopeLow * _log10f(C.minPoint.x) );
} else if (( logx > _log10f(C.minPoint.x) ) && ( logx < _log10f(C.midPoint.x) )) {
float knot_coord = (N_KNOTS_LOW - 1) * (logx - _log10f(C.minPoint.x)) / (_log10f(C.midPoint.x) - _log10f(C.minPoint.x));
int j = knot_coord;
float t = knot_coord - j;
float3 cf = make_float3( C.coefsLow[ j], C.coefsLow[ j + 1], C.coefsLow[ j + 2]);
float3 monomials = make_float3( t * t, t, 1.0f );
logy = dot_f3_f3( monomials, mult_f3_f33( cf, MM));
} else if (( logx >= _log10f(C.midPoint.x) ) && ( logx < _log10f(C.maxPoint.x) )) {
float knot_coord = (N_KNOTS_HIGH-1) * (logx-log10(C.midPoint.x)) / (_log10f(C.maxPoint.x) - log10(C.midPoint.x));
int j = knot_coord;
float t = knot_coord - j;
float3 cf = { C.coefsHigh[ j], C.coefsHigh[ j + 1], C.coefsHigh[ j + 2]};
float3 monomials = make_float3( t * t, t, 1.0f );
logy = dot_f3_f3( monomials, mult_f3_f33( cf, MM));
} else {
logy = logx * C.slopeHigh + ( _log10f(C.maxPoint.y) - C.slopeHigh * _log10f(C.maxPoint.x) );
}
return _exp10f(logy);
}
__DEVICE__ SegmentedSplineParams_c9 ODT_48nits() {
SegmentedSplineParams_c9 A =
{{ -1.6989700043f, -1.6989700043f, -1.4779f, -1.2291f, -0.8648f, -0.448f, 0.00518f, 0.4511080334f, 0.9113744414f, 0.9113744414f},
{ 0.5154386965f, 0.8470437783f, 1.1358f, 1.3802f, 1.5197f, 1.5985f, 1.6467f, 1.6746091357f, 1.6878733390f, 1.6878733390f },
{segmented_spline_c5_fwd( 0.18f * _exp2f(-6.5f) ), 0.02f}, {segmented_spline_c5_fwd( 0.18f ), 4.8f},
{segmented_spline_c5_fwd( 0.18f * _exp2f(6.5f) ), 48.0f}, 0.0f, 0.04f};
return A;
};
__DEVICE__ SegmentedSplineParams_c9 ODT_1000nits() {
SegmentedSplineParams_c9 A =
{{ -4.9706219331f, -3.0293780669f, -2.1262f, -1.5105f, -1.0578f, -0.4668f, 0.11938f, 0.7088134201f, 1.2911865799f, 1.2911865799f },
{ 0.8089132070f, 1.1910867930f, 1.5683f, 1.9483f, 2.3083f, 2.6384f, 2.8595f, 2.9872608805f, 3.0127391195f, 3.0127391195f },
{segmented_spline_c5_fwd( 0.18f * _exp2f(-12.0f) ), 0.0001f}, {segmented_spline_c5_fwd( 0.18f ), 10.0f},
{segmented_spline_c5_fwd( 0.18 * _exp2f(10.0f) ), 1000.0f}, 3.0f, 0.06f};
return A;
};
__DEVICE__ SegmentedSplineParams_c9 ODT_2000nits() {
SegmentedSplineParams_c9 A =
{{ -4.9706219331f, -3.0293780669f, -2.1262f, -1.5105f, -1.0578f, -0.4668f, 0.11938f, 0.7088134201f, 1.2911865799f, 1.2911865799f },
{ 0.8019952042f, 1.1980047958f, 1.5943f, 1.9973f, 2.3783f, 2.7684f, 3.0515f, 3.2746293562f, 3.3274306351f, 3.3274306351f },
{segmented_spline_c5_fwd( 0.18f * _exp2f(-12.0f) ), 0.0001f}, {segmented_spline_c5_fwd( 0.18f ), 10.0f},
{segmented_spline_c5_fwd( 0.18f * _exp2f(11.0f) ), 2000.0f}, 3.0f, 0.12f};
return A;
};
__DEVICE__ SegmentedSplineParams_c9 ODT_4000nits() {
SegmentedSplineParams_c9 A =
{{ -4.9706219331f, -3.0293780669f, -2.1262f, -1.5105f, -1.0578f, -0.4668f, 0.11938f, 0.7088134201f, 1.2911865799f, 1.2911865799f },
{ 0.7973186613f, 1.2026813387f, 1.6093f, 2.0108f, 2.4148f, 2.8179f, 3.1725f, 3.5344995451f, 3.6696204376f, 3.6696204376f },
{segmented_spline_c5_fwd( 0.18f * _exp2f(-12.0f) ), 0.0001f}, {segmented_spline_c5_fwd( 0.18f ), 10.0f},
{segmented_spline_c5_fwd( 0.18f * _exp2f(12.0f) ), 4000.0f}, 3.0f, 0.3f};
return A;
};
__DEVICE__ float segmented_spline_c5_rev( float y) {
SegmentedSplineParams_c5 C = RRT_PARAMS();
const int N_KNOTS_LOW = 4;
const int N_KNOTS_HIGH = 4;
const float KNOT_INC_LOW = (_log10f(C.midPoint.x) - _log10f(C.minPoint.x)) / (N_KNOTS_LOW - 1.0f);
const float KNOT_INC_HIGH = (_log10f(C.maxPoint.x) - _log10f(C.midPoint.x)) / (N_KNOTS_HIGH - 1.0f);
float KNOT_Y_LOW[ N_KNOTS_LOW];
for (int i = 0; i < N_KNOTS_LOW; i = i + 1) {
KNOT_Y_LOW[i] = ( C.coefsLow[i] + C.coefsLow[i + 1]) / 2.0f;
};
float KNOT_Y_HIGH[ N_KNOTS_HIGH];
for (int i = 0; i < N_KNOTS_HIGH; i = i+1) {
KNOT_Y_HIGH[ i] = ( C.coefsHigh[i] + C.coefsHigh[i + 1]) / 2.0f;
};
float logy = _log10f( _fmaxf(y, 1e-10f));
float logx;
if (logy <= _log10f(C.minPoint.y)) {
logx = _log10f(C.minPoint.x);
} else if ( (logy > _log10f(C.minPoint.y)) && (logy <= _log10f(C.midPoint.y)) ) {
unsigned int j = 0;
float3 cf = make_float3(0.0f, 0.0f, 0.0f);
if ( logy > KNOT_Y_LOW[0] && logy <= KNOT_Y_LOW[1]) {
cf.x = C.coefsLow[0]; cf.y = C.coefsLow[1]; cf.z = C.coefsLow[2]; j = 0;
} else if ( logy > KNOT_Y_LOW[ 1] && logy <= KNOT_Y_LOW[ 2]) {
cf.x = C.coefsLow[1]; cf.y = C.coefsLow[2]; cf.z = C.coefsLow[3]; j = 1;
} else if ( logy > KNOT_Y_LOW[ 2] && logy <= KNOT_Y_LOW[ 3]) {
cf.x = C.coefsLow[2]; cf.y = C.coefsLow[3]; cf.z = C.coefsLow[4]; j = 2;
}
const float3 tmp = mult_f3_f33( cf, MM);
float a = tmp.x; float b = tmp.y; float c = tmp.z;
c = c - logy;
const float d = _sqrtf( b * b - 4.0f * a * c);
const float t = ( 2.0f * c) / ( -d - b);
logx = _log10f(C.minPoint.x) + ( t + j) * KNOT_INC_LOW;
} else if ( (logy > _log10f(C.midPoint.y)) && (logy < _log10f(C.maxPoint.y)) ) {
unsigned int j = 0;
float3 cf = make_float3(0.0f, 0.0f, 0.0f);
if ( logy > KNOT_Y_HIGH[ 0] && logy <= KNOT_Y_HIGH[ 1]) {
cf.x = C.coefsHigh[0]; cf.y = C.coefsHigh[1]; cf.z = C.coefsHigh[2]; j = 0;
} else if ( logy > KNOT_Y_HIGH[ 1] && logy <= KNOT_Y_HIGH[ 2]) {
cf.x = C.coefsHigh[1]; cf.y = C.coefsHigh[2]; cf.z = C.coefsHigh[3]; j = 1;
} else if ( logy > KNOT_Y_HIGH[ 2] && logy <= KNOT_Y_HIGH[ 3]) {
cf.x = C.coefsHigh[2]; cf.y = C.coefsHigh[3]; cf.z = C.coefsHigh[4]; j = 2;
}
const float3 tmp = mult_f3_f33( cf, MM);
float a = tmp.x; float b = tmp.y; float c = tmp.z;
c = c - logy;
const float d = _sqrtf( b * b - 4.0f * a * c);
const float t = ( 2.0f * c) / ( -d - b);
logx = _log10f(C.midPoint.x) + ( t + j) * KNOT_INC_HIGH;
} else {
logx = _log10f(C.maxPoint.x);
}
return _exp10f( logx);
}
__DEVICE__ float segmented_spline_c9_fwd( float x, SegmentedSplineParams_c9 C) {
const int N_KNOTS_LOW = 8;
const int N_KNOTS_HIGH = 8;
float logx = _log10f( _fmaxf(x, 0.0f));
float logy = 0.0f;
if ( logx <= _log10f(C.minPoint.x) ) {
logy = logx * C.slopeLow + ( _log10f(C.minPoint.y) - C.slopeLow * _log10f(C.minPoint.x) );
} else if (( logx > _log10f(C.minPoint.x) ) && ( logx < _log10f(C.midPoint.x) )) {
float knot_coord = (N_KNOTS_LOW - 1) * (logx - _log10f(C.minPoint.x)) / (_log10f(C.midPoint.x) - _log10f(C.minPoint.x));
int j = knot_coord;
float t = knot_coord - j;
float3 cf = { C.coefsLow[ j], C.coefsLow[ j + 1], C.coefsLow[ j + 2]};
float3 monomials = make_float3( t * t, t, 1.0f );
logy = dot_f3_f3( monomials, mult_f3_f33( cf, MM));
} else if (( logx >= _log10f(C.midPoint.x) ) && ( logx < _log10f(C.maxPoint.x) )) {
float knot_coord = (N_KNOTS_HIGH - 1) * (logx - _log10f(C.midPoint.x)) / (_log10f(C.maxPoint.x) - _log10f(C.midPoint.x));
int j = knot_coord;
float t = knot_coord - j;
float3 cf = { C.coefsHigh[ j], C.coefsHigh[ j + 1], C.coefsHigh[ j + 2]};
float3 monomials = make_float3( t * t, t, 1.0f );
logy = dot_f3_f3( monomials, mult_f3_f33( cf, MM));
} else {
logy = logx * C.slopeHigh + ( _log10f(C.maxPoint.y) - C.slopeHigh * _log10f(C.maxPoint.x) );
}
return _exp10f(logy);
}
__DEVICE__ float segmented_spline_c9_rev( float y, SegmentedSplineParams_c9 C) {
const int N_KNOTS_LOW = 8;
const int N_KNOTS_HIGH = 8;
const float KNOT_INC_LOW = (_log10f(C.midPoint.x) - _log10f(C.minPoint.x)) / (N_KNOTS_LOW - 1.0f);
const float KNOT_INC_HIGH = (_log10f(C.maxPoint.x) - _log10f(C.midPoint.x)) / (N_KNOTS_HIGH - 1.0f);
float KNOT_Y_LOW[ N_KNOTS_LOW];
for (int i = 0; i < N_KNOTS_LOW; i = i + 1) {
KNOT_Y_LOW[ i] = ( C.coefsLow[i] + C.coefsLow[i + 1]) / 2.0f;
};
float KNOT_Y_HIGH[ N_KNOTS_HIGH];
for (int i = 0; i < N_KNOTS_HIGH; i = i + 1) {
KNOT_Y_HIGH[ i] = ( C.coefsHigh[i] + C.coefsHigh[i + 1]) / 2.0f;
};
float logy = _log10f( _fmaxf( y, 1e-10f));
float logx;
if (logy <= _log10f(C.minPoint.y)) {
logx = _log10f(C.minPoint.x);
} else if ( (logy > _log10f(C.minPoint.y)) && (logy <= _log10f(C.midPoint.y)) ) {
unsigned int j = 0;
float3 cf = make_float3(0.0f, 0.0f, 0.0f);
if ( logy > KNOT_Y_LOW[ 0] && logy <= KNOT_Y_LOW[ 1]) {
cf.x = C.coefsLow[0]; cf.y = C.coefsLow[1]; cf.z = C.coefsLow[2]; j = 0;
} else if ( logy > KNOT_Y_LOW[ 1] && logy <= KNOT_Y_LOW[ 2]) {
cf.x = C.coefsLow[1]; cf.y = C.coefsLow[2]; cf.z = C.coefsLow[3]; j = 1;
} else if ( logy > KNOT_Y_LOW[ 2] && logy <= KNOT_Y_LOW[ 3]) {
cf.x = C.coefsLow[2]; cf.y = C.coefsLow[3]; cf.z = C.coefsLow[4]; j = 2;
} else if ( logy > KNOT_Y_LOW[ 3] && logy <= KNOT_Y_LOW[ 4]) {
cf.x = C.coefsLow[3]; cf.y = C.coefsLow[4]; cf.z = C.coefsLow[5]; j = 3;
} else if ( logy > KNOT_Y_LOW[ 4] && logy <= KNOT_Y_LOW[ 5]) {
cf.x = C.coefsLow[4]; cf.y = C.coefsLow[5]; cf.z = C.coefsLow[6]; j = 4;
} else if ( logy > KNOT_Y_LOW[ 5] && logy <= KNOT_Y_LOW[ 6]) {
cf.x = C.coefsLow[5]; cf.y = C.coefsLow[6]; cf.z = C.coefsLow[7]; j = 5;
} else if ( logy > KNOT_Y_LOW[ 6] && logy <= KNOT_Y_LOW[ 7]) {
cf.x = C.coefsLow[6]; cf.y = C.coefsLow[7]; cf.z = C.coefsLow[8]; j = 6;
}
const float3 tmp = mult_f3_f33( cf, MM);
float a = tmp.x; float b = tmp.y; float c = tmp.z;
c = c - logy;
const float d = _sqrtf( b * b - 4.0f * a * c);