20 {
21
25
26
30
31 u16 h = 0;
32 u16 s = 0;
34
35
36 if (mx > 0) {
37
38
39 if (delta == mx) {
40 s = 65535;
41 } else {
42 s = (u16)(((u32)delta * 65535 + (mx >> 1)) / mx);
43 }
44 }
45
46
47 if (delta > 0) {
48 u32 hue_calc = 0;
49
50 if (mx == r) {
51
53
54 u32 numerator = (u32)(
g - b) * 65535;
55 if (delta <= 42) {
56 hue_calc = numerator / (6 * delta);
57 } else {
58 hue_calc = numerator / delta / 6;
59 }
60 } else {
61 u32 numerator = (u32)(b -
g) * 65535;
62 if (delta <= 42) {
63 hue_calc = 65535 - numerator / (6 * delta);
64 } else {
65 hue_calc = 65535 - numerator / delta / 6;
66 }
67 }
69
70
71 i32 signed_diff = (i32)b - (i32)r;
72 u32 sector_offset = 65535 / 3;
73
74 if (signed_diff >= 0) {
75
76 u32 numerator = (u32)signed_diff * 65535;
77 if (delta <= 42) {
78 hue_calc = sector_offset + numerator / (6 * delta);
79 } else {
80 hue_calc = sector_offset + numerator / delta / 6;
81 }
82 } else {
83
84 u32 numerator = (u32)(-signed_diff) * 65535;
85 if (delta <= 42) {
86 hue_calc = sector_offset - numerator / (6 * delta);
87 } else {
88 hue_calc = sector_offset - numerator / delta / 6;
89 }
90 }
91 } else {
92
93
94 i32 signed_diff = (i32)r - (i32)
g;
95 u32 sector_offset = (2 * 65535) / 3;
96
97 if (signed_diff >= 0) {
98
99 u32 numerator = (u32)signed_diff * 65535;
100 if (delta <= 42) {
101 hue_calc = sector_offset + numerator / (6 * delta);
102 } else {
103 hue_calc = sector_offset + numerator / delta / 6;
104 }
105 } else {
106
107 u32 numerator = (u32)(-signed_diff) * 65535;
108 if (delta <= 42) {
109 hue_calc = sector_offset - numerator / (6 * delta);
110 } else {
111 hue_calc = sector_offset - numerator / delta / 6;
112 }
113 }
114 }
115
116 h = (u16)(hue_calc & 0xFFFF);
117 }
118
119 return HSV16{h, s, v};
120}
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
static u16 scale8_to_16_accurate(u8 x) FL_NO_EXCEPT