Blender  V2.93
COM_GammaCorrectOperation.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 
25 {
28  this->m_inputProgram = nullptr;
29 }
31 {
32  this->m_inputProgram = this->getInputSocketReader(0);
33 }
34 
36  float x,
37  float y,
38  PixelSampler sampler)
39 {
40  float inputColor[4];
41  this->m_inputProgram->readSampled(inputColor, x, y, sampler);
42  if (inputColor[3] > 0.0f) {
43  inputColor[0] /= inputColor[3];
44  inputColor[1] /= inputColor[3];
45  inputColor[2] /= inputColor[3];
46  }
47 
48  /* check for negative to avoid nan's */
49  output[0] = inputColor[0] > 0.0f ? inputColor[0] * inputColor[0] : 0.0f;
50  output[1] = inputColor[1] > 0.0f ? inputColor[1] * inputColor[1] : 0.0f;
51  output[2] = inputColor[2] > 0.0f ? inputColor[2] * inputColor[2] : 0.0f;
52  output[3] = inputColor[3];
53 
54  if (inputColor[3] > 0.0f) {
55  output[0] *= inputColor[3];
56  output[1] *= inputColor[3];
57  output[2] *= inputColor[3];
58  }
59 }
60 
62 {
63  this->m_inputProgram = nullptr;
64 }
65 
67 {
70  this->m_inputProgram = nullptr;
71 }
73 {
74  this->m_inputProgram = this->getInputSocketReader(0);
75 }
76 
78  float x,
79  float y,
80  PixelSampler sampler)
81 {
82  float inputColor[4];
83  this->m_inputProgram->readSampled(inputColor, x, y, sampler);
84 
85  if (inputColor[3] > 0.0f) {
86  inputColor[0] /= inputColor[3];
87  inputColor[1] /= inputColor[3];
88  inputColor[2] /= inputColor[3];
89  }
90 
91  output[0] = inputColor[0] > 0.0f ? sqrtf(inputColor[0]) : 0.0f;
92  output[1] = inputColor[1] > 0.0f ? sqrtf(inputColor[1]) : 0.0f;
93  output[2] = inputColor[2] > 0.0f ? sqrtf(inputColor[2]) : 0.0f;
94  output[3] = inputColor[3];
95 
96  if (inputColor[3] > 0.0f) {
97  output[0] *= inputColor[3];
98  output[1] *= inputColor[3];
99  output[2] *= inputColor[3];
100  }
101 }
102 
104 {
105  this->m_inputProgram = nullptr;
106 }
107 
108 } // namespace blender::compositor
_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 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)
#define sqrtf(x)