Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2015-01-19 20:13:26 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2015-01-19 20:17:50 +0300
commit35d3b6316b21ad9ae7eb96a7a541c4051eae3441 (patch)
treedd4eea63f9229d87041e2f5a5679d05f1360afea /source
parenta8fa291b8c539da7669463ef622d5c61ee9c90e7 (diff)
D627: Memory usage optimization for the compositor.
The compostor used a fixed size of 4 floats to hold pixel data. this patch will select size of a pixel based on its type. It uses 1 float for Value, 3 float for vector and 4 floats for color data types. When benchmarking on shots (opening shot of caminandes) we get a reduction of memory of 30% and a tiny speedup as less data transformations needs to take place (but these are negligable. More information of the patch can be found on https://developer.blender.org/D627 and http://wiki.blender.org/index.php/Dev:Ref/Proposals/Compositor2014_p1.1_TD Developers: jbakker & mdewanchand Thanks for Sergey for his indept review.
Diffstat (limited to 'source')
-rw-r--r--source/blender/compositor/CMakeLists.txt2
-rw-r--r--source/blender/compositor/COM_defines.h4
-rw-r--r--source/blender/compositor/intern/COM_ChannelInfo.cpp35
-rw-r--r--source/blender/compositor/intern/COM_ChannelInfo.h121
-rw-r--r--source/blender/compositor/intern/COM_ExecutionSystem.cpp16
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.cpp91
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.h139
-rw-r--r--source/blender/compositor/intern/COM_MemoryProxy.cpp3
-rw-r--r--source/blender/compositor/intern/COM_MemoryProxy.h9
-rw-r--r--source/blender/compositor/intern/COM_NodeOperationBuilder.cpp8
-rw-r--r--source/blender/compositor/intern/COM_OpenCLDevice.cpp34
-rw-r--r--source/blender/compositor/intern/COM_OpenCLDevice.h6
-rw-r--r--source/blender/compositor/intern/COM_WorkScheduler.cpp2
-rw-r--r--source/blender/compositor/nodes/COM_SocketProxyNode.cpp5
-rw-r--r--source/blender/compositor/nodes/COM_TranslateNode.cpp4
-rw-r--r--source/blender/compositor/operations/COM_AntiAliasOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_BokehBlurOperation.cpp4
-rw-r--r--source/blender/compositor/operations/COM_CompositorOperation.cpp6
-rw-r--r--source/blender/compositor/operations/COM_ConvertOperation.cpp20
-rw-r--r--source/blender/compositor/operations/COM_DilateErodeOperation.cpp25
-rw-r--r--source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp6
-rw-r--r--source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp25
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp7
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp4
-rw-r--r--source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp6
-rw-r--r--source/blender/compositor/operations/COM_GlareBaseOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp18
-rw-r--r--source/blender/compositor/operations/COM_GlareGhostOperation.cpp6
-rw-r--r--source/blender/compositor/operations/COM_GlareStreaksOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_InpaintOperation.cpp4
-rw-r--r--source/blender/compositor/operations/COM_KeyingBlurOperation.cpp4
-rw-r--r--source/blender/compositor/operations/COM_KeyingClipOperation.cpp4
-rw-r--r--source/blender/compositor/operations/COM_MapUVOperation.cpp10
-rw-r--r--source/blender/compositor/operations/COM_NormalizeOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_QualityStepHelper.cpp6
-rw-r--r--source/blender/compositor/operations/COM_ReadBufferOperation.cpp21
-rw-r--r--source/blender/compositor/operations/COM_ReadBufferOperation.h3
-rw-r--r--source/blender/compositor/operations/COM_RenderLayersProg.cpp49
-rw-r--r--source/blender/compositor/operations/COM_SetVectorOperation.cpp1
-rw-r--r--source/blender/compositor/operations/COM_SunBeamsOperation.cpp8
-rw-r--r--source/blender/compositor/operations/COM_TextureOperation.cpp18
-rw-r--r--source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp29
-rw-r--r--source/blender/compositor/operations/COM_VectorBlurOperation.cpp6
-rw-r--r--source/blender/compositor/operations/COM_VectorCurveOperation.cpp1
-rw-r--r--source/blender/compositor/operations/COM_WrapOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_WrapOperation.h2
-rw-r--r--source/blender/compositor/operations/COM_WriteBufferOperation.cpp22
-rw-r--r--source/blender/compositor/operations/COM_WriteBufferOperation.h2
48 files changed, 364 insertions, 442 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 4bcdd4d9e34..048c974423f 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -90,8 +90,6 @@ set(SRC
intern/COM_OpenCLDevice.h
intern/COM_CompositorContext.cpp
intern/COM_CompositorContext.h
- intern/COM_ChannelInfo.cpp
- intern/COM_ChannelInfo.h
intern/COM_SingleThreadedOperation.cpp
intern/COM_SingleThreadedOperation.h
intern/COM_Debug.cpp
diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h
index b60fffc6a22..9936914d3d8 100644
--- a/source/blender/compositor/COM_defines.h
+++ b/source/blender/compositor/COM_defines.h
@@ -105,7 +105,9 @@ typedef enum OrderOfChunks {
#define COM_RULE_OF_THIRDS_DIVIDER 100.0f
-#define COM_NUMBER_OF_CHANNELS 4
+#define COM_NUM_CHANNELS_VALUE 1
+#define COM_NUM_CHANNELS_VECTOR 3
+#define COM_NUM_CHANNELS_COLOR 4
#define COM_BLUR_BOKEH_PIXELS 512
diff --git a/source/blender/compositor/intern/COM_ChannelInfo.cpp b/source/blender/compositor/intern/COM_ChannelInfo.cpp
deleted file mode 100644
index 557075cdc80..00000000000
--- a/source/blender/compositor/intern/COM_ChannelInfo.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2011, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor:
- * Jeroen Bakker
- * Monique Dewanchand
- */
-
-#include "COM_ChannelInfo.h"
-#include "COM_defines.h"
-#include <stdio.h>
-
-/**
- * @brief create new ChannelInfo instance and sets the defaults.
- */
-ChannelInfo::ChannelInfo()
-{
- this->m_number = 0;
- this->m_premultiplied = true;
- this->m_type = COM_CT_UNUSED;
-}
diff --git a/source/blender/compositor/intern/COM_ChannelInfo.h b/source/blender/compositor/intern/COM_ChannelInfo.h
deleted file mode 100644
index ec78e7e1cb1..00000000000
--- a/source/blender/compositor/intern/COM_ChannelInfo.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2011, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor:
- * Jeroen Bakker
- * Monique Dewanchand
- */
-
-#ifndef _COM_ChannelInfo_h
-#define _COM_ChannelInfo_h
-
-#include <vector>
-#include "BKE_text.h"
-#include <string>
-#include "DNA_node_types.h"
-#include "BLI_rect.h"
-
-using namespace std;
-
-/**
- * @brief List of possible channel types
- * @ingroup Model
- */
-typedef enum ChannelType {
- COM_CT_ColorComponent /** @brief this channel is contains color information. Specific used is determined by channelnumber, and in the future color space */,
- COM_CT_Alpha /** @brief this channel is contains transparency value */,
- COM_CT_Value /** @brief this channel is contains a value */,
- COM_CT_X /** @brief this channel is contains a X value */,
- COM_CT_Y /** @brief this channel is contains a Y value */,
- COM_CT_Z /** @brief this channel is contains a Z value */,
- COM_CT_W /** @brief this channel is contains a W value */,
- COM_CT_UNUSED /** @brief this channel is unused */
-} ChannelType;
-
-/**
- * @brief ChannelInfo holds information about a channel.
- *
- * Channels are transported from node to node via a NodeLink.
- * ChannelInfo holds specific setting of these channels in order that the to-node of the link
- * Can handle specific logic per channel setting.
- *
- * @note currently this is not used, but a future place to implement color spacing and other things.
- * @ingroup Model
- */
-class ChannelInfo {
-private:
- /**
- * @brief the channel number, in the link. [0-3]
- */
- int m_number;
-
- /**
- * @brief type of channel
- */
- ChannelType m_type;
-
- /**
- * @brieg Is this value in this channel premultiplied with its alpha
- * @note only valid if type = ColorComponent;
- */
- bool m_premultiplied;
-
-// /**
-// * Color space of this value.
-// * only valid when type = ColorComponent;
-// */
-// string colorspacename;
-
-public:
- /**
- * @brief creates a new ChannelInfo and set default values
- */
- ChannelInfo();
-
- /**
- * @brief set the index of this channel in the NodeLink
- */
- void setNumber(const int number) { this->m_number = number; }
-
- /**
- * @brief get the index of this channel in the NodeLink
- */
- const int getNumber() const { return this->m_number; }
-
- /**
- * @brief set the type of channel
- */
- void setType(const ChannelType type) { this->m_type = type; }
-
- /**
- * @brief get the type of channel
- */
- const ChannelType getType() const { return this->m_type; }
-
- /**
- * @brief set the premultiplicatioin of this channel
- */
- void setPremultiplied(const bool premultiplied) { this->m_premultiplied = premultiplied; }
-
- /**
- * @brief is this channel premultiplied
- */
- const bool isPremultiplied() const { return this->m_premultiplied; }
-};
-
-
-#endif
diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cpp b/source/blender/compositor/intern/COM_ExecutionSystem.cpp
index 7c08188db90..0667271f4b1 100644
--- a/source/blender/compositor/intern/COM_ExecutionSystem.cpp
+++ b/source/blender/compositor/intern/COM_ExecutionSystem.cpp
@@ -137,11 +137,15 @@ void ExecutionSystem::execute()
}
unsigned int index;
+ // First allocale all write buffer
for (index = 0; index < this->m_operations.size(); index++) {
NodeOperation *operation = this->m_operations[index];
- operation->setbNodeTree(this->m_context.getbNodeTree());
- operation->initExecution();
+ if (operation->isWriteBufferOperation()) {
+ operation->setbNodeTree(this->m_context.getbNodeTree());
+ operation->initExecution();
+ }
}
+ // Connect read buffers to their write buffers
for (index = 0; index < this->m_operations.size(); index++) {
NodeOperation *operation = this->m_operations[index];
if (operation->isReadBufferOperation()) {
@@ -149,6 +153,14 @@ void ExecutionSystem::execute()
readOperation->updateMemoryBuffer();
}
}
+ // initialize other operations
+ for (index = 0; index < this->m_operations.size(); index++) {
+ NodeOperation *operation = this->m_operations[index];
+ if (!operation->isWriteBufferOperation()) {
+ operation->setbNodeTree(this->m_context.getbNodeTree());
+ operation->initExecution();
+ }
+ }
for (index = 0; index < this->m_groups.size(); index++) {
ExecutionGroup *executionGroup = this->m_groups[index];
executionGroup->setChunksize(this->m_context.getChunksize());
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
index c59ecced93c..58767960cc8 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp
@@ -27,6 +27,18 @@
using std::min;
using std::max;
+static unsigned int determine_num_channels(DataType datatype) {
+ switch (datatype) {
+ case COM_DT_VALUE:
+ return COM_NUM_CHANNELS_VALUE;
+ case COM_DT_VECTOR:
+ return COM_NUM_CHANNELS_VECTOR;
+ case COM_DT_COLOR:
+ default:
+ return COM_NUM_CHANNELS_COLOR;
+ }
+}
+
unsigned int MemoryBuffer::determineBufferSize()
{
return getWidth() * getHeight();
@@ -34,61 +46,62 @@ unsigned int MemoryBuffer::determineBufferSize()
int MemoryBuffer::getWidth() const
{
- return this->m_rect.xmax - this->m_rect.xmin;
+ return this->m_width;
}
int MemoryBuffer::getHeight() const
{
- return this->m_rect.ymax - this->m_rect.ymin;
+ return this->m_height;
}
MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect)
{
BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+ this->m_width = BLI_rcti_size_x(&this->m_rect);
+ this->m_height = BLI_rcti_size_y(&this->m_rect);
this->m_memoryProxy = memoryProxy;
this->m_chunkNumber = chunkNumber;
- this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, 16, "COM_MemoryBuffer");
+ this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
+ this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
this->m_state = COM_MB_ALLOCATED;
- this->m_datatype = COM_DT_COLOR;
- this->m_chunkWidth = this->m_rect.xmax - this->m_rect.xmin;
+ this->m_datatype = memoryProxy->getDataType();;
}
MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect)
{
BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+ this->m_width = BLI_rcti_size_x(&this->m_rect);
+ this->m_height = BLI_rcti_size_y(&this->m_rect);
this->m_memoryProxy = memoryProxy;
this->m_chunkNumber = -1;
- this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, 16, "COM_MemoryBuffer");
+ this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
+ this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
+ this->m_state = COM_MB_TEMPORARILY;
+ this->m_datatype = memoryProxy->getDataType();
+}
+MemoryBuffer::MemoryBuffer(DataType dataType, rcti *rect)
+{
+ BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+ this->m_width = BLI_rcti_size_x(&this->m_rect);
+ this->m_height = BLI_rcti_size_y(&this->m_rect);
+ this->m_height = this->m_rect.ymax - this->m_rect.ymin;
+ this->m_memoryProxy = NULL;
+ this->m_chunkNumber = -1;
+ this->m_num_channels = determine_num_channels(dataType);
+ this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
this->m_state = COM_MB_TEMPORARILY;
- this->m_datatype = COM_DT_COLOR;
- this->m_chunkWidth = this->m_rect.xmax - this->m_rect.xmin;
+ this->m_datatype = dataType;
}
MemoryBuffer *MemoryBuffer::duplicate()
{
MemoryBuffer *result = new MemoryBuffer(this->m_memoryProxy, &this->m_rect);
- memcpy(result->m_buffer, this->m_buffer, this->determineBufferSize() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ memcpy(result->m_buffer, this->m_buffer, this->determineBufferSize() * this->m_num_channels * sizeof(float));
return result;
}
void MemoryBuffer::clear()
{
- memset(this->m_buffer, 0, this->determineBufferSize() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ memset(this->m_buffer, 0, this->determineBufferSize() * this->m_num_channels * sizeof(float));
}
-float *MemoryBuffer::convertToValueBuffer()
-{
- const unsigned int size = this->determineBufferSize();
- unsigned int i;
-
- float *result = (float *)MEM_mallocN(sizeof(float) * size, __func__);
-
- const float *fp_src = this->m_buffer;
- float *fp_dst = result;
-
- for (i = 0; i < size; i++, fp_dst++, fp_src += COM_NUMBER_OF_CHANNELS) {
- *fp_dst = *fp_src;
- }
-
- return result;
-}
float MemoryBuffer::getMaximumValue()
{
@@ -98,7 +111,7 @@ float MemoryBuffer::getMaximumValue()
const float *fp_src = this->m_buffer;
- for (i = 0; i < size; i++, fp_src += COM_NUMBER_OF_CHANNELS) {
+ for (i = 0; i < size; i++, fp_src += this->m_num_channels) {
float value = *fp_src;
if (value > result) {
result = value;
@@ -116,7 +129,7 @@ float MemoryBuffer::getMaximumValue(rcti *rect)
BLI_rcti_isect(rect, &this->m_rect, &rect_clamp);
if (!BLI_rcti_is_empty(&rect_clamp)) {
- MemoryBuffer *temp = new MemoryBuffer(NULL, &rect_clamp);
+ MemoryBuffer *temp = new MemoryBuffer(this->m_datatype, &rect_clamp);
temp->copyContentFrom(this);
float result = temp->getMaximumValue();
delete temp;
@@ -152,9 +165,9 @@ void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer)
for (otherY = minY; otherY < maxY; otherY++) {
- otherOffset = ((otherY - otherBuffer->m_rect.ymin) * otherBuffer->m_chunkWidth + minX - otherBuffer->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
- offset = ((otherY - this->m_rect.ymin) * this->m_chunkWidth + minX - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
- memcpy(&this->m_buffer[offset], &otherBuffer->m_buffer[otherOffset], (maxX - minX) * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ otherOffset = ((otherY - otherBuffer->m_rect.ymin) * otherBuffer->m_width + minX - otherBuffer->m_rect.xmin) * this->m_num_channels;
+ offset = ((otherY - this->m_rect.ymin) * this->m_width + minX - this->m_rect.xmin) * this->m_num_channels;
+ memcpy(&this->m_buffer[offset], &otherBuffer->m_buffer[otherOffset], (maxX - minX) * this->m_num_channels * sizeof(float));
}
}
@@ -163,9 +176,8 @@ void MemoryBuffer::writePixel(int x, int y, const float color[4])
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
y >= this->m_rect.ymin && y < this->m_rect.ymax)
{
- const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
- copy_v4_v4(&this->m_buffer[offset], color);
- }
+ const int offset = (this->m_width * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * this->m_num_channels;
+ memcpy(&this->m_buffer[offset], color, sizeof(float)*this->m_num_channels); }
}
void MemoryBuffer::addPixel(int x, int y, const float color[4])
@@ -173,8 +185,12 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4])
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
y >= this->m_rect.ymin && y < this->m_rect.ymax)
{
- const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
- add_v4_v4(&this->m_buffer[offset], color);
+ const int offset = (this->m_width * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * this->m_num_channels;
+ float *dst = &this->m_buffer[offset];
+ const float *src = color;
+ for (int i = 0; i < this->m_num_channels ; i++, dst++, src++) {
+ *dst += *src;
+ }
}
}
@@ -208,8 +224,9 @@ static void read_ewa_pixel_sampled(void *userdata, int x, int y, float result[4]
}
}
-void MemoryBuffer::readEWA(float result[4], const float uv[2], const float derivatives[2][2], PixelSampler sampler)
+void MemoryBuffer::readEWA(float *result, const float uv[2], const float derivatives[2][2], PixelSampler sampler)
{
+ BLI_assert(this->m_datatype==COM_DT_COLOR);
ReadEWAData data;
data.buffer = this;
data.sampler = sampler;
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index d6ef9cd673e..70b4dec2bed 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -83,11 +83,6 @@ private:
unsigned int m_chunkNumber;
/**
- * @brief width of the chunk
- */
- unsigned int m_chunkWidth;
-
- /**
* @brief state of the buffer
*/
MemoryBufferState m_state;
@@ -97,6 +92,15 @@ private:
*/
float *m_buffer;
+ /**
+ * @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;
+
+ int m_width;
+ int m_height;
+
public:
/**
* @brief construct new MemoryBuffer for a chunk
@@ -107,7 +111,12 @@ public:
* @brief construct new temporarily MemoryBuffer for an area
*/
MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect);
-
+
+ /**
+ * @brief construct new temporarily MemoryBuffer for an area
+ */
+ MemoryBuffer(DataType datatype, rcti *rect);
+
/**
* @brief destructor
*/
@@ -117,7 +126,9 @@ public:
* @brief read the ChunkNumber of this MemoryBuffer
*/
unsigned int getChunkNumber() { return this->m_chunkNumber; }
-
+
+ unsigned int get_num_channels() { return this->m_num_channels; }
+
/**
* @brief get the data of this MemoryBuffer
* @note buffer should already be available in memory
@@ -134,8 +145,8 @@ public:
inline void wrap_pixel(int &x, int &y, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
{
- int w = m_rect.xmax - m_rect.xmin;
- int h = m_rect.ymax - m_rect.ymin;
+ int w = this->m_width;
+ int h = this->m_height;
x = x - m_rect.xmin;
y = y - m_rect.ymin;
@@ -164,7 +175,39 @@ public:
}
}
- inline void read(float result[4], int x, int y,
+ inline void wrap_pixel(float &x, float &y, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
+ {
+ float w = (float)this->m_width;
+ float h = (float)this->m_height;
+ x = x - m_rect.xmin;
+ y = y - m_rect.ymin;
+
+ switch (extend_x) {
+ case COM_MB_CLIP:
+ break;
+ case COM_MB_EXTEND:
+ if (x < 0) x = 0.0f;
+ if (x >= w) x = w;
+ break;
+ case COM_MB_REPEAT:
+ x = fmodf(x, w);
+ break;
+ }
+
+ switch (extend_y) {
+ case COM_MB_CLIP:
+ break;
+ case COM_MB_EXTEND:
+ if (y < 0) y = 0.0f;
+ if (y >= h) y = h;
+ break;
+ case COM_MB_REPEAT:
+ y = fmodf(y, h);
+ break;
+ }
+ }
+
+ inline void read(float *result, int x, int y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
@@ -172,81 +215,54 @@ public:
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);
+ memset(result, 0, this->m_num_channels*sizeof(float));
}
else {
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
- copy_v4_v4(result, &this->m_buffer[offset]);
+ int u = x;
+ int v = y;
+ this->wrap_pixel(u, v, extend_x, extend_y);
+ const int offset = (this->m_width * y + x) * this->m_num_channels;
+ float* buffer = &this->m_buffer[offset];
+ memcpy(result, buffer, sizeof(float)*this->m_num_channels);
}
}
- inline void readNoCheck(float result[4], int x, int y,
+ inline void readNoCheck(float *result, int x, int y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
- wrap_pixel(x, y, extend_x, extend_y);
- const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
+ int u = x;
+ int v = y;
- BLI_assert(offset >= 0);
- BLI_assert(offset < this->determineBufferSize() * COM_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)));
+ this->wrap_pixel(u, v, extend_x, extend_y);
+ const int offset = (this->m_width * v + u) * this->m_num_channels;
+ BLI_assert(offset >= 0);
+ BLI_assert(offset < this->determineBufferSize() * this->m_num_channels);
+ BLI_assert(!(extend_x == COM_MB_CLIP && (u < m_rect.xmin || u >= m_rect.xmax)) &&
+ !(extend_y == COM_MB_CLIP && (v < m_rect.ymin || v >= m_rect.ymax)));
#if 0
/* always true */
BLI_assert((int)(MEM_allocN_len(this->m_buffer) / sizeof(*this->m_buffer)) ==
(int)(this->determineBufferSize() * COM_NUMBER_OF_CHANNELS));
#endif
-
- copy_v4_v4(result, &this->m_buffer[offset]);
+ float* buffer = &this->m_buffer[offset];
+ memcpy(result, buffer, sizeof(float)*this->m_num_channels);
}
void writePixel(int x, int y, const float color[4]);
void addPixel(int x, int y, const float color[4]);
- inline void readBilinear(float result[4], float x, float y,
+ inline void readBilinear(float *result, float x, float y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
- 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;
+ float u = x;
+ float v = y;
+ this->wrap_pixel(u, v, extend_x, extend_y);
+ BLI_bilinear_interpolation_fl(this->m_buffer, result, this->m_width, this->m_height, this->m_num_channels, u, v);
}
- void readEWA(float result[4], const float uv[2], const float derivatives[2][2], PixelSampler sampler);
+ void readEWA(float *result, const float uv[2], const float derivatives[2][2], PixelSampler sampler);
/**
* @brief is this MemoryBuffer a temporarily buffer (based on an area, not on a chunk)
@@ -284,7 +300,6 @@ public:
MemoryBuffer *duplicate();
- float *convertToValueBuffer();
float getMaximumValue();
float getMaximumValue(rcti *rect);
private:
diff --git a/source/blender/compositor/intern/COM_MemoryProxy.cpp b/source/blender/compositor/intern/COM_MemoryProxy.cpp
index 90ca0baea06..1df3e59db62 100644
--- a/source/blender/compositor/intern/COM_MemoryProxy.cpp
+++ b/source/blender/compositor/intern/COM_MemoryProxy.cpp
@@ -23,10 +23,11 @@
#include "COM_MemoryProxy.h"
-MemoryProxy::MemoryProxy()
+MemoryProxy::MemoryProxy(DataType datatype)
{
this->m_writeBufferOperation = NULL;
this->m_executor = NULL;
+ this->m_datatype = datatype;
}
void MemoryProxy::allocate(unsigned int width, unsigned int height)
diff --git a/source/blender/compositor/intern/COM_MemoryProxy.h b/source/blender/compositor/intern/COM_MemoryProxy.h
index 233b035a2d7..b332852088b 100644
--- a/source/blender/compositor/intern/COM_MemoryProxy.h
+++ b/source/blender/compositor/intern/COM_MemoryProxy.h
@@ -63,8 +63,13 @@ private:
*/
MemoryBuffer *m_buffer;
+ /**
+ * @brief datatype of this MemoryProxy
+ */
+ DataType m_datatype;
+
public:
- MemoryProxy();
+ MemoryProxy(DataType type);
/**
* @brief set the ExecutionGroup that can be scheduled to calculate a certain chunk.
@@ -104,6 +109,8 @@ public:
*/
inline MemoryBuffer *getBuffer() { return this->m_buffer; }
+ inline DataType getDataType() { return this->m_datatype; }
+
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:MemoryProxy")
#endif
diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp b/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp
index fb5bc8fcd9b..74c05c3e62e 100644
--- a/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp
+++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp
@@ -476,7 +476,7 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation *operation, NodeOpera
/* check of other end already has write operation, otherwise add a new one */
WriteBufferOperation *writeoperation = find_attached_write_buffer_operation(output);
if (!writeoperation) {
- writeoperation = new WriteBufferOperation();
+ writeoperation = new WriteBufferOperation(output->getDataType());
writeoperation->setbNodeTree(m_context->getbNodeTree());
addOperation(writeoperation);
@@ -486,7 +486,7 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation *operation, NodeOpera
}
/* add readbuffer op for the input */
- ReadBufferOperation *readoperation = new ReadBufferOperation();
+ ReadBufferOperation *readoperation = new ReadBufferOperation(output->getDataType());
readoperation->setMemoryProxy(writeoperation->getMemoryProxy());
this->addOperation(readoperation);
@@ -519,7 +519,7 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper
/* if no write buffer operation exists yet, create a new one */
if (!writeOperation) {
- writeOperation = new WriteBufferOperation();
+ writeOperation = new WriteBufferOperation(operation->getOutputSocket()->getDataType());
writeOperation->setbNodeTree(m_context->getbNodeTree());
addOperation(writeOperation);
@@ -534,7 +534,7 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper
if (&target->getOperation() == writeOperation)
continue; /* skip existing write op links */
- ReadBufferOperation *readoperation = new ReadBufferOperation();
+ ReadBufferOperation *readoperation = new ReadBufferOperation(operation->getOutputSocket()->getDataType());
readoperation->setMemoryProxy(writeOperation->getMemoryProxy());
addOperation(readoperation);
diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp
index c5b663d2aef..7fc4fd38abd 100644
--- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp
+++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp
@@ -24,6 +24,18 @@
#include "COM_WorkScheduler.h"
typedef enum COM_VendorID {NVIDIA = 0x10DE, AMD = 0x1002} COM_VendorID;
+const cl_image_format IMAGE_FORMAT_COLOR = {
+ CL_RGBA,
+ CL_FLOAT
+};
+const cl_image_format IMAGE_FORMAT_VECTOR = {
+ CL_RGB,
+ CL_FLOAT
+};
+const cl_image_format IMAGE_FORMAT_VALUE = {
+ CL_R,
+ CL_FLOAT
+};
OpenCLDevice::OpenCLDevice(cl_context context, cl_device_id device, cl_program program, cl_int vendorId)
{
@@ -72,6 +84,21 @@ cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
return COM_clAttachMemoryBufferToKernelParameter(kernel, parameterIndex, offsetIndex, cleanup, inputMemoryBuffers, (ReadBufferOperation *)reader);
}
+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;
+ }
+
+ return imageFormat;
+}
+
cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex,
list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers,
ReadBufferOperation *reader)
@@ -80,12 +107,9 @@ cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
MemoryBuffer *result = reader->getInputMemoryBuffer(inputMemoryBuffers);
- const cl_image_format imageFormat = {
- CL_RGBA,
- CL_FLOAT
- };
+ const cl_image_format *imageFormat = determineImageFormat(result);
- cl_mem clBuffer = clCreateImage2D(this->m_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat, result->getWidth(),
+ cl_mem clBuffer = clCreateImage2D(this->m_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageFormat, result->getWidth(),
result->getHeight(), 0, result->getBuffer(), &error);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.h b/source/blender/compositor/intern/COM_OpenCLDevice.h
index 94df2f2b44c..f8a8841ef47 100644
--- a/source/blender/compositor/intern/COM_OpenCLDevice.h
+++ b/source/blender/compositor/intern/COM_OpenCLDevice.h
@@ -94,6 +94,12 @@ public:
*/
void execute(WorkPackage *work);
+ /**
+ * @brief determine an image format
+ * @param memorybuffer
+ */
+ static const cl_image_format* determineImageFormat(MemoryBuffer *memoryBuffer);
+
cl_context getContext() { return this->m_context; }
cl_command_queue getQueue() { return this->m_queue; }
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp
index e1016731c7f..8445dee5ae4 100644
--- a/source/blender/compositor/intern/COM_WorkScheduler.cpp
+++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp
@@ -196,7 +196,7 @@ void WorkScheduler::schedule(ExecutionGroup *group, int chunkNumber)
BLI_thread_queue_push(g_cpuqueue, package);
}
#else
- BLI_thread_queue_push(cpuqueue, package);
+ BLI_thread_queue_push(g_cpuqueue, package);
#endif
#endif
}
diff --git a/source/blender/compositor/nodes/COM_SocketProxyNode.cpp b/source/blender/compositor/nodes/COM_SocketProxyNode.cpp
index 48c8acfc6a1..17b00af16d8 100644
--- a/source/blender/compositor/nodes/COM_SocketProxyNode.cpp
+++ b/source/blender/compositor/nodes/COM_SocketProxyNode.cpp
@@ -73,8 +73,9 @@ void SocketBufferNode::convertToOperations(NodeConverter &converter, const Compo
NodeOutput *output = this->getOutputSocket(0);
NodeInput *input = this->getInputSocket(0);
- WriteBufferOperation *writeOperation = new WriteBufferOperation();
- ReadBufferOperation *readOperation = new ReadBufferOperation();
+ DataType datatype = output->getDataType();
+ WriteBufferOperation *writeOperation = new WriteBufferOperation(datatype);
+ ReadBufferOperation *readOperation = new ReadBufferOperation(datatype);
readOperation->setMemoryProxy(writeOperation->getMemoryProxy());
converter.addOperation(writeOperation);
converter.addOperation(readOperation);
diff --git a/source/blender/compositor/nodes/COM_TranslateNode.cpp b/source/blender/compositor/nodes/COM_TranslateNode.cpp
index 990cbe19be2..04dc1d435d3 100644
--- a/source/blender/compositor/nodes/COM_TranslateNode.cpp
+++ b/source/blender/compositor/nodes/COM_TranslateNode.cpp
@@ -57,8 +57,8 @@ void TranslateNode::convertToOperations(NodeConverter &converter, const Composit
converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
if (data->wrap_axis) {
- WriteBufferOperation *writeOperation = new WriteBufferOperation();
- WrapOperation *wrapOperation = new WrapOperation();
+ WriteBufferOperation *writeOperation = new WriteBufferOperation(COM_DT_COLOR);
+ WrapOperation *wrapOperation = new WrapOperation(COM_DT_COLOR);
wrapOperation->setMemoryProxy(writeOperation->getMemoryProxy());
wrapOperation->setWrapping(data->wrap_axis);
diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
index 995c61589cc..b25e2281467 100644
--- a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
+++ b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
@@ -95,7 +95,7 @@ void *AntiAliasOperation::initializeTileData(rcti *rect)
float *input = tile->getBuffer();
char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
for (int i = 0; i < size; i++) {
- float in = input[i * COM_NUMBER_OF_CHANNELS];
+ float in = input[i];
valuebuffer[i] = FTOCHAR(in);
}
antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
index f5bca5371e6..22f6fc33a0d 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
@@ -110,11 +110,11 @@ void BokehBlurOperation::executePixel(float output[4], int x, int y, void *data)
int step = getStep();
- int offsetadd = getOffsetAdd();
+ int offsetadd = getOffsetAdd() * COM_NUM_CHANNELS_COLOR;
float m = this->m_bokehDimension / pixelSize;
for (int ny = miny; ny < maxy; ny += step) {
- int bufferindex = ((minx - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
+ int bufferindex = ((minx - bufferstartx) * COM_NUM_CHANNELS_COLOR) + ((ny - bufferstarty) * COM_NUM_CHANNELS_COLOR * bufferwidth);
for (int nx = minx; nx < maxx; nx += step) {
float u = this->m_bokehMidX - (nx - x) * m;
float v = this->m_bokehMidY - (ny - y) * m;
diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cpp b/source/blender/compositor/operations/COM_CompositorOperation.cpp
index ef331a50dfd..e3438bcbd15 100644
--- a/source/blender/compositor/operations/COM_CompositorOperation.cpp
+++ b/source/blender/compositor/operations/COM_CompositorOperation.cpp
@@ -138,7 +138,7 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y2 = rect->ymax;
int offset = (y1 * this->getWidth() + x1);
int add = (this->getWidth() - (x2 - x1));
- int offset4 = offset * COM_NUMBER_OF_CHANNELS;
+ int offset4 = offset * COM_NUM_CHANNELS_COLOR;
int x;
int y;
bool breaked = false;
@@ -196,14 +196,14 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
this->m_depthInput->readSampled(color, input_x, input_y, COM_PS_NEAREST);
zbuffer[offset] = color[0];
- offset4 += COM_NUMBER_OF_CHANNELS;
+ offset4 += COM_NUM_CHANNELS_COLOR;
offset++;
if (isBreaked()) {
breaked = true;
}
}
offset += add;
- offset4 += add * COM_NUMBER_OF_CHANNELS;
+ offset4 += add * COM_NUM_CHANNELS_COLOR;
}
}
diff --git a/source/blender/compositor/operations/COM_ConvertOperation.cpp b/source/blender/compositor/operations/COM_ConvertOperation.cpp
index 1445b78552f..977586acb60 100644
--- a/source/blender/compositor/operations/COM_ConvertOperation.cpp
+++ b/source/blender/compositor/operations/COM_ConvertOperation.cpp
@@ -49,9 +49,9 @@ ConvertValueToColorOperation::ConvertValueToColorOperation() : ConvertBaseOperat
void ConvertValueToColorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
- float inputValue[4];
- this->m_inputOperation->readSampled(inputValue, x, y, sampler);
- output[0] = output[1] = output[2] = inputValue[0];
+ float value;
+ this->m_inputOperation->readSampled(&value, x, y, sampler);
+ output[0] = output[1] = output[2] = value;
output[3] = 1.0f;
}
@@ -98,8 +98,9 @@ ConvertColorToVectorOperation::ConvertColorToVectorOperation() : ConvertBaseOper
void ConvertColorToVectorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
- this->m_inputOperation->readSampled(output, x, y, sampler);
-}
+ float color[4];
+ this->m_inputOperation->readSampled(color, x, y, sampler);
+ copy_v3_v3(output, color);}
/* ******** Value to Vector ******** */
@@ -112,12 +113,9 @@ ConvertValueToVectorOperation::ConvertValueToVectorOperation() : ConvertBaseOper
void ConvertValueToVectorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
- float input[4];
- this->m_inputOperation->readSampled(input, x, y, sampler);
- output[0] = input[0];
- output[1] = input[0];
- output[2] = input[0];
- output[3] = 0.0f;
+ float value;
+ this->m_inputOperation->readSampled(&value, x, y, sampler);
+ output[0] = output[1] = output[2] = value;
}
diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp
index cbf4ce693d9..cee39994aed 100644
--- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp
+++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp
@@ -72,7 +72,7 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
const float inset = this->m_inset;
float mindist = rd * 2;
- MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
+ MemoryBuffer *inputBuffer = (MemoryBuffer*)data;
float *buffer = inputBuffer->getBuffer();
rcti *rect = inputBuffer->getRect();
const int minx = max(x - this->m_scope, rect->xmin);
@@ -82,18 +82,18 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
const int bufferWidth = BLI_rcti_size_x(rect);
int offset;
- this->m_inputProgram->read(inputValue, x, y, NULL);
+ inputBuffer->read(inputValue, x, y);
if (inputValue[0] > sw) {
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
- offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
+ offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
if (buffer[offset] < sw) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
mindist = min(mindist, dis);
}
- offset += 4;
+ offset ++;
}
}
pixelvalue = -sqrtf(mindist);
@@ -101,15 +101,14 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
else {
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
- offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
+ offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
if (buffer[offset] > sw) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
mindist = min(mindist, dis);
}
- offset += 4;
-
+ offset ++;
}
}
pixelvalue = sqrtf(mindist);
@@ -206,14 +205,14 @@ void DilateDistanceOperation::executePixel(float output[4], int x, int y, void *
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
- offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
+ offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
if (dis <= mindist) {
value = max(buffer[offset], value);
}
- offset += 4;
+ offset ++;
}
}
output[0] = value;
@@ -280,14 +279,14 @@ void ErodeDistanceOperation::executePixel(float output[4], int x, int y, void *d
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
- offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
+ offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
if (dis <= mindist) {
value = min(buffer[offset], value);
}
- offset += 4;
+ offset ++;
}
}
output[0] = value;
@@ -383,7 +382,7 @@ void *DilateStepOperation::initializeTileData(rcti *rect)
buf[x] = -FLT_MAX;
}
for (x = xmin; x < xmax; ++x) {
- buf[x - rect->xmin + window - 1] = buffer[4 * (y * width + x)];
+ buf[x - rect->xmin + window - 1] = buffer[(y * width + x)];
}
for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {
@@ -510,7 +509,7 @@ void *ErodeStepOperation::initializeTileData(rcti *rect)
buf[x] = FLT_MAX;
}
for (x = xmin; x < xmax; ++x) {
- buf[x - rect->xmin + window - 1] = buffer[4 * (y * width + x)];
+ buf[x - rect->xmin + window - 1] = buffer[(y * width + x)];
}
for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {
diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
index 5006720f091..234a61a4c41 100644
--- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
+++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
@@ -1270,11 +1270,9 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect)
MemoryBuffer *innerMask = (MemoryBuffer *)this->m_inputInnerMask->initializeTileData(rect);
MemoryBuffer *outerMask = (MemoryBuffer *)this->m_inputOuterMask->initializeTileData(rect);
float *data = (float *)MEM_mallocN(sizeof(float) * this->getWidth() * this->getHeight(), __func__);
- float *imask = innerMask->convertToValueBuffer();
- float *omask = outerMask->convertToValueBuffer();
+ float *imask = innerMask->getBuffer();
+ float *omask = outerMask->getBuffer();
doDoubleEdgeMask(imask, omask, data);
- MEM_freeN(imask);
- MEM_freeN(omask);
this->m_cachedInstance = data;
}
unlockMutex();
diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
index 705a8c07381..08f520e4271 100644
--- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
@@ -92,16 +92,16 @@ void *FastGaussianBlurOperation::initializeTileData(rcti *rect)
this->m_sy = this->m_data.sizey * this->m_size / 2.0f;
if ((this->m_sx == this->m_sy) && (this->m_sx > 0.f)) {
- for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
+ for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sx, c, 3);
}
else {
if (this->m_sx > 0.0f) {
- for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
+ for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sx, c, 1);
}
if (this->m_sy > 0.0f) {
- for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
+ for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sy, c, 2);
}
}
@@ -120,6 +120,7 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, unsign
unsigned int x, y, sz;
unsigned int i;
float *buffer = src->getBuffer();
+ const unsigned int num_channels = src->get_num_channels();
// <0.5 not valid, though can have a possibly useful sort of sharpening effect
if (sigma < 0.5f) return;
@@ -198,31 +199,31 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, unsign
int offset;
for (y = 0; y < src_height; ++y) {
const int yx = y * src_width;
- offset = yx * COM_NUMBER_OF_CHANNELS + chan;
+ offset = yx * num_channels + chan;
for (x = 0; x < src_width; ++x) {
X[x] = buffer[offset];
- offset += COM_NUMBER_OF_CHANNELS;
+ offset += num_channels;
}
YVV(src_width);
- offset = yx * COM_NUMBER_OF_CHANNELS + chan;
+ offset = yx * num_channels + chan;
for (x = 0; x < src_width; ++x) {
buffer[offset] = Y[x];
- offset += COM_NUMBER_OF_CHANNELS;
+ offset += num_channels;
}
}
}
if (xy & 2) { // V
int offset;
- const int add = src_width * COM_NUMBER_OF_CHANNELS;
+ const int add = src_width * num_channels;
for (x = 0; x < src_width; ++x) {
- offset = x * COM_NUMBER_OF_CHANNELS + chan;
+ offset = x * num_channels + chan;
for (y = 0; y < src_height; ++y) {
X[y] = buffer[offset];
offset += add;
}
YVV(src_height);
- offset = x * COM_NUMBER_OF_CHANNELS + chan;
+ offset = x * num_channels + chan;
for (y = 0; y < src_height; ++y) {
buffer[offset] = Y[y];
offset += add;
@@ -298,7 +299,7 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
- for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUMBER_OF_CHANNELS, dst += COM_NUMBER_OF_CHANNELS) {
+ for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src < *dst) {
*dst = *src;
}
@@ -307,7 +308,7 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
- for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUMBER_OF_CHANNELS, dst += COM_NUMBER_OF_CHANNELS) {
+ for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src > *dst) {
*dst = *src;
}
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
index c78347e7b1c..dde57ab640f 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
@@ -102,15 +102,14 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
/* *** this is the main part which is different to 'GaussianXBlurOperation' *** */
int step = getStep();
- int offsetadd = getOffsetAdd();
- int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth);
+ int bufferindex = ((xmin - bufferstartx)) + ((ymin - bufferstarty) * bufferwidth);
/* gauss */
float alpha_accum = 0.0f;
float multiplier_accum = 0.0f;
/* dilate */
- float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
+ float value_max = finv_test(buffer[(x) + (y * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int nx = xmin; nx < xmax; nx += step) {
@@ -134,7 +133,7 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
distfacinv_max = multiplier;
}
}
- bufferindex += offsetadd;
+ bufferindex += step;
}
/* blend between the max value and gauss blue - gives nice feather */
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
index ab97c8b0d13..bb5b3c044af 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
@@ -108,11 +108,11 @@ void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, vo
float multiplier_accum = 0.0f;
/* dilate */
- float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
+ float value_max = finv_test(buffer[(x) + (y * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int ny = ymin; ny < ymax; ny += step) {
- int bufferindex = ((xmin - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
+ int bufferindex = ((xmin - bufferstartx)) + ((ny - bufferstarty) * bufferwidth);
const int index = (ny - y) + this->m_filtersize;
float value = finv_test(buffer[bufferindex], do_invert);
diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
index 441b623b589..dbad51c4329 100644
--- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
@@ -296,7 +296,7 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
int minyr = y - refrady < 0 ? -y : -refrady;
int maxyr = y + refrady > imgy ? imgy - y : refrady;
- float *srcd = buffer + COM_NUMBER_OF_CHANNELS * ( (y + minyr) * imgx + x + minxr);
+ float *srcd = buffer + COM_NUM_CHANNELS_COLOR * ( (y + minyr) * imgx + x + minxr);
gausstabx = m_maintabs[refradx - 1];
gausstabcentx = gausstabx + refradx;
@@ -304,9 +304,9 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
gausstabcenty = gausstaby + refrady;
sum = gval = rval = bval = aval = 0.0f;
- for (i = minyr; i < maxyr; i++, srcd += COM_NUMBER_OF_CHANNELS * imgx) {
+ for (i = minyr; i < maxyr; i++, srcd += COM_NUM_CHANNELS_COLOR * imgx) {
src = srcd;
- for (j = minxr; j < maxxr; j++, src += COM_NUMBER_OF_CHANNELS) {
+ for (j = minxr; j < maxxr; j++, src += COM_NUM_CHANNELS_COLOR) {
val = gausstabcenty[i] * gausstabcentx[j];
sum += val;
diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.cpp b/source/blender/compositor/operations/COM_GlareBaseOperation.cpp
index 99c745d7fb0..98919f1b161 100644
--- a/source/blender/compositor/operations/COM_GlareBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareBaseOperation.cpp
@@ -49,7 +49,7 @@ MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2)
rect.ymin = 0;
rect.xmax = getWidth();
rect.ymax = getHeight();
- MemoryBuffer *result = new MemoryBuffer(NULL, &rect);
+ MemoryBuffer *result = new MemoryBuffer(COM_DT_COLOR, &rect);
float *data = result->getBuffer();
this->generateGlare(data, tile, this->m_settings);
return result;
diff --git a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp
index 99a7c5b64c4..04993b08ddf 100644
--- a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp
@@ -259,8 +259,8 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
float *kernelBuffer = in2->getBuffer();
float *imageBuffer = in1->getBuffer();
- MemoryBuffer *rdst = new MemoryBuffer(NULL, in1->getRect());
- memset(rdst->getBuffer(), 0, rdst->getWidth() * rdst->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ MemoryBuffer *rdst = new MemoryBuffer(COM_DT_COLOR, in1->getRect());
+ memset(rdst->getBuffer(), 0, rdst->getWidth() * rdst->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
// convolution result width & height
w2 = 2 * kernelWidth - 1;
@@ -276,7 +276,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// normalize convolutor
wt[0] = wt[1] = wt[2] = 0.f;
for (y = 0; y < kernelHeight; y++) {
- colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
add_v3_v3(wt, colp[x]);
}
@@ -284,7 +284,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
if (wt[1] != 0.f) wt[1] = 1.f / wt[1];
if (wt[2] != 0.f) wt[2] = 1.f / wt[2];
for (y = 0; y < kernelHeight; y++) {
- colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
mul_v3_v3(colp[x], wt);
}
@@ -313,7 +313,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// in2, channel ch -> data1
for (y = 0; y < kernelHeight; y++) {
fp = &data1ch[y * w2];
- colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
+ colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
fp[x] = colp[x][ch];
}
@@ -325,7 +325,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
int yy = ybl * ybsz + y;
if (yy >= imageHeight) continue;
fp = &data2[y * w2];
- colp = (fRGB *)&imageBuffer[yy * imageWidth * COM_NUMBER_OF_CHANNELS];
+ colp = (fRGB *)&imageBuffer[yy * imageWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < xbsz; x++) {
int xx = xbl * xbsz + x;
if (xx >= imageWidth) continue;
@@ -349,7 +349,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
const int yy = ybl * ybsz + y - hh;
if ((yy < 0) || (yy >= imageHeight)) continue;
fp = &data2[y * w2];
- colp = (fRGB *)&rdst->getBuffer()[yy * imageWidth * COM_NUMBER_OF_CHANNELS];
+ colp = (fRGB *)&rdst->getBuffer()[yy * imageWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < (int)w2; x++) {
const int xx = xbl * xbsz + x - hw;
if ((xx < 0) || (xx >= imageWidth)) continue;
@@ -364,7 +364,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
MEM_freeN(data2);
MEM_freeN(data1);
- memcpy(dst, rdst->getBuffer(), sizeof(float) * imageWidth * imageHeight * COM_NUMBER_OF_CHANNELS);
+ memcpy(dst, rdst->getBuffer(), sizeof(float) * imageWidth * imageHeight * COM_NUM_CHANNELS_COLOR);
delete(rdst);
}
@@ -381,7 +381,7 @@ void GlareFogGlowOperation::generateGlare(float *data, MemoryBuffer *inputTile,
// make the convolution kernel
rcti kernelRect;
BLI_rcti_init(&kernelRect, 0, sz, 0, sz);
- ckrn = new MemoryBuffer(NULL, &kernelRect);
+ ckrn = new MemoryBuffer(COM_DT_COLOR, &kernelRect);
scale = 0.25f * sqrtf((float)(sz * sz));
diff --git a/source/blender/compositor/operations/COM_GlareGhostOperation.cpp b/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
index 8854be52ded..69b5bd7d6bf 100644
--- a/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
@@ -97,7 +97,7 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
}
- memset(tbuf1->getBuffer(), 0, tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ memset(tbuf1->getBuffer(), 0, tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
for (n = 1; n < settings->iter && (!breaked); n++) {
for (y = 0; y < gbuf->getHeight() && (!breaked); y++) {
v = ((float)y + 0.5f) / (float)gbuf->getHeight();
@@ -117,9 +117,9 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
}
if (isBreaked()) breaked = true;
}
- memcpy(gbuf->getBuffer(), tbuf1->getBuffer(), tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ memcpy(gbuf->getBuffer(), tbuf1->getBuffer(), tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
}
- memcpy(data, gbuf->getBuffer(), gbuf->getWidth() * gbuf->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+ memcpy(data, gbuf->getBuffer(), gbuf->getWidth() * gbuf->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
delete gbuf;
delete tbuf1;
diff --git a/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp b/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
index 5644ff30ef3..deeb5094bd0 100644
--- a/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
@@ -36,7 +36,7 @@ void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile,
bool breaked = false;
MemoryBuffer *tsrc = inputTile->duplicate();
- MemoryBuffer *tdst = new MemoryBuffer(NULL, inputTile->getRect());
+ MemoryBuffer *tdst = new MemoryBuffer(COM_DT_COLOR, inputTile->getRect());
tdst->clear();
memset(data, 0, size4 * sizeof(float));
diff --git a/source/blender/compositor/operations/COM_InpaintOperation.cpp b/source/blender/compositor/operations/COM_InpaintOperation.cpp
index b64c98be0c7..922441a68b6 100644
--- a/source/blender/compositor/operations/COM_InpaintOperation.cpp
+++ b/source/blender/compositor/operations/COM_InpaintOperation.cpp
@@ -83,8 +83,8 @@ float *InpaintSimpleOperation::get_pixel(int x, int y)
ASSERT_XY_RANGE(x, y);
return &this->m_cached_buffer[
- y * width * COM_NUMBER_OF_CHANNELS +
- x * COM_NUMBER_OF_CHANNELS];
+ y * width * COM_NUM_CHANNELS_COLOR +
+ x * COM_NUM_CHANNELS_COLOR];
}
int InpaintSimpleOperation::mdist(int x, int y)
diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp
index ddc09ecb483..72c7512cb23 100644
--- a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp
@@ -58,7 +58,7 @@ void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data
const int start = max(0, x - this->m_size + 1),
end = min(bufferWidth, x + this->m_size);
for (int cx = start; cx < end; ++cx) {
- int bufferIndex = (y * bufferWidth + cx) * 4;
+ int bufferIndex = (y * bufferWidth + cx);
average += buffer[bufferIndex];
count++;
}
@@ -67,7 +67,7 @@ void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data
const int start = max(0, y - this->m_size + 1),
end = min(inputBuffer->getHeight(), y + this->m_size);
for (int cy = start; cy < end; ++cy) {
- int bufferIndex = (cy * bufferWidth + x) * 4;
+ int bufferIndex = (cy * bufferWidth + x);
average += buffer[bufferIndex];
count++;
}
diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
index d9eb7b588a8..d4ba94f240f 100644
--- a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
+++ b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
@@ -62,7 +62,7 @@ void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data
int bufferWidth = inputBuffer->getWidth();
int bufferHeight = inputBuffer->getHeight();
- float value = buffer[(y * bufferWidth + x) * 4];
+ float value = buffer[(y * bufferWidth + x)];
bool ok = false;
int start_x = max_ff(0, x - delta + 1),
@@ -83,7 +83,7 @@ void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data
continue;
}
- int bufferIndex = (cy * bufferWidth + cx) * 4;
+ int bufferIndex = (cy * bufferWidth + cx);
float currentValue = buffer[bufferIndex];
if (fabsf(currentValue - value) < tolerance) {
diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cpp b/source/blender/compositor/operations/COM_MapUVOperation.cpp
index 6bf730253e7..bb8fe825c68 100644
--- a/source/blender/compositor/operations/COM_MapUVOperation.cpp
+++ b/source/blender/compositor/operations/COM_MapUVOperation.cpp
@@ -83,11 +83,11 @@ bool MapUVOperation::read_uv(float x, float y, float &r_u, float &r_v, float &r_
return false;
}
else {
- float col[4];
- m_inputUVProgram->readSampled(col, x, y, COM_PS_BILINEAR);
- r_u = col[0] * m_inputColorProgram->getWidth();
- r_v = col[1] * m_inputColorProgram->getHeight();
- r_alpha = col[2];
+ float vector[3];
+ m_inputUVProgram->readSampled(vector, x, y, COM_PS_BILINEAR);
+ r_u = vector[0] * m_inputColorProgram->getWidth();
+ r_v = vector[1] * m_inputColorProgram->getHeight();
+ r_alpha = vector[2];
return true;
}
}
diff --git a/source/blender/compositor/operations/COM_NormalizeOperation.cpp b/source/blender/compositor/operations/COM_NormalizeOperation.cpp
index f81b50e6836..e0b5893ffbb 100644
--- a/source/blender/compositor/operations/COM_NormalizeOperation.cpp
+++ b/source/blender/compositor/operations/COM_NormalizeOperation.cpp
@@ -104,7 +104,7 @@ void *NormalizeOperation::initializeTileData(rcti *rect)
if ((value < minv) && (value >= -BLENDER_ZMAX)) {
minv = value;
}
- bc += 4;
+ bc ++;
}
minmult->x = minv;
diff --git a/source/blender/compositor/operations/COM_QualityStepHelper.cpp b/source/blender/compositor/operations/COM_QualityStepHelper.cpp
index d99d6f28eff..4d9c15f9747 100644
--- a/source/blender/compositor/operations/COM_QualityStepHelper.cpp
+++ b/source/blender/compositor/operations/COM_QualityStepHelper.cpp
@@ -37,15 +37,15 @@ void QualityStepHelper::initExecution(QualityHelper helper)
case COM_QUALITY_HIGH:
default:
this->m_step = 1;
- this->m_offsetadd = 4;
+ this->m_offsetadd = 1;
break;
case COM_QUALITY_MEDIUM:
this->m_step = 2;
- this->m_offsetadd = 8;
+ this->m_offsetadd = 2;
break;
case COM_QUALITY_LOW:
this->m_step = 3;
- this->m_offsetadd = 12;
+ this->m_offsetadd = 3;
break;
}
break;
diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
index 47d5fc6bcca..709c30f4015 100644
--- a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
+++ b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
@@ -24,9 +24,9 @@
#include "COM_WriteBufferOperation.h"
#include "COM_defines.h"
-ReadBufferOperation::ReadBufferOperation() : NodeOperation()
+ReadBufferOperation::ReadBufferOperation(DataType datatype) : NodeOperation()
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(datatype);
this->m_single_value = false;
this->m_offset = 0;
this->m_buffer = NULL;
@@ -58,11 +58,20 @@ void ReadBufferOperation::executePixelSampled(float output[4], float x, float y,
/* write buffer has a single value stored at (0,0) */
m_buffer->read(output, 0, 0);
}
- else if (sampler == COM_PS_NEAREST) {
- m_buffer->read(output, x, y);
- }
else {
- m_buffer->readBilinear(output, x, y);
+ switch (sampler) {
+ case COM_PS_NEAREST:
+ m_buffer->read(output, x, y);
+ break;
+ case COM_PS_BILINEAR:
+ default:
+ m_buffer->readBilinear(output, x, y);
+ break;
+ case COM_PS_BICUBIC:
+ m_buffer->readBilinear(output, x, y);
+ break;
+ }
+
}
}
diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.h b/source/blender/compositor/operations/COM_ReadBufferOperation.h
index 569920d51ef..7e5bc55a8ca 100644
--- a/source/blender/compositor/operations/COM_ReadBufferOperation.h
+++ b/source/blender/compositor/operations/COM_ReadBufferOperation.h
@@ -25,6 +25,7 @@
#include "COM_NodeOperation.h"
#include "COM_MemoryProxy.h"
+#include "COM_MemoryBuffer.h"
class ReadBufferOperation : public NodeOperation {
private:
@@ -33,7 +34,7 @@ private:
unsigned int m_offset;
MemoryBuffer *m_buffer;
public:
- ReadBufferOperation();
+ ReadBufferOperation(DataType datetype);
void setMemoryProxy(MemoryProxy *memoryProxy) { this->m_memoryProxy = memoryProxy; }
MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; }
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
diff --git a/source/blender/compositor/operations/COM_RenderLayersProg.cpp b/source/blender/compositor/operations/COM_RenderLayersProg.cpp
index 06f4f6d77cf..f1990453fc6 100644
--- a/source/blender/compositor/operations/COM_RenderLayersProg.cpp
+++ b/source/blender/compositor/operations/COM_RenderLayersProg.cpp
@@ -111,15 +111,6 @@ void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, Pi
BLI_bicubic_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
break;
}
-
- if (this->m_elementsize == 1) {
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
- }
- else if (this->m_elementsize == 3) {
- output[3] = 1.0f;
- }
}
void RenderLayersBaseProg::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
@@ -145,7 +136,16 @@ void RenderLayersBaseProg::executePixelSampled(float output[4], float x, float y
#endif
if (this->m_inputBuffer == NULL) {
- zero_v4(output);
+ int elemsize = this->m_elementsize;
+ if (elemsize == 1) {
+ output[0] = 0.0f;
+ }
+ else if (elemsize == 3) {
+ zero_v3(output);
+ } else {
+ BLI_assert(elemsize == 4);
+ zero_v4(output);
+ }
}
else {
doInterpolation(output, x, y, sampler);
@@ -204,15 +204,12 @@ void RenderLayersAlphaProg::executePixelSampled(float output[4], float x, float
float *inputBuffer = this->getInputBuffer();
if (inputBuffer == NULL) {
- zero_v4(output);
+ output[0] = 0.0f;
}
else {
float temp[4];
doInterpolation(temp, x, y, sampler);
output[0] = temp[3];
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
}
}
@@ -227,7 +224,7 @@ RenderLayersColorOperation::RenderLayersColorOperation() : RenderLayersBaseProg(
RenderLayersCyclesOperation::RenderLayersCyclesOperation(int pass) : RenderLayersBaseProg(pass, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Depth Operation ******** */
@@ -245,16 +242,10 @@ void RenderLayersDepthProg::executePixelSampled(float output[4], float x, float
if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
output[0] = 0.0f;
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
}
else {
unsigned int offset = (iy * this->getWidth() + ix);
output[0] = inputBuffer[offset];
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
}
}
@@ -262,21 +253,21 @@ void RenderLayersDepthProg::executePixelSampled(float output[4], float x, float
RenderLayersDiffuseOperation::RenderLayersDiffuseOperation() : RenderLayersBaseProg(SCE_PASS_DIFFUSE, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Emit Operation ******** */
RenderLayersEmitOperation::RenderLayersEmitOperation() : RenderLayersBaseProg(SCE_PASS_EMIT, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Environment Operation ******** */
RenderLayersEnvironmentOperation::RenderLayersEnvironmentOperation() : RenderLayersBaseProg(SCE_PASS_ENVIRONMENT, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Image Operation ******** */
@@ -290,7 +281,7 @@ RenderLayersColorProg::RenderLayersColorProg() : RenderLayersBaseProg(SCE_PASS_C
RenderLayersIndirectOperation::RenderLayersIndirectOperation() : RenderLayersBaseProg(SCE_PASS_INDIRECT, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Material Index Operation ******** */
@@ -325,28 +316,28 @@ RenderLayersObjectIndexOperation::RenderLayersObjectIndexOperation() : RenderLay
RenderLayersReflectionOperation::RenderLayersReflectionOperation() : RenderLayersBaseProg(SCE_PASS_REFLECT, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Refraction Operation ******** */
RenderLayersRefractionOperation::RenderLayersRefractionOperation() : RenderLayersBaseProg(SCE_PASS_REFRACT, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Shadow Operation ******** */
RenderLayersShadowOperation::RenderLayersShadowOperation() : RenderLayersBaseProg(SCE_PASS_SHADOW, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Specular Operation ******** */
RenderLayersSpecularOperation::RenderLayersSpecularOperation() : RenderLayersBaseProg(SCE_PASS_SPEC, 3)
{
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Speed Operation ******** */
diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.cpp b/source/blender/compositor/operations/COM_SetVectorOperation.cpp
index 17212d78e15..769eaf1d2ed 100644
--- a/source/blender/compositor/operations/COM_SetVectorOperation.cpp
+++ b/source/blender/compositor/operations/COM_SetVectorOperation.cpp
@@ -33,7 +33,6 @@ void SetVectorOperation::executePixelSampled(float output[4], float x, float y,
output[0] = this->m_x;
output[1] = this->m_y;
output[2] = this->m_z;
- output[3] = this->m_w;
}
void SetVectorOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.cpp b/source/blender/compositor/operations/COM_SunBeamsOperation.cpp
index 12b04c386f2..0ca687ea162 100644
--- a/source/blender/compositor/operations/COM_SunBeamsOperation.cpp
+++ b/source/blender/compositor/operations/COM_SunBeamsOperation.cpp
@@ -135,7 +135,7 @@ struct BufferLineAccumulator {
falloff_factor = dist_max > dist_min ? dr / (float)(dist_max - dist_min) : 0.0f;
- float *iter = input->getBuffer() + COM_NUMBER_OF_CHANNELS * (x + input->getWidth() * y);
+ float *iter = input->getBuffer() + COM_NUM_CHANNELS_COLOR * (x + input->getWidth() * y);
return iter;
}
@@ -159,7 +159,7 @@ struct BufferLineAccumulator {
zero_v4(output);
if ((int)(co[0] - source[0]) == 0 && (int)(co[1] - source[1]) == 0) {
- copy_v4_v4(output, input->getBuffer() + COM_NUMBER_OF_CHANNELS * ((int)source[0] + input->getWidth() * (int)source[1]));
+ copy_v4_v4(output, input->getBuffer() + COM_NUM_CHANNELS_COLOR * ((int)source[0] + input->getWidth() * (int)source[1]));
return;
}
@@ -198,7 +198,7 @@ struct BufferLineAccumulator {
/* decrement u */
x -= fxu;
y -= fyu;
- buffer -= (fxu + fyu * buffer_width) * COM_NUMBER_OF_CHANNELS;
+ buffer -= (fxu + fyu * buffer_width) * COM_NUM_CHANNELS_COLOR;
/* decrement v (in steps of dv < 1) */
v_local -= dv;
@@ -207,7 +207,7 @@ struct BufferLineAccumulator {
x -= fxv;
y -= fyv;
- buffer -= (fxv + fyv * buffer_width) * COM_NUMBER_OF_CHANNELS;
+ buffer -= (fxv + fyv * buffer_width) * COM_NUM_CHANNELS_COLOR;
}
}
diff --git a/source/blender/compositor/operations/COM_TextureOperation.cpp b/source/blender/compositor/operations/COM_TextureOperation.cpp
index ede767cbff7..da01aa3b7ca 100644
--- a/source/blender/compositor/operations/COM_TextureOperation.cpp
+++ b/source/blender/compositor/operations/COM_TextureOperation.cpp
@@ -77,12 +77,9 @@ void TextureBaseOperation::determineResolution(unsigned int resolution[2], unsig
void TextureAlphaOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
- TextureBaseOperation::executePixelSampled(output, x, y, sampler);
- output[0] = output[3];
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
-}
+ float color[4];
+ TextureBaseOperation::executePixelSampled(color, x, y, sampler);
+ output[0] = color[3];}
void TextureBaseOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
@@ -124,18 +121,23 @@ MemoryBuffer *TextureBaseOperation::createMemoryBuffer(rcti *rect2)
{
int height = getHeight();
int width = getWidth();
+ DataType datatype = this->getOutputSocket()->getDataType();
+ int add = 4;
+ if (datatype == COM_DT_VALUE) {
+ add = 1;
+ }
rcti rect;
rect.xmin = 0;
rect.ymin = 0;
rect.xmax = width;
rect.ymax = height;
- MemoryBuffer *result = new MemoryBuffer(NULL, &rect);
+ MemoryBuffer *result = new MemoryBuffer(datatype, &rect);
float *data = result->getBuffer();
for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++, data += 4) {
+ for (int x = 0; x < width; x++, data += add) {
this->executePixelSampled(data, x, y, COM_PS_NEAREST);
}
}
diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
index 4b81001fdab..4809efd7436 100644
--- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
@@ -137,30 +137,33 @@ void VariableSizeBokehBlurOperation::executePixel(float output[4], int x, int y,
copy_v4_fl(multiplier_accum, 1.0f);
float size_center = tempSize[0] * scalar;
- const int addXStep = QualityStepHelper::getStep() * COM_NUMBER_OF_CHANNELS;
-
+ const int addXStepValue = QualityStepHelper::getStep();
+ const int addYStepValue = addXStepValue;
+ const int addXStepColor = addXStepValue * COM_NUM_CHANNELS_COLOR;
+
if (size_center > this->m_threshold) {
- for (int ny = miny; ny < maxy; ny += QualityStepHelper::getStep()) {
+ for (int ny = miny; ny < maxy; ny += addYStepValue) {
float dy = ny - y;
- int offsetNy = ny * inputSizeBuffer->getWidth() * COM_NUMBER_OF_CHANNELS;
- int offsetNxNy = offsetNy + (minx * COM_NUMBER_OF_CHANNELS);
- for (int nx = minx; nx < maxx; nx += QualityStepHelper::getStep()) {
+ int offsetValueNy = ny * inputSizeBuffer->getWidth();
+ int offsetValueNxNy = offsetValueNy + (minx);
+ int offsetColorNxNy = offsetValueNxNy * COM_NUM_CHANNELS_COLOR;
+ for (int nx = minx; nx < maxx; nx += addXStepValue) {
if (nx != x || ny != y) {
- float size = min(inputSizeFloatBuffer[offsetNxNy] * scalar, size_center);
+ float size = min(inputSizeFloatBuffer[offsetValueNxNy] * scalar, size_center);
if (size > this->m_threshold) {
float dx = nx - x;
if (size > fabsf(dx) && size > fabsf(dy)) {
float uv[2] = {
- (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1),
- (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1)};
- inputBokehBuffer->readNoCheck(bokeh, uv[0], uv[1]);
- madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetNxNy]);
+ (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1),
+ (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1)};
+ inputBokehBuffer->read(bokeh, uv[0], uv[1]);
+ madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetColorNxNy]);
add_v4_v4(multiplier_accum, bokeh);
}
}
}
- offsetNxNy += addXStep;
- }
+ offsetColorNxNy += addXStepColor;
+ offsetValueNxNy += addXStepValue; }
}
}
diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp
index f5890157440..8dc06ef07d7 100644
--- a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp
@@ -57,7 +57,7 @@ void VectorBlurOperation::initExecution()
void VectorBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
float *buffer = (float *) data;
- int index = (y * this->getWidth() + x) * COM_NUMBER_OF_CHANNELS;
+ int index = (y * this->getWidth() + x) * COM_NUM_CHANNELS_COLOR;
copy_v4_v4(output, &buffer[index]);
}
@@ -108,14 +108,12 @@ bool VectorBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuff
void VectorBlurOperation::generateVectorBlur(float *data, MemoryBuffer *inputImage, MemoryBuffer *inputSpeed, MemoryBuffer *inputZ)
{
- float *zbuf = inputZ->convertToValueBuffer();
NodeBlurData blurdata;
blurdata.samples = this->m_settings->samples / QualityStepHelper::getStep();
blurdata.maxspeed = this->m_settings->maxspeed;
blurdata.minspeed = this->m_settings->minspeed;
blurdata.curved = this->m_settings->curved;
blurdata.fac = this->m_settings->fac;
- RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), zbuf);
- MEM_freeN((void *)zbuf);
+ RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), inputZ->getBuffer());
return;
}
diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.cpp b/source/blender/compositor/operations/COM_VectorCurveOperation.cpp
index fedc8c6db7d..dfdc54012a8 100644
--- a/source/blender/compositor/operations/COM_VectorCurveOperation.cpp
+++ b/source/blender/compositor/operations/COM_VectorCurveOperation.cpp
@@ -51,7 +51,6 @@ void VectorCurveOperation::executePixelSampled(float output[4], float x, float y
this->m_inputProgram->readSampled(input, x, y, sampler);
curvemapping_evaluate_premulRGBF(this->m_curveMapping, output, input);
- output[3] = input[3];
}
void VectorCurveOperation::deinitExecution()
diff --git a/source/blender/compositor/operations/COM_WrapOperation.cpp b/source/blender/compositor/operations/COM_WrapOperation.cpp
index c30361d1df8..7fbef453a13 100644
--- a/source/blender/compositor/operations/COM_WrapOperation.cpp
+++ b/source/blender/compositor/operations/COM_WrapOperation.cpp
@@ -23,7 +23,7 @@
#include "COM_WrapOperation.h"
-WrapOperation::WrapOperation() : ReadBufferOperation()
+WrapOperation::WrapOperation(DataType datatype) : ReadBufferOperation(datatype)
{
this->m_wrappingType = CMP_NODE_WRAP_NONE;
}
diff --git a/source/blender/compositor/operations/COM_WrapOperation.h b/source/blender/compositor/operations/COM_WrapOperation.h
index 33ea1280564..92c93565691 100644
--- a/source/blender/compositor/operations/COM_WrapOperation.h
+++ b/source/blender/compositor/operations/COM_WrapOperation.h
@@ -29,7 +29,7 @@ class WrapOperation : public ReadBufferOperation {
private:
int m_wrappingType;
public:
- WrapOperation();
+ WrapOperation(DataType datetype);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp
index 832864b399d..fccff2a33bf 100644
--- a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp
+++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp
@@ -25,10 +25,10 @@
#include <stdio.h>
#include "COM_OpenCLDevice.h"
-WriteBufferOperation::WriteBufferOperation() : NodeOperation()
+WriteBufferOperation::WriteBufferOperation(DataType datatype) : NodeOperation()
{
- this->addInputSocket(COM_DT_COLOR);
- this->m_memoryProxy = new MemoryProxy();
+ this->addInputSocket(datatype);
+ this->m_memoryProxy = new MemoryProxy(datatype);
this->m_memoryProxy->setWriteBufferOperation(this);
this->m_memoryProxy->setExecutor(NULL);
}
@@ -61,6 +61,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();
if (this->m_input->isComplex()) {
void *data = this->m_input->initializeTileData(rect);
int x1 = rect->xmin;
@@ -71,10 +72,10 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y;
bool breaked = false;
for (y = y1; y < y2 && (!breaked); y++) {
- int offset4 = (y * memoryBuffer->getWidth() + x1) * COM_NUMBER_OF_CHANNELS;
+ int offset4 = (y * memoryBuffer->getWidth() + x1) * num_channels;
for (x = x1; x < x2; x++) {
this->m_input->read(&(buffer[offset4]), x, y, data);
- offset4 += COM_NUMBER_OF_CHANNELS;
+ offset4 += num_channels;
}
if (isBreaked()) {
breaked = true;
@@ -96,10 +97,10 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y;
bool breaked = false;
for (y = y1; y < y2 && (!breaked); y++) {
- int offset4 = (y * memoryBuffer->getWidth() + x1) * COM_NUMBER_OF_CHANNELS;
+ int offset4 = (y * memoryBuffer->getWidth() + x1) * num_channels;
for (x = x1; x < x2; x++) {
this->m_input->readSampled(&(buffer[offset4]), x, y, COM_PS_NEAREST);
- offset4 += COM_NUMBER_OF_CHANNELS;
+ offset4 += num_channels;
}
if (isBreaked()) {
breaked = true;
@@ -126,12 +127,9 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, rcti *rect,
const unsigned int outputBufferWidth = outputBuffer->getWidth();
const unsigned int outputBufferHeight = outputBuffer->getHeight();
- const cl_image_format imageFormat = {
- CL_RGBA,
- CL_FLOAT
- };
+ const cl_image_format *imageFormat = device->determineImageFormat(outputBuffer);
- cl_mem clOutputBuffer = clCreateImage2D(device->getContext(), CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, &imageFormat, outputBufferWidth, outputBufferHeight, 0, outputFloatBuffer, &error);
+ cl_mem clOutputBuffer = clCreateImage2D(device->getContext(), CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, imageFormat, outputBufferWidth, outputBufferHeight, 0, outputFloatBuffer, &error);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
// STEP 2
diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.h b/source/blender/compositor/operations/COM_WriteBufferOperation.h
index 96466df979c..9220cb179c6 100644
--- a/source/blender/compositor/operations/COM_WriteBufferOperation.h
+++ b/source/blender/compositor/operations/COM_WriteBufferOperation.h
@@ -35,7 +35,7 @@ class WriteBufferOperation : public NodeOperation {
bool m_single_value; /* single value stored in buffer */
NodeOperation *m_input;
public:
- WriteBufferOperation();
+ WriteBufferOperation(DataType datatype);
~WriteBufferOperation();
MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; }
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);