Internal refactoring of tracking module, should be no functional changes
[blender.git] / source / blender / compositor / operations / COM_MovieClipAttributeOperation.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_MovieClipAttributeOperation.h"
24 extern "C" {
25         #include "BKE_tracking.h"
26 }
27 MovieClipAttributeOperation::MovieClipAttributeOperation(): NodeOperation()
28 {
29         this->addOutputSocket(COM_DT_VALUE);
30         this->valueSet = false;
31         this->framenumber = 0;
32         this->attribute = MCA_X;
33 }
34
35 void MovieClipAttributeOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
36 {
37         if (!valueSet) {
38                 float loc[2], scale, angle;
39                 loc[0] = 0.0f;
40                 loc[1] = 0.0f;
41                 scale = 1.0f;
42                 angle = 0.0f;
43                 if (clip) {
44                         BKE_tracking_stabilization_data_get(&clip->tracking, framenumber, getWidth(), getHeight(), loc, &scale, &angle);
45                 }
46                 switch (this->attribute) {
47                 case MCA_SCALE:
48                         this->value = scale;
49                         break;
50                 case MCA_ANGLE:
51                         this->value = angle;
52                         break;
53                 case MCA_X:
54                         this->value = loc[0];
55                         break;
56                 case MCA_Y:
57                         this->value = loc[1];
58                         break;
59                 }
60                 valueSet = true;
61         }
62         outputValue[0] = this->value;
63 }
64
65 void MovieClipAttributeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
66 {
67         resolution[0] = preferredResolution[0];
68         resolution[1] = preferredResolution[1];
69 }
70