Blender  V2.93
COM_ColorSpillOperation.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 #define AVG(a, b) ((a + b) / 2)
22 
23 namespace blender::compositor {
24 
26 {
30 
31  this->m_inputImageReader = nullptr;
32  this->m_inputFacReader = nullptr;
33  this->m_spillChannel = 1; // GREEN
34  this->m_spillMethod = 0;
35 }
36 
38 {
40  this->m_inputFacReader = this->getInputSocketReader(1);
41  if (this->m_spillChannel == 0) {
42  this->m_rmut = -1.0f;
43  this->m_gmut = 1.0f;
44  this->m_bmut = 1.0f;
45  this->m_channel2 = 1;
46  this->m_channel3 = 2;
47  if (this->m_settings->unspill == 0) {
48  this->m_settings->uspillr = 1.0f;
49  this->m_settings->uspillg = 0.0f;
50  this->m_settings->uspillb = 0.0f;
51  }
52  }
53  else if (this->m_spillChannel == 1) {
54  this->m_rmut = 1.0f;
55  this->m_gmut = -1.0f;
56  this->m_bmut = 1.0f;
57  this->m_channel2 = 0;
58  this->m_channel3 = 2;
59  if (this->m_settings->unspill == 0) {
60  this->m_settings->uspillr = 0.0f;
61  this->m_settings->uspillg = 1.0f;
62  this->m_settings->uspillb = 0.0f;
63  }
64  }
65  else {
66  this->m_rmut = 1.0f;
67  this->m_gmut = 1.0f;
68  this->m_bmut = -1.0f;
69 
70  this->m_channel2 = 0;
71  this->m_channel3 = 1;
72  if (this->m_settings->unspill == 0) {
73  this->m_settings->uspillr = 0.0f;
74  this->m_settings->uspillg = 0.0f;
75  this->m_settings->uspillb = 1.0f;
76  }
77  }
78 }
79 
81 {
82  this->m_inputImageReader = nullptr;
83  this->m_inputFacReader = nullptr;
84 }
85 
87  float x,
88  float y,
89  PixelSampler sampler)
90 {
91  float fac[4];
92  float input[4];
93  this->m_inputFacReader->readSampled(fac, x, y, sampler);
94  this->m_inputImageReader->readSampled(input, x, y, sampler);
95  float rfac = MIN2(1.0f, fac[0]);
96  float map;
97 
98  switch (this->m_spillMethod) {
99  case 0: /* simple */
100  map = rfac * (input[this->m_spillChannel] -
101  (this->m_settings->limscale * input[this->m_settings->limchan]));
102  break;
103  default: /* average */
104  map = rfac *
105  (input[this->m_spillChannel] -
106  (this->m_settings->limscale * AVG(input[this->m_channel2], input[this->m_channel3])));
107  break;
108  }
109 
110  if (map > 0.0f) {
111  output[0] = input[0] + this->m_rmut * (this->m_settings->uspillr * map);
112  output[1] = input[1] + this->m_gmut * (this->m_settings->uspillg * map);
113  output[2] = input[2] + this->m_bmut * (this->m_settings->uspillb * map);
114  output[3] = input[3];
115  }
116  else {
117  copy_v4_v4(output, input);
118  }
119 }
120 
121 } // namespace blender::compositor
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define MIN2(a, b)
#define AVG(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)