10 #include "filexml.inc"
11 #include "keyframe.inc"
12 #include "loadbalance.h"
13 #include "motionwindow.inc"
14 #include "overlayframe.inc"
15 #include "pluginvclient.h"
16 #include "rotateframe.inc"
28 // Limits of global range in percent
32 // Limits of rotation range in degrees
33 #define MIN_ROTATION 1
34 #define MAX_ROTATION 25
36 // Limits of block size in percent.
40 // Limits of block count
42 #define MAX_BLOCKS 200
44 // Precision of rotation
45 #define MIN_ANGLE 0.0001
47 #define MOTION_FILE "/tmp/motion"
48 #define ROTATION_FILE "/tmp/rotate"
55 int equivalent(MotionConfig
&that
);
56 void copy_from(MotionConfig
&that
);
57 void interpolate(MotionConfig
&prev
,
61 int64_t current_frame
);
71 // Percent of image size
76 // Number of search positions in each refinement of the log search
79 // Block position in percentage 0 - 100
87 // Track or stabilize, single pixel, scan only, or nothing
89 // Recalculate, no calculate, save, or load coordinates from disk
91 // Track a single frame, previous frame, or previous frame same block
111 // Number of single frame to track relative to timeline start
114 int bottom_is_master
;
120 class MotionMain
: public PluginVClient
123 MotionMain(PluginServer
*server
);
126 int process_buffer(VFrame
**frame
,
127 int64_t start_position
,
129 void process_global();
130 void process_rotation();
131 void draw_vectors(VFrame
*frame
);
132 int is_multichannel();
136 void save_data(KeyFrame
*keyframe
);
137 void read_data(KeyFrame
*keyframe
);
139 // Calculate frame to copy from and frame to move
140 void calculate_pointers(VFrame
**frame
, VFrame
**src
, VFrame
**dst
);
141 void allocate_temp(int w
, int h
, int color_model
);
143 PLUGIN_CLASS_MEMBERS(MotionConfig
, MotionThread
)
145 int64_t abs_diff(unsigned char *prev_ptr
,
146 unsigned char *current_ptr
,
151 int64_t abs_diff_sub(unsigned char *prev_ptr
,
152 unsigned char *current_ptr
,
160 static void clamp_scan(int w
,
171 static void draw_pixel(VFrame
*frame
, int x
, int y
);
172 static void draw_line(VFrame
*frame
, int x1
, int y1
, int x2
, int y2
);
173 void draw_arrow(VFrame
*frame
, int x1
, int y1
, int x2
, int y2
);
175 // Number of the previous reference frame on the timeline.
176 int64_t previous_frame_number
;
177 // The frame compared with the previous frame to get the motion.
178 // It is moved to compensate for motion and copied to the previous_frame.
181 RotateScan
*motion_rotate
;
182 OverlayFrame
*overlayer
;
183 AffineEngine
*rotate_engine
;
185 // Accumulation of all global tracks since the plugin start.
186 // Multiplied by OVERSAMPLE.
190 // Rotation motion tracking
193 // Current motion vector for drawing vectors
200 // Oversampled current frame for motion estimation
201 int32_t *search_area
;
205 // The layer to track motion in.
207 // The layer to apply motion in.
210 // Pointer to the source and destination of each operation.
211 // These are fully allocated buffers.
213 // The previous reference frame for global motion tracking
214 VFrame
*prev_global_ref
;
215 // The current reference frame for global motion tracking
216 VFrame
*current_global_ref
;
217 // The input target frame for global motion tracking
218 VFrame
*global_target_src
;
219 // The output target frame for global motion tracking
220 VFrame
*global_target_dst
;
222 // The previous reference frame for rotation tracking
223 VFrame
*prev_rotate_ref
;
224 // The current reference frame for rotation tracking
225 VFrame
*current_rotate_ref
;
226 // The input target frame for rotation tracking.
227 VFrame
*rotate_target_src
;
228 // The output target frame for rotation tracking.
229 VFrame
*rotate_target_dst
;
231 // The output of process_buffer
232 VFrame
*output_frame
;
261 class MotionScanPackage
: public LoadPackage
266 // For multiple blocks
267 int block_x1
, block_y1
, block_x2
, block_y2
;
268 int scan_x1
, scan_y1
, scan_x2
, scan_y2
;
271 int64_t max_difference
;
272 int64_t min_difference
;
282 class MotionScanCache
285 MotionScanCache(int x
, int y
, int64_t difference
);
290 class MotionScanUnit
: public LoadClient
293 MotionScanUnit(MotionScan
*server
, MotionMain
*plugin
);
296 void process_package(LoadPackage
*package
);
297 int64_t get_cache(int x
, int y
);
298 void put_cache(int x
, int y
, int64_t difference
);
303 ArrayList
<MotionScanCache
*> cache
;
307 class MotionScan
: public LoadServer
310 MotionScan(MotionMain
*plugin
,
315 friend class MotionScanUnit
;
317 void init_packages();
318 LoadClient
* new_client();
319 LoadPackage
* new_package();
321 // Invoke the motion engine for a search
322 // Frame before motion
323 void scan_frame(VFrame
*previous_frame
,
324 // Frame after motion
325 VFrame
*current_frame
);
326 int64_t get_cache(int x
, int y
);
327 void put_cache(int x
, int y
, int64_t difference
);
329 // Change between previous frame and current frame multiplied by
335 VFrame
*previous_frame
;
336 // Frame after motion
337 VFrame
*current_frame
;
354 ArrayList
<MotionScanCache
*> cache
;
370 class RotateScanPackage
: public LoadPackage
378 class RotateScanCache
381 RotateScanCache(float angle
, int64_t difference
);
386 class RotateScanUnit
: public LoadClient
389 RotateScanUnit(RotateScan
*server
, MotionMain
*plugin
);
392 void process_package(LoadPackage
*package
);
396 AffineEngine
*rotater
;
400 class RotateScan
: public LoadServer
403 RotateScan(MotionMain
*plugin
,
408 friend class RotateScanUnit
;
410 void init_packages();
411 LoadClient
* new_client();
412 LoadPackage
* new_package();
414 // Invoke the motion engine for a search
415 // Frame before rotation
416 float scan_frame(VFrame
*previous_frame
,
417 // Frame after rotation
418 VFrame
*current_frame
,
422 int64_t get_cache(float angle
);
423 void put_cache(float angle
, int64_t difference
);
430 VFrame
*previous_frame
;
431 // Frame after motion
432 VFrame
*current_frame
;
450 // Range of angles to compare
451 float scan_angle1
, scan_angle2
;
454 ArrayList
<RotateScanCache
*> cache
;