00001 #ifndef MOTION_H
00002 #define MOTION_H
00003
00004 #include <math.h>
00005 #include <stdint.h>
00006 #include <string.h>
00007
00008 #include "affine.inc"
00009 #include "bchash.inc"
00010 #include "filexml.inc"
00011 #include "keyframe.inc"
00012 #include "loadbalance.h"
00013 #include "motionwindow.inc"
00014 #include "overlayframe.inc"
00015 #include "pluginvclient.h"
00016 #include "rotateframe.inc"
00017 #include "vframe.inc"
00018
00019 class MotionMain;
00020 class MotionWindow;
00021 class MotionScan;
00022 class RotateScan;
00023
00024
00025 #define OVERSAMPLE 4
00026
00027
00028
00029 #define MIN_RADIUS 1
00030 #define MAX_RADIUS 50
00031
00032
00033 #define MIN_ROTATION 1
00034 #define MAX_ROTATION 25
00035
00036
00037 #define MIN_BLOCK 1
00038 #define MAX_BLOCK 100
00039
00040
00041 #define MIN_BLOCKS 1
00042 #define MAX_BLOCKS 200
00043
00044
00045 #define MIN_ANGLE 0.0001
00046
00047 #define MOTION_FILE "/tmp/motion"
00048 #define ROTATION_FILE "/tmp/rotate"
00049
00050 class MotionConfig
00051 {
00052 public:
00053 MotionConfig();
00054
00055 int equivalent(MotionConfig &that);
00056 void copy_from(MotionConfig &that);
00057 void interpolate(MotionConfig &prev,
00058 MotionConfig &next,
00059 int64_t prev_frame,
00060 int64_t next_frame,
00061 int64_t current_frame);
00062 void boundaries();
00063
00064 int block_count;
00065 int global_range_w;
00066 int global_range_h;
00067 int rotation_range;
00068 int magnitude;
00069 int return_speed;
00070 int draw_vectors;
00071
00072 int global_block_w;
00073 int global_block_h;
00074 int rotation_block_w;
00075 int rotation_block_h;
00076
00077 int global_positions;
00078 int rotate_positions;
00079
00080 double block_x;
00081 double block_y;
00082
00083 int horizontal_only;
00084 int vertical_only;
00085 int global;
00086 int rotate;
00087 int addtrackedframeoffset;
00088
00089 int mode1;
00090
00091 int mode2;
00092
00093 int mode3;
00094 enum
00095 {
00096
00097 TRACK,
00098 STABILIZE,
00099 TRACK_PIXEL,
00100 STABILIZE_PIXEL,
00101 NOTHING,
00102
00103 RECALCULATE,
00104 SAVE,
00105 LOAD,
00106 NO_CALCULATE,
00107
00108 TRACK_SINGLE,
00109 TRACK_PREVIOUS,
00110 PREVIOUS_SAME_BLOCK
00111 };
00112
00113 int64_t track_frame;
00114
00115 int bottom_is_master;
00116 };
00117
00118
00119
00120
00121 class MotionMain : public PluginVClient
00122 {
00123 public:
00124 MotionMain(PluginServer *server);
00125 ~MotionMain();
00126
00127 int process_buffer(VFrame **frame,
00128 int64_t start_position,
00129 double frame_rate);
00130 void process_global();
00131 void process_rotation();
00132 void draw_vectors(VFrame *frame);
00133 int is_multichannel();
00134 int is_realtime();
00135 int load_defaults();
00136 int save_defaults();
00137 void save_data(KeyFrame *keyframe);
00138 void read_data(KeyFrame *keyframe);
00139 void update_gui();
00140
00141 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
00142 void allocate_temp(int w, int h, int color_model);
00143
00144 PLUGIN_CLASS_MEMBERS(MotionConfig, MotionThread)
00145
00146 int64_t abs_diff(unsigned char *prev_ptr,
00147 unsigned char *current_ptr,
00148 int row_bytes,
00149 int w,
00150 int h,
00151 int color_model);
00152 int64_t abs_diff_sub(unsigned char *prev_ptr,
00153 unsigned char *current_ptr,
00154 int row_bytes,
00155 int w,
00156 int h,
00157 int color_model,
00158 int sub_x,
00159 int sub_y);
00160
00161 static void clamp_scan(int w,
00162 int h,
00163 int *block_x1,
00164 int *block_y1,
00165 int *block_x2,
00166 int *block_y2,
00167 int *scan_x1,
00168 int *scan_y1,
00169 int *scan_x2,
00170 int *scan_y2,
00171 int use_absolute);
00172 static void draw_pixel(VFrame *frame, int x, int y);
00173 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
00174 void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
00175
00176
00177 int64_t previous_frame_number;
00178
00179
00180 VFrame *temp_frame;
00181 MotionScan *engine;
00182 RotateScan *motion_rotate;
00183 OverlayFrame *overlayer;
00184 AffineEngine *rotate_engine;
00185
00186
00187
00188 int total_dx;
00189 int total_dy;
00190
00191
00192 float total_angle;
00193
00194
00195 int current_dx;
00196 int current_dy;
00197 float current_angle;
00198
00199
00200
00201
00202 int32_t *search_area;
00203 int search_size;
00204
00205
00206
00207 int reference_layer;
00208
00209 int target_layer;
00210
00211
00212
00213
00214
00215 VFrame *prev_global_ref;
00216
00217 VFrame *current_global_ref;
00218
00219 VFrame *global_target_src;
00220
00221 VFrame *global_target_dst;
00222
00223
00224 VFrame *prev_rotate_ref;
00225
00226 VFrame *current_rotate_ref;
00227
00228 VFrame *rotate_target_src;
00229
00230 VFrame *rotate_target_dst;
00231
00232
00233 VFrame *output_frame;
00234 int w;
00235 int h;
00236 };
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 class MotionScanPackage : public LoadPackage
00263 {
00264 public:
00265 MotionScanPackage();
00266
00267
00268 int block_x1, block_y1, block_x2, block_y2;
00269 int scan_x1, scan_y1, scan_x2, scan_y2;
00270 int dx;
00271 int dy;
00272 int64_t max_difference;
00273 int64_t min_difference;
00274 int64_t min_pixel;
00275 int is_border;
00276 int valid;
00277
00278 int pixel;
00279 int64_t difference1;
00280 int64_t difference2;
00281 };
00282
00283 class MotionScanCache
00284 {
00285 public:
00286 MotionScanCache(int x, int y, int64_t difference);
00287 int x, y;
00288 int64_t difference;
00289 };
00290
00291 class MotionScanUnit : public LoadClient
00292 {
00293 public:
00294 MotionScanUnit(MotionScan *server, MotionMain *plugin);
00295 ~MotionScanUnit();
00296
00297 void process_package(LoadPackage *package);
00298 int64_t get_cache(int x, int y);
00299 void put_cache(int x, int y, int64_t difference);
00300
00301 MotionScan *server;
00302 MotionMain *plugin;
00303
00304 ArrayList<MotionScanCache*> cache;
00305 Mutex *cache_lock;
00306 };
00307
00308 class MotionScan : public LoadServer
00309 {
00310 public:
00311 MotionScan(MotionMain *plugin,
00312 int total_clients,
00313 int total_packages);
00314 ~MotionScan();
00315
00316 friend class MotionScanUnit;
00317
00318 void init_packages();
00319 LoadClient* new_client();
00320 LoadPackage* new_package();
00321
00322
00323
00324 void scan_frame(VFrame *previous_frame,
00325
00326 VFrame *current_frame);
00327 int64_t get_cache(int x, int y);
00328 void put_cache(int x, int y, int64_t difference);
00329
00330
00331
00332 int dx_result;
00333 int dy_result;
00334
00335 private:
00336 VFrame *previous_frame;
00337
00338 VFrame *current_frame;
00339 MotionMain *plugin;
00340 int skip;
00341
00342 int block_x1;
00343 int block_x2;
00344 int block_y1;
00345 int block_y2;
00346 int scan_x1;
00347 int scan_y1;
00348 int scan_x2;
00349 int scan_y2;
00350 int total_pixels;
00351 int total_steps;
00352 int subpixel;
00353
00354
00355 ArrayList<MotionScanCache*> cache;
00356 Mutex *cache_lock;
00357 };
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 class RotateScanPackage : public LoadPackage
00372 {
00373 public:
00374 RotateScanPackage();
00375 float angle;
00376 int64_t difference;
00377 };
00378
00379 class RotateScanCache
00380 {
00381 public:
00382 RotateScanCache(float angle, int64_t difference);
00383 float angle;
00384 int64_t difference;
00385 };
00386
00387 class RotateScanUnit : public LoadClient
00388 {
00389 public:
00390 RotateScanUnit(RotateScan *server, MotionMain *plugin);
00391 ~RotateScanUnit();
00392
00393 void process_package(LoadPackage *package);
00394
00395 RotateScan *server;
00396 MotionMain *plugin;
00397 AffineEngine *rotater;
00398 VFrame *temp;
00399 };
00400
00401 class RotateScan : public LoadServer
00402 {
00403 public:
00404 RotateScan(MotionMain *plugin,
00405 int total_clients,
00406 int total_packages);
00407 ~RotateScan();
00408
00409 friend class RotateScanUnit;
00410
00411 void init_packages();
00412 LoadClient* new_client();
00413 LoadPackage* new_package();
00414
00415
00416
00417 float scan_frame(VFrame *previous_frame,
00418
00419 VFrame *current_frame,
00420
00421 int block_x,
00422 int block_y);
00423 int64_t get_cache(float angle);
00424 void put_cache(float angle, int64_t difference);
00425
00426
00427
00428 float result;
00429
00430 private:
00431 VFrame *previous_frame;
00432
00433 VFrame *current_frame;
00434
00435 MotionMain *plugin;
00436 int skip;
00437
00438
00439 int block_x;
00440 int block_y;
00441
00442 int block_x1;
00443 int block_x2;
00444 int block_y1;
00445 int block_y2;
00446
00447 int scan_x;
00448 int scan_y;
00449 int scan_w;
00450 int scan_h;
00451
00452 float scan_angle1, scan_angle2;
00453 int total_steps;
00454
00455 ArrayList<RotateScanCache*> cache;
00456 Mutex *cache_lock;
00457 };
00458
00459
00460
00461
00462 #endif
00463
00464
00465
00466
00467
00468