Blender  V2.93
COM_KeyingDespillOperation.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 
21 #include "MEM_guardedalloc.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_math.h"
25 
26 namespace blender::compositor {
27 
29 {
33 
34  this->m_despillFactor = 0.5f;
35  this->m_colorBalance = 0.5f;
36 
37  this->m_pixelReader = nullptr;
38  this->m_screenReader = nullptr;
39 }
40 
42 {
43  this->m_pixelReader = this->getInputSocketReader(0);
44  this->m_screenReader = this->getInputSocketReader(1);
45 }
46 
48 {
49  this->m_pixelReader = nullptr;
50  this->m_screenReader = nullptr;
51 }
52 
54  float x,
55  float y,
56  PixelSampler sampler)
57 {
58  float pixelColor[4];
59  float screenColor[4];
60 
61  this->m_pixelReader->readSampled(pixelColor, x, y, sampler);
62  this->m_screenReader->readSampled(screenColor, x, y, sampler);
63 
64  const int screen_primary_channel = max_axis_v3(screenColor);
65  const int other_1 = (screen_primary_channel + 1) % 3;
66  const int other_2 = (screen_primary_channel + 2) % 3;
67 
68  const int min_channel = MIN2(other_1, other_2);
69  const int max_channel = MAX2(other_1, other_2);
70 
71  float average_value, amount;
72 
73  average_value = this->m_colorBalance * pixelColor[min_channel] +
74  (1.0f - this->m_colorBalance) * pixelColor[max_channel];
75  amount = (pixelColor[screen_primary_channel] - average_value);
76 
77  copy_v4_v4(output, pixelColor);
78 
79  const float amount_despill = this->m_despillFactor * amount;
80  if (amount_despill > 0.0f) {
81  output[screen_primary_channel] = pixelColor[screen_primary_channel] - amount_despill;
82  }
83 }
84 
85 } // namespace blender::compositor
MINLINE int max_axis_v3(const float vec[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
#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
Read Guarded memory(de)allocation.
#define output
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
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)