Blender  V2.93
COM_CalculateMeanOperation.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 #include "BLI_utildefines.h"
22 
23 #include "IMB_colormanagement.h"
24 
25 namespace blender::compositor {
26 
28 {
31  this->m_imageReader = nullptr;
32  this->m_iscalculated = false;
33  this->m_setting = 1;
34  this->flags.complex = true;
35 }
37 {
38  this->m_imageReader = this->getInputSocketReader(0);
39  this->m_iscalculated = false;
41 }
42 
43 void CalculateMeanOperation::executePixel(float output[4], int /*x*/, int /*y*/, void * /*data*/)
44 {
45  output[0] = this->m_result;
46 }
47 
49 {
50  this->m_imageReader = nullptr;
52 }
53 
55  ReadBufferOperation *readOperation,
56  rcti *output)
57 {
58  rcti imageInput;
59  if (this->m_iscalculated) {
60  return false;
61  }
62  NodeOperation *operation = getInputOperation(0);
63  imageInput.xmax = operation->getWidth();
64  imageInput.xmin = 0;
65  imageInput.ymax = operation->getHeight();
66  imageInput.ymin = 0;
67  if (operation->determineDependingAreaOfInterest(&imageInput, readOperation, output)) {
68  return true;
69  }
70  return false;
71 }
72 
74 {
75  lockMutex();
76  if (!this->m_iscalculated) {
78  calculateMean(tile);
79  this->m_iscalculated = true;
80  }
81  unlockMutex();
82  return nullptr;
83 }
84 
86 {
87  this->m_result = 0.0f;
88  float *buffer = tile->getBuffer();
89  int size = tile->getWidth() * tile->getHeight();
90  int pixels = 0;
91  float sum = 0.0f;
92  for (int i = 0, offset = 0; i < size; i++, offset += 4) {
93  if (buffer[offset + 3] > 0) {
94  pixels++;
95 
96  switch (this->m_setting) {
97  case 1: {
99  break;
100  }
101  case 2: {
102  sum += buffer[offset];
103  break;
104  }
105  case 3: {
106  sum += buffer[offset + 1];
107  break;
108  }
109  case 4: {
110  sum += buffer[offset + 2];
111  break;
112  }
113  case 5: {
114  float yuv[3];
115  rgb_to_yuv(buffer[offset],
116  buffer[offset + 1],
117  buffer[offset + 2],
118  &yuv[0],
119  &yuv[1],
120  &yuv[2],
122  sum += yuv[0];
123  break;
124  }
125  }
126  }
127  }
128  this->m_result = sum / pixels;
129 }
130 
131 } // namespace blender::compositor
#define BLI_YUV_ITU_BT709
void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
Definition: math_color.c:79
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define output
static T sum(const btAlignedObjectArray< T > &items)
SocketReader * m_imageReader
Cached reference to the reader.
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void executePixel(float output[4], int x, int y, void *data) override
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 addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@ None
The bottom left of the input image is the bottom left of the working area of the node,...
__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