Blender  V2.93
COM_ColorBalanceASCCDLOperation.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_cdl(float in, float offset, float power, float slope)
25 {
26  float x = in * slope + offset;
27 
28  /* prevent NaN */
29  if (x < 0.0f) {
30  x = 0.0f;
31  }
32 
33  return powf(x, power);
34 }
35 
37 {
41  this->m_inputValueOperation = nullptr;
42  this->m_inputColorOperation = nullptr;
44 }
45 
47 {
50 }
51 
53  float x,
54  float y,
55  PixelSampler sampler)
56 {
57  float inputColor[4];
58  float value[4];
59 
60  this->m_inputValueOperation->readSampled(value, x, y, sampler);
61  this->m_inputColorOperation->readSampled(inputColor, x, y, sampler);
62 
63  float fac = value[0];
64  fac = MIN2(1.0f, fac);
65  const float mfac = 1.0f - fac;
66 
67  output[0] = mfac * inputColor[0] +
68  fac * colorbalance_cdl(
69  inputColor[0], this->m_offset[0], this->m_power[0], this->m_slope[0]);
70  output[1] = mfac * inputColor[1] +
71  fac * colorbalance_cdl(
72  inputColor[1], this->m_offset[1], this->m_power[1], this->m_slope[1]);
73  output[2] = mfac * inputColor[2] +
74  fac * colorbalance_cdl(
75  inputColor[2], this->m_offset[2], this->m_power[2], this->m_slope[2]);
76  output[3] = inputColor[3];
77 }
78 
80 {
81  this->m_inputValueOperation = nullptr;
82  this->m_inputColorOperation = nullptr;
83 }
84 
85 } // namespace blender::compositor
#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_cdl(float in, float offset, float power, float slope)