dvd/bd scaling fixes, es/de .po file updates
[goodguy/history.git] / cinelerra-5.1 / plugins / motion / motion.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "rotateframe.inc"
39 #include "vframe.inc"
40
41 class MotionMain;
42 class MotionWindow;
43 class RotateScan;
44
45
46
47
48 // Limits of global range in percent
49 #define MIN_RADIUS 1
50 #define MAX_RADIUS 100
51
52 // Limits of rotation range in degrees
53 #define MIN_ROTATION 1
54 #define MAX_ROTATION 25
55
56 // Limits of block size in percent.
57 #define MIN_BLOCK 1
58 #define MAX_BLOCK 100
59
60 // Limits of block count
61 #define MIN_BLOCKS 1
62 #define MAX_BLOCKS 200
63
64 // Precision of rotation
65 #define MIN_ANGLE 0.0001
66
67 #define ROTATION_FILE "/tmp/r"
68
69 class MotionConfig
70 {
71 public:
72         MotionConfig();
73
74         int equivalent(MotionConfig &that);
75         void copy_from(MotionConfig &that);
76         void interpolate(MotionConfig &prev,
77                 MotionConfig &next,
78                 int64_t prev_frame,
79                 int64_t next_frame,
80                 int64_t current_frame);
81         void boundaries();
82
83         int block_count;
84         int global_range_w;
85         int global_range_h;
86 // Range of angles above and below center rotation angle to search
87         int rotation_range;
88 // Center angle of rotation search
89         int rotation_center;
90         int magnitude;
91         int rotate_magnitude;
92         int return_speed;
93         int rotate_return_speed;
94         int draw_vectors;
95 // Percent of image size
96         int global_block_w;
97         int global_block_h;
98 //      int rotation_block_w;
99 //      int rotation_block_h;
100 // Number of search positions in each refinement of the log search
101         int global_positions;
102         int rotate_positions;
103 // Block position in percentage 0 - 100
104         double block_x;
105         double block_y;
106
107         int horizontal_only;
108         int vertical_only;
109         int global;
110         int rotate;
111         int addtrackedframeoffset;
112 // Track or stabilize, single pixel, scan only, or nothing
113         int action_type;
114 // Recalculate, no calculate, save, or load coordinates from disk
115         int tracking_type;
116 // Track a single frame, previous frame, or previous frame same block
117         int tracking_object;
118
119 #if 0
120         enum
121         {
122 // action_type
123                 TRACK,
124                 STABILIZE,
125                 TRACK_PIXEL,
126                 STABILIZE_PIXEL,
127                 NOTHING,
128 // mode2
129                 RECALCULATE,
130                 SAVE,
131                 LOAD,
132                 NO_CALCULATE,
133 // tracking_object
134                 TRACK_SINGLE,
135                 TRACK_PREVIOUS,
136                 PREVIOUS_SAME_BLOCK
137         };
138 #endif
139
140
141 // Number of single frame to track relative to timeline start
142         int64_t track_frame;
143 // Master layer
144         int bottom_is_master;
145 };
146
147
148
149
150 class MotionMain : public PluginVClient
151 {
152 public:
153         MotionMain(PluginServer *server);
154         ~MotionMain();
155
156         int process_buffer(VFrame **frame,
157                 int64_t start_position,
158                 double frame_rate);
159         void process_global();
160         void process_rotation();
161         void draw_vectors(VFrame *frame);
162         int is_multichannel();
163         int is_realtime();
164         void save_data(KeyFrame *keyframe);
165         void read_data(KeyFrame *keyframe);
166         void update_gui();
167 // Calculate frame to copy from and frame to move
168         void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
169         void allocate_temp(int w, int h, int color_model);
170
171         PLUGIN_CLASS_MEMBERS2(MotionConfig)
172
173
174         static void draw_pixel(VFrame *frame, int x, int y);
175         static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
176         void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
177
178 // Number of the previous reference frame on the timeline.
179         int64_t previous_frame_number;
180 // The frame compared with the previous frame to get the motion.
181 // It is moved to compensate for motion and copied to the previous_frame.
182         VFrame *temp_frame;
183         MotionScan *engine;
184         RotateScan *motion_rotate;
185         OverlayFrame *overlayer;
186         AffineEngine *rotate_engine;
187
188 // Accumulation of all global tracks since the plugin start.
189 // Multiplied by OVERSAMPLE.
190         int total_dx;
191         int total_dy;
192
193 // Rotation motion tracking
194         float total_angle;
195
196 // Current motion vector for drawing vectors
197         int current_dx;
198         int current_dy;
199         float current_angle;
200
201
202
203 // Oversampled current frame for motion estimation
204         int32_t *search_area;
205         int search_size;
206
207
208 // The layer to track motion in.
209         int reference_layer;
210 // The layer to apply motion in.
211         int target_layer;
212
213 // Pointer to the source and destination of each operation.
214 // These are fully allocated buffers.
215
216 // The previous reference frame for global motion tracking
217         VFrame *prev_global_ref;
218 // The current reference frame for global motion tracking
219         VFrame *current_global_ref;
220 // The input target frame for global motion tracking
221         VFrame *global_target_src;
222 // The output target frame for global motion tracking
223         VFrame *global_target_dst;
224
225 // The previous reference frame for rotation tracking
226         VFrame *prev_rotate_ref;
227 // The current reference frame for rotation tracking
228         VFrame *current_rotate_ref;
229 // The input target frame for rotation tracking.
230         VFrame *rotate_target_src;
231 // The output target frame for rotation tracking.
232         VFrame *rotate_target_dst;
233
234 // The output of process_buffer
235         VFrame *output_frame;
236         int w;
237         int h;
238 };
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 class RotateScanPackage : public LoadPackage
264 {
265 public:
266         RotateScanPackage();
267         float angle;
268         int64_t difference;
269 };
270
271 class RotateScanCache
272 {
273 public:
274         RotateScanCache(float angle, int64_t difference);
275         float angle;
276         int64_t difference;
277 };
278
279 class RotateScanUnit : public LoadClient
280 {
281 public:
282         RotateScanUnit(RotateScan *server, MotionMain *plugin);
283         ~RotateScanUnit();
284
285         void process_package(LoadPackage *package);
286
287         RotateScan *server;
288         MotionMain *plugin;
289         AffineEngine *rotater;
290         VFrame *temp;
291 };
292
293 class RotateScan : public LoadServer
294 {
295 public:
296         RotateScan(MotionMain *plugin,
297                 int total_clients,
298                 int total_packages);
299         ~RotateScan();
300
301         friend class RotateScanUnit;
302
303         void init_packages();
304         LoadClient* new_client();
305         LoadPackage* new_package();
306
307 // Invoke the motion engine for a search
308 // Frame before rotation
309         float scan_frame(VFrame *previous_frame,
310 // Frame after rotation
311                 VFrame *current_frame,
312 // Pivot
313                 int block_x,
314                 int block_y);
315         int64_t get_cache(float angle);
316         void put_cache(float angle, int64_t difference);
317
318
319 // Angle result
320         float result;
321
322 private:
323         VFrame *previous_frame;
324 // Frame after motion
325         VFrame *current_frame;
326
327         MotionMain *plugin;
328         int skip;
329
330 // Pivot
331         int block_x;
332         int block_y;
333 // Block to rotate
334         int block_x1;
335         int block_x2;
336         int block_y1;
337         int block_y2;
338 // Area to compare
339         int scan_x;
340         int scan_y;
341         int scan_w;
342         int scan_h;
343 // Range of angles to compare
344         float scan_angle1, scan_angle2;
345         int total_steps;
346
347         ArrayList<RotateScanCache*> cache;
348         Mutex *cache_lock;
349 };
350
351
352
353
354 #endif
355
356
357
358
359
360