[Bf-blender-cvs] [88e0ed32888] master: Cleanup: Use constexpr.

Jeroen Bakker noreply at git.blender.org
Tue Mar 30 16:06:23 CEST 2021


Commit: 88e0ed32888f4a87ec1192e3b54aebe8686e029c
Author: Jeroen Bakker
Date:   Tue Mar 30 14:12:41 2021 +0200
Branches: master
https://developer.blender.org/rB88e0ed32888f4a87ec1192e3b54aebe8686e029c

Cleanup: Use constexpr.

===================================================================

M	source/blender/compositor/COM_defines.h
M	source/blender/compositor/intern/COM_MemoryBuffer.cc
M	source/blender/compositor/intern/COM_compositor.cc
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 66da43eda89..7e580f40d97 100644
--- a/source/blender/compositor/COM_defines.h
+++ b/source/blender/compositor/COM_defines.h
@@ -33,6 +33,22 @@ enum class DataType {
   Color = 2,
 };
 
+/**
+ * Utility to get the number of channels of the given data type.
+ */
+constexpr int COM_data_type_num_channels(const DataType datatype)
+{
+  switch (datatype) {
+    case DataType::Value:
+      return 1;
+    case DataType::Vector:
+      return 3;
+    case DataType::Color:
+    default:
+      return 4;
+  }
+}
+
 /**
  * \brief Possible quality settings
  * \see CompositorContext.quality
@@ -63,7 +79,6 @@ enum class CompositorPriority {
 // configurable items
 
 // chunk size determination
-#define COM_PREVIEW_SIZE 140.0f
 // #define COM_DEBUG
 
 // chunk order
@@ -84,12 +99,8 @@ enum class ChunkOrdering {
   Default = ChunkOrdering::CenterOut,
 };
 
-#define COM_RULE_OF_THIRDS_DIVIDER 100.0f
-
-#define COM_NUM_CHANNELS_VALUE 1
-#define COM_NUM_CHANNELS_VECTOR 3
-#define COM_NUM_CHANNELS_COLOR 4
-
-#define COM_BLUR_BOKEH_PIXELS 512
+constexpr float COM_PREVIEW_SIZE = 140.f;
+constexpr float COM_RULE_OF_THIRDS_DIVIDER = 100.0f;
+constexpr float COM_BLUR_BOKEH_PIXELS = 512;
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index 241e0c66aeb..d9694169ab8 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -22,24 +22,12 @@
 
 namespace blender::compositor {
 
-static unsigned int determine_num_channels(DataType datatype)
-{
-  switch (datatype) {
-    case DataType::Value:
-      return COM_NUM_CHANNELS_VALUE;
-    case DataType::Vector:
-      return COM_NUM_CHANNELS_VECTOR;
-    case DataType::Color:
-    default:
-      return COM_NUM_CHANNELS_COLOR;
-  }
-}
 
 MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, const rcti &rect, MemoryBufferState state)
 {
   m_rect = rect;
   this->m_memoryProxy = memoryProxy;
-  this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
+  this->m_num_channels = COM_data_type_num_channels(memoryProxy->getDataType());
   this->m_buffer = (float *)MEM_mallocN_aligned(
       sizeof(float) * buffer_len() * this->m_num_channels, 16, "COM_MemoryBuffer");
   this->m_state = state;
@@ -50,7 +38,7 @@ MemoryBuffer::MemoryBuffer(DataType dataType, const rcti &rect)
 {
   m_rect = rect;
   this->m_memoryProxy = nullptr;
-  this->m_num_channels = determine_num_channels(dataType);
+  this->m_num_channels = COM_data_type_num_channels(dataType);
   this->m_buffer = (float *)MEM_mallocN_aligned(
       sizeof(float) * buffer_len() * this->m_num_channels, 16, "COM_MemoryBuffer");
   this->m_state = MemoryBufferState::Temporary;
diff --git a/source/blender/compositor/intern/COM_compositor.cc b/source/blender/compositor/intern/COM_compositor.cc
index 3aa711c6594..5839f53976b 100644
--- a/source/blender/compositor/intern/COM_compositor.cc
+++ b/source/blender/compositor/intern/COM_compositor.cc
@@ -46,12 +46,12 @@ static void compositor_init_node_previews(const RenderData *render_data, bNodeTr
                            1.0f;
   int preview_width, preview_height;
   if (aspect < 1.0f) {
-    preview_width = COM_PREVIEW_SIZE;
-    preview_height = (int)(COM_PREVIEW_SIZE * aspect);
+    preview_width = blender::compositor::COM_PREVIEW_SIZE;
+    preview_height = (int)(blender::compositor::COM_PREVIEW_SIZE * aspect);
   }
   else {
-    preview_width = (int)(COM_PREVIEW_SIZE / aspect);
-    preview_height = COM_PREVIEW_SIZE;
+    preview_width = (int)(blender::compositor::COM_PREVIEW_SIZE / aspect);
+    preview_height = blender::compositor::COM_PREVIEW_SIZE;
   }
   BKE_node_preview_init_tree(node_tree, preview_width, preview_height, false);
 }
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cc b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
index 8d331758377..46f3de820ef 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
@@ -109,12 +109,13 @@ 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_NUM_CHANNELS_COLOR;
+    int offsetadd = getOffsetAdd() * COM_data_type_num_channels(DataType::Color);
 
     float m = this->m_bokehDimension / pixelSize;
     for (int ny = miny; ny < maxy; ny += step) {
-      int bufferindex = ((minx - bufferstartx) * COM_NUM_CHANNELS_COLOR) +
-                        ((ny - bufferstarty) * COM_NUM_CHANNELS_COLOR * bufferwidth);
+      int bufferindex = ((minx - bufferstartx) * COM_data_type_num_channels(DataType::Color)) +
+                        ((ny - bufferstarty) * COM_data_type_num_channels(DataType::Color) *
+                         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 f70b5cc9dad..f35a63ac9a1 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_NUM_CHANNELS_COLOR;
+  int offset4 = offset * COM_data_type_num_channels(DataType::Color);
   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_NUM_CHANNELS_COLOR;
+      offset4 += COM_data_type_num_channels(DataType::Color);
       offset++;
       if (isBraked()) {
         breaked = true;
       }
     }
     offset += add;
-    offset4 += add * COM_NUM_CHANNELS_COLOR;
+    offset4 += add * COM_data_type_num_channels(DataType::Color);
   }
 }
 
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
index 6f2ac73d251..cd6bb3952bf 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_NUM_CHANNELS_COLOR; c++) {
+      for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
         IIR_gauss(copy, this->m_sx, c, 3);
       }
     }
     else {
       if (this->m_sx > 0.0f) {
-        for (c = 0; c < COM_NUM_CHANNELS_COLOR; c++) {
+        for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
           IIR_gauss(copy, this->m_sx, c, 1);
         }
       }
       if (this->m_sy > 0.0f) {
-        for (c = 0; c < COM_NUM_CHANNELS_COLOR; c++) {
+        for (c = 0; c < COM_data_type_num_channels(DataType::Color); c++) {
           IIR_gauss(copy, this->m_sy, c, 2);
         }
       }
@@ -318,8 +318,9 @@ 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_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
+      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)) {
         if (*src < *dst) {
           *dst = *src;
         }
@@ -328,8 +329,9 @@ 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_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
+      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)) {
         if (*src > *dst) {
           *dst = *src;
         }
diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
index 7e86b26bfd9..ac88ce0f894 100644
--- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc
@@ -305,7 +305,8 @@ 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_NUM_CHANNELS_COLOR * ((y + minyr) * imgx + x + minxr);
+    float *srcd = buffer +
+                  COM_data_type_num_channels(DataType::Color) * ((y + minyr) * imgx + x + minxr);
 
     gausstabx = m_maintabs[refradx - 1];
     gausstabcentx = gausstabx + refradx;
@@ -313,9 +314,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_NUM_CHANNELS_COLOR * imgx) {
+    for (i = minyr; i < maxyr; i++, srcd += COM_data_type_num_channels(DataType::Color) * imgx) {
       src = srcd;
-      for (j 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list