[Bf-blender-cvs] [e9616c82bd1] master: Cleanup: use constexpr for num channels.
Jeroen Bakker
noreply at git.blender.org
Wed Mar 31 11:10:34 CEST 2021
Commit: e9616c82bd10a5444478d4b86fa4a8dea2041f09
Author: Jeroen Bakker
Date: Wed Mar 31 09:24:14 2021 +0200
Branches: master
https://developer.blender.org/rBe9616c82bd10a5444478d4b86fa4a8dea2041f09
Cleanup: use constexpr for num channels.
Don't assume all compilers are smart. MSVC doesn't inline the call away like CLANG and GCC did.
===================================================================
M source/blender/compositor/COM_defines.h
M source/blender/compositor/operations/COM_BokehBlurOperation.cc
M source/blender/compositor/operations/COM_CompositorOperation.cc
M source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
M source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
M source/blender/compositor/operations/COM_GlareFogGlowOperation.cc
M source/blender/compositor/operations/COM_GlareGhostOperation.cc
M source/blender/compositor/operations/COM_InpaintOperation.cc
M source/blender/compositor/operations/COM_SunBeamsOperation.cc
M source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
M source/blender/compositor/operations/COM_VectorBlurOperation.cc
===================================================================
diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h
index 7e580f40d97..b8f10448030 100644
--- a/source/blender/compositor/COM_defines.h
+++ b/source/blender/compositor/COM_defines.h
@@ -49,6 +49,9 @@ constexpr int COM_data_type_num_channels(const DataType datatype)
}
}
+constexpr int COM_DATA_TYPE_VALUE_CHANNELS = COM_data_type_num_channels(DataType::Value);
+constexpr int COM_DATA_TYPE_COLOR_CHANNELS = COM_data_type_num_channels(DataType::Color);
+
/**
* \brief Possible quality settings
* \see CompositorContext.quality
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cc b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
index 46f3de820ef..3f98732b403 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
@@ -109,13 +109,12 @@ void BokehBlurOperation::executePixel(float output[4], int x, int y, void *data)
maxx = MIN2(maxx, input_rect.xmax);
int step = getStep();
- int offsetadd = getOffsetAdd() * COM_data_type_num_channels(DataType::Color);
+ int offsetadd = getOffsetAdd() * COM_DATA_TYPE_COLOR_CHANNELS;
float m = this->m_bokehDimension / pixelSize;
for (int ny = miny; ny < maxy; ny += step) {
- int bufferindex = ((minx - bufferstartx) * COM_data_type_num_channels(DataType::Color)) +
- ((ny - bufferstarty) * COM_data_type_num_channels(DataType::Color) *
- bufferwidth);
+ int bufferindex = ((minx - bufferstartx) * COM_DATA_TYPE_COLOR_CHANNELS) +
+ ((ny - bufferstarty) * COM_DATA_TYPE_COLOR_CHANNELS * bufferwidth);
for (int nx = minx; nx < maxx; nx += step) {
float u = this->m_bokehMidX - (nx - x) * m;
float v = this->m_bokehMidY - (ny - y) * m;
diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc b/source/blender/compositor/operations/COM_CompositorOperation.cc
index f35a63ac9a1..94d41b28f5d 100644
--- a/source/blender/compositor/operations/COM_CompositorOperation.cc
+++ b/source/blender/compositor/operations/COM_CompositorOperation.cc
@@ -151,7 +151,7 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/)
int y2 = rect->ymax;
int offset = (y1 * this->getWidth() + x1);
int add = (this->getWidth() - (x2 - x1));
- int offset4 = offset * COM_data_type_num_channels(DataType::Color);
+ int offset4 = offset * COM_DATA_TYPE_COLOR_CHANNELS;
int x;
int y;
bool breaked = false;
@@ -209,14 +209,14 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/)
this->m_depthInput->readSampled(color, input_x, input_y, PixelSampler::Nearest);
zbuffer[offset] = color[0];
- offset4 += COM_data_type_num_channels(DataType::Color);
+ offset4 += COM_DATA_TYPE_COLOR_CHANNELS;
offset++;
if (isBraked()) {
breaked = true;
}
}
offset += add;
- offset4 += add * COM_data_type_num_channels(DataType::Color);
+ offset4 += add * COM_DATA_TYPE_COLOR_CHANNELS;
}
}
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
index cd6bb3952bf..2be6e4d1be7 100644
--- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
@@ -90,18 +90,18 @@ void *FastGaussianBlurOperation::initializeTileData(rcti *rect)
this->m_sy = this->m_data.sizey * this->m_size / 2.0f;
if ((this->m_sx == this->m_sy) && (this->m_sx > 0.0f)) {
- for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
+ for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) {
IIR_gauss(copy, this->m_sx, c, 3);
}
}
else {
if (this->m_sx > 0.0f) {
- for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
+ for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) {
IIR_gauss(copy, this->m_sx, c, 1);
}
}
if (this->m_sy > 0.0f) {
- for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
+ for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) {
IIR_gauss(copy, this->m_sy, c, 2);
}
}
@@ -318,9 +318,8 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
- for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--,
- src += COM_data_type_num_channels(DataType::Value),
- dst += COM_data_type_num_channels(DataType::Value)) {
+ for (int i = copy->getWidth() * copy->getHeight(); i != 0;
+ i--, src += COM_DATA_TYPE_VALUE_CHANNELS, dst += COM_DATA_TYPE_VALUE_CHANNELS) {
if (*src < *dst) {
*dst = *src;
}
@@ -329,9 +328,8 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
- for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--,
- src += COM_data_type_num_channels(DataType::Value),
- dst += COM_data_type_num_channels(DataType::Value)) {
+ for (int i = copy->getWidth() * copy->getHeight(); i != 0;
+ i--, src += COM_DATA_TYPE_VALUE_CHANNELS, dst += COM_DATA_TYPE_VALUE_CHANNELS) {
if (*src > *dst) {
*dst = *src;
}
diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
index ac88ce0f894..b2c65ff2c96 100644
--- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
@@ -305,8 +305,7 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
int minyr = y - refrady < 0 ? -y : -refrady;
int maxyr = y + refrady > imgy ? imgy - y : refrady;
- float *srcd = buffer +
- COM_data_type_num_channels(DataType::Color) * ((y + minyr) * imgx + x + minxr);
+ float *srcd = buffer + COM_DATA_TYPE_COLOR_CHANNELS * ((y + minyr) * imgx + x + minxr);
gausstabx = m_maintabs[refradx - 1];
gausstabcentx = gausstabx + refradx;
@@ -314,9 +313,9 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
gausstabcenty = gausstaby + refrady;
sum = gval = rval = bval = aval = 0.0f;
- for (i = minyr; i < maxyr; i++, srcd += COM_data_type_num_channels(DataType::Color) * imgx) {
+ for (i = minyr; i < maxyr; i++, srcd += COM_DATA_TYPE_COLOR_CHANNELS * imgx) {
src = srcd;
- for (j = minxr; j < maxxr; j++, src += COM_data_type_num_channels(DataType::Color)) {
+ for (j = minxr; j < maxxr; j++, src += COM_DATA_TYPE_COLOR_CHANNELS) {
val = gausstabcenty[i] * gausstabcentx[j];
sum += val;
diff --git a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc
index 1e121c246f4..1c1eaebd331 100644
--- a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc
+++ b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc
@@ -273,8 +273,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
MemoryBuffer *rdst = new MemoryBuffer(DataType::Color, in1->get_rect());
memset(rdst->getBuffer(),
0,
- rdst->getWidth() * rdst->getHeight() * COM_data_type_num_channels(DataType::Color) *
- sizeof(float));
+ rdst->getWidth() * rdst->getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
// convolution result width & height
w2 = 2 * kernelWidth - 1;
@@ -290,7 +289,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// normalize convolutor
wt[0] = wt[1] = wt[2] = 0.0f;
for (y = 0; y < kernelHeight; y++) {
- colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_data_type_num_channels(DataType::Color)];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_DATA_TYPE_COLOR_CHANNELS];
for (x = 0; x < kernelWidth; x++) {
add_v3_v3(wt, colp[x]);
}
@@ -305,7 +304,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
wt[2] = 1.0f / wt[2];
}
for (y = 0; y < kernelHeight; y++) {
- colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_data_type_num_channels(DataType::Color)];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_DATA_TYPE_COLOR_CHANNELS];
for (x = 0; x < kernelWidth; x++) {
mul_v3_v3(colp[x], wt);
}
@@ -339,8 +338,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// in2, channel ch -> data1
for (y = 0; y < kernelHeight; y++) {
fp = &data1ch[y * w2];
- colp = (fRGB *)&kernelBuffer[y * kernelWidth *
- COM_data_type_num_channels(DataType::Color)];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_DATA_TYPE_COLOR_CHANNELS];
for (x = 0; x < kernelWidth; x++) {
fp[x] = colp[x][ch];
}
@@ -355,8 +353,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
continue;
}
fp = &data2[y * w2];
- colp =
- (fRGB *)&imageBuffer[yy * imageWidth * COM_data_type_num_channels(DataType::Color)];
+ colp = (fRGB *)&imageBuffer[yy * imageWidth * COM_DATA_TYPE_COLOR_CHANNELS];
for (x = 0; x < xbsz; x++) {
int xx = xbl * xbsz + x;
if (xx >= imageWidth) {
@@ -386,8 +383,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
continue;
}
fp = &data2[y * w2];
- colp = (fRGB *)&rdst
- ->getBuffer()[yy * imageWidth * COM_data_type_num_channels(DataType::Co
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list