~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/compositor/operations/COM_PreviewOperation.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * Contributor: 
 
19
 *              Jeroen Bakker 
 
20
 *              Monique Dewanchand
 
21
 */
 
22
 
 
23
#include "COM_PreviewOperation.h"
 
24
#include "COM_SocketConnection.h"
 
25
#include "BLI_listbase.h"
 
26
#include "BKE_image.h"
 
27
#include "WM_api.h"
 
28
#include "WM_types.h"
 
29
#include "PIL_time.h"
 
30
#include "BLI_utildefines.h"
 
31
#include "BLI_math_color.h"
 
32
#include "COM_defines.h"
 
33
#include "BLI_math.h"
 
34
extern "C" {
 
35
        #include "MEM_guardedalloc.h"
 
36
        #include "IMB_imbuf.h"
 
37
        #include "IMB_imbuf_types.h"
 
38
        #include "IMB_colormanagement.h"
 
39
}
 
40
 
 
41
 
 
42
PreviewOperation::PreviewOperation(const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings) : NodeOperation()
 
43
{
 
44
        this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
 
45
        this->m_outputBuffer = NULL;
 
46
        this->m_input = NULL;
 
47
        this->m_divider = 1.0f;
 
48
        this->m_node = NULL;
 
49
        this->m_viewSettings = viewSettings;
 
50
        this->m_displaySettings = displaySettings;
 
51
}
 
52
 
 
53
void PreviewOperation::initExecution()
 
54
{
 
55
        this->m_input = getInputSocketReader(0);
 
56
        if (!this->m_node->preview) {
 
57
                this->m_node->preview = (bNodePreview *)MEM_callocN(sizeof(bNodePreview), "node preview");
 
58
        }
 
59
        else {
 
60
                if (this->getWidth() == (unsigned int)this->m_node->preview->xsize &&
 
61
                    this->getHeight() == (unsigned int)this->m_node->preview->ysize)
 
62
                {
 
63
                        this->m_outputBuffer = this->m_node->preview->rect;
 
64
                }
 
65
        }
 
66
 
 
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);
 
71
                }
 
72
                this->m_node->preview->xsize = getWidth();
 
73
                this->m_node->preview->ysize = getHeight();
 
74
                this->m_node->preview->rect = this->m_outputBuffer;
 
75
        }
 
76
}
 
77
 
 
78
void PreviewOperation::deinitExecution()
 
79
{
 
80
        this->m_outputBuffer = NULL;
 
81
        this->m_input = NULL;
 
82
}
 
83
 
 
84
void PreviewOperation::executeRegion(rcti *rect, unsigned int tileNumber)
 
85
{
 
86
        int offset;
 
87
        float color[4];
 
88
        struct ColormanageProcessor *cm_processor;
 
89
 
 
90
        cm_processor = IMB_colormanagement_display_processor_new(this->m_viewSettings, this->m_displaySettings);
 
91
 
 
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);
 
97
        
 
98
                        color[0] = 0.0f;
 
99
                        color[1] = 0.0f;
 
100
                        color[2] = 0.0f;
 
101
                        color[3] = 1.0f;
 
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);
 
105
                        offset += 4;
 
106
                }
 
107
        }
 
108
 
 
109
        IMB_colormanagement_processor_free(cm_processor);
 
110
}
 
111
bool PreviewOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
 
112
{
 
113
        rcti newInput;
 
114
 
 
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;
 
119
 
 
120
        return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
 
121
}
 
122
void PreviewOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
 
123
{
 
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);
 
130
        }
 
131
        else {
 
132
                this->m_divider = COM_PREVIEW_SIZE / (height - 1);
 
133
        }
 
134
        width = width * this->m_divider;
 
135
        height = height * this->m_divider;
 
136
        
 
137
        resolution[0] = width;
 
138
        resolution[1] = height;
 
139
}
 
140
 
 
141
const CompositorPriority PreviewOperation::getRenderPriority() const
 
142
{
 
143
        return COM_PRIORITY_LOW;
 
144
}