Blender  V2.93
COM_DistanceRGBMatteOperation.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 {
37  this->m_inputKeyProgram = this->getInputSocketReader(1);
38 }
39 
41 {
42  this->m_inputImageProgram = nullptr;
43  this->m_inputKeyProgram = nullptr;
44 }
45 
46 float DistanceRGBMatteOperation::calculateDistance(float key[4], float image[4])
47 {
48  return len_v3v3(key, image);
49 }
50 
52  float x,
53  float y,
54  PixelSampler sampler)
55 {
56  float inKey[4];
57  float inImage[4];
58 
59  const float tolerance = this->m_settings->t1;
60  const float falloff = this->m_settings->t2;
61 
62  float distance;
63  float alpha;
64 
65  this->m_inputKeyProgram->readSampled(inKey, x, y, sampler);
66  this->m_inputImageProgram->readSampled(inImage, x, y, sampler);
67 
68  distance = this->calculateDistance(inKey, inImage);
69 
70  /* Store matte(alpha) value in [0] to go with
71  * COM_SetAlphaMultiplyOperation and the Value output.
72  */
73 
74  /*make 100% transparent */
75  if (distance < tolerance) {
76  output[0] = 0.0f;
77  }
78  /*in the falloff region, make partially transparent */
79  else if (distance < falloff + tolerance) {
80  distance = distance - tolerance;
81  alpha = distance / falloff;
82  /*only change if more transparent than before */
83  if (alpha < inImage[3]) {
84  output[0] = alpha;
85  }
86  else { /* leave as before */
87  output[0] = inImage[3];
88  }
89  }
90  else {
91  /* leave as before */
92  output[0] = inImage[3];
93  }
94 }
95 
96 } // namespace blender::compositor
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
_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
virtual float calculateDistance(float key[4], float image[4])
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
ccl_device_inline float distance(const float2 &a, const float2 &b)