[Bf-blender-cvs] [31d5c5078c5] master: Cleanup: MemoryBuffer do not store width and height.

Jeroen Bakker noreply at git.blender.org
Fri Mar 19 17:18:40 CET 2021


Commit: 31d5c5078c5ac67b334c0567a03314f2da524e1d
Author: Jeroen Bakker
Date:   Fri Mar 19 16:45:29 2021 +0100
Branches: master
https://developer.blender.org/rB31d5c5078c5ac67b334c0567a03314f2da524e1d

Cleanup: MemoryBuffer do not store width and height.

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

M	source/blender/compositor/intern/COM_MemoryBuffer.cc
M	source/blender/compositor/intern/COM_MemoryBuffer.h
M	source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc

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

diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index b812659543b..4c80472c4de 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -33,30 +33,14 @@ static unsigned int determine_num_channels(DataType datatype)
   }
 }
 
-unsigned int MemoryBuffer::determineBufferSize()
-{
-  return getWidth() * getHeight();
-}
-
-int MemoryBuffer::getWidth() const
-{
-  return this->m_width;
-}
-int MemoryBuffer::getHeight() const
-{
-  return this->m_height;
-}
-
 MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, const rcti &rect)
 {
   m_rect = rect;
-  this->m_width = BLI_rcti_size_x(&this->m_rect);
-  this->m_height = BLI_rcti_size_y(&this->m_rect);
   this->m_memoryProxy = memoryProxy;
   this->m_chunkNumber = chunkNumber;
   this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
   this->m_buffer = (float *)MEM_mallocN_aligned(
-      sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
+      sizeof(float) * buffer_len() * this->m_num_channels, 16, "COM_MemoryBuffer");
   this->m_state = COM_MB_ALLOCATED;
   this->m_datatype = memoryProxy->getDataType();
 }
@@ -64,13 +48,11 @@ MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, c
 MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, const rcti &rect)
 {
   m_rect = rect;
-  this->m_width = BLI_rcti_size_x(&this->m_rect);
-  this->m_height = BLI_rcti_size_y(&this->m_rect);
   this->m_memoryProxy = memoryProxy;
   this->m_chunkNumber = -1;
   this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
   this->m_buffer = (float *)MEM_mallocN_aligned(
-      sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
+      sizeof(float) * buffer_len() * this->m_num_channels, 16, "COM_MemoryBuffer");
   this->m_state = COM_MB_TEMPORARILY;
   this->m_datatype = memoryProxy->getDataType();
 }
@@ -78,37 +60,29 @@ MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, const rcti &rect)
 MemoryBuffer::MemoryBuffer(DataType dataType, const rcti &rect)
 {
   m_rect = rect;
-  this->m_width = BLI_rcti_size_x(&this->m_rect);
-  this->m_height = BLI_rcti_size_y(&this->m_rect);
-  this->m_height = this->m_rect.ymax - this->m_rect.ymin;
   this->m_memoryProxy = nullptr;
   this->m_chunkNumber = -1;
   this->m_num_channels = determine_num_channels(dataType);
   this->m_buffer = (float *)MEM_mallocN_aligned(
-      sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
+      sizeof(float) * buffer_len() * this->m_num_channels, 16, "COM_MemoryBuffer");
   this->m_state = COM_MB_TEMPORARILY;
   this->m_datatype = dataType;
 }
 
 MemoryBuffer::MemoryBuffer(const MemoryBuffer &src) : MemoryBuffer(src.m_memoryProxy, src.m_rect)
 {
-  memcpy(m_buffer, src.m_buffer, determineBufferSize() * m_num_channels * sizeof(float));
+  memcpy(m_buffer, src.m_buffer, buffer_len() * m_num_channels * sizeof(float));
 }
 
-// MemoryBuffer *MemoryBuffer::duplicate()
-// {
-//   return new MemoryBuffer(*this);
-// }
-
 void MemoryBuffer::clear()
 {
-  memset(this->m_buffer, 0, this->determineBufferSize() * this->m_num_channels * sizeof(float));
+  memset(this->m_buffer, 0, this->buffer_len() * this->m_num_channels * sizeof(float));
 }
 
-float MemoryBuffer::getMaximumValue()
+float MemoryBuffer::get_max_value() const
 {
   float result = this->m_buffer[0];
-  const unsigned int size = this->determineBufferSize();
+  const unsigned int size = this->buffer_len();
   unsigned int i;
 
   const float *fp_src = this->m_buffer;
@@ -123,17 +97,17 @@ float MemoryBuffer::getMaximumValue()
   return result;
 }
 
-float MemoryBuffer::getMaximumValue(rcti *rect)
+float MemoryBuffer::get_max_value(const rcti &rect) const
 {
   rcti rect_clamp;
 
   /* first clamp the rect by the bounds or we get un-initialized values */
-  BLI_rcti_isect(rect, &this->m_rect, &rect_clamp);
+  BLI_rcti_isect(&rect, &this->m_rect, &rect_clamp);
 
   if (!BLI_rcti_is_empty(&rect_clamp)) {
     MemoryBuffer temp_buffer(this->m_datatype, rect_clamp);
     temp_buffer.fill_from(*this);
-    return temp_buffer.getMaximumValue();
+    return temp_buffer.get_max_value();
   }
 
   BLI_assert(0);
@@ -159,9 +133,9 @@ void MemoryBuffer::fill_from(const MemoryBuffer &src)
   int otherOffset;
 
   for (otherY = minY; otherY < maxY; otherY++) {
-    otherOffset = ((otherY - src.m_rect.ymin) * src.m_width + minX - src.m_rect.xmin) *
+    otherOffset = ((otherY - src.m_rect.ymin) * src.getWidth() + minX - src.m_rect.xmin) *
                   this->m_num_channels;
-    offset = ((otherY - this->m_rect.ymin) * this->m_width + minX - this->m_rect.xmin) *
+    offset = ((otherY - this->m_rect.ymin) * getWidth() + minX - this->m_rect.xmin) *
              this->m_num_channels;
     memcpy(&this->m_buffer[offset],
            &src.m_buffer[otherOffset],
@@ -173,7 +147,7 @@ void MemoryBuffer::writePixel(int x, int y, const float color[4])
 {
   if (x >= this->m_rect.xmin && x < this->m_rect.xmax && y >= this->m_rect.ymin &&
       y < this->m_rect.ymax) {
-    const int offset = (this->m_width * (y - this->m_rect.ymin) + x - this->m_rect.xmin) *
+    const int offset = (getWidth() * (y - this->m_rect.ymin) + x - this->m_rect.xmin) *
                        this->m_num_channels;
     memcpy(&this->m_buffer[offset], color, sizeof(float) * this->m_num_channels);
   }
@@ -183,7 +157,7 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4])
 {
   if (x >= this->m_rect.xmin && x < this->m_rect.xmax && y >= this->m_rect.ymin &&
       y < this->m_rect.ymax) {
-    const int offset = (this->m_width * (y - this->m_rect.ymin) + x - this->m_rect.xmin) *
+    const int offset = (getWidth() * (y - this->m_rect.ymin) + x - this->m_rect.xmin) *
                        this->m_num_channels;
     float *dst = &this->m_buffer[offset];
     const float *src = color;
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index bc6306754e0..fb17167505a 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -91,9 +91,6 @@ class MemoryBuffer {
    */
   unsigned int m_num_channels;
 
-  int m_width;
-  int m_height;
-
  public:
   /**
    * \brief construct new MemoryBuffer for a chunk
@@ -152,8 +149,8 @@ class MemoryBuffer {
 
   inline void wrap_pixel(int &x, int &y, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
   {
-    int w = this->m_width;
-    int h = this->m_height;
+    const int w = getWidth();
+    const int h = getHeight();
     x = x - m_rect.xmin;
     y = y - m_rect.ymin;
 
@@ -195,8 +192,8 @@ class MemoryBuffer {
                          MemoryBufferExtend extend_x,
                          MemoryBufferExtend extend_y)
   {
-    float w = (float)this->m_width;
-    float h = (float)this->m_height;
+    const float w = (float)getWidth();
+    const float h = (float)getHeight();
     x = x - m_rect.xmin;
     y = y - m_rect.ymin;
 
@@ -249,7 +246,7 @@ class MemoryBuffer {
       int u = x;
       int v = y;
       this->wrap_pixel(u, v, extend_x, extend_y);
-      const int offset = (this->m_width * y + x) * this->m_num_channels;
+      const int offset = (getWidth() * y + x) * this->m_num_channels;
       float *buffer = &this->m_buffer[offset];
       memcpy(result, buffer, sizeof(float) * this->m_num_channels);
     }
@@ -265,10 +262,10 @@ class MemoryBuffer {
     int v = y;
 
     this->wrap_pixel(u, v, extend_x, extend_y);
-    const int offset = (this->m_width * v + u) * this->m_num_channels;
+    const int offset = (getWidth() * v + u) * this->m_num_channels;
 
     BLI_assert(offset >= 0);
-    BLI_assert(offset < this->determineBufferSize() * this->m_num_channels);
+    BLI_assert(offset < this->buffer_len() * this->m_num_channels);
     BLI_assert(!(extend_x == COM_MB_CLIP && (u < m_rect.xmin || u >= m_rect.xmax)) &&
                !(extend_y == COM_MB_CLIP && (v < m_rect.ymin || v >= m_rect.ymax)));
     float *buffer = &this->m_buffer[offset];
@@ -286,15 +283,15 @@ class MemoryBuffer {
     float u = x;
     float v = y;
     this->wrap_pixel(u, v, extend_x, extend_y);
-    if ((extend_x != COM_MB_REPEAT && (u < 0.0f || u >= this->m_width)) ||
-        (extend_y != COM_MB_REPEAT && (v < 0.0f || v >= this->m_height))) {
+    if ((extend_x != COM_MB_REPEAT && (u < 0.0f || u >= getWidth())) ||
+        (extend_y != COM_MB_REPEAT && (v < 0.0f || v >= getHeight()))) {
       copy_vn_fl(result, this->m_num_channels, 0.0f);
       return;
     }
     BLI_bilinear_interpolation_wrap_fl(this->m_buffer,
                                        result,
-                                       this->m_width,
-                                       this->m_height,
+                                       getWidth(),
+                                       getHeight(),
                                        this->m_num_channels,
                                        u,
                                        v,
@@ -332,23 +329,32 @@ class MemoryBuffer {
   /**
    * \brief get the width of this MemoryBuffer
    */
-  int getWidth() const;
+  const int getWidth() const
+  {
+    return BLI_rcti_size_x(&m_rect);
+  }
 
   /**
    * \brief get the height of this MemoryBuffer
    */
-  int getHeight() const;
+  const int getHeight() const
+  {
+    return BLI_rcti_size_y(&m_rect);
+  }
 
   /**
    * \brief clear the buffer. Make all pixels black transparent.
    */
   void clear();
 
-  float getMaximumValue();
-  float getMaximumValue(rcti *rect);
+  float get_max_value() const;
+  float get_max_value(const rcti &rect) const;
 
  private:
-  unsigned int determineBufferSize();
+  const int buffer_len() const
+  {
+    return getWidth() * getHeight();
+  }
 
 #ifdef WITH_CXX_GUARDEDALLOC
   MEM_CXX_CLASS_ALLOC_FUNCS("COM:MemoryBuffer")
diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
index a002a853bd4..ea33f3cd7

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list