Blender  V2.93
COM_MapRangeOperation.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 
19 #include "COM_MapRangeOperation.h"
20 
21 namespace blender::compositor {
22 
24 {
31  this->m_inputOperation = nullptr;
32  this->m_useClamp = false;
33 }
34 
36 {
37  this->m_inputOperation = this->getInputSocketReader(0);
38  this->m_sourceMinOperation = this->getInputSocketReader(1);
39  this->m_sourceMaxOperation = this->getInputSocketReader(2);
40  this->m_destMinOperation = this->getInputSocketReader(3);
41  this->m_destMaxOperation = this->getInputSocketReader(4);
42 }
43 
44 /* The code below assumes all data is inside range +- this, and that input buffer is single channel
45  */
46 #define BLENDER_ZMAX 10000.0f
47 
49  float x,
50  float y,
51  PixelSampler sampler)
52 {
53  float inputs[8]; /* includes the 5 inputs + 3 pads */
54  float value;
55  float source_min, source_max;
56  float dest_min, dest_max;
57 
58  this->m_inputOperation->readSampled(inputs, x, y, sampler);
59  this->m_sourceMinOperation->readSampled(inputs + 1, x, y, sampler);
60  this->m_sourceMaxOperation->readSampled(inputs + 2, x, y, sampler);
61  this->m_destMinOperation->readSampled(inputs + 3, x, y, sampler);
62  this->m_destMaxOperation->readSampled(inputs + 4, x, y, sampler);
63 
64  value = inputs[0];
65  source_min = inputs[1];
66  source_max = inputs[2];
67  dest_min = inputs[3];
68  dest_max = inputs[4];
69 
70  if (fabsf(source_max - source_min) < 1e-6f) {
71  output[0] = 0.0f;
72  return;
73  }
74 
75  if (value >= -BLENDER_ZMAX && value <= BLENDER_ZMAX) {
76  value = (value - source_min) / (source_max - source_min);
77  value = dest_min + value * (dest_max - dest_min);
78  }
79  else if (value > BLENDER_ZMAX) {
80  value = dest_max;
81  }
82  else {
83  value = dest_min;
84  }
85 
86  if (this->m_useClamp) {
87  if (dest_max > dest_min) {
88  CLAMP(value, dest_min, dest_max);
89  }
90  else {
91  CLAMP(value, dest_max, dest_min);
92  }
93  }
94 
95  output[0] = value;
96 }
97 
99 {
100  this->m_inputOperation = nullptr;
101  this->m_sourceMinOperation = nullptr;
102  this->m_sourceMaxOperation = nullptr;
103  this->m_destMinOperation = nullptr;
104  this->m_destMaxOperation = nullptr;
105 }
106 
107 } // namespace blender::compositor
#define BLENDER_ZMAX
_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
Group RGB to Bright Vector Camera CLAMP
#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)
static bNodeSocketTemplate inputs[]