Revision: 48788
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48788
Author:   jbakker
Date:     2012-07-10 06:31:16 +0000 (Tue, 10 Jul 2012)
Log Message:
-----------
Inline the read Memory Buffer functions for speed optimizations.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_threads.h
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h

Modified: trunk/blender/source/blender/blenlib/BLI_threads.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_threads.h  2012-07-10 05:16:43 UTC 
(rev 48787)
+++ trunk/blender/source/blender/blenlib/BLI_threads.h  2012-07-10 06:31:16 UTC 
(rev 48788)
@@ -31,6 +31,9 @@
 /** \file BLI_threads.h
  *  \ingroup bli
  */
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #include <pthread.h>
 
@@ -139,5 +142,9 @@
 void BLI_thread_queue_wait_finish(ThreadQueue *queue);
 void BLI_thread_queue_nowait(ThreadQueue *queue);
 
+#ifdef __cplusplus
+}
 #endif
 
+#endif
+

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp 
2012-07-10 05:16:43 UTC (rev 48787)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp 
2012-07-10 06:31:16 UTC (rev 48788)
@@ -22,8 +22,7 @@
 
 #include "COM_MemoryBuffer.h"
 #include "MEM_guardedalloc.h"
-#include "BLI_math.h"
-#include "BKE_global.h"
+//#include "BKE_global.h"
 
 unsigned int MemoryBuffer::determineBufferSize()
 {
@@ -117,20 +116,6 @@
        }
 }
 
-void MemoryBuffer::read(float result[4], int x, int y)
-{
-       if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
-           y >= this->m_rect.ymin && y < this->m_rect.ymax)
-       {
-               const int dx = x - this->m_rect.xmin;
-               const int dy = y - this->m_rect.ymin;
-               const int offset = (this->m_chunkWidth * dy + dx) * 
COM_NUMBER_OF_CHANNELS;
-               copy_v4_v4(result, &this->m_buffer[offset]);
-       }
-       else {
-               zero_v4(result);
-       }
-}
 void MemoryBuffer::writePixel(int x, int y, const float color[4])
 {
        if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
@@ -151,45 +136,7 @@
        }
 }
 
-void MemoryBuffer::readCubic(float result[4], float x, float y)
-{
-       int x1 = floor(x);
-       int x2 = x1 + 1;
-       int y1 = floor(y);
-       int y2 = y1 + 1;
-       
-       float valuex = x - x1;
-       float valuey = y - y1;
-       float mvaluex = 1.0f - valuex;
-       float mvaluey = 1.0f - valuey;
-       
-       float color1[4];
-       float color2[4];
-       float color3[4];
-       float color4[4];
-       
-       read(color1, x1, y1);
-       read(color2, x1, y2);
-       read(color3, x2, y1);
-       read(color4, x2, y2);
-       
-       color1[0] = color1[0] * mvaluey + color2[0] * valuey;
-       color1[1] = color1[1] * mvaluey + color2[1] * valuey;
-       color1[2] = color1[2] * mvaluey + color2[2] * valuey;
-       color1[3] = color1[3] * mvaluey + color2[3] * valuey;
 
-       color3[0] = color3[0] * mvaluey + color4[0] * valuey;
-       color3[1] = color3[1] * mvaluey + color4[1] * valuey;
-       color3[2] = color3[2] * mvaluey + color4[2] * valuey;
-       color3[3] = color3[3] * mvaluey + color4[3] * valuey;
-
-       result[0] = color1[0] * mvaluex + color3[0] * valuex;
-       result[1] = color1[1] * mvaluex + color3[1] * valuex;
-       result[2] = color1[2] * mvaluex + color3[2] * valuex;
-       result[3] = color1[3] * mvaluex + color3[3] * valuex;
-}
-
-
 // table of (exp(ar) - exp(a)) / (1 - exp(a)) for r in range [0, 1] and a = -2
 // used instead of actual gaussian, otherwise at high texture magnifications 
circular artifacts are visible
 #define EWA_MAXIDX 255

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h   
2012-07-10 05:16:43 UTC (rev 48787)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h   
2012-07-10 06:31:16 UTC (rev 48788)
@@ -28,11 +28,13 @@
 #include "COM_ExecutionGroup.h"
 #include "BLI_rect.h"
 #include "COM_MemoryProxy.h"
-extern "C" {
-       #include "BLI_threads.h"
-}
-#include <vector>
+#include "BLI_math.h"
 
+//extern "C" {
+//     #include "BLI_threads.h"
+//}
+//#include <vector>
+
 /**
  * @brief state of a memory buffer
  * @ingroup Memory
@@ -124,10 +126,62 @@
                this->m_state = COM_MB_AVAILABLE;
        }
        
-       void read(float result[4], int x, int y);
+       inline void read(float result[4], int x, int y)  {
+               if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
+                   y >= this->m_rect.ymin && y < this->m_rect.ymax)
+               {
+                       const int dx = x - this->m_rect.xmin;
+                       const int dy = y - this->m_rect.ymin;
+                       const int offset = (this->m_chunkWidth * dy + dx) * 
COM_NUMBER_OF_CHANNELS;
+                       copy_v4_v4(result, &this->m_buffer[offset]);
+               }
+               else {
+                       zero_v4(result);
+               }
+       }
+
        void writePixel(int x, int y, const float color[4]);
        void addPixel(int x, int y, const float color[4]);
-       void readCubic(float result[4], float x, float y);
+       inline void readCubic(float result[4], float x, float y)
+               {
+                       int x1 = floor(x);
+                       int x2 = x1 + 1;
+                       int y1 = floor(y);
+                       int y2 = y1 + 1;
+                       
+                       float valuex = x - x1;
+                       float valuey = y - y1;
+                       float mvaluex = 1.0f - valuex;
+                       float mvaluey = 1.0f - valuey;
+                       
+                       float color1[4];
+                       float color2[4];
+                       float color3[4];
+                       float color4[4];
+                       
+                       read(color1, x1, y1);
+                       read(color2, x1, y2);
+                       read(color3, x2, y1);
+                       read(color4, x2, y2);
+                       
+                       color1[0] = color1[0] * mvaluey + color2[0] * valuey;
+                       color1[1] = color1[1] * mvaluey + color2[1] * valuey;
+                       color1[2] = color1[2] * mvaluey + color2[2] * valuey;
+                       color1[3] = color1[3] * mvaluey + color2[3] * valuey;
+               
+                       color3[0] = color3[0] * mvaluey + color4[0] * valuey;
+                       color3[1] = color3[1] * mvaluey + color4[1] * valuey;
+                       color3[2] = color3[2] * mvaluey + color4[2] * valuey;
+                       color3[3] = color3[3] * mvaluey + color4[3] * valuey;
+               
+                       result[0] = color1[0] * mvaluex + color3[0] * valuex;
+                       result[1] = color1[1] * mvaluex + color3[1] * valuex;
+                       result[2] = color1[2] * mvaluex + color3[2] * valuex;
+                       result[3] = color1[3] * mvaluex + color3[3] * valuex;
+               }
+               
+
+
        void readEWA(float result[4], float fx, float fy, float dx, float dy);
        
        /**

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to