r1006: configure: Use libx264_pic instead of libx264 if available.
[cinelerra_cv/mob.git] / cinelerra / maskautos.C
blob9b7ba4b1de3573f17f41b4d47e29beaacec31f94
1 #include "automation.inc"
2 #include "clip.h"
3 #include "maskauto.h"
4 #include "maskautos.h"
5 #include "transportque.inc"
10 MaskAutos::MaskAutos(EDL *edl, 
11         Track *track)
12  : Autos(edl, track)
14         type = AUTOMATION_TYPE_MASK;
17 MaskAutos::~MaskAutos()
22 void MaskAutos::get_points(ArrayList<MaskPoint*> *points, int submask, int64_t position, int direction)
24         MaskAuto *begin = 0, *end = 0;
25         position = (direction == PLAY_FORWARD) ? position : (position - 1);
27 // Get auto before and after position
28         for(MaskAuto* current = (MaskAuto*)last; 
29                 current; 
30                 current = (MaskAuto*)PREVIOUS)
31         {
32                 if(current->position <= position)
33                 {
34                         begin = current;
35                         end = NEXT ? (MaskAuto*)NEXT : current;
36                         break;
37                 }
38         }
40 // Nothing before position found
41         if(!begin)
42         {
43                 begin = end = (MaskAuto*)first;
44         }
46 // Nothing after position found
47         if(!begin)
48         {
49                 begin = end = (MaskAuto*)default_auto;
50         }
53         SubMask *mask1 = begin->get_submask(submask);
54         SubMask *mask2 = end->get_submask(submask);
56         points->remove_all_objects();
57         int total_points = MIN(mask1->points.total, mask2->points.total);
58         for(int i = 0; i < total_points; i++)
59         {
60                 MaskPoint *point = new MaskPoint;
61                 avg_points(point, 
62                         mask1->points.values[i], 
63                         mask2->points.values[i],
64                         position,
65                         begin->position,
66                         end->position);
67                 points->append(point);
68         }
71 void MaskAutos::avg_points(MaskPoint *output, 
72                 MaskPoint *input1, 
73                 MaskPoint *input2, 
74                 int64_t output_position,
75                 int64_t position1, 
76                 int64_t position2)
78         if(position2 == position1)
79         {
80                 *output = *input1;
81         }
82         else
83         {
84                 float fraction2 = (float)(output_position - position1) / (position2 - position1);
85                 float fraction1 = 1 - fraction2;
86                 output->x = input1->x * fraction1 + input2->x * fraction2;
87                 output->y = input1->y * fraction1 + input2->y * fraction2;
88                 output->control_x1 = input1->control_x1 * fraction1 + input2->control_x1 * fraction2;
89                 output->control_y1 = input1->control_y1 * fraction1 + input2->control_y1 * fraction2;
90                 output->control_x2 = input1->control_x2 * fraction1 + input2->control_x2 * fraction2;
91                 output->control_y2 = input1->control_y2 * fraction1 + input2->control_y2 * fraction2;
92         }
93         
97 Auto* MaskAutos::new_auto()
99         return new MaskAuto(edl, this);
102 void MaskAutos::dump()
104         printf("        MaskAutos::dump %p\n", this);
105         printf("        Default: position %ld submasks %d\n", 
106                 default_auto->position, 
107                 ((MaskAuto*)default_auto)->masks.total);
108         ((MaskAuto*)default_auto)->dump();
109         for(Auto* current = first; current; current = NEXT)
110         {
111                 printf("        position %ld masks %d\n", 
112                         current->position, 
113                         ((MaskAuto*)current)->masks.total);
114                 ((MaskAuto*)current)->dump();
115         }
118 int MaskAutos::mask_exists(int64_t position, int direction)
120         Auto *current = 0;
121         position = (direction == PLAY_FORWARD) ? position : (position - 1);
123         MaskAuto* keyframe = (MaskAuto*)get_prev_auto(position, direction, current);
127         for(int i = 0; i < keyframe->masks.total; i++)
128         {
129                 SubMask *mask = keyframe->get_submask(i);
130                 if(mask->points.total > 1) 
131                         return 1;
132         }
133         return 0;
136 int MaskAutos::total_submasks(int64_t position, int direction)
138         position = (direction == PLAY_FORWARD) ? position : (position - 1);
139         for(MaskAuto* current = (MaskAuto*)last; 
140                 current; 
141                 current = (MaskAuto*)PREVIOUS)
142         {
143                 if(current->position <= position)
144                 {
145                         return current->masks.total;
146                 }
147         }
149         return ((MaskAuto*)default_auto)->masks.total;
153 void MaskAutos::translate_masks(float translate_x, float translate_y)
155         ((MaskAuto *)default_auto)->translate_submasks(translate_x, translate_y);
156         for(MaskAuto* current = (MaskAuto*)first; 
157                 current; 
158                 current = (MaskAuto*)NEXT)
159         {
160                 current->translate_submasks(translate_x, translate_y);
161                 for(int i = 0; i < current->masks.total; i++)
162                 {
163                         SubMask *mask = current->get_submask(i);
164                         for (int j = 0; j < mask->points.total; j++) 
165                         {
166                                 mask->points.values[j]->x += translate_x;
167                                 mask->points.values[j]->y += translate_y;
168                                 printf("mpx: %f, mpy:%f\n",mask->points.values[j]->x,mask->points.values[j]->y);
169                         }
170                 }
171                 
172         }