remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / motion / motion.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2016 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef MOTION_H
23 #define MOTION_H
24
25 #include <math.h>
26 #include <stdint.h>
27 #include <string.h>
28
29 #include "affine.inc"
30 #include "bchash.inc"
31 #include "filexml.inc"
32 #include "keyframe.inc"
33 #include "loadbalance.h"
34 #include "motionscan.inc"
35 #include "motionwindow.inc"
36 #include "overlayframe.inc"
37 #include "pluginvclient.h"
38 #include "rotatescan.inc"
39 #include "vframe.inc"
40
41 class MotionMain;
42 class MotionWindow;
43
44
45
46
47 // Limits of global range in percent
48 #define MIN_RADIUS 1
49 #define MAX_RADIUS 100
50
51 // Limits of rotation range in degrees
52 #define MIN_ROTATION 1
53 #define MAX_ROTATION 25
54
55 // Limits of block size in percent.
56 #define MIN_BLOCK 1
57 #define MAX_BLOCK 100
58
59 // Limits of block count
60 #define MIN_BLOCKS 1
61 #define MAX_BLOCKS 200
62
63 // Precision of rotation
64 #define MIN_ANGLE 0.0001
65
66
67 class MotionConfig
68 {
69 public:
70         MotionConfig();
71
72         int equivalent(MotionConfig &that);
73         void copy_from(MotionConfig &that);
74         void interpolate(MotionConfig &prev,
75                 MotionConfig &next,
76                 int64_t prev_frame,
77                 int64_t next_frame,
78                 int64_t current_frame);
79         void boundaries();
80
81         int block_count;
82         int global_range_w;
83         int global_range_h;
84 // Range of angles above and below center rotation angle to search
85         int rotation_range;
86 // Center angle of rotation search
87         int rotation_center;
88         int magnitude;
89         int rotate_magnitude;
90         int return_speed;
91         int rotate_return_speed;
92         int draw_vectors;
93 // Percent of image size
94         int global_block_w;
95         int global_block_h;
96 //      int rotation_block_w;
97 //      int rotation_block_h;
98 // Number of search positions in each refinement of the log search
99 //      int global_positions;
100 //      int rotate_positions;
101 // Block position in percentage 0 - 100
102         double block_x;
103         double block_y;
104
105         int horizontal_only;
106         int vertical_only;
107         int global;
108         int rotate;
109 // Track or stabilize, single pixel, scan only, or nothing
110         int action_type;
111 // Recalculate, no calculate, save, or load coordinates from disk
112         int tracking_type;
113 // Track a single frame, previous frame, or previous frame same block
114         int tracking_object;
115
116 #if 0
117         enum
118         {
119 // action_type
120                 TRACK,
121                 STABILIZE,
122                 TRACK_PIXEL,
123                 STABILIZE_PIXEL,
124                 NOTHING,
125 // mode2
126                 RECALCULATE,
127                 SAVE,
128                 LOAD,
129                 NO_CALCULATE,
130 // tracking_object
131                 TRACK_SINGLE,
132                 TRACK_PREVIOUS,
133                 PREVIOUS_SAME_BLOCK
134         };
135 #endif
136
137
138 // Number of single frame to track relative to timeline start
139         int64_t track_frame;
140 // Master layer
141         int bottom_is_master;
142 };
143
144
145
146
147 class MotionMain : public PluginVClient
148 {
149 public:
150         MotionMain(PluginServer *server);
151         ~MotionMain();
152
153         int process_buffer(VFrame **frame,
154                 int64_t start_position,
155                 double frame_rate);
156         void process_global();
157         void process_rotation();
158         void draw_vectors(VFrame *frame);
159         int is_multichannel();
160         int is_realtime();
161         void save_data(KeyFrame *keyframe);
162         void read_data(KeyFrame *keyframe);
163         void update_gui();
164 // Calculate frame to copy from and frame to move
165         void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
166         void allocate_temp(int w, int h, int color_model);
167
168         PLUGIN_CLASS_MEMBERS2(MotionConfig)
169
170
171         static void draw_pixel(VFrame *frame, int x, int y);
172         static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
173         void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
174
175 // Number of the previous reference frame on the timeline.
176         int64_t previous_frame_number;
177 // The frame compared with the previous frame to get the motion.
178 // It is moved to compensate for motion and copied to the previous_frame.
179         VFrame *temp_frame;
180         MotionScan *engine;
181 //      RotateScan *motion_rotate;
182         OverlayFrame *overlayer;
183         AffineEngine *rotate_engine;
184
185 // Accumulation of all global tracks since the plugin start.
186 // Multiplied by OVERSAMPLE.
187         int total_dx;
188         int total_dy;
189
190 // Rotation motion tracking
191         float total_angle;
192
193 // Current motion vector for drawing vectors
194         int current_dx;
195         int current_dy;
196         float current_angle;
197
198
199
200 // Oversampled current frame for motion estimation
201         int32_t *search_area;
202         int search_size;
203
204
205 // The layer to track motion in.
206         int reference_layer;
207 // The layer to apply motion in.
208         int target_layer;
209
210 // Pointer to the source and destination of each operation.
211 // These are fully allocated buffers.
212
213 // The previous reference frame for global motion tracking
214         VFrame *prev_global_ref;
215 // The current reference frame for global motion tracking
216         VFrame *current_global_ref;
217 // The input target frame for global motion tracking
218         VFrame *global_target_src;
219 // The output target frame for global motion tracking
220         VFrame *global_target_dst;
221
222 // The previous reference frame for rotation tracking
223         VFrame *prev_rotate_ref;
224 // The current reference frame for rotation tracking
225         VFrame *current_rotate_ref;
226 // The input target frame for rotation tracking.
227         VFrame *rotate_target_src;
228 // The output target frame for rotation tracking.
229         VFrame *rotate_target_dst;
230
231 // The output of process_buffer
232         VFrame *output_frame;
233         int w;
234         int h;
235 };
236
237
238
239
240
241
242
243
244
245
246
247 #endif
248
249
250
251
252
253