Blender  V3.3
COM_ColorBalanceLGGOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 namespace blender::compositor {
7 
8 inline float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)
9 {
10  /* 1:1 match with the sequencer with linear/srgb conversions, the conversion isn't pretty
11  * but best keep it this way, since testing for durian shows a similar calculation
12  * without lin/srgb conversions gives bad results (over-saturated shadows) with colors
13  * slightly below 1.0. some correction can be done but it ends up looking bad for shadows or
14  * lighter tones - campbell */
15  float x = (((linearrgb_to_srgb(in) - 1.0f) * lift_lgg) + 1.0f) * gain;
16 
17  /* prevent NaN */
18  if (x < 0.0f) {
19  x = 0.0f;
20  }
21 
22  return powf(srgb_to_linearrgb(x), gamma_inv);
23 }
24 
26 {
30  input_value_operation_ = nullptr;
31  input_color_operation_ = nullptr;
32  this->set_canvas_input_index(1);
33  flags_.can_be_constant = true;
34 }
35 
37 {
40 }
41 
43  float x,
44  float y,
46 {
47  float input_color[4];
48  float value[4];
49 
52 
53  float fac = value[0];
54  fac = MIN2(1.0f, fac);
55  const float mfac = 1.0f - fac;
56 
57  output[0] = mfac * input_color[0] +
58  fac * colorbalance_lgg(input_color[0], lift_[0], gamma_inv_[0], gain_[0]);
59  output[1] = mfac * input_color[1] +
60  fac * colorbalance_lgg(input_color[1], lift_[1], gamma_inv_[1], gain_[1]);
61  output[2] = mfac * input_color[2] +
62  fac * colorbalance_lgg(input_color[2], lift_[2], gamma_inv_[2], gain_[2]);
63  output[3] = input_color[3];
64 }
65 
67 {
68  for (; p.out < p.row_end; p.next()) {
69  const float *in_factor = p.ins[0];
70  const float *in_color = p.ins[1];
71  const float fac = MIN2(1.0f, in_factor[0]);
72  const float fac_m = 1.0f - fac;
73  p.out[0] = fac_m * in_color[0] +
74  fac * colorbalance_lgg(in_color[0], lift_[0], gamma_inv_[0], gain_[0]);
75  p.out[1] = fac_m * in_color[1] +
76  fac * colorbalance_lgg(in_color[1], lift_[1], gamma_inv_[1], gain_[1]);
77  p.out[2] = fac_m * in_color[2] +
78  fac * colorbalance_lgg(in_color[2], lift_[2], gamma_inv_[2], gain_[2]);
79  p.out[3] = in_color[3];
80  }
81 }
82 
84 {
85  input_value_operation_ = nullptr;
86  input_color_operation_ = nullptr;
87 }
88 
89 } // namespace blender::compositor
float srgb_to_linearrgb(float c)
Definition: math_color.c:403
float linearrgb_to_srgb(float c)
Definition: math_color.c:412
#define MIN2(a, b)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
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)
Definition: cuda/compat.h:103
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_global KernelShaderEvalInput ccl_global float * output
float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)