From e343f7f3201eac6318fbcb55330a0b746f5fea03 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 10 Jul 2012 06:31:16 +0000 Subject: Inline the read Memory Buffer functions for speed optimizations. --- .../blender/compositor/intern/COM_MemoryBuffer.cpp | 55 +----------------- .../blender/compositor/intern/COM_MemoryBuffer.h | 66 ++++++++++++++++++++-- 2 files changed, 61 insertions(+), 60 deletions(-) (limited to 'source/blender/compositor') diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index 8dd1e55274f..223c582d999 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -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::copyContentFrom(MemoryBuffer *otherBuffer) } } -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,44 +136,6 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4]) } } -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 diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 63b41aeddde..3d3a40d8fba 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -28,10 +28,12 @@ class MemoryBuffer; #include "COM_ExecutionGroup.h" #include "BLI_rect.h" #include "COM_MemoryProxy.h" -extern "C" { - #include "BLI_threads.h" -} -#include +#include "BLI_math.h" + +//extern "C" { +// #include "BLI_threads.h" +//} +//#include /** * @brief state of a memory buffer @@ -124,10 +126,62 @@ public: 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); /** -- cgit v1.2.3