Blender  V2.93
COM_ColorBalanceLGGOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
20 #include "BLI_math.h"
21 
22 namespace blender::compositor {
23 
24 inline float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)
25 {
26  /* 1:1 match with the sequencer with linear/srgb conversions, the conversion isn't pretty
27  * but best keep it this way, since testing for durian shows a similar calculation
28  * without lin/srgb conversions gives bad results (over-saturated shadows) with colors
29  * slightly below 1.0. some correction can be done but it ends up looking bad for shadows or
30  * lighter tones - campbell */
31  float x = (((linearrgb_to_srgb(in) - 1.0f) * lift_lgg) + 1.0f) * gain;
32 
33  /* prevent NaN */
34  if (x < 0.0f) {
35  x = 0.0f;
36  }
37 
38  return powf(srgb_to_linearrgb(x), gamma_inv);
39 }
40 
42 {
46  this->m_inputValueOperation = nullptr;
47  this->m_inputColorOperation = nullptr;
49 }
50 
52 {
55 }
56 
58  float x,
59  float y,
60  PixelSampler sampler)
61 {
62  float inputColor[4];
63  float value[4];
64 
65  this->m_inputValueOperation->readSampled(value, x, y, sampler);
66  this->m_inputColorOperation->readSampled(inputColor, x, y, sampler);
67 
68  float fac = value[0];
69  fac = MIN2(1.0f, fac);
70  const float mfac = 1.0f - fac;
71 
72  output[0] = mfac * inputColor[0] +
73  fac * colorbalance_lgg(
74  inputColor[0], this->m_lift[0], this->m_gamma_inv[0], this->m_gain[0]);
75  output[1] = mfac * inputColor[1] +
76  fac * colorbalance_lgg(
77  inputColor[1], this->m_lift[1], this->m_gamma_inv[1], this->m_gain[1]);
78  output[2] = mfac * inputColor[2] +
79  fac * colorbalance_lgg(
80  inputColor[2], this->m_lift[2], this->m_gamma_inv[2], this->m_gain[2]);
81  output[3] = inputColor[3];
82 }
83 
85 {
86  this->m_inputValueOperation = nullptr;
87  this->m_inputColorOperation = nullptr;
88 }
89 
90 } // namespace blender::compositor
float srgb_to_linearrgb(float c)
Definition: math_color.c:434
float linearrgb_to_srgb(float c)
Definition: math_color.c:443
#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
#define output
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
void setResolutionInputSocketIndex(unsigned int index)
set the index of the input socket that will determine the resolution of this operation
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
#define powf(x, y)
float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)