[Bf-blender-cvs] [a9e64d8613c] master: Cleanup: Use uint8_t for num of channels.

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


Commit: a9e64d8613cc9f1286cece0e963562e57f48e233
Author: Jeroen Bakker
Date:   Fri Mar 19 17:11:40 2021 +0100
Branches: master
https://developer.blender.org/rBa9e64d8613cc9f1286cece0e963562e57f48e233

Cleanup: Use uint8_t for num of channels.

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

M	source/blender/compositor/intern/COM_MemoryBuffer.h
M	source/blender/compositor/intern/COM_OpenCLDevice.cc
M	source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
M	source/blender/compositor/operations/COM_WriteBufferOperation.cc

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

diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index dea4328d76d..6f719b61122 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -81,7 +81,7 @@ class MemoryBuffer {
    * \brief the number of channels of a single value in the buffer.
    * For value buffers this is 1, vector 3 and color 4
    */
-  unsigned int m_num_channels;
+  uint8_t m_num_channels;
 
  public:
   /**
@@ -104,7 +104,7 @@ class MemoryBuffer {
    */
   ~MemoryBuffer();
 
-  unsigned int get_num_channels()
+  uint8_t get_num_channels()
   {
     return this->m_num_channels;
   }
diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cc b/source/blender/compositor/intern/COM_OpenCLDevice.cc
index d5aed2052ac..9a6012e5c68 100644
--- a/source/blender/compositor/intern/COM_OpenCLDevice.cc
+++ b/source/blender/compositor/intern/COM_OpenCLDevice.cc
@@ -93,19 +93,21 @@ cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
 
 const cl_image_format *OpenCLDevice::determineImageFormat(MemoryBuffer *memoryBuffer)
 {
-  const cl_image_format *imageFormat;
-  int num_channels = memoryBuffer->get_num_channels();
-  if (num_channels == 1) {
-    imageFormat = &IMAGE_FORMAT_VALUE;
-  }
-  else if (num_channels == 3) {
-    imageFormat = &IMAGE_FORMAT_VECTOR;
-  }
-  else {
-    imageFormat = &IMAGE_FORMAT_COLOR;
+  switch (memoryBuffer->get_num_channels()) {
+    case 1:
+      return &IMAGE_FORMAT_VALUE;
+      break;
+    case 3:
+      return &IMAGE_FORMAT_VECTOR;
+      break;
+    case 4:
+      return &IMAGE_FORMAT_COLOR;
+      break;
+    default:
+      BLI_assert(!"Unsupported num_channels.");
   }
 
-  return imageFormat;
+  return &IMAGE_FORMAT_COLOR;
 }
 
 cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
index 922d6a859a3..4dded61fba5 100644
--- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc
@@ -122,7 +122,7 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src,
   unsigned int x, y, sz;
   unsigned int i;
   float *buffer = src->getBuffer();
-  const unsigned int num_channels = src->get_num_channels();
+  const uint8_t num_channels = src->get_num_channels();
 
   // <0.5 not valid, though can have a possibly useful sort of sharpening effect
   if (sigma < 0.5f) {
diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cc b/source/blender/compositor/operations/COM_WriteBufferOperation.cc
index e2d5c4de4cb..e426bc76ef3 100644
--- a/source/blender/compositor/operations/COM_WriteBufferOperation.cc
+++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cc
@@ -60,7 +60,7 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/
 {
   MemoryBuffer *memoryBuffer = this->m_memoryProxy->getBuffer();
   float *buffer = memoryBuffer->getBuffer();
-  const int num_channels = memoryBuffer->get_num_channels();
+  const uint8_t num_channels = memoryBuffer->get_num_channels();
   if (this->m_input->isComplex()) {
     void *data = this->m_input->initializeTileData(rect);
     int x1 = rect->xmin;



More information about the Bf-blender-cvs mailing list