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

« back to all changes in this revision

Viewing changes to source/blender/compositor/operations/COM_ViewerOperation.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_ViewerOperation.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 "BLI_math_vector.h"
 
33
 
 
34
extern "C" {
 
35
        #include "MEM_guardedalloc.h"
 
36
        #include "IMB_imbuf.h"
 
37
        #include "IMB_imbuf_types.h"
 
38
}
 
39
 
 
40
 
 
41
ViewerOperation::ViewerOperation() : ViewerBaseOperation()
 
42
{
 
43
        this->addInputSocket(COM_DT_COLOR);
 
44
        this->addInputSocket(COM_DT_VALUE);
 
45
        this->addInputSocket(COM_DT_VALUE);
 
46
 
 
47
        this->m_imageInput = NULL;
 
48
        this->m_alphaInput = NULL;
 
49
        this->m_depthInput = NULL;
 
50
}
 
51
 
 
52
void ViewerOperation::initExecution()
 
53
{
 
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();
 
60
}
 
61
 
 
62
void ViewerOperation::deinitExecution()
 
63
{
 
64
        this->m_imageInput = NULL;
 
65
        this->m_alphaInput = NULL;
 
66
        this->m_depthInput = NULL;
 
67
        ViewerBaseOperation::deinitExecution();
 
68
}
 
69
 
 
70
 
 
71
void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
 
72
{
 
73
        float *buffer = this->m_outputBuffer;
 
74
        float *depthbuffer = this->m_depthBuffer;
 
75
        if (!buffer) return;
 
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];
 
85
        int x;
 
86
        int y;
 
87
        bool breaked = false;
 
88
 
 
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;
 
94
                        }
 
95
                        else {
 
96
                                if (this->m_alphaInput != NULL) {
 
97
                                        this->m_alphaInput->read(alpha, x, y, COM_PS_NEAREST);
 
98
                                        buffer[offset4 + 3] = alpha[0];
 
99
                                }
 
100
                        }
 
101
                        if (m_depthInput) {
 
102
                                this->m_depthInput->read(depth, x, y, COM_PS_NEAREST);
 
103
                                depthbuffer[offset] = depth[0];
 
104
                        }
 
105
 
 
106
                        offset ++;
 
107
                        offset4 += 4;
 
108
                }
 
109
                if (isBreaked()) {
 
110
                        breaked = true;
 
111
                }
 
112
                offset += offsetadd;
 
113
                offset4 += offsetadd4;
 
114
        }
 
115
        updateImage(rect);
 
116
}