Blender  V2.93
COM_NormalizeOperation.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_NormalizeOperation.h"
20 
21 namespace blender::compositor {
22 
24 {
27  this->m_imageReader = nullptr;
28  this->m_cachedInstance = nullptr;
29  this->flags.complex = true;
30 }
32 {
33  this->m_imageReader = this->getInputSocketReader(0);
35 }
36 
37 void NormalizeOperation::executePixel(float output[4], int x, int y, void *data)
38 {
39  /* using generic two floats struct to store x: min y: mult */
40  NodeTwoFloats *minmult = (NodeTwoFloats *)data;
41 
42  this->m_imageReader->read(output, x, y, nullptr);
43 
44  output[0] = (output[0] - minmult->x) * minmult->y;
45 
46  /* clamp infinities */
47  if (output[0] > 1.0f) {
48  output[0] = 1.0f;
49  }
50  else if (output[0] < 0.0f) {
51  output[0] = 0.0f;
52  }
53 }
54 
56 {
57  this->m_imageReader = nullptr;
58  delete this->m_cachedInstance;
60 }
61 
63  ReadBufferOperation *readOperation,
64  rcti *output)
65 {
66  rcti imageInput;
67  if (this->m_cachedInstance) {
68  return false;
69  }
70 
71  NodeOperation *operation = getInputOperation(0);
72  imageInput.xmax = operation->getWidth();
73  imageInput.xmin = 0;
74  imageInput.ymax = operation->getHeight();
75  imageInput.ymin = 0;
76 
77  if (operation->determineDependingAreaOfInterest(&imageInput, readOperation, output)) {
78  return true;
79  }
80  return false;
81 }
82 
83 /* The code below assumes all data is inside range +- this, and that input buffer is single channel
84  */
85 #define BLENDER_ZMAX 10000.0f
86 
88 {
89  lockMutex();
90  if (this->m_cachedInstance == nullptr) {
92  /* using generic two floats struct to store x: min y: mult */
93  NodeTwoFloats *minmult = new NodeTwoFloats();
94 
95  float *buffer = tile->getBuffer();
96  int p = tile->getWidth() * tile->getHeight();
97  float *bc = buffer;
98 
99  float minv = 1.0f + BLENDER_ZMAX;
100  float maxv = -1.0f - BLENDER_ZMAX;
101 
102  float value;
103  while (p--) {
104  value = bc[0];
105  if ((value > maxv) && (value <= BLENDER_ZMAX)) {
106  maxv = value;
107  }
108  if ((value < minv) && (value >= -BLENDER_ZMAX)) {
109  minv = value;
110  }
111  bc++;
112  }
113 
114  minmult->x = minv;
115  /* The rare case of flat buffer would cause a divide by 0 */
116  minmult->y = ((maxv != minv) ? 1.0f / (maxv - minv) : 0.0f);
117 
118  this->m_cachedInstance = minmult;
119  }
120 
121  unlockMutex();
122  return this->m_cachedInstance;
123 }
124 
125 void NormalizeOperation::deinitializeTileData(rcti * /*rect*/, void * /*data*/)
126 {
127  /* pass */
128 }
129 
130 } // namespace blender::compositor
#define BLENDER_ZMAX
struct NodeTwoFloats NodeTwoFloats
_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
a MemoryBuffer contains access to the data of a chunk
const int getHeight() const
get the height of this MemoryBuffer
const int getWidth() const
get the width of this MemoryBuffer
float * getBuffer()
get the data of this MemoryBuffer
NodeOperation contains calculation logic.
virtual void * initializeTileData(rcti *)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
void read(float result[4], int x, int y, void *chunkData)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
void executePixel(float output[4], int x, int y, void *data) override
SocketReader * m_imageReader
Cached reference to the reader.
void deinitializeTileData(rcti *rect, void *data) override
NodeTwoFloats * m_cachedInstance
temporarily cache of the execution storage it stores x->min and y->mult
void * initializeTileData(rcti *rect) override
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79