34 const float *in_color = p.
ins[0];
35 const float *in_mask = p.
ins[1];
37 const float level = (in_color[0] + in_color[1] + in_color[2]) / 3.0f;
38 float level_shadows = 0.0f;
39 float level_midtones = 0.0f;
40 float level_highlights = 0.0f;
41 constexpr float MARGIN = 0.10f;
42 constexpr float MARGIN_DIV = 0.5f / MARGIN;
43 if (level < data_->startmidtones - MARGIN) {
46 else if (level < data_->startmidtones + MARGIN) {
47 level_midtones = ((level - data_->startmidtones) * MARGIN_DIV) + 0.5f;
48 level_shadows = 1.0f - level_midtones;
50 else if (level < data_->endmidtones - MARGIN) {
51 level_midtones = 1.0f;
53 else if (level < data_->endmidtones + MARGIN) {
54 level_highlights = ((level - data_->endmidtones) * MARGIN_DIV) + 0.5f;
55 level_midtones = 1.0f - level_highlights;
58 level_highlights = 1.0f;
60 float contrast = data_->master.contrast;
62 float gamma = data_->master.gamma;
63 float gain = data_->master.gain;
64 float lift = data_->master.lift;
65 contrast *= level_shadows * data_->shadows.contrast +
66 level_midtones * data_->midtones.contrast +
67 level_highlights * data_->highlights.contrast;
68 saturation *= level_shadows * data_->shadows.saturation +
69 level_midtones * data_->midtones.saturation +
70 level_highlights * data_->highlights.saturation;
71 gamma *= level_shadows * data_->shadows.gamma + level_midtones * data_->midtones.gamma +
72 level_highlights * data_->highlights.gamma;
73 gain *= level_shadows * data_->shadows.gain + level_midtones * data_->midtones.gain +
74 level_highlights * data_->highlights.gain;
75 lift += level_shadows * data_->shadows.lift + level_midtones * data_->midtones.lift +
76 level_highlights * data_->highlights.lift;
78 const float inv_gamma = 1.0f / gamma;
81 float r = luma +
saturation * (in_color[0] - luma);
82 float g = luma +
saturation * (in_color[1] - luma);
85 r = 0.5f + (r - 0.5f) * contrast;
86 g = 0.5f + (g - 0.5f) * contrast;
87 b = 0.5f + (
b - 0.5f) * contrast;
95 const float value = std::min(1.0f, in_mask[0]);
96 const float value_ = 1.0f - value;
97 r = value_ * in_color[0] + value * r;
98 g = value_ * in_color[1] + value * g;
99 b = value_ * in_color[2] + value *
b;
101 p.
out[0] = red_channel_enabled_ ? r : in_color[0];
102 p.
out[1] = green_channel_enabled_ ? g : in_color[1];
103 p.
out[2] = blue_channel_enabled_ ?
b : in_color[2];
104 p.
out[3] = in_color[3];