Skip to content

Commit e569509

Browse files
committed
ODT: use oklab to perform hue/sat tweaks in neutral mode
(the old mode is still available as "Legacy")
1 parent fccf61e commit e569509

1 file changed

Lines changed: 73 additions & 17 deletions

File tree

odt.ctl

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SOFTWARE.
3131
// @ART-label: "$CTL_ART_OUTPUT_TRANSFORM;ART output transform"
3232
//
3333

34-
// @ART-param: ["mode", "Color mode", ["Neutral", "Blender-AgX"], 0]
34+
// @ART-param: ["mode", "Color mode", ["Legacy", "Blender-AgX", "Neutral"], 2]
3535
// @ART-param: ["evgain", "$CTL_GAIN;Gain (Ev)", -4.0, 4.0, 0.0, 0.01]
3636
// @ART-param: ["brightness", "Brightness", -100, 100, 0]
3737
// @ART-param: ["contrast", "$CTL_CONTRAST;Contrast", -100, 100, 25]
@@ -112,29 +112,84 @@ float[3] tonemap(float p_R, float p_G, float p_B,
112112
}
113113

114114

115-
const float rhue = rgb2hsl(1, 0, 0)[0];
116-
const float bhue = rgb2hsl(0, 0, 1)[0];
117-
const float yhue = rgb2hsl(1, 1, 0)[0];
118-
const float ohue = rgb2hsl(1, 0.5, 0)[0];
119-
const float yrange = fabs(ohue - yhue) * 0.8;
120-
const float rrange = fabs(ohue - rhue);
121-
const float brange = rrange;
115+
float[3] to_hsl(float r, float g, float b, int mode)
116+
{
117+
if (mode == 0) {
118+
return rgb2hsl(r, g, b);
119+
} else {
120+
return rgb2okhcl(r, g, b);
121+
}
122+
}
123+
124+
const float rec2020_xyz_t[3][3] = invert_f33(xyz_rec2020_t);
125+
126+
float[3] to_rgb(float hsl[3], int mode)
127+
{
128+
if (mode == 0) {
129+
return hsl2rgb(hsl);
130+
} else {
131+
return okhcl2rgb(hsl);
132+
}
133+
}
134+
135+
const float hpars[2][4] = { // parameters for hue tweaks
136+
{
137+
rgb2hsl(1, 0, 0)[0], // rhue
138+
rgb2hsl(0, 0, 1)[0], // bhue
139+
rgb2hsl(1, 1, 0)[0], // yhue
140+
rgb2hsl(1, 0.5, 0)[0] // ohue
141+
},
142+
{
143+
rgb2okhcl(1, 0, 0)[0], // rhue
144+
rgb2okhcl(0, 0, 1)[0], // bhue
145+
rgb2okhcl(1, 1, 0)[0], // yhue
146+
rgb2okhcl(1, 0.5, 0)[0] // ohue
147+
}
148+
};
149+
150+
const float rpars[2][3] = {
151+
{
152+
fabs(hpars[0][3] - hpars[0][2]) * 0.8,
153+
fabs(hpars[0][3] - hpars[0][0]),
154+
fabs(hpars[0][3] - hpars[0][0])
155+
},
156+
{
157+
fabs(hpars[1][3] - hpars[1][2]) * 0.8,
158+
fabs(hpars[1][3] - hpars[1][0]),
159+
fabs(hpars[1][3] - hpars[1][0])
160+
}
161+
};
162+
/* const float rhue = to_hsl(1, 0, 0)[0]; */
163+
/* const float bhue = to_hsl(0, 0, 1)[0]; */
164+
/* const float yhue = to_hsl(1, 1, 0)[0]; */
165+
/* const float ohue = to_hsl(1, 0.5, 0)[0]; */
166+
/* const float yrange = fabs(ohue - yhue) * 0.8; */
167+
/* const float rrange = fabs(ohue - rhue); */
168+
/* const float brange = rrange; */
122169

123170
float[3] creative_hue_sat_tweaks(float hue_shift_amount, float sat_factor,
124171
float in_r, float in_g, float in_b,
125-
float white_point, float rgb[3])
172+
float white_point, float rgb[3], int mode)
126173
{
127-
float hue = rgb2hsl(in_r, in_g, in_b)[0];
174+
const float rhue = hpars[mode][0];
175+
const float bhue = hpars[mode][1];
176+
const float yhue = hpars[mode][2];
177+
const float ohue = hpars[mode][3];
178+
const float yrange = rpars[mode][0];
179+
const float rrange = rpars[mode][1];
180+
const float brange = rpars[mode][2];
181+
182+
float hue = to_hsl(in_r, in_g, in_b, mode)[0];
128183
const float base_shift = 15.0 * hue_shift_amount;
129184
float hue_shift = base_shift * M_PI / 180.0 * gauss(rhue, rrange, hue);
130185
hue_shift = hue_shift + -base_shift * M_PI / 180.0 * gauss(bhue, brange, hue);
131186
hue_shift = hue_shift * clamp((rgb[0] + rgb[1] + rgb[2]) / (3.0 * white_point), 0, 1);
132187
hue = hue + hue_shift;
133188

134-
float hsl[3] = rgb2hsl(rgb[0], rgb[1], rgb[2]);
189+
float hsl[3] = to_hsl(rgb[0], rgb[1], rgb[2], mode);
135190
hsl[0] = hue;
136191
hsl[1] = hsl[1] * sat_factor;
137-
float res[3] = hsl2rgb(hsl);
192+
float res[3] = to_rgb(hsl, mode);
138193
return res;
139194
}
140195

@@ -156,8 +211,9 @@ const float AgXInsetMatrix_t[3][3] = transpose_f33(AgXInsetMatrix);
156211

157212
const float AgXOutsetMatrix_t[3][3] = invert_f33(AgXInsetMatrix_t);
158213

159-
const int MODE_NEUTRAL = 0;
214+
const int MODE_NEUTRAL = 2;
160215
const int MODE_BLENDERAGX = 1;
216+
const int MODE_LEGACY = 0;
161217

162218
void ART_main(varying float r, varying float g, varying float b,
163219
output varying float rout,
@@ -235,18 +291,18 @@ void ART_main(varying float r, varying float g, varying float b,
235291
if (mode == MODE_BLENDERAGX) {
236292
res = mult_f3_f33(res, AgXOutsetMatrix_t);
237293
if (hue_preservation > 0 || sat_factor != 1.0) {
238-
float hsl[3] = rgb2hsl(res[0], res[1], res[2]);
294+
float hsl[3] = to_hsl(res[0], res[1], res[2], 1);
239295
if (hue_preservation > 0) {
240-
float hue = rgb2hsl(r, g, b)[0];
296+
float hue = to_hsl(r, g, b, 1)[0];
241297
hsl[0] = intp(hue_preservation, hue, hsl[0]);
242298
}
243299
hsl[1] = hsl[1] * sat_factor;
244-
res = hsl2rgb(hsl);
300+
res = to_rgb(hsl, 1);
245301
}
246302
} else {
247303
res = creative_hue_sat_tweaks(1.0 - hue_preservation,
248304
sat_factor, r, g, b,
249-
white_point, res);
305+
white_point, res, fmin(mode, 1));
250306
}
251307

252308
rout = clamp(res[0], 0, white_point);

0 commit comments

Comments
 (0)