Blender  V2.93
COM_ColorCurveOperation.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 #include "BKE_colortools.h"
22 
23 #include "MEM_guardedalloc.h"
24 
25 namespace blender::compositor {
26 
28 {
34 
35  this->m_inputFacProgram = nullptr;
36  this->m_inputImageProgram = nullptr;
37  this->m_inputBlackProgram = nullptr;
38  this->m_inputWhiteProgram = nullptr;
39 
41 }
43 {
45  this->m_inputFacProgram = this->getInputSocketReader(0);
46  this->m_inputImageProgram = this->getInputSocketReader(1);
47  this->m_inputBlackProgram = this->getInputSocketReader(2);
48  this->m_inputWhiteProgram = this->getInputSocketReader(3);
49 
51 }
52 
54  float x,
55  float y,
56  PixelSampler sampler)
57 {
58  CurveMapping *cumap = this->m_curveMapping;
59 
60  float fac[4];
61  float image[4];
62 
63  /* local versions of cumap->black, cumap->white, cumap->bwmul */
64  float black[4];
65  float white[4];
66  float bwmul[3];
67 
68  this->m_inputBlackProgram->readSampled(black, x, y, sampler);
69  this->m_inputWhiteProgram->readSampled(white, x, y, sampler);
70 
71  /* get our own local bwmul value,
72  * since we can't be threadsafe and use cumap->bwmul & friends */
73  BKE_curvemapping_set_black_white_ex(black, white, bwmul);
74 
75  this->m_inputFacProgram->readSampled(fac, x, y, sampler);
76  this->m_inputImageProgram->readSampled(image, x, y, sampler);
77 
78  if (*fac >= 1.0f) {
79  BKE_curvemapping_evaluate_premulRGBF_ex(cumap, output, image, black, bwmul);
80  }
81  else if (*fac <= 0.0f) {
82  copy_v3_v3(output, image);
83  }
84  else {
85  float col[4];
86  BKE_curvemapping_evaluate_premulRGBF_ex(cumap, col, image, black, bwmul);
87  interp_v3_v3v3(output, image, col, *fac);
88  }
89  output[3] = image[3];
90 }
91 
93 {
95  this->m_inputFacProgram = nullptr;
96  this->m_inputImageProgram = nullptr;
97  this->m_inputBlackProgram = nullptr;
98  this->m_inputWhiteProgram = nullptr;
99 }
100 
101 // Constant level curve mapping
102 
104 {
108 
109  this->m_inputFacProgram = nullptr;
110  this->m_inputImageProgram = nullptr;
111 
113 }
115 {
117  this->m_inputFacProgram = this->getInputSocketReader(0);
118  this->m_inputImageProgram = this->getInputSocketReader(1);
119 
121 
122  BKE_curvemapping_set_black_white(this->m_curveMapping, this->m_black, this->m_white);
123 }
124 
126  float x,
127  float y,
128  PixelSampler sampler)
129 {
130  float fac[4];
131  float image[4];
132 
133  this->m_inputFacProgram->readSampled(fac, x, y, sampler);
134  this->m_inputImageProgram->readSampled(image, x, y, sampler);
135 
136  if (*fac >= 1.0f) {
138  }
139  else if (*fac <= 0.0f) {
140  copy_v3_v3(output, image);
141  }
142  else {
143  float col[4];
145  interp_v3_v3v3(output, image, col, *fac);
146  }
147  output[3] = image[3];
148 }
149 
151 {
153  this->m_inputFacProgram = nullptr;
154  this->m_inputImageProgram = nullptr;
155 }
156 
157 } // namespace blender::compositor
void BKE_curvemapping_evaluate_premulRGBF_ex(const struct CurveMapping *cumap, float vecout[3], const float vecin[3], const float black[3], const float bwmul[3])
void BKE_curvemapping_evaluate_premulRGBF(const struct CurveMapping *cumap, float vecout[3], const float vecin[3])
void BKE_curvemapping_set_black_white(struct CurveMapping *cumap, const float black[3], const float white[3])
Definition: colortools.c:168
void BKE_curvemapping_set_black_white_ex(const float black[3], const float white[3], float r_bwmul[3])
Definition: colortools.c:156
void BKE_curvemapping_premultiply(struct CurveMapping *cumap, int restore)
Definition: colortools.c:805
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
Definition: math_vector.c:49
MINLINE void copy_v3_v3(float r[3], const float a[3])
_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
Read Guarded memory(de)allocation.
#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)
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)
uint col