svn merge ^/trunk/blender -r49933:49939

This commit is contained in:
Campbell Barton
2012-08-16 14:48:43 +00:00
22 changed files with 263 additions and 92 deletions

View File

@@ -38,6 +38,7 @@
#include "COM_ChunkOrder.h"
#include "COM_ExecutionSystemHelper.h"
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "PIL_time.h"
#include "WM_api.h"
@@ -148,14 +149,14 @@ NodeOperation *ExecutionGroup::getOutputNodeOperation() const
void ExecutionGroup::initExecution()
{
if (this->m_chunkExecutionStates != NULL) {
delete[] this->m_chunkExecutionStates;
MEM_freeN(this->m_chunkExecutionStates);
}
unsigned int index;
determineNumberOfChunks();
this->m_chunkExecutionStates = NULL;
if (this->m_numberOfChunks != 0) {
this->m_chunkExecutionStates = new ChunkExecutionState[this->m_numberOfChunks];
this->m_chunkExecutionStates = (ChunkExecutionState *)MEM_mallocN(sizeof(ChunkExecutionState) * this->m_numberOfChunks, __func__);
for (index = 0; index < this->m_numberOfChunks; index++) {
this->m_chunkExecutionStates[index] = COM_ES_NOT_SCHEDULED;
}
@@ -180,7 +181,7 @@ void ExecutionGroup::initExecution()
void ExecutionGroup::deinitExecution()
{
if (this->m_chunkExecutionStates != NULL) {
delete[] this->m_chunkExecutionStates;
MEM_freeN(this->m_chunkExecutionStates);
this->m_chunkExecutionStates = NULL;
}
this->m_numberOfChunks = 0;
@@ -227,7 +228,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
this->m_chunksFinished = 0;
this->m_bTree = bTree;
unsigned int index;
unsigned int *chunkOrder = new unsigned int[this->m_numberOfChunks];
unsigned int *chunkOrder = (unsigned int *)MEM_mallocN(sizeof(unsigned int) * this->m_numberOfChunks, __func__);
for (chunkNumber = 0; chunkNumber < this->m_numberOfChunks; chunkNumber++) {
chunkOrder[chunkNumber] = chunkNumber;
@@ -256,10 +257,10 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
break;
case COM_TO_CENTER_OUT:
{
ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[1];
ChunkOrderHotspot *hotspots[1];
hotspots[0] = new ChunkOrderHotspot(this->m_width * centerX, this->m_height * centerY, 0.0f);
rcti rect;
ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
for (index = 0; index < this->m_numberOfChunks; index++) {
determineChunkRect(&rect, index);
chunkOrders[index].setChunkNumber(index);
@@ -274,13 +275,12 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
}
delete hotspots[0];
delete[] hotspots;
delete[] chunkOrders;
MEM_freeN(chunkOrders);
}
break;
case COM_TO_RULE_OF_THIRDS:
{
ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[9];
ChunkOrderHotspot *hotspots[9];
unsigned int tx = this->m_width / 6;
unsigned int ty = this->m_height / 6;
unsigned int mx = this->m_width / 2;
@@ -299,7 +299,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
hotspots[7] = new ChunkOrderHotspot(mx, ty, addition * 7);
hotspots[8] = new ChunkOrderHotspot(mx, by, addition * 8);
rcti rect;
ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
for (index = 0; index < this->m_numberOfChunks; index++) {
determineChunkRect(&rect, index);
chunkOrders[index].setChunkNumber(index);
@@ -323,8 +323,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
delete hotspots[6];
delete hotspots[7];
delete hotspots[8];
delete[] hotspots;
delete[] chunkOrders;
MEM_freeN(chunkOrders);
}
break;
case COM_TO_TOP_DOWN:
@@ -372,7 +371,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
}
}
delete[] chunkOrder;
MEM_freeN(chunkOrder);
}
MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
@@ -383,10 +382,7 @@ MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
determineChunkRect(&rect, chunkNumber);
this->determineDependingMemoryProxies(&memoryproxies);
MemoryBuffer **memoryBuffers = new MemoryBuffer *[this->m_cachedMaxReadBufferOffset];
for (index = 0; index < this->m_cachedMaxReadBufferOffset; index++) {
memoryBuffers[index] = NULL;
}
MemoryBuffer **memoryBuffers = (MemoryBuffer **)MEM_callocN(sizeof(MemoryBuffer *) * this->m_cachedMaxReadBufferOffset, __func__);
rcti output;
for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index];
@@ -422,7 +418,7 @@ void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memo
}
}
}
delete[] memoryBuffers;
MEM_freeN(memoryBuffers);
}
if (this->m_bTree) {
// status report is only performed for top level Execution Groups.

View File

@@ -75,7 +75,7 @@ float *MemoryBuffer::convertToValueBuffer()
const unsigned int size = this->determineBufferSize();
unsigned int i;
float *result = new float[size];
float *result = (float *)MEM_mallocN(sizeof(float) * size, __func__);
const float *fp_src = this->m_buffer;
float *fp_dst = result;

View File

@@ -32,6 +32,8 @@
#include "OCL_opencl.h"
#include "COM_WriteBufferOperation.h"
#include "MEM_guardedalloc.h"
#include "PIL_time.h"
#include "BLI_threads.h"
@@ -99,20 +101,20 @@ void **g_highlightedNodesRead;
void COM_startReadHighlights()
{
if (g_highlightedNodesRead) {
delete [] g_highlightedNodesRead;
MEM_freeN(g_highlightedNodesRead);
}
g_highlightedNodesRead = g_highlightedNodes;
g_highlightedNodes = new void *[MAX_HIGHLIGHT];
g_highlightedNodes = (void **)MEM_callocN(sizeof(void *) * MAX_HIGHLIGHT, __func__);
g_highlightIndex = 0;
for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
g_highlightedNodes[i] = 0;
}
}
int COM_isHighlightedbNode(bNode *bnode)
{
if (!g_highlightedNodesRead) return false;
if (!g_highlightedNodesRead) {
return false;
}
for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
void *p = g_highlightedNodesRead[i];
if (!p) return false;
@@ -255,8 +257,12 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t
void WorkScheduler::initialize()
{
g_highlightedNodesRead = 0;
g_highlightedNodes = 0;
if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead);
if (g_highlightedNodes) MEM_freeN(g_highlightedNodes);
g_highlightedNodesRead = NULL;
g_highlightedNodes = NULL;
COM_startReadHighlights();
#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
int numberOfCPUThreads = BLI_system_thread_count();
@@ -275,7 +281,7 @@ void WorkScheduler::initialize()
error = clGetPlatformIDs(0, 0, &numberOfPlatforms);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms);
cl_platform_id *platforms = new cl_platform_id[numberOfPlatforms];
cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__);
error = clGetPlatformIDs(numberOfPlatforms, platforms, 0);
unsigned int indexPlatform;
for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) {
@@ -283,7 +289,7 @@ void WorkScheduler::initialize()
cl_uint numberOfDevices = 0;
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices);
if (numberOfDevices > 0) {
cl_device_id *cldevices = new cl_device_id[numberOfDevices];
cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__);
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0);
g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error);
@@ -297,12 +303,12 @@ void WorkScheduler::initialize()
printf("CLERROR[%d]: %s\n", error, clewErrorString(error));
error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
char *build_log = new char[ret_val_size + 1];
char *build_log = (char *)MEM_mallocN(sizeof(char) * ret_val_size + 1, __func__);
error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
build_log[ret_val_size] = '\0';
printf("%s", build_log);
delete build_log;
MEM_freeN(build_log);
}
else {
unsigned int indexDevices;
@@ -316,10 +322,10 @@ void WorkScheduler::initialize()
g_gpudevices.push_back(clDevice);
}
}
delete[] cldevices;
MEM_freeN(cldevices);
}
}
delete[] platforms;
MEM_freeN(platforms);
}
#endif
#endif
@@ -352,5 +358,13 @@ void WorkScheduler::deinitialize()
}
#endif
#endif
if (g_highlightedNodes) {
MEM_freeN(g_highlightedNodes);
}
if (g_highlightedNodesRead) {
MEM_freeN(g_highlightedNodesRead);
}
}

View File

@@ -38,7 +38,11 @@ void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContex
{
bNode *b_node = this->getbNode();
if (b_node->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) {
InputSocket *inputSizeSocket = this->getInputSocket(2);
bool connectedSizeSocket = inputSizeSocket->isConnected();
if ((b_node->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) && connectedSizeSocket) {
VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation();
this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
@@ -55,9 +59,6 @@ void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContex
}
else {
BokehBlurOperation *operation = new BokehBlurOperation();
InputSocket *inputSizeSocket = this->getInputSocket(2);
bool connectedSizeSocket = inputSizeSocket->isConnected();
const bNodeSocket *sock = this->getInputSocket(2)->getbNodeSocket();
const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value;

View File

@@ -23,6 +23,10 @@
#include "COM_AntiAliasOperation.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_render_ext.h"
}
@@ -58,7 +62,7 @@ void AntiAliasOperation::deinitExecution()
{
this->m_valueReader = NULL;
if (this->m_buffer) {
delete this->m_buffer;
MEM_freeN(this->m_buffer);
}
NodeOperation::deinitMutex();
}
@@ -90,12 +94,10 @@ void *AntiAliasOperation::initializeTileData(rcti *rect)
MemoryBuffer *tile = (MemoryBuffer *)this->m_valueReader->initializeTileData(rect);
int size = tile->getHeight() * tile->getWidth();
float *input = tile->getBuffer();
char *valuebuffer = new char[size];
char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
for (int i = 0; i < size; i++) {
float in = input[i * COM_NUMBER_OF_CHANNELS];
if (in < 0.0f) { in = 0.0f; }
if (in > 1.0f) {in = 1.0f; }
valuebuffer[i] = in * 255;
valuebuffer[i] = FTOCHAR(in);
}
antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
this->m_buffer = valuebuffer;

View File

@@ -22,6 +22,7 @@
#include "COM_BlurBaseOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_pipeline.h"
@@ -74,7 +75,7 @@ float *BlurBaseOperation::make_gausstab(int rad)
n = 2 * rad + 1;
gausstab = new float[n];
gausstab = (float *)MEM_mallocN(sizeof(float) * n, __func__);
sum = 0.0f;
for (i = -rad; i <= rad; i++) {
@@ -99,7 +100,7 @@ float *BlurBaseOperation::make_dist_fac_inverse(int rad, int falloff)
n = 2 * rad + 1;
dist_fac_invert = new float[n];
dist_fac_invert = (float *)MEM_mallocN(sizeof(float) * n, __func__);
for (i = -rad; i <= rad; i++) {
val = 1.0f - fabsf(((float)i / (float)rad));

View File

@@ -24,6 +24,8 @@
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
ConvolutionFilterOperation::ConvolutionFilterOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
@@ -42,7 +44,7 @@ void ConvolutionFilterOperation::initExecution()
void ConvolutionFilterOperation::set3x3Filter(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9)
{
this->m_filter = new float[9];
this->m_filter = (float *)MEM_mallocN(sizeof(float) * 9, __func__);
this->m_filter[0] = f1;
this->m_filter[1] = f2;
this->m_filter[2] = f3;
@@ -61,7 +63,7 @@ void ConvolutionFilterOperation::deinitExecution()
this->m_inputOperation = NULL;
this->m_inputValueOperation = NULL;
if (this->m_filter) {
delete[] this->m_filter;
MEM_freeN(this->m_filter);
this->m_filter = NULL;
}
}

View File

@@ -24,6 +24,8 @@
#include "BLI_math.h"
#include "COM_OpenCLDevice.h"
#include "MEM_guardedalloc.h"
// DilateErode Distance Threshold
DilateErodeThresholdOperation::DilateErodeThresholdOperation() : NodeOperation()
{
@@ -384,7 +386,7 @@ void DilateStepOperation::deinitExecution()
this->m_inputProgram = NULL;
this->deinitMutex();
if (this->m_cached_buffer) {
delete [] this->m_cached_buffer;
MEM_freeN(this->m_cached_buffer);
this->m_cached_buffer = NULL;
}
}

View File

@@ -1269,12 +1269,12 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect)
if (this->m_cachedInstance == NULL) {
MemoryBuffer *innerMask = (MemoryBuffer *)this->m_inputInnerMask->initializeTileData(rect);
MemoryBuffer *outerMask = (MemoryBuffer *)this->m_inputOuterMask->initializeTileData(rect);
float *data = new float[this->getWidth() * this->getHeight()];
float *data = (float *)MEM_mallocN(sizeof(float) * this->getWidth() * this->getHeight(), __func__);
float *imask = innerMask->convertToValueBuffer();
float *omask = outerMask->convertToValueBuffer();
doDoubleEdgeMask(imask, omask, data);
delete [] imask;
delete [] omask;
MEM_freeN(imask);
MEM_freeN(omask);
this->m_cachedInstance = data;
}
unlockMutex();
@@ -1293,7 +1293,7 @@ void DoubleEdgeMaskOperation::deinitExecution()
this->m_inputOuterMask = NULL;
deinitMutex();
if (this->m_cachedInstance) {
delete this->m_cachedInstance;
MEM_freeN(this->m_cachedInstance);
this->m_cachedInstance = NULL;
}
}

View File

@@ -23,6 +23,7 @@
#include "COM_GaussianAlphaXBlurOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_pipeline.h"
@@ -154,9 +155,9 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
void GaussianAlphaXBlurOperation::deinitExecution()
{
BlurBaseOperation::deinitExecution();
delete [] this->m_gausstab;
MEM_freeN(this->m_gausstab);
this->m_gausstab = NULL;
delete [] this->m_distbuf_inv;
MEM_freeN(this->m_distbuf_inv);
this->m_distbuf_inv = NULL;
deinitMutex();

View File

@@ -23,6 +23,7 @@
#include "COM_GaussianAlphaYBlurOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_pipeline.h"
@@ -154,9 +155,9 @@ void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, vo
void GaussianAlphaYBlurOperation::deinitExecution()
{
BlurBaseOperation::deinitExecution();
delete [] this->m_gausstab;
MEM_freeN(this->m_gausstab);
this->m_gausstab = NULL;
delete [] this->m_distbuf_inv;
MEM_freeN(this->m_distbuf_inv);
this->m_distbuf_inv = NULL;
deinitMutex();

View File

@@ -88,7 +88,7 @@ void GaussianBokehBlurOperation::updateGauss()
n = (2 * this->m_radx + 1) * (2 * this->m_rady + 1);
/* create a full filter image */
ddgauss = new float[n];
ddgauss = (float *)MEM_mallocN(sizeof(float) * n, __func__);
dgauss = ddgauss;
val = 0.0f;
for (j = -this->m_rady; j <= this->m_rady; j++) {
@@ -103,8 +103,9 @@ void GaussianBokehBlurOperation::updateGauss()
}
if (val != 0.0f) {
val = 1.0f / val;
for (j = n - 1; j >= 0; j--)
for (j = n - 1; j >= 0; j--) {
ddgauss[j] *= val;
}
}
else ddgauss[4] = 1.0f;
@@ -158,7 +159,7 @@ void GaussianBokehBlurOperation::executePixel(float output[4], int x, int y, voi
void GaussianBokehBlurOperation::deinitExecution()
{
BlurBaseOperation::deinitExecution();
delete [] this->m_gausstab;
MEM_freeN(this->m_gausstab);
this->m_gausstab = NULL;
deinitMutex();
@@ -258,8 +259,9 @@ void GaussianBlurReferenceOperation::updateGauss()
int i;
int x = MAX2(m_radx, m_rady);
this->m_maintabs = (float **)MEM_mallocN(x * sizeof(float *), "gauss array");
for (i = 0; i < x; i++)
for (i = 0; i < x; i++) {
m_maintabs[i] = make_gausstab(i + 1);
}
}
void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y, void *data)
@@ -326,8 +328,9 @@ void GaussianBlurReferenceOperation::deinitExecution()
{
int x, i;
x = MAX2(m_radx, m_rady);
for (i = 0; i < x; i++)
delete []m_maintabs[i];
for (i = 0; i < x; i++) {
MEM_freeN(m_maintabs[i]);
}
MEM_freeN(m_maintabs);
BlurBaseOperation::deinitExecution();
}

View File

@@ -22,6 +22,7 @@
#include "COM_GaussianXBlurOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_pipeline.h"
@@ -107,7 +108,7 @@ void GaussianXBlurOperation::executePixel(float output[4], int x, int y, void *d
void GaussianXBlurOperation::deinitExecution()
{
BlurBaseOperation::deinitExecution();
delete [] this->m_gausstab;
MEM_freeN(this->m_gausstab);
this->m_gausstab = NULL;
deinitMutex();

View File

@@ -22,6 +22,7 @@
#include "COM_GaussianYBlurOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "RE_pipeline.h"
@@ -108,7 +109,7 @@ void GaussianYBlurOperation::executePixel(float output[4], int x, int y, void *d
void GaussianYBlurOperation::deinitExecution()
{
BlurBaseOperation::deinitExecution();
delete [] this->m_gausstab;
MEM_freeN(this->m_gausstab);
this->m_gausstab = NULL;
deinitMutex();

View File

@@ -121,7 +121,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
{
int width = this->getWidth();
int height = this->getHeight();
short *m = this->m_manhatten_distance = new short[width * height];
short *m = this->m_manhatten_distance = (short *)MEM_mallocN(sizeof(short) * width * height, __func__);
int *offsets;
offsets = (int *)MEM_callocN(sizeof(int) * (width + height + 1), "InpaintSimpleOperation offsets");
@@ -140,7 +140,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
m[j * width + i] = r;
}
}
for (int j = height - 1; j >= 0; j--) {
for (int i = width - 1; i >= 0; i--) {
int r = m[j * width + i];
@@ -163,7 +163,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
}
this->m_area_size = offsets[width + height];
this->m_pixelorder = new int[this->m_area_size];
this->m_pixelorder = (int *)MEM_mallocN(sizeof(int) * this->m_area_size, __func__);
for (int i = 0; i < width * height; i++) {
if (m[i] > 0) {
@@ -225,9 +225,7 @@ void *InpaintSimpleOperation::initializeTileData(rcti *rect)
lockMutex();
if (!this->m_cached_buffer_ready) {
MemoryBuffer *buf = (MemoryBuffer *)this->m_inputImageProgram->initializeTileData(rect);
this->m_cached_buffer = new float[this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS];
memcpy(this->m_cached_buffer, buf->getBuffer(), this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
this->m_cached_buffer = (float *)MEM_dupallocN(buf->getBuffer());
this->calc_manhatten_distance();
@@ -256,17 +254,17 @@ void InpaintSimpleOperation::deinitExecution()
this->m_inputImageProgram = NULL;
this->deinitMutex();
if (this->m_cached_buffer) {
delete [] this->m_cached_buffer;
MEM_freeN(this->m_cached_buffer);
this->m_cached_buffer = NULL;
}
if (this->m_pixelorder) {
delete [] this->m_pixelorder;
MEM_freeN(this->m_pixelorder);
this->m_pixelorder = NULL;
}
if (this->m_manhatten_distance) {
delete [] this->m_manhatten_distance;
MEM_freeN(this->m_manhatten_distance);
this->m_manhatten_distance = NULL;
}
this->m_cached_buffer_ready = false;

View File

@@ -25,6 +25,8 @@
#include "COM_NodeOperation.h"
#include "DNA_movieclip_types.h"
#include "MEM_guardedalloc.h"
extern "C" {
#include "BKE_tracking.h"
#include "PIL_time.h"
@@ -62,22 +64,19 @@ public:
this->m_calibration_width = calibration_width;
this->m_calibration_height = calibration_height;
this->m_inverted = inverted;
this->m_bufferCalculated = new int[this->m_width * this->m_height];
this->m_buffer = new float[this->m_width * this->m_height * 2];
for (int i = 0; i < this->m_width * this->m_height; i++) {
this->m_bufferCalculated[i] = 0;
}
this->m_bufferCalculated = (int *)MEM_callocN(sizeof(int) * this->m_width * this->m_height, __func__);
this->m_buffer = (float *)MEM_mallocN(sizeof(float) * this->m_width * this->m_height * 2, __func__);
this->updateLastUsage();
}
~DistortionCache() {
if (this->m_buffer) {
delete[] this->m_buffer;
MEM_freeN(this->m_buffer);
this->m_buffer = NULL;
}
if (this->m_bufferCalculated) {
delete[] this->m_bufferCalculated;
MEM_freeN(this->m_bufferCalculated);
this->m_bufferCalculated = NULL;
}
}

View File

@@ -23,6 +23,8 @@
#include "COM_VectorBlurOperation.h"
#include "BLI_math.h"
#include "MEM_guardedalloc.h"
// use the implementation of blender internal renderer to calculate the vector blur.
extern "C" {
#include "RE_pipeline.h"
@@ -66,7 +68,7 @@ void VectorBlurOperation::deinitExecution()
this->m_inputSpeedProgram = NULL;
this->m_inputZProgram = NULL;
if (this->m_cachedInstance) {
delete [] this->m_cachedInstance;
MEM_freeN(this->m_cachedInstance);
this->m_cachedInstance = NULL;
}
}
@@ -81,8 +83,7 @@ void *VectorBlurOperation::initializeTileData(rcti *rect)
MemoryBuffer *tile = (MemoryBuffer *)this->m_inputImageProgram->initializeTileData(rect);
MemoryBuffer *speed = (MemoryBuffer *)this->m_inputSpeedProgram->initializeTileData(rect);
MemoryBuffer *z = (MemoryBuffer *)this->m_inputZProgram->initializeTileData(rect);
float *data = new float[this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS];
memcpy(data, tile->getBuffer(), this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
float *data = (float *)MEM_dupallocN(tile->getBuffer());
this->generateVectorBlur(data, tile, speed, z);
this->m_cachedInstance = data;
}
@@ -115,6 +116,6 @@ void VectorBlurOperation::generateVectorBlur(float *data, MemoryBuffer *inputIma
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);
delete [] zbuf;
MEM_freeN((void *)zbuf);
return;
}

View File

@@ -46,6 +46,7 @@ void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, s
struct Mask *ED_space_image_get_mask(struct SpaceImage *sima);
void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
int ED_space_image_color_sample(struct SpaceImage *sima, struct ARegion *ar, int mval[2], float r_col[3]);
struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **lock_r);
void ED_space_image_release_buffer(struct SpaceImage *sima, void *lock);
int ED_space_image_has_buffer(struct SpaceImage *sima);

View File

@@ -76,8 +76,11 @@ void ED_node_set_active(struct Main *bmain, struct bNodeTree *ntree, struct bNod
void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, struct Scene *scene_owner);
/* node ops.c */
/* node_ops.c */
void ED_operatormacros_node(void);
/* node_view.c */
int ED_space_node_color_sample(struct SpaceNode *snode, struct ARegion *ar, int mval[2], float r_col[3]);
#endif /* __ED_NODE_H__ */

View File

@@ -69,6 +69,8 @@
#include "BKE_main.h"
#include "BLI_ghash.h"
#include "ED_image.h" /* for HDR color sampling */
#include "ED_node.h" /* for HDR color sampling */
/* ********************************************************** */
@@ -126,9 +128,47 @@ static int eyedropper_cancel(bContext *C, wmOperator *op)
/* *** eyedropper_color_ helper functions *** */
/* simply get the color from the screen */
static void eyedropper_color_sample_fl(Eyedropper *UNUSED(eye), int mx, int my, float r_col[3])
/**
* \brief get the color from the screen.
*
* Special check for image or nodes where we MAY have HDR pixels which don't display.
*/
static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int mx, int my, float r_col[3])
{
/* we could use some clever */
wmWindow *win = CTX_wm_window(C);
ScrArea *sa;
for (sa = win->screen->areabase.first; sa; sa = sa->next) {
if (BLI_in_rcti(&sa->totrct, mx, my)) {
if (sa->spacetype == SPACE_IMAGE) {
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
if (BLI_in_rcti(&ar->winrct, mx, my)) {
SpaceImage *sima = sa->spacedata.first;
int mval[2] = {mx - ar->winrct.xmin,
my - ar->winrct.ymin};
if (ED_space_image_color_sample(sima, ar, mval, r_col)) {
return;
}
}
}
else if (sa->spacetype == SPACE_NODE) {
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
if (BLI_in_rcti(&ar->winrct, mx, my)) {
SpaceNode *snode = sa->spacedata.first;
int mval[2] = {mx - ar->winrct.xmin,
my - ar->winrct.ymin};
if (ED_space_node_color_sample(snode, ar, mval, r_col)) {
return;
}
}
}
}
}
/* fallback to simple opengl picker */
glReadBuffer(GL_FRONT);
glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, r_col);
glReadBuffer(GL_BACK);
@@ -167,14 +207,14 @@ static void eyedropper_color_set_accum(bContext *C, Eyedropper *eye)
static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my)
{
float col[3];
eyedropper_color_sample_fl(eye, mx, my, col);
eyedropper_color_sample_fl(C, eye, mx, my, col);
eyedropper_color_set(C, eye, col);
}
static void eyedropper_color_sample_accum(Eyedropper *eye, int mx, int my)
static void eyedropper_color_sample_accum(bContext *C, Eyedropper *eye, int mx, int my)
{
float col[3];
eyedropper_color_sample_fl(eye, mx, my, col);
eyedropper_color_sample_fl(C, eye, mx, my, col);
/* delay linear conversion */
add_v3_v3(eye->accum_col, col);
eye->accum_tot++;
@@ -203,13 +243,13 @@ static int eyedropper_modal(bContext *C, wmOperator *op, wmEvent *event)
else if (event->val == KM_PRESS) {
/* enable accum and make first sample */
eye->accum_start = TRUE;
eyedropper_color_sample_accum(eye, event->x, event->y);
eyedropper_color_sample_accum(C, eye, event->x, event->y);
}
break;
case MOUSEMOVE:
if (eye->accum_start) {
/* button is pressed so keep sampling */
eyedropper_color_sample_accum(eye, event->x, event->y);
eyedropper_color_sample_accum(C, eye, event->x, event->y);
eyedropper_color_set_accum(C, eye);
}
break;
@@ -217,7 +257,7 @@ static int eyedropper_modal(bContext *C, wmOperator *op, wmEvent *event)
if (event->val == KM_RELEASE) {
eye->accum_tot = 0;
zero_v3(eye->accum_col);
eyedropper_color_sample_accum(eye, event->x, event->y);
eyedropper_color_sample_accum(C, eye, event->x, event->y);
eyedropper_color_set_accum(C, eye);
}
break;

View File

@@ -2000,6 +2000,54 @@ static void image_sample_draw(const bContext *UNUSED(C), ARegion *ar, void *arg_
}
}
/* returns color in SRGB */
/* matching ED_space_node_color_sample() */
int ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], float r_col[3])
{
void *lock;
ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
float fx, fy;
int ret = FALSE;
if (ibuf == NULL) {
ED_space_image_release_buffer(sima, lock);
return FALSE;
}
UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &fx, &fy);
if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
float *fp;
unsigned char *cp;
int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
CLAMP(x, 0, ibuf->x - 1);
CLAMP(y, 0, ibuf->y - 1);
if (ibuf->rect_float) {
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
linearrgb_to_srgb_v3_v3(r_col, fp);
}
else {
copy_v3_v3(r_col, fp);
}
ret = TRUE;
}
else if (ibuf->rect) {
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
r_col[0] = cp[0] / 255.0f;
r_col[1] = cp[1] / 255.0f;
r_col[2] = cp[2] / 255.0f;
ret = TRUE;
}
}
ED_space_image_release_buffer(sima, lock);
return ret;
}
static void image_sample_apply(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceImage *sima = CTX_wm_space_image(C);

View File

@@ -32,6 +32,7 @@
#include "BLI_rect.h"
#include "BLI_utildefines.h"
#include "BLI_math.h"
#include "BKE_context.h"
#include "BKE_image.h"
@@ -350,6 +351,61 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
}
}
/* returns color in SRGB */
/* matching ED_space_image_color_sample() */
int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3])
{
void *lock;
Image *ima;
ImBuf *ibuf;
float fx, fy, bufx, bufy;
int ret = FALSE;
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (!ibuf) {
return FALSE;
}
/* map the mouse coords to the backdrop image space */
bufx = ibuf->x * snode->zoom;
bufy = ibuf->y * snode->zoom;
fx = (bufx > 0.0f ? ((float)mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f);
fy = (bufy > 0.0f ? ((float)mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f);
if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
float *fp;
char *cp;
int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
CLAMP(x, 0, ibuf->x - 1);
CLAMP(y, 0, ibuf->y - 1);
if (ibuf->rect_float) {
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
linearrgb_to_srgb_v3_v3(r_col, fp);
}
else {
copy_v3_v3(r_col, fp);
}
ret = TRUE;
}
else if (ibuf->rect) {
cp = (char *)(ibuf->rect + y * ibuf->x + x);
r_col[0] = cp[0] / 255.0f;
r_col[1] = cp[1] / 255.0f;
r_col[2] = cp[2] / 255.0f;
ret = TRUE;
}
}
BKE_image_release_ibuf(ima, lock);
return ret;
}
static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceNode *snode = CTX_wm_space_node(C);