Blender  V2.93
COM_ChannelMatteOperation.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 2012, Blender Foundation.
17  */
18 
20 #include "BLI_math.h"
21 
22 namespace blender::compositor {
23 
25 {
28 
29  this->m_inputImageProgram = nullptr;
30 }
31 
33 {
34  this->m_inputImageProgram = this->getInputSocketReader(0);
35 
36  this->m_limit_range = this->m_limit_max - this->m_limit_min;
37 
38  switch (this->m_limit_method) {
39  /* SINGLE */
40  case 0: {
41  /* 123 / RGB / HSV / YUV / YCC */
42  const int matte_channel = this->m_matte_channel - 1;
43  const int limit_channel = this->m_limit_channel - 1;
44  this->m_ids[0] = matte_channel;
45  this->m_ids[1] = limit_channel;
46  this->m_ids[2] = limit_channel;
47  break;
48  }
49  /* MAX */
50  case 1: {
51  switch (this->m_matte_channel) {
52  case 1: {
53  this->m_ids[0] = 0;
54  this->m_ids[1] = 1;
55  this->m_ids[2] = 2;
56  break;
57  }
58  case 2: {
59  this->m_ids[0] = 1;
60  this->m_ids[1] = 0;
61  this->m_ids[2] = 2;
62  break;
63  }
64  case 3: {
65  this->m_ids[0] = 2;
66  this->m_ids[1] = 0;
67  this->m_ids[2] = 1;
68  break;
69  }
70  default:
71  break;
72  }
73  break;
74  }
75  default:
76  break;
77  }
78 }
79 
81 {
82  this->m_inputImageProgram = nullptr;
83 }
84 
86  float x,
87  float y,
88  PixelSampler sampler)
89 {
90  float inColor[4];
91  float alpha;
92 
93  const float limit_max = this->m_limit_max;
94  const float limit_min = this->m_limit_min;
95  const float limit_range = this->m_limit_range;
96 
97  this->m_inputImageProgram->readSampled(inColor, x, y, sampler);
98 
99  /* matte operation */
100  alpha = inColor[this->m_ids[0]] - MAX2(inColor[this->m_ids[1]], inColor[this->m_ids[2]]);
101 
102  /* flip because 0.0 is transparent, not 1.0 */
103  alpha = 1.0f - alpha;
104 
105  /* test range */
106  if (alpha > limit_max) {
107  alpha = inColor[3]; /*whatever it was prior */
108  }
109  else if (alpha < limit_min) {
110  alpha = 0.0f;
111  }
112  else { /*blend */
113  alpha = (alpha - limit_min) / limit_range;
114  }
115 
116  /* Store matte(alpha) value in [0] to go with
117  * COM_SetAlphaMultiplyOperation and the Value output.
118  */
119 
120  /* Don't make something that was more transparent less transparent. */
121  output[0] = MIN2(alpha, inColor[3]);
122 }
123 
124 } // namespace blender::compositor
#define MAX2(a, b)
#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)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
static CCL_NAMESPACE_BEGIN const double alpha