2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "COM_ProjectorLensDistortionOperation.h"
25
#include "BLI_utildefines.h"
27
ProjectorLensDistortionOperation::ProjectorLensDistortionOperation() : NodeOperation()
29
this->addInputSocket(COM_DT_COLOR);
30
this->addInputSocket(COM_DT_VALUE);
31
this->addOutputSocket(COM_DT_COLOR);
32
this->setComplex(true);
33
this->m_inputProgram = NULL;
34
this->m_dispersionAvailable = false;
35
this->m_dispersion = 0.0f;
37
void ProjectorLensDistortionOperation::initExecution()
40
this->m_inputProgram = this->getInputSocketReader(0);
43
void *ProjectorLensDistortionOperation::initializeTileData(rcti *rect)
46
void *buffer = this->m_inputProgram->initializeTileData(NULL);
50
void ProjectorLensDistortionOperation::executePixel(float output[4], int x, int y, void *data)
53
const float height = this->getHeight();
54
const float width = this->getWidth();
55
const float v = (y + 0.5f) / height;
56
const float u = (x + 0.5f) / width;
57
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
58
inputBuffer->readCubic(inputValue, (u * width + this->m_kr2) - 0.5f, v * height - 0.5f);
59
output[0] = inputValue[0];
60
inputBuffer->read(inputValue, x, y);
61
output[1] = inputValue[1];
62
inputBuffer->readCubic(inputValue, (u * width - this->m_kr2) - 0.5f, v * height - 0.5f);
63
output[2] = inputValue[2];
67
void ProjectorLensDistortionOperation::deinitExecution()
70
this->m_inputProgram = NULL;
73
bool ProjectorLensDistortionOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
76
if (this->m_dispersionAvailable) {
77
newInput.ymax = input->ymax;
78
newInput.ymin = input->ymin;
79
newInput.xmin = input->xmin - this->m_kr2 - 2;
80
newInput.xmax = input->xmax + this->m_kr2 + 2;
84
BLI_rcti_init(&dispInput, 0, 5, 0, 5);
85
if (this->getInputOperation(1)->determineDependingAreaOfInterest(&dispInput, readOperation, output)) {
88
newInput.xmin = input->xmin - 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */
89
newInput.ymin = input->ymin;
90
newInput.ymax = input->ymax;
91
newInput.xmax = input->xmax + 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */
93
if (this->getInputOperation(0)->determineDependingAreaOfInterest(&newInput, readOperation, output)) {
99
void ProjectorLensDistortionOperation::updateDispersion()
101
if (this->m_dispersionAvailable) return;
103
if (!this->m_dispersionAvailable) {
105
this->getInputSocketReader(1)->read(result, 1, 1, COM_PS_NEAREST);
106
this->m_dispersion = result[0];
107
this->m_kr = 0.25f * max_ff(min_ff(this->m_dispersion, 1.0f), 0.0f);
108
this->m_kr2 = this->m_kr * 20;
109
this->m_dispersionAvailable = true;