[Bf-blender-cvs] [5897c67] blender-tiles: First implementation of the samplers. Refactored the read methods from the buffers to wpecialized classes. these classes can be optimized locally.
Jeroen Bakker
noreply at git.blender.org
Mon Jul 14 23:03:16 CEST 2014
Commit: 5897c6799c3ae48e2e3a5d2e3f22a884b8f04f01
Author: Jeroen Bakker
Date: Mon Jul 14 23:01:35 2014 +0200
https://developer.blender.org/rB5897c6799c3ae48e2e3a5d2e3f22a884b8f04f01
First implementation of the samplers. Refactored the read methods from the buffers to wpecialized classes.
these classes can be optimized locally.
next step: remove the read methods from the buffer. they should al go through the samplers of the buffers
===================================================================
M source/blender/compositor/CMakeLists.txt
M source/blender/compositor/intern/COM_MemoryBuffer.cpp
M source/blender/compositor/intern/COM_MemoryBuffer.h
M source/blender/compositor/intern/COM_MemoryBufferColor.cpp
M source/blender/compositor/intern/COM_MemoryBufferColor.h
M source/blender/compositor/intern/COM_MemoryBufferValue.cpp
M source/blender/compositor/intern/COM_MemoryBufferValue.h
M source/blender/compositor/intern/COM_MemoryBufferVector.cpp
M source/blender/compositor/intern/COM_MemoryBufferVector.h
A source/blender/compositor/intern/COM_Sampler.cpp
A source/blender/compositor/intern/COM_Sampler.h
===================================================================
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 3a300fa..6ff0d19 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -80,6 +80,8 @@ set(SRC
intern/COM_MemoryBufferVector.h
intern/COM_MemoryBufferValue.cpp
intern/COM_MemoryBufferValue.h
+ intern/COM_Sampler.cpp
+ intern/COM_Sampler.h
intern/COM_WorkScheduler.cpp
intern/COM_WorkScheduler.h
intern/COM_Tile.cpp
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
index 05e8a0d..55c819f 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
@@ -192,6 +192,7 @@ float MemoryBuffer::getMaximumValue(rcti *rect)
MemoryBuffer::~MemoryBuffer()
{
+ this->deinit_samplers();
if (this->m_buffer) {
MEM_freeN(this->m_buffer);
this->m_buffer = NULL;
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index 8eddcb9..60dee84 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -119,6 +119,7 @@ protected:
* @param num_channels Number of channels that must be allocated for every pixel
*/
MemoryBuffer(DataType datatype, rcti *rect, unsigned int num_channels);
+
public:
/**
* @brief factory method for the constructor, selecting the right subclass
@@ -191,7 +192,9 @@ public:
}
}
- virtual void read(float *result, int x, int y,
+ virtual void init_samplers() {}
+ virtual void deinit_samplers() {}
+ virtual void read(float *result, int x, int y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP) = 0;
diff --git a/source/blender/compositor/intern/COM_MemoryBufferColor.cpp b/source/blender/compositor/intern/COM_MemoryBufferColor.cpp
index 1513e2a..6bbe56c 100644
--- a/source/blender/compositor/intern/COM_MemoryBufferColor.cpp
+++ b/source/blender/compositor/intern/COM_MemoryBufferColor.cpp
@@ -27,17 +27,32 @@
MemoryBufferColor::MemoryBufferColor(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect):
MemoryBuffer(memoryProxy, chunkNumber, rect, NUMBER_OF_CHANNELS)
{
+ this->init_samplers();
+
}
MemoryBufferColor::MemoryBufferColor(MemoryProxy *memoryProxy, rcti *rect) :
MemoryBuffer(memoryProxy, rect, NUMBER_OF_CHANNELS)
{
+ this->init_samplers();
}
MemoryBufferColor::MemoryBufferColor(DataType datatype, rcti *rect) :
MemoryBuffer(datatype, rect, NUMBER_OF_CHANNELS) {
+ this->init_samplers();
+}
+
+void MemoryBufferColor::init_samplers() {
+ this->m_sampler_nearest = new SamplerNearestColor(this);
+ this->m_sampler_nocheck = new SamplerNearestNoCheckColor(this);
+ this->m_sampler_bilinear = new SamplerBilinearColor(this);
}
+void MemoryBufferColor::deinit_samplers() {
+ delete this->m_sampler_nearest;
+ delete this->m_sampler_nocheck;
+ delete this->m_sampler_bilinear;
+}
MemoryBuffer *MemoryBufferColor::duplicate()
{
@@ -69,79 +84,24 @@ void MemoryBufferColor::addPixel(int x, int y, const float *color)
// --- SAMPLERS ---
inline void MemoryBufferColor::read(float *result, int x, int y,
- MemoryBufferExtend extend_x,
- MemoryBufferExtend extend_y)
+ MemoryBufferExtend extend_x,
+ MemoryBufferExtend extend_y)
{
- bool clip_x = (extend_x == COM_MB_CLIP && (x < m_rect.xmin || x >= m_rect.xmax));
- bool clip_y = (extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax));
- if (clip_x || clip_y) {
- /* clip result outside rect is zero */
- zero_v4(result);
- }
- else
- {
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * NUMBER_OF_CHANNELS;
- copy_v4_v4(result, &this->m_buffer[offset]);
- }
+ this->m_sampler_nearest->read(result, x, y, extend_x, extend_y);
}
inline void MemoryBufferColor::readNoCheck(float *result, int x, int y,
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y)
{
-
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * NUMBER_OF_CHANNELS;
-
- BLI_assert(offset >= 0);
- BLI_assert(offset < this->determineBufferSize() * NUMBER_OF_CHANNELS);
- BLI_assert(!(extend_x == COM_MB_CLIP && (x < m_rect.xmin || x >= m_rect.xmax)) &&
- !(extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax)));
-
- copy_v4_v4(result, &this->m_buffer[offset]);
+ this->m_sampler_nocheck->read(result, x, y, extend_x, extend_y);
}
inline void MemoryBufferColor::readBilinear(float *result, float x, float y,
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y)
{
- int x1 = floor(x);
- int y1 = floor(y);
- int x2 = x1 + 1;
- int y2 = y1 + 1;
- wrap_pixel(x1, y1, extend_x, extend_y);
- wrap_pixel(x2, y2, extend_x, extend_y);
-
- 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;
+ this->m_sampler_bilinear->read(result, x, y, extend_x, extend_y);
}
// --- EWA Filtering ---
diff --git a/source/blender/compositor/intern/COM_MemoryBufferColor.h b/source/blender/compositor/intern/COM_MemoryBufferColor.h
index 9195d08..b2b78a5 100644
--- a/source/blender/compositor/intern/COM_MemoryBufferColor.h
+++ b/source/blender/compositor/intern/COM_MemoryBufferColor.h
@@ -26,9 +26,15 @@ class MemoryBufferColor;
#define _COM_MemoryBufferColor_h_
#include "COM_MemoryBuffer.h"
+#include "COM_Sampler.h"
class MemoryBufferColor: MemoryBuffer
{
+private:
+ SamplerNearestColor *m_sampler_nearest;
+ SamplerNearestNoCheckColor *m_sampler_nocheck;
+ SamplerBilinearColor *m_sampler_bilinear;
+
protected:
/**
* @brief construct new MemoryBuffer for a chunk
@@ -41,7 +47,11 @@ protected:
MemoryBufferColor(MemoryProxy *memoryProxy, rcti *rect);
MemoryBufferColor(DataType datatype, rcti *rect);
+
+
public:
+ void init_samplers();
+ void deinit_samplers();
void writePixel(int x, int y, const float *color);
void addPixel(int x, int y, const float *color);
void read(float *result, int x, int y,
diff --git a/source/blender/compositor/intern/COM_MemoryBufferValue.cpp b/source/blender/compositor/intern/COM_MemoryBufferValue.cpp
index 0aff4c0..8672f11 100644
--- a/source/blender/compositor/intern/COM_MemoryBufferValue.cpp
+++ b/source/blender/compositor/intern/COM_MemoryBufferValue.cpp
@@ -27,15 +27,18 @@
MemoryBufferValue::MemoryBufferValue(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect):
MemoryBuffer(memoryProxy, chunkNumber, rect, NUMBER_OF_CHANNELS)
{
+ this->init_samplers();
}
MemoryBufferValue::MemoryBufferValue(MemoryProxy *memoryProxy, rcti *rect) :
MemoryBuffer(memoryProxy, rect, NUMBER_OF_CHANNELS)
{
+ this->init_samplers();
}
MemoryBufferValue::MemoryBufferValue(DataType datatype, rcti *rect) :
MemoryBuffer(datatype, rect, NUMBER_OF_CHANNELS) {
+ this->init_samplers();
}
MemoryBuffer *MemoryBufferValue::duplicate()
@@ -72,65 +75,34 @@ inline void MemoryBufferValue::read(float *result, int x, int y,
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y)
{
- bool clip_x = (extend_x == COM_MB_CLIP && (x < m_rect.xmin || x >= m_rect.xmax));
- bool clip_y = (extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax));
- if (clip_x || clip_y) {
- /* clip result outside rect is zero */
- zero_v4(result);
- }
- else
- {
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * NUMBER_OF_CHANNELS;
- result[0] = this->m_buffer[offset];
- }
+ this->m_sampler_nearest->read(result, x, y, extend_x, extend_y);
}
+void MemoryBufferValue::init_samplers() {
+ this->m_sampler_nearest = new SamplerNearestValue(this);
+ this->m_sampler_nocheck = new SamplerNearestNoCheckValue(this);
+ this->m_sampler_bilinear = new SamplerBilinearValue(this);
+}
+
+void MemoryBufferValue::deinit_samplers() {
+ delete this->m_sampler_nearest;
+ delete this->m_sampler_nocheck;
+ delete this->m_sampler_bilinear;
+}
+
+
inline void MemoryBufferValue::readNoCheck(float *result, int x, int y,
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y)
{
-
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * NUMBER_OF_CHANNELS;
-
- BLI_assert(offset >= 0);
- BLI_assert(offset < this->determineBufferSize() * NUMBER_OF_CHANNELS);
- BLI_assert(!(extend_x == COM_MB_CLIP && (x < m_rect.xmin || x >= m_rect.xmax)) &&
- !(extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax)));
-
- result[0] = this->m_buffer[offset];
+ this->m_sampler_nocheck->read(result, x, y, extend_x, extend_y);
}
inline void MemoryBufferValue::readBilinear(float *result, float x, float y,
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y)
{
- int x1 = floor(x);
- int y1 = floor(y);
- int x2 = x1 + 1;
- int y2 = y1 + 1;
- wrap_pixel(x1, y1, extend_x, extend_y);
- wrap_pixel(x2, y2, extend_x, extend_y);
-
- float valuex = x - x1;
- float valuey = y - y1;
- float mvaluex = 1.0f - valuex;
- float mvaluey = 1.0f - valuey;
-
- float value1;
- float value2;
- float value3;
- float value4;
-
- read(&value1, x1, y1);
- r
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list