-
Notifications
You must be signed in to change notification settings - Fork 1
/
PD-Grade.dctl
83 lines (76 loc) · 4.04 KB
/
PD-Grade.dctl
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
// Copyright 2022-present Contributors to the photographic-dctl project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/photographic-dctls
// clang-format off
DEFINE_UI_PARAMS(blackpoint_r, Black Point R, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(blackpoint_g, Black Point G, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(blackpoint_b, Black Point B, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(whitepoint_r, White Point R, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(whitepoint_g, White Point G, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(whitepoint_b, White Point B, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(lift_r, Lift R, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(lift_g, Lift G, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(lift_b, Lift B, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(gain_r, Gain R, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(gain_g, Gain G, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(gain_b, Gain B, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(multiply_r, Multiply R, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(multiply_g, Multiply G, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(multiply_b, Multiply B, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.01);
DEFINE_UI_PARAMS(offset_r, Offset R, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(offset_g, Offset G, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(offset_b, Offset B, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(gamma_r, Gamma R, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(gamma_g, Gamma G, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(gamma_b, Gamma B, DCTLUI_SLIDER_FLOAT, 0.0, -1.0, 1.0, 0.01);
DEFINE_UI_PARAMS(adjustdisplay, Adjust for display, DCTLUI_CHECK_BOX, 1)
// headers
#include "PD-Common.h"
// Grade
struct Grade
{
float3 blackpoint;
float3 whitepoint;
float3 lift;
float3 gain;
float3 multiply;
float3 offset;
float3 gamma;
float2 gamma_scale;
};
__DEVICE__ float3 apply_scale(float3 rgb, float2 scale) {
float3 result;
result.r = (rgb.r < 0.0) ? rgb.r * scale.x : rgb.r * scale.y;
result.g = (rgb.g < 0.0) ? rgb.g * scale.x : rgb.g * scale.y;
result.b = (rgb.b < 0.0) ? rgb.b * scale.x : rgb.b * scale.y;
return result;
}
__DEVICE__ float apply_grading(float rgb, float blackpoint, float whitepoint, float lift, float gain, float multiply, float offset, float gamma) {
float scaled = (rgb - blackpoint) / (whitepoint - blackpoint);
float lifted = scaled * multiply * (gain - lift) + lift;
float final_offset = lifted + offset;
return pow_f(final_offset, 1.0 + (gamma));
}
__DEVICE__ float3 grade(float3 rgb, struct Grade gr) {
rgb.x = apply_grading(rgb.x, gr.blackpoint.x, gr.whitepoint.x, gr.lift.x, gr.gain.x, gr.multiply.x, gr.offset.x, gr.gamma.x);
rgb.y = apply_grading(rgb.y, gr.blackpoint.y, gr.whitepoint.y, gr.lift.y, gr.gain.y, gr.multiply.y, gr.offset.y, gr.gamma.y);
rgb.z = apply_grading(rgb.z, gr.blackpoint.z, gr.whitepoint.z, gr.lift.z, gr.gain.z, gr.multiply.z, gr.offset.z, gr.gamma.z);
return rgb;
}
// transform
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B) {
struct Grade gr;
gr.whitepoint = make_float3(whitepoint_r, whitepoint_g, whitepoint_b);
gr.blackpoint = make_float3(blackpoint_r, blackpoint_g, blackpoint_b);
gr.lift = make_float3(lift_r, lift_g, lift_b);
gr.gain = make_float3(gain_r, gain_g, gain_b);
gr.multiply = make_float3(multiply_r, multiply_g, multiply_b);
gr.offset = make_float3(offset_r, offset_g, offset_b);
gr.gamma_scale = make_float2(-5.0, -0.8);
gr.gamma = apply_scale(make_float3(gamma_r, gamma_g, gamma_b), gr.gamma_scale);
float3 rgb = grade(make_float3(p_R, p_G, p_B), gr);
if (adjustdisplay) {
rgb = adjust_display(rgb);
}
return rgb;
}