initial commit
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / motion51 / motion51.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_51_H__
23 #define __MOTION_51_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 "motion51.inc"
35 #include "overlayframe.inc"
36 #include "pluginvclient.h"
37 #include "vframe.inc"
38
39 class FFT;
40 class Motion51Config;
41 class Motion51Main;
42 class Motion51ScanUnit;
43 class Motion51ScanPackage;
44 class Motion51Scan;
45 class Motion51VVFrame;
46
47 class Motion51Config
48 {
49 public:
50         Motion51Config();
51
52         void init();
53         int equivalent(Motion51Config &that);
54         void copy_from(Motion51Config &that);
55         void interpolate(Motion51Config &prev, Motion51Config &next,
56                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
57
58         float block_x, block_y, block_w, block_h;
59         float sample_r;
60         int sample_steps;
61         float horiz_limit, vert_limit, twist_limit;
62         float shake_fade, twist_fade;
63         int draw_vectors;
64
65         char tracking_file[BCTEXTLEN];
66         int tracking;
67 };
68
69
70 class Motion51Main : public PluginVClient
71 {
72 public:
73         Motion51Main(PluginServer *server);
74         ~Motion51Main();
75
76         int process_buffer(VFrame **frame, int64_t position, double frame_rate);
77         int is_multichannel();
78         int is_realtime();
79         void save_data(KeyFrame *keyframe);
80         void read_data(KeyFrame *keyframe);
81         void update_gui();
82         void reset_sample(int sz, double r);
83         void get_samples(VFrame *img, double *pix[3], double x, double y);
84         void centroid(double *pix[3], double *ctr_v, double *ctr_x, double *ctr_y);
85         void draw_vectors(VFrame *img);
86
87         int64_t get_ref_position();
88         void update_tracking_cache();
89         int load_tracking_cache(int64_t position);
90         void save_tracking_cache(int64_t position);
91
92         void match(VFrame *ref, VFrame *cur);
93         int transform_target(int use_opengl);
94         int handle_opengl();
95         VFrame* new_temp(VFrame *&tmp, VFrame *ref);
96
97         PLUGIN_CLASS_MEMBERS2(Motion51Config)
98
99         char cache_file[BCTEXTLEN];
100         FILE *cache_fp, *active_fp;
101         void set_tracking_path();
102         int open_cache_file();
103         void close_cache_file();
104         int load_cache_line();
105         int locate_cache_line(int64_t key);
106         int get_cache_line(int64_t key);
107         int put_cache_line(const char *line);
108         void update_cache_file();
109         void (*get_pixel)(double *pix[3], double rx, double ry,
110                 uint8_t **rows, int psz, int iw1, int ih1);
111
112         VFrame *out;
113         VFrame *out_frame;
114         int64_t out_position;
115         VFrame *ref_frame;
116         int64_t ref_position;
117         VFrame *tmp_frame;
118         AffineEngine *affine;
119         Motion51Scan *motion_scan;
120
121         char cache_line[BCSTRLEN];
122         int64_t cache_key, active_key;
123         int64_t tracking_position;
124         float out_w, out_h, out_r;
125         float dx, dy, dt;
126         double rx, ry, rr, rw, rh;
127         float current_dx, current_dy;
128         int x_steps, y_steps, r_steps;
129         double cir_r;  int cir_sz;
130         double *xpts, *ypts;
131         float total_dx, total_dy;
132         float total_angle;
133 };
134
135 class Motion51ScanPackage : public LoadPackage
136 {
137 public:
138         Motion51ScanPackage() {}
139         ~Motion51ScanPackage() {}
140         double x, y;
141 };
142 class Motion51ScanUnit : public LoadClient
143 {
144 public:
145         Motion51ScanUnit(Motion51Scan *server, Motion51Main *plugin);
146         ~Motion51ScanUnit();
147         void process_package(LoadPackage *package);
148
149         Motion51Scan *server;
150         Motion51Main *plugin;
151         FFT *fft;
152 };
153
154 class Motion51Scan : public LoadServer
155 {
156 public:
157         Motion51Scan(Motion51Main *plugin, int total_clients, int x_steps, int y_steps);
158         ~Motion51Scan();
159         friend class Motion51ScanUnit;
160
161         Motion51Main *plugin;
162         Mutex *result_lock;
163         FFT *fft;
164         VFrame *cur, *ref;
165
166         int x_steps, y_steps;
167         double bx, by, br, bw, bh;
168         int rpix_sz;
169         double *rpix[3], rpwr[3];
170         double rctr_v[3], rctr_x[3], rctr_y[3];
171         double *ref_real[3], *ref_imag[3];
172         double cor_value, value;
173         double dx_result, dy_result, dt_result;
174
175         void init_packages();
176         LoadClient *new_client() { return new Motion51ScanUnit(this, plugin); }
177         LoadPackage *new_package() { return new Motion51ScanPackage(); }
178         void scan(VFrame *ref, VFrame *cur, int sz);
179         double compare(double cx, double cy, double ct);
180 };
181
182 class Motion51VVFrame : public VFrame
183 {
184 public:
185         Motion51VVFrame(VFrame *vfrm, int n);
186         int draw_pixel(int x, int y);
187         int n;
188 };
189
190 #endif