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_PreviewOperation.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 "COM_defines.h"
35
#include "MEM_guardedalloc.h"
36
#include "IMB_imbuf.h"
37
#include "IMB_imbuf_types.h"
38
#include "IMB_colormanagement.h"
42
PreviewOperation::PreviewOperation(const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings) : NodeOperation()
44
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
45
this->m_outputBuffer = NULL;
47
this->m_divider = 1.0f;
49
this->m_viewSettings = viewSettings;
50
this->m_displaySettings = displaySettings;
53
void PreviewOperation::initExecution()
55
this->m_input = getInputSocketReader(0);
56
if (!this->m_node->preview) {
57
this->m_node->preview = (bNodePreview *)MEM_callocN(sizeof(bNodePreview), "node preview");
60
if (this->getWidth() == (unsigned int)this->m_node->preview->xsize &&
61
this->getHeight() == (unsigned int)this->m_node->preview->ysize)
63
this->m_outputBuffer = this->m_node->preview->rect;
67
if (this->m_outputBuffer == NULL) {
68
this->m_outputBuffer = (unsigned char *)MEM_callocN(sizeof(unsigned char) * 4 * getWidth() * getHeight(), "PreviewOperation");
69
if (this->m_node->preview->rect) {
70
MEM_freeN(this->m_node->preview->rect);
72
this->m_node->preview->xsize = getWidth();
73
this->m_node->preview->ysize = getHeight();
74
this->m_node->preview->rect = this->m_outputBuffer;
78
void PreviewOperation::deinitExecution()
80
this->m_outputBuffer = NULL;
84
void PreviewOperation::executeRegion(rcti *rect, unsigned int tileNumber)
88
struct ColormanageProcessor *cm_processor;
90
cm_processor = IMB_colormanagement_display_processor_new(this->m_viewSettings, this->m_displaySettings);
92
for (int y = rect->ymin; y < rect->ymax; y++) {
93
offset = (y * getWidth() + rect->xmin) * 4;
94
for (int x = rect->xmin; x < rect->xmax; x++) {
95
float rx = floor(x / this->m_divider);
96
float ry = floor(y / this->m_divider);
102
this->m_input->read(color, rx, ry, COM_PS_NEAREST);
103
IMB_colormanagement_processor_apply_v4(cm_processor, color);
104
F4TOCHAR4(color, this->m_outputBuffer + offset);
109
IMB_colormanagement_processor_free(cm_processor);
111
bool PreviewOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
115
newInput.xmin = input->xmin / this->m_divider;
116
newInput.xmax = input->xmax / this->m_divider;
117
newInput.ymin = input->ymin / this->m_divider;
118
newInput.ymax = input->ymax / this->m_divider;
120
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
122
void PreviewOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
124
NodeOperation::determineResolution(resolution, preferredResolution);
125
int width = resolution[0];
126
int height = resolution[1];
127
this->m_divider = 0.0f;
128
if (width > height) {
129
this->m_divider = COM_PREVIEW_SIZE / (width - 1);
132
this->m_divider = COM_PREVIEW_SIZE / (height - 1);
134
width = width * this->m_divider;
135
height = height * this->m_divider;
137
resolution[0] = width;
138
resolution[1] = height;
141
const CompositorPriority PreviewOperation::getRenderPriority() const
143
return COM_PRIORITY_LOW;