Blender
V2.93
source
blender
compositor
operations
COM_CalculateStandardDeviationOperation.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
19
#include "
COM_CalculateStandardDeviationOperation.h
"
20
#include "
BLI_math.h
"
21
#include "
BLI_utildefines.h
"
22
23
#include "
IMB_colormanagement.h
"
24
25
namespace
blender::compositor
{
26
27
void
CalculateStandardDeviationOperation::executePixel
(
float
output
[4],
28
int
/*x*/
,
29
int
/*y*/
,
30
void
*
/*data*/
)
31
{
32
output
[0] = this->
m_standardDeviation
;
33
}
34
35
void
*
CalculateStandardDeviationOperation::initializeTileData
(
rcti
*rect)
36
{
37
lockMutex
();
38
if
(!this->
m_iscalculated
) {
39
MemoryBuffer
*tile = (
MemoryBuffer
*)this->
m_imageReader
->
initializeTileData
(rect);
40
CalculateMeanOperation::calculateMean
(tile);
41
this->
m_standardDeviation
= 0.0f;
42
float
*
buffer
= tile->
getBuffer
();
43
int
size
= tile->
getWidth
() * tile->
getHeight
();
44
int
pixels = 0;
45
float
sum
= 0.0f;
46
float
mean = this->
m_result
;
47
for
(
int
i = 0, offset = 0; i <
size
; i++, offset += 4) {
48
if
(
buffer
[offset + 3] > 0) {
49
pixels++;
50
51
switch
(this->
m_setting
) {
52
case
1:
/* rgb combined */
53
{
54
float
value =
IMB_colormanagement_get_luminance
(&
buffer
[offset]);
55
sum
+= (value - mean) * (value - mean);
56
break
;
57
}
58
case
2:
/* red */
59
{
60
float
value =
buffer
[offset];
61
sum
+= (value - mean) * (value - mean);
62
break
;
63
}
64
case
3:
/* green */
65
{
66
float
value =
buffer
[offset + 1];
67
sum
+= (value - mean) * (value - mean);
68
break
;
69
}
70
case
4:
/* blue */
71
{
72
float
value =
buffer
[offset + 2];
73
sum
+= (value - mean) * (value - mean);
74
break
;
75
}
76
case
5:
/* luminance */
77
{
78
float
yuv[3];
79
rgb_to_yuv
(
buffer
[offset],
80
buffer
[offset + 1],
81
buffer
[offset + 2],
82
&yuv[0],
83
&yuv[1],
84
&yuv[2],
85
BLI_YUV_ITU_BT709
);
86
sum
+= (yuv[0] - mean) * (yuv[0] - mean);
87
break
;
88
}
89
}
90
}
91
}
92
this->
m_standardDeviation
=
sqrt
(sum / (
float
)(pixels - 1));
93
this->
m_iscalculated
=
true
;
94
}
95
unlockMutex
();
96
return
nullptr
;
97
}
98
99
}
// namespace blender::compositor
sqrt
sqrt(x)+1/max(0
BLI_math.h
BLI_YUV_ITU_BT709
#define BLI_YUV_ITU_BT709
Definition:
BLI_math_color.h:41
rgb_to_yuv
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_utildefines.h
COM_CalculateStandardDeviationOperation.h
IMB_colormanagement.h
IMB_colormanagement_get_luminance
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
Definition:
colormanagement_inline.c:41
size
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition:
btDbvt.cpp:52
output
#define output
sum
static T sum(const btAlignedObjectArray< T > &items)
Definition:
btSoftBodyHelpers.cpp:94
blender::compositor::CalculateMeanOperation::m_result
float m_result
Definition:
COM_CalculateMeanOperation.h:38
blender::compositor::CalculateMeanOperation::m_imageReader
SocketReader * m_imageReader
Cached reference to the reader.
Definition:
COM_CalculateMeanOperation.h:35
blender::compositor::CalculateMeanOperation::m_setting
int m_setting
Definition:
COM_CalculateMeanOperation.h:39
blender::compositor::CalculateMeanOperation::m_iscalculated
bool m_iscalculated
Definition:
COM_CalculateMeanOperation.h:37
blender::compositor::CalculateMeanOperation::calculateMean
void calculateMean(MemoryBuffer *tile)
Definition:
COM_CalculateMeanOperation.cc:85
blender::compositor::CalculateStandardDeviationOperation::executePixel
void executePixel(float output[4], int x, int y, void *data) override
Definition:
COM_CalculateStandardDeviationOperation.cc:27
blender::compositor::CalculateStandardDeviationOperation::m_standardDeviation
float m_standardDeviation
Definition:
COM_CalculateStandardDeviationOperation.h:34
blender::compositor::CalculateStandardDeviationOperation::initializeTileData
void * initializeTileData(rcti *rect) override
Definition:
COM_CalculateStandardDeviationOperation.cc:35
blender::compositor::MemoryBuffer
a MemoryBuffer contains access to the data of a chunk
Definition:
COM_MemoryBuffer.h:52
blender::compositor::MemoryBuffer::getHeight
const int getHeight() const
get the height of this MemoryBuffer
Definition:
COM_MemoryBuffer.h:310
blender::compositor::MemoryBuffer::getWidth
const int getWidth() const
get the width of this MemoryBuffer
Definition:
COM_MemoryBuffer.h:302
blender::compositor::MemoryBuffer::getBuffer
float * getBuffer()
get the data of this MemoryBuffer
Definition:
COM_MemoryBuffer.h:115
blender::compositor::NodeOperation::initializeTileData
virtual void * initializeTileData(rcti *)
Definition:
COM_NodeOperation.h:517
blender::compositor::NodeOperation::lockMutex
void lockMutex()
Definition:
COM_NodeOperation.cc:111
blender::compositor::NodeOperation::unlockMutex
void unlockMutex()
Definition:
COM_NodeOperation.cc:116
buffer
__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
Definition:
kernel_split_function.h:33
blender::compositor
Definition:
COM_defines.h:21
rcti
Definition:
DNA_vec_types.h:78
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1