diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2012-07-10 10:31:16 +0400 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2012-07-10 10:31:16 +0400 |
commit | e343f7f3201eac6318fbcb55330a0b746f5fea03 (patch) | |
tree | de9f8a25793a3674128a42596a42066d4c2abad3 /source/blender/compositor/intern/COM_MemoryBuffer.h | |
parent | bbbdcaa462f1737edee58f66610231ccb4009d35 (diff) |
Inline the read Memory Buffer functions for speed optimizations.
Diffstat (limited to 'source/blender/compositor/intern/COM_MemoryBuffer.h')
-rw-r--r-- | source/blender/compositor/intern/COM_MemoryBuffer.h | 66 |
1 files changed, 60 insertions, 6 deletions
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 <vector> +#include "BLI_math.h" + +//extern "C" { +// #include "BLI_threads.h" +//} +//#include <vector> /** * @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); /** |