r553: Modern gccs require __attribute__((used)) for variables used only in assembly.
[cinelerra_cv/mob.git] / cinelerra / maskautos.C
blobd263bac27018cda8d3cafcef765bda84f9452f73
1 #include "clip.h"
2 #include "maskauto.h"
3 #include "maskautos.h"
4 #include "transportque.inc"
9 MaskAutos::MaskAutos(EDL *edl, 
10         Track *track)
11  : Autos(edl, track)
15 MaskAutos::~MaskAutos()
20 void MaskAutos::get_points(ArrayList<MaskPoint*> *points, int submask, int64_t position, int direction)
22         MaskAuto *begin = 0, *end = 0;
23         position = (direction == PLAY_FORWARD) ? position : (position - 1);
25 // Get auto before and after position
26         for(MaskAuto* current = (MaskAuto*)last; 
27                 current; 
28                 current = (MaskAuto*)PREVIOUS)
29         {
30                 if(current->position <= position)
31                 {
32                         begin = current;
33                         end = NEXT ? (MaskAuto*)NEXT : current;
34                         break;
35                 }
36         }
38 // Nothing before position found
39         if(!begin)
40         {
41                 begin = end = (MaskAuto*)first;
42         }
44 // Nothing after position found
45         if(!begin)
46         {
47                 begin = end = (MaskAuto*)default_auto;
48         }
51         SubMask *mask1 = begin->get_submask(submask);
52         SubMask *mask2 = end->get_submask(submask);
54         points->remove_all_objects();
55         int total_points = MIN(mask1->points.total, mask2->points.total);
56         for(int i = 0; i < total_points; i++)
57         {
58                 MaskPoint *point = new MaskPoint;
59                 avg_points(point, 
60                         mask1->points.values[i], 
61                         mask2->points.values[i],
62                         position,
63                         begin->position,
64                         end->position);
65                 points->append(point);
66         }
69 void MaskAutos::avg_points(MaskPoint *output, 
70                 MaskPoint *input1, 
71                 MaskPoint *input2, 
72                 int64_t output_position,
73                 int64_t position1, 
74                 int64_t position2)
76         if(position2 == position1)
77         {
78                 *output = *input1;
79         }
80         else
81         {
82                 float fraction2 = (float)(output_position - position1) / (position2 - position1);
83                 float fraction1 = 1 - fraction2;
84                 output->x = input1->x * fraction1 + input2->x * fraction2;
85                 output->y = input1->y * fraction1 + input2->y * fraction2;
86                 output->control_x1 = input1->control_x1 * fraction1 + input2->control_x1 * fraction2;
87                 output->control_y1 = input1->control_y1 * fraction1 + input2->control_y1 * fraction2;
88                 output->control_x2 = input1->control_x2 * fraction1 + input2->control_x2 * fraction2;
89                 output->control_y2 = input1->control_y2 * fraction1 + input2->control_y2 * fraction2;
90         }
91         
95 Auto* MaskAutos::new_auto()
97         return new MaskAuto(edl, this);
100 int MaskAutos::dump()
102         printf("        MaskAutos::dump %p\n", this);
103         printf("        Default: position %ld submasks %d\n", 
104                 default_auto->position, 
105                 ((MaskAuto*)default_auto)->masks.total);
106         ((MaskAuto*)default_auto)->dump();
107         for(Auto* current = first; current; current = NEXT)
108         {
109                 printf("        position %ld masks %d\n", 
110                         current->position, 
111                         ((MaskAuto*)current)->masks.total);
112                 ((MaskAuto*)current)->dump();
113         }
114         return 0;
117 int MaskAutos::mask_exists(int64_t position, int direction)
119         Auto *current = 0;
120         position = (direction == PLAY_FORWARD) ? position : (position - 1);
122         MaskAuto* keyframe = (MaskAuto*)get_prev_auto(position, direction, current);
126         for(int i = 0; i < keyframe->masks.total; i++)
127         {
128                 SubMask *mask = keyframe->get_submask(i);
129                 if(mask->points.total > 1) 
130                         return 1;
131         }
132         return 0;
135 int MaskAutos::total_submasks(int64_t position, int direction)
137         position = (direction == PLAY_FORWARD) ? position : (position - 1);
138         for(MaskAuto* current = (MaskAuto*)last; 
139                 current; 
140                 current = (MaskAuto*)PREVIOUS)
141         {
142                 if(current->position <= position)
143                 {
144                         return current->masks.total;
145                 }
146         }
148         return ((MaskAuto*)default_auto)->masks.total;