Blender  V2.93
COM_ColorMatteOperation.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 {
29 
30  this->m_inputImageProgram = nullptr;
31  this->m_inputKeyProgram = nullptr;
32 }
33 
35 {
36  this->m_inputImageProgram = this->getInputSocketReader(0);
37  this->m_inputKeyProgram = this->getInputSocketReader(1);
38 }
39 
41 {
42  this->m_inputImageProgram = nullptr;
43  this->m_inputKeyProgram = nullptr;
44 }
45 
47  float x,
48  float y,
49  PixelSampler sampler)
50 {
51  float inColor[4];
52  float inKey[4];
53 
54  const float hue = this->m_settings->t1;
55  const float sat = this->m_settings->t2;
56  const float val = this->m_settings->t3;
57 
58  float h_wrap;
59 
60  this->m_inputImageProgram->readSampled(inColor, x, y, sampler);
61  this->m_inputKeyProgram->readSampled(inKey, x, y, sampler);
62 
63  /* Store matte(alpha) value in [0] to go with
64  * COM_SetAlphaMultiplyOperation and the Value output.
65  */
66 
67  if (
68  /* do hue last because it needs to wrap, and does some more checks */
69 
70  /* sat */ (fabsf(inColor[1] - inKey[1]) < sat) &&
71  /* val */ (fabsf(inColor[2] - inKey[2]) < val) &&
72 
73  /* multiply by 2 because it wraps on both sides of the hue,
74  * otherwise 0.5 would key all hue's */
75 
76  /* hue */ ((h_wrap = 2.0f * fabsf(inColor[0] - inKey[0])) < hue || (2.0f - h_wrap) < hue)) {
77  output[0] = 0.0f; /* make transparent */
78  }
79 
80  else { /*pixel is outside key color */
81  output[0] = inColor[3]; /* make pixel just as transparent as it was before */
82  }
83 }
84 
85 } // 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 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 fabsf(x)