Blender  V2.93
COM_BrightnessOperation.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 
21 namespace blender::compositor {
22 
24 {
29  this->m_inputProgram = nullptr;
30  this->m_use_premultiply = false;
31 }
32 
33 void BrightnessOperation::setUsePremultiply(bool use_premultiply)
34 {
35  this->m_use_premultiply = use_premultiply;
36 }
37 
39 {
40  this->m_inputProgram = this->getInputSocketReader(0);
41  this->m_inputBrightnessProgram = this->getInputSocketReader(1);
42  this->m_inputContrastProgram = this->getInputSocketReader(2);
43 }
44 
46  float x,
47  float y,
48  PixelSampler sampler)
49 {
50  float inputValue[4];
51  float a, b;
52  float inputBrightness[4];
53  float inputContrast[4];
54  this->m_inputProgram->readSampled(inputValue, x, y, sampler);
55  this->m_inputBrightnessProgram->readSampled(inputBrightness, x, y, sampler);
56  this->m_inputContrastProgram->readSampled(inputContrast, x, y, sampler);
57  float brightness = inputBrightness[0];
58  float contrast = inputContrast[0];
59  brightness /= 100.0f;
60  float delta = contrast / 200.0f;
61  /*
62  * The algorithm is by Werner D. Streidt
63  * (http://visca.com/ffactory/archives/5-99/msg00021.html)
64  * Extracted of OpenCV demhist.c
65  */
66  if (contrast > 0) {
67  a = 1.0f - delta * 2.0f;
68  a = 1.0f / max_ff(a, FLT_EPSILON);
69  b = a * (brightness - delta);
70  }
71  else {
72  delta *= -1;
73  a = max_ff(1.0f - delta * 2.0f, 0.0f);
74  b = a * brightness + delta;
75  }
76  if (this->m_use_premultiply) {
77  premul_to_straight_v4(inputValue);
78  }
79  output[0] = a * inputValue[0] + b;
80  output[1] = a * inputValue[1] + b;
81  output[2] = a * inputValue[2] + b;
82  output[3] = inputValue[3];
83  if (this->m_use_premultiply) {
85  }
86 }
87 
89 {
90  this->m_inputProgram = nullptr;
91  this->m_inputBrightnessProgram = nullptr;
92  this->m_inputContrastProgram = nullptr;
93 }
94 
95 } // namespace blender::compositor
MINLINE float max_ff(float a, float b)
MINLINE void premul_to_straight_v4(float color[4])
MINLINE void straight_to_premul_v4(float color[4])
_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)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
static unsigned a[3]
Definition: RandGen.cpp:92