no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / motion51 / motion51.h
1 /*
2  * CINELERRA
3  * Copyright (C) 2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #ifndef __MOTION_51_H__
22 #define __MOTION_51_H__
23
24 #include <math.h>
25 #include <stdint.h>
26 #include <string.h>
27
28 #include "affine.inc"
29 #include "bchash.inc"
30 #include "filexml.inc"
31 #include "keyframe.inc"
32 #include "loadbalance.h"
33 #include "motion51.inc"
34 #include "overlayframe.inc"
35 #include "pluginvclient.h"
36 #include "vframe.inc"
37
38 class FFT;
39 class Motion51Config;
40 class Motion51Main;
41 class Motion51ScanUnit;
42 class Motion51ScanPackage;
43 class Motion51Scan;
44 class Motion51VVFrame;
45
46 class Motion51Config
47 {
48 public:
49         Motion51Config();
50
51         void init();
52         int equivalent(Motion51Config &that);
53         void copy_from(Motion51Config &that);
54         void interpolate(Motion51Config &prev, Motion51Config &next,
55                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
56
57         float block_x, block_y, block_w, block_h;
58         float sample_r;
59         int sample_steps;
60         float horiz_limit, vert_limit, twist_limit;
61         float shake_fade, twist_fade;
62         int draw_vectors;
63
64         char tracking_file[BCTEXTLEN];
65         int tracking;
66 };
67
68
69 class Motion51Main : public PluginVClient
70 {
71 public:
72         Motion51Main(PluginServer *server);
73         ~Motion51Main();
74
75         int process_buffer(VFrame **frame, int64_t position, double frame_rate);
76         int is_multichannel();
77         int is_realtime();
78         void save_data(KeyFrame *keyframe);
79         void read_data(KeyFrame *keyframe);
80         void update_gui();
81         void reset_sample(int sz, double r);
82         void get_samples(VFrame *img, double *pix[3], double x, double y);
83         void centroid(double *pix[3], double *ctr_v, double *ctr_x, double *ctr_y);
84         void draw_vectors(VFrame *img);
85
86         int64_t get_ref_position();
87         void update_tracking_cache();
88         int load_tracking_cache(int64_t position);
89         void save_tracking_cache(int64_t position);
90
91         void match(VFrame *ref, VFrame *cur);
92         int transform_target(int use_opengl);
93         int handle_opengl();
94         VFrame* new_temp(VFrame *&tmp, VFrame *ref);
95
96         PLUGIN_CLASS_MEMBERS2(Motion51Config)
97
98         char cache_file[BCTEXTLEN];
99         FILE *cache_fp, *active_fp;
100         void set_tracking_path();
101         int open_cache_file();
102         void close_cache_file();
103         int load_cache_line();
104         int locate_cache_line(int64_t key);
105         int get_cache_line(int64_t key);
106         int put_cache_line(const char *line);
107         void update_cache_file();
108         void (*get_pixel)(double *pix[3], double rx, double ry,
109                 uint8_t **rows, int psz, int iw1, int ih1);
110
111         VFrame *out;
112         VFrame *out_frame;
113         int64_t out_position;
114         VFrame *ref_frame;
115         int64_t ref_position;
116         VFrame *tmp_frame;
117         AffineEngine *affine;
118         Motion51Scan *motion_scan;
119
120         char cache_line[BCSTRLEN];
121         int64_t cache_key, active_key;
122         int64_t tracking_position;
123         float out_w, out_h, out_r;
124         float dx, dy, dt;
125         double rx, ry, rr, rw, rh;
126         float current_dx, current_dy;
127         int x_steps, y_steps, r_steps;
128         double cir_r;  int cir_sz;
129         double *xpts, *ypts;
130         float total_dx, total_dy;
131         float total_angle;
132 };
133
134 class Motion51ScanPackage : public LoadPackage
135 {
136 public:
137         Motion51ScanPackage() {}
138         ~Motion51ScanPackage() {}
139         double x, y;
140 };
141 class Motion51ScanUnit : public LoadClient
142 {
143 public:
144         Motion51ScanUnit(Motion51Scan *server, Motion51Main *plugin);
145         ~Motion51ScanUnit();
146         void process_package(LoadPackage *package);
147
148         Motion51Scan *server;
149         Motion51Main *plugin;
150         FFT *fft;
151 };
152
153 class Motion51Scan : public LoadServer
154 {
155 public:
156         Motion51Scan(Motion51Main *plugin, int total_clients, int x_steps, int y_steps);
157         ~Motion51Scan();
158         friend class Motion51ScanUnit;
159
160         Motion51Main *plugin;
161         Mutex *result_lock;
162         FFT *fft;
163         VFrame *cur, *ref;
164
165         int x_steps, y_steps;
166         double bx, by, br, bw, bh;
167         int rpix_sz;
168         double *rpix[3], rpwr[3];
169         double rctr_v[3], rctr_x[3], rctr_y[3];
170         double *ref_real[3], *ref_imag[3];
171         double cor_value, value;
172         double dx_result, dy_result, dt_result;
173
174         void init_packages();
175         LoadClient *new_client() { return new Motion51ScanUnit(this, plugin); }
176         LoadPackage *new_package() { return new Motion51ScanPackage(); }
177         void scan(VFrame *ref, VFrame *cur, int sz);
178         double compare(double cx, double cy, double ct);
179 };
180
181 class Motion51VVFrame : public VFrame
182 {
183 public:
184         Motion51VVFrame(VFrame *vfrm, int n);
185         int draw_pixel(int x, int y);
186         int n;
187 };
188
189 #endif