r121: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / plugins / motion / motion.h
blobb0c0726b9f5739b5326c1a27f1b2e926a6d79ba3
1 #ifndef MOTION_H
2 #define MOTION_H
4 #include <math.h>
5 #include <stdint.h>
6 #include <string.h>
8 #include "bcdisplayinfo.inc"
9 #include "defaults.h"
10 #include "filexml.inc"
11 #include "keyframe.inc"
12 #include "loadbalance.h"
13 #include "overlayframe.inc"
14 #include "pluginvclient.h"
15 #include "vframe.inc"
17 class MotionMain;
18 class MotionWindow;
19 class MotionEngine;
23 #define OVERSAMPLE 4
25 class MotionConfig
27 public:
28 MotionConfig();
30 int equivalent(MotionConfig &that);
31 void copy_from(MotionConfig &that);
32 void interpolate(MotionConfig &prev,
33 MotionConfig &next,
34 int64_t prev_frame,
35 int64_t next_frame,
36 int64_t current_frame);
38 int block_size;
39 int search_radius;
40 int magnitude;
41 int return_speed;
42 int draw_vectors;
43 int mode;
44 enum
46 TRACK,
47 STABILIZE,
48 DRAW_VECTORS
53 class MotionSearchRadius : public BC_IPot
55 public:
56 MotionSearchRadius(MotionMain *plugin,
57 int x,
58 int y);
59 int handle_event();
60 MotionMain *plugin;
63 class MotionBlockSize : public BC_IPot
65 public:
66 MotionBlockSize(MotionMain *plugin,
67 int x,
68 int y);
69 int handle_event();
70 MotionMain *plugin;
73 class MotionMagnitude : public BC_IPot
75 public:
76 MotionMagnitude(MotionMain *plugin,
77 int x,
78 int y);
79 int handle_event();
80 MotionMain *plugin;
83 class MotionReturnSpeed : public BC_IPot
85 public:
86 MotionReturnSpeed(MotionMain *plugin,
87 int x,
88 int y);
89 int handle_event();
90 MotionMain *plugin;
93 class MotionStabilize : public BC_Radial
95 public:
96 MotionStabilize(MotionMain *plugin,
97 MotionWindow *gui,
98 int x,
99 int y);
100 int handle_event();
101 MotionWindow *gui;
102 MotionMain *plugin;
105 class MotionTrack : public BC_Radial
107 public:
108 MotionTrack(MotionMain *plugin,
109 MotionWindow *gui,
110 int x,
111 int y);
112 int handle_event();
113 MotionWindow *gui;
114 MotionMain *plugin;
117 class MotionDrawVectors : public BC_Radial
119 public:
120 MotionDrawVectors(MotionMain *plugin,
121 MotionWindow *gui,
122 int x,
123 int y);
124 int handle_event();
125 MotionMain *plugin;
126 MotionWindow *gui;
129 class MotionWindow : public BC_Window
131 public:
132 MotionWindow(MotionMain *plugin, int x, int y);
133 ~MotionWindow();
135 int create_objects();
136 int close_event();
137 void update_mode();
139 MotionSearchRadius *radius;
140 MotionBlockSize *block_size;
141 MotionMagnitude *magnitude;
142 MotionReturnSpeed *return_speed;
143 MotionStabilize *stabilize;
144 MotionTrack *track;
145 MotionDrawVectors *vectors;
146 MotionMain *plugin;
151 PLUGIN_THREAD_HEADER(MotionMain, MotionThread, MotionWindow)
154 typedef struct
156 int x;
157 int y;
158 int dx_oversampled;
159 int dy_oversampled;
160 int valid;
161 } macroblock_t;
164 class MotionMain : public PluginVClient
166 public:
167 MotionMain(PluginServer *server);
168 ~MotionMain();
170 int process_realtime(VFrame **input_ptr, VFrame **output_ptr);
171 int is_multichannel();
172 int is_realtime();
173 int load_defaults();
174 int save_defaults();
175 void save_data(KeyFrame *keyframe);
176 void read_data(KeyFrame *keyframe);
177 void update_gui();
179 PLUGIN_CLASS_MEMBERS(MotionConfig, MotionThread)
181 static void oversample(int32_t *dst,
182 VFrame *src,
183 int x1,
184 int x2,
185 int y1,
186 int y2,
187 int dst_stride);
189 static void draw_pixel(VFrame *frame, int x, int y);
190 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
192 VFrame *prev_frame;
193 VFrame *current_frame;
194 VFrame *temp_frame;
195 MotionEngine *engine;
196 OverlayFrame *overlayer;
197 macroblock_t *macroblocks;
198 int total_macroblocks;
200 // Absolute position of current frame relative to center * OVERSAMPLE
201 int current_dx;
202 int current_dy;
203 // Oversampled current frame for motion estimation
204 int32_t *search_area;
205 int search_size;
209 class MotionPackage : public LoadPackage
211 public:
212 MotionPackage();
213 macroblock_t *macroblock;
216 class MotionUnit : public LoadClient
218 public:
219 MotionUnit(MotionEngine *server, MotionMain *plugin);
220 ~MotionUnit();
222 void process_package(LoadPackage *package);
223 int64_t abs_diff(int32_t *search_pixel,
224 int32_t *block_pixel,
225 int search_side,
226 int block_side);
228 MotionEngine *server;
229 MotionMain *plugin;
230 // Oversampled macroblock in previous frame
231 int32_t *block_area;
232 int block_size;
233 // Results of scan go here so the same places don't need to be scanned twice.
234 int64_t *scan_result;
235 int scan_result_size;
238 class MotionEngine : public LoadServer
240 public:
241 MotionEngine(MotionMain *plugin,
242 int total_clients,
243 int total_packages);
244 void init_packages();
245 LoadClient* new_client();
246 LoadPackage* new_package();
247 MotionMain *plugin;
255 #endif