1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* 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_RotateOperation.h"
#include "BLI_math.h"
RotateOperation::RotateOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_COLOR);
this->setResolutionInputSocketIndex(0);
this->imageSocket = NULL;
this->degreeSocket = NULL;
this->doDegree2RadConversion = false;
}
void RotateOperation::initExecution()
{
this->imageSocket = this->getInputSocketReader(0);
this->degreeSocket = this->getInputSocketReader(1);
this->centerX = this->getWidth()/2.0;
this->centerY = this->getHeight()/2.0;
float degree[4];
this->degreeSocket->read(degree, 0, 0, COM_PS_NEAREST, NULL);
double rad;
if (this->doDegree2RadConversion) {
rad = DEG2RAD((double)degree[0]);
}
else {
rad = degree[0];
}
this->cosine = cos(rad);
this->sine = sin(rad);
}
void RotateOperation::deinitExecution()
{
this->imageSocket = NULL;
this->degreeSocket = NULL;
}
void RotateOperation::executePixel(float *color,float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
{
const float dy = y - this->centerY;
const float dx = x - this->centerX;
const float nx = this->centerX+(this->cosine*dx + this->sine*dy);
const float ny = this->centerY+(-this->sine*dx + this->cosine*dy);
this->imageSocket->read(color, nx, ny, sampler, inputBuffers);
}
bool RotateOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
rcti newInput;
const float dxmin = input->xmin - this->centerX;
const float dymin = input->ymin - this->centerY;
const float dxmax = input->xmax - this->centerX;
const float dymax = input->ymax - this->centerY;
const float x1 = this->centerX+(this->cosine*dxmin + this->sine*dymin);
const float x2 = this->centerX+(this->cosine*dxmax + this->sine*dymin);
const float x3 = this->centerX+(this->cosine*dxmin + this->sine*dymax);
const float x4 = this->centerX+(this->cosine*dxmax + this->sine*dymax);
const float y1 = this->centerY+(-this->sine*dxmin + this->cosine*dymin);
const float y2 = this->centerY+(-this->sine*dxmax + this->cosine*dymin);
const float y3 = this->centerY+(-this->sine*dxmin + this->cosine*dymax);
const float y4 = this->centerY+(-this->sine*dxmax + this->cosine*dymax);
const float minx = min(x1, min(x2, min(x3, x4)));
const float maxx = max(x1, max(x2, max(x3, x4)));
const float miny = min(y1, min(y2, min(y3, y4)));
const float maxy = max(y1, max(y2, max(y3, y4)));
newInput.xmax = ceil(maxx)+1;
newInput.xmin = floor(minx)-1;
newInput.ymax = ceil(maxy)+1;
newInput.ymin = floor(miny)-1;
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
|