Blender  V2.93
COM_LuminanceMatteOperation.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 #include "IMB_colormanagement.h"
23 
24 namespace blender::compositor {
25 
27 {
30 
31  this->m_inputImageProgram = nullptr;
32 }
33 
35 {
36  this->m_inputImageProgram = this->getInputSocketReader(0);
37 }
38 
40 {
41  this->m_inputImageProgram = nullptr;
42 }
43 
45  float x,
46  float y,
47  PixelSampler sampler)
48 {
49  float inColor[4];
50  this->m_inputImageProgram->readSampled(inColor, x, y, sampler);
51 
52  const float high = this->m_settings->t1;
53  const float low = this->m_settings->t2;
54  const float luminance = IMB_colormanagement_get_luminance(inColor);
55 
56  float alpha;
57 
58  /* one line thread-friend algorithm:
59  * output[0] = MIN2(inputValue[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));
60  */
61 
62  /* test range */
63  if (luminance > high) {
64  alpha = 1.0f;
65  }
66  else if (luminance < low) {
67  alpha = 0.0f;
68  }
69  else { /*blend */
70  alpha = (luminance - low) / (high - low);
71  }
72 
73  /* Store matte(alpha) value in [0] to go with
74  * COM_SetAlphaMultiplyOperation and the Value output.
75  */
76 
77  /* don't make something that was more transparent less transparent */
78  output[0] = min_ff(alpha, inColor[3]);
79 }
80 
81 } // namespace blender::compositor
MINLINE float min_ff(float a, float 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
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
#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 CCL_NAMESPACE_BEGIN const double alpha
__forceinline ssef low(const avxf &a)
Definition: util_avxf.h:277
__forceinline ssef high(const avxf &a)
Definition: util_avxf.h:281