a2385f79c045b456732378798263971392f16081
[blender.git] / source / blender / compositor / operations / COM_ReadBufferOperation.cpp
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_ReadBufferOperation.h"
24 #include "COM_WriteBufferOperation.h"
25 #include "COM_defines.h"
26
27 ReadBufferOperation::ReadBufferOperation() : NodeOperation()
28 {
29         this->addOutputSocket(COM_DT_COLOR);
30         this->m_offset = 0;
31         this->m_buffer = NULL;
32 }
33
34 void *ReadBufferOperation::initializeTileData(rcti *rect)
35 {
36         return m_buffer;
37 }
38
39 void ReadBufferOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
40 {
41         if (this->m_memoryProxy != NULL) {
42                 WriteBufferOperation *operation = this->m_memoryProxy->getWriteBufferOperation();
43                 operation->determineResolution(resolution, preferredResolution);
44                 operation->setResolution(resolution);
45
46                 /// @todo: may not occur!, but does with blur node
47                 if (this->m_memoryProxy->getExecutor()) {
48                         this->m_memoryProxy->getExecutor()->setResolution(resolution);
49                 }
50         }
51 }
52 void ReadBufferOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
53 {
54         if (sampler == COM_PS_NEAREST) {
55                 m_buffer->read(output, x, y);
56         }
57         else {
58                 m_buffer->readCubic(output, x, y);
59         }
60 }
61
62 void ReadBufferOperation::executePixel(float output[4], float x, float y, float dx, float dy)
63 {
64         m_buffer->readEWA(output, x, y, dx, dy);
65 }
66
67 bool ReadBufferOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
68 {
69         if (this == readOperation) {
70                 BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
71                 return true;
72         }
73         return false;
74 }
75
76 void ReadBufferOperation::readResolutionFromWriteBuffer()
77 {
78         if (this->m_memoryProxy != NULL) {
79                 WriteBufferOperation *operation = this->m_memoryProxy->getWriteBufferOperation();
80                 this->setWidth(operation->getWidth());
81                 this->setHeight(operation->getHeight());
82         }
83 }
84
85 void ReadBufferOperation::updateMemoryBuffer() 
86 {
87         this->m_buffer = this->getMemoryProxy()->getBuffer();
88         
89 }