diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-31 10:24:14 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-31 12:00:07 +0300 |
commit | e9616c82bd10a5444478d4b86fa4a8dea2041f09 (patch) | |
tree | e42bf8ef6212cb070576de6bf7d40d25e93411d6 /source | |
parent | 645fc0c7679423667eb25a77bbd8fb2626d71080 (diff) |
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.
Diffstat (limited to 'source')
11 files changed, 38 insertions, 47 deletions
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::Color)]; + colp = (fRGB *)&rdst->getBuffer()[yy * imageWidth * COM_DATA_TYPE_COLOR_CHANNELS]; for (x = 0; x < (int)w2; x++) { const int xx = xbl * xbsz + x - hw; if ((xx < 0) || (xx >= imageWidth)) { @@ -405,7 +401,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) MEM_freeN(data1); memcpy(dst, rdst->getBuffer(), - sizeof(float) * imageWidth * imageHeight * COM_data_type_num_channels(DataType::Color)); + sizeof(float) * imageWidth * imageHeight * COM_DATA_TYPE_COLOR_CHANNELS); delete (rdst); } diff --git a/source/blender/compositor/operations/COM_GlareGhostOperation.cc b/source/blender/compositor/operations/COM_GlareGhostOperation.cc index 7ba49c97244..22c8767632e 100644 --- a/source/blender/compositor/operations/COM_GlareGhostOperation.cc +++ b/source/blender/compositor/operations/COM_GlareGhostOperation.cc @@ -125,8 +125,7 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No memset(tbuf1.getBuffer(), 0, - tbuf1.getWidth() * tbuf1.getHeight() * COM_data_type_num_channels(DataType::Color) * - sizeof(float)); + tbuf1.getWidth() * tbuf1.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float)); for (n = 1; n < settings->iter && (!breaked); n++) { for (y = 0; y < gbuf.getHeight() && (!breaked); y++) { v = ((float)y + 0.5f) / (float)gbuf.getHeight(); @@ -150,13 +149,11 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No } memcpy(gbuf.getBuffer(), tbuf1.getBuffer(), - tbuf1.getWidth() * tbuf1.getHeight() * COM_data_type_num_channels(DataType::Color) * - sizeof(float)); + tbuf1.getWidth() * tbuf1.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float)); } memcpy(data, gbuf.getBuffer(), - gbuf.getWidth() * gbuf.getHeight() * COM_data_type_num_channels(DataType::Color) * - sizeof(float)); + gbuf.getWidth() * gbuf.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float)); } } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_InpaintOperation.cc b/source/blender/compositor/operations/COM_InpaintOperation.cc index 6b71d80b963..413ed2694a9 100644 --- a/source/blender/compositor/operations/COM_InpaintOperation.cc +++ b/source/blender/compositor/operations/COM_InpaintOperation.cc @@ -78,8 +78,8 @@ float *InpaintSimpleOperation::get_pixel(int x, int y) ASSERT_XY_RANGE(x, y); - return &this->m_cached_buffer[y * width * COM_data_type_num_channels(DataType::Color) + - x * COM_data_type_num_channels(DataType::Color)]; + return &this->m_cached_buffer[y * width * COM_DATA_TYPE_COLOR_CHANNELS + + x * COM_DATA_TYPE_COLOR_CHANNELS]; } int InpaintSimpleOperation::mdist(int x, int y) diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.cc b/source/blender/compositor/operations/COM_SunBeamsOperation.cc index 46fc716b2d7..839eeb9ff8f 100644 --- a/source/blender/compositor/operations/COM_SunBeamsOperation.cc +++ b/source/blender/compositor/operations/COM_SunBeamsOperation.cc @@ -140,8 +140,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator { falloff_factor = dist_max > dist_min ? dr / (float)(dist_max - dist_min) : 0.0f; - float *iter = input->getBuffer() + - COM_data_type_num_channels(DataType::Color) * (x + input->getWidth() * y); + float *iter = input->getBuffer() + COM_DATA_TYPE_COLOR_CHANNELS * (x + input->getWidth() * y); return iter; } @@ -170,7 +169,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator { if ((int)(co[0] - source[0]) == 0 && (int)(co[1] - source[1]) == 0) { copy_v4_v4(output, - input->getBuffer() + COM_data_type_num_channels(DataType::Color) * + input->getBuffer() + COM_DATA_TYPE_COLOR_CHANNELS * ((int)source[0] + input->getWidth() * (int)source[1])); return; } @@ -211,7 +210,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator { /* decrement u */ x -= fxu; y -= fyu; - buffer -= (fxu + fyu * buffer_width) * COM_data_type_num_channels(DataType::Color); + buffer -= (fxu + fyu * buffer_width) * COM_DATA_TYPE_COLOR_CHANNELS; /* decrement v (in steps of dv < 1) */ v_local -= dv; @@ -220,7 +219,7 @@ template<int fxu, int fxv, int fyu, int fyv> struct BufferLineAccumulator { x -= fxv; y -= fyv; - buffer -= (fxv + fyv * buffer_width) * COM_data_type_num_channels(DataType::Color); + buffer -= (fxv + fyv * buffer_width) * COM_DATA_TYPE_COLOR_CHANNELS; } } diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc index f61074a44d9..19cd5a53084 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc @@ -137,14 +137,14 @@ void VariableSizeBokehBlurOperation::executePixel(float output[4], int x, int y, const int addXStepValue = QualityStepHelper::getStep(); const int addYStepValue = addXStepValue; - const int addXStepColor = addXStepValue * COM_data_type_num_channels(DataType::Color); + const int addXStepColor = addXStepValue * COM_DATA_TYPE_COLOR_CHANNELS; if (size_center > this->m_threshold) { for (int ny = miny; ny < maxy; ny += addYStepValue) { float dy = ny - y; int offsetValueNy = ny * inputSizeBuffer->getWidth(); int offsetValueNxNy = offsetValueNy + (minx); - int offsetColorNxNy = offsetValueNxNy * COM_data_type_num_channels(DataType::Color); + int offsetColorNxNy = offsetValueNxNy * COM_DATA_TYPE_COLOR_CHANNELS; for (int nx = minx; nx < maxx; nx += addXStepValue) { if (nx != x || ny != y) { float size = MIN2(inputSizeFloatBuffer[offsetValueNxNy] * scalar, size_center); diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cc b/source/blender/compositor/operations/COM_VectorBlurOperation.cc index fb810dd4673..fd64bda156b 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.cc +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cc @@ -71,7 +71,7 @@ void VectorBlurOperation::initExecution() void VectorBlurOperation::executePixel(float output[4], int x, int y, void *data) { float *buffer = (float *)data; - int index = (y * this->getWidth() + x) * COM_data_type_num_channels(DataType::Color); + int index = (y * this->getWidth() + x) * COM_DATA_TYPE_COLOR_CHANNELS; copy_v4_v4(output, &buffer[index]); } |