Blender  V2.93
COM_DifferenceMatteOperation.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_inputImage1Program = nullptr;
31  this->m_inputImage2Program = nullptr;
32 }
33 
35 {
36  this->m_inputImage1Program = this->getInputSocketReader(0);
37  this->m_inputImage2Program = this->getInputSocketReader(1);
38 }
40 {
41  this->m_inputImage1Program = nullptr;
42  this->m_inputImage2Program = nullptr;
43 }
44 
46  float x,
47  float y,
48  PixelSampler sampler)
49 {
50  float inColor1[4];
51  float inColor2[4];
52 
53  const float tolerance = this->m_settings->t1;
54  const float falloff = this->m_settings->t2;
55  float difference;
56  float alpha;
57 
58  this->m_inputImage1Program->readSampled(inColor1, x, y, sampler);
59  this->m_inputImage2Program->readSampled(inColor2, x, y, sampler);
60 
61  difference = (fabsf(inColor2[0] - inColor1[0]) + fabsf(inColor2[1] - inColor1[1]) +
62  fabsf(inColor2[2] - inColor1[2]));
63 
64  /* average together the distances */
65  difference = difference / 3.0f;
66 
67  /* make 100% transparent */
68  if (difference <= tolerance) {
69  output[0] = 0.0f;
70  }
71  /*in the falloff region, make partially transparent */
72  else if (difference <= falloff + tolerance) {
73  difference = difference - tolerance;
74  alpha = difference / falloff;
75  /*only change if more transparent than before */
76  if (alpha < inColor1[3]) {
77  output[0] = alpha;
78  }
79  else { /* leave as before */
80  output[0] = inColor1[3];
81  }
82  }
83  else {
84  /* foreground object */
85  output[0] = inColor1[3];
86  }
87 }
88 
89 } // 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)
static CCL_NAMESPACE_BEGIN const double alpha
#define fabsf(x)