Blender V4.3
COM_ColorBalanceLGGOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BLI_math_color.h"
8
9namespace blender::compositor {
10
11inline float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)
12{
13 /* 1:1 match with the sequencer with linear/srgb conversions, the conversion isn't pretty
14 * but best keep it this way, since testing for durian shows a similar calculation
15 * without lin/srgb conversions gives bad results (over-saturated shadows) with colors
16 * slightly below 1.0. some correction can be done but it ends up looking bad for shadows or
17 * lighter tones - campbell */
18 float x = (((linearrgb_to_srgb(in) - 1.0f) * lift_lgg) + 1.0f) * gain;
19
20 /* prevent NaN */
21 if (x < 0.0f) {
22 x = 0.0f;
23 }
24
25 return powf(srgb_to_linearrgb(x), gamma_inv);
26}
27
36
38{
39 for (; p.out < p.row_end; p.next()) {
40 const float *in_factor = p.ins[0];
41 const float *in_color = p.ins[1];
42 const float fac = std::min(1.0f, in_factor[0]);
43 const float fac_m = 1.0f - fac;
44 p.out[0] = fac_m * in_color[0] +
45 fac * colorbalance_lgg(in_color[0], lift_[0], gamma_inv_[0], gain_[0]);
46 p.out[1] = fac_m * in_color[1] +
47 fac * colorbalance_lgg(in_color[1], lift_[1], gamma_inv_[1], gain_[1]);
48 p.out[2] = fac_m * in_color[2] +
49 fac * colorbalance_lgg(in_color[2], lift_[2], gamma_inv_[2], gain_[2]);
50 p.out[3] = in_color[3];
51 }
52}
53
54} // namespace blender::compositor
float srgb_to_linearrgb(float c)
float linearrgb_to_srgb(float c)
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void set_canvas_input_index(unsigned int index)
set the index of the input socket that will determine the canvas of this operation
#define powf(x, y)
float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)