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_ViewerOperation.h"
24
#include "COM_SocketConnection.h"
25
#include "BLI_listbase.h"
26
#include "BKE_image.h"
30
#include "BLI_utildefines.h"
31
#include "BLI_math_color.h"
32
#include "BLI_math_vector.h"
35
#include "MEM_guardedalloc.h"
36
#include "IMB_imbuf.h"
37
#include "IMB_imbuf_types.h"
41
ViewerOperation::ViewerOperation() : ViewerBaseOperation()
43
this->addInputSocket(COM_DT_COLOR);
44
this->addInputSocket(COM_DT_VALUE);
45
this->addInputSocket(COM_DT_VALUE);
47
this->m_imageInput = NULL;
48
this->m_alphaInput = NULL;
49
this->m_depthInput = NULL;
52
void ViewerOperation::initExecution()
54
// When initializing the tree during initial load the width and height can be zero.
55
this->m_imageInput = getInputSocketReader(0);
56
this->m_alphaInput = getInputSocketReader(1);
57
this->m_depthInput = getInputSocketReader(2);
58
this->m_doDepthBuffer = (this->m_depthInput != NULL);
59
ViewerBaseOperation::initExecution();
62
void ViewerOperation::deinitExecution()
64
this->m_imageInput = NULL;
65
this->m_alphaInput = NULL;
66
this->m_depthInput = NULL;
67
ViewerBaseOperation::deinitExecution();
71
void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
73
float *buffer = this->m_outputBuffer;
74
float *depthbuffer = this->m_depthBuffer;
76
const int x1 = rect->xmin;
77
const int y1 = rect->ymin;
78
const int x2 = rect->xmax;
79
const int y2 = rect->ymax;
80
const int offsetadd = (this->getWidth() - (x2 - x1));
81
const int offsetadd4 = offsetadd * 4;
82
int offset = (y1 * this->getWidth() + x1);
83
int offset4 = offset * 4;
84
float alpha[4], depth[4];
89
for (y = y1; y < y2 && (!breaked); y++) {
90
for (x = x1; x < x2; x++) {
91
this->m_imageInput->read(&(buffer[offset4]), x, y, COM_PS_NEAREST);
92
if (this->m_ignoreAlpha) {
93
buffer[offset4 + 3] = 1.0f;
96
if (this->m_alphaInput != NULL) {
97
this->m_alphaInput->read(alpha, x, y, COM_PS_NEAREST);
98
buffer[offset4 + 3] = alpha[0];
102
this->m_depthInput->read(depth, x, y, COM_PS_NEAREST);
103
depthbuffer[offset] = depth[0];
113
offset4 += offsetadd4;