4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
31 #include "filexml.inc"
32 #include "keyframe.inc"
33 #include "loadbalance.h"
34 #include "motionscan.inc"
35 #include "motionwindow.inc"
36 #include "overlayframe.inc"
37 #include "pluginvclient.h"
38 #include "rotateframe.inc"
48 // Limits of global range in percent
50 #define MAX_RADIUS 100
52 // Limits of rotation range in degrees
53 #define MIN_ROTATION 1
54 #define MAX_ROTATION 25
56 // Limits of block size in percent.
60 // Limits of block count
62 #define MAX_BLOCKS 200
64 // Precision of rotation
65 #define MIN_ANGLE 0.0001
67 #define ROTATION_FILE "/tmp/r"
74 int equivalent(MotionConfig &that);
75 void copy_from(MotionConfig &that);
76 void interpolate(MotionConfig &prev,
80 int64_t current_frame);
82 void set_cpus(int cpus);
87 // Range of angles above and below center rotation angle to search
89 // Center angle of rotation search
94 int rotate_return_speed;
96 // Percent of image size
99 // int rotation_block_w;
100 // int rotation_block_h;
101 // Number of search positions in each refinement of the log search
102 int global_positions;
103 int rotate_positions;
104 // Block position in percentage 0 - 100
112 int addtrackedframeoffset;
113 // Track or stabilize, single pixel, scan only, or nothing
115 // Recalculate, no calculate, save, or load coordinates from disk
117 // Track a single frame, previous frame, or previous frame same block
142 // Number of single frame to track relative to timeline start
145 int bottom_is_master;
151 class MotionMain : public PluginVClient
154 MotionMain(PluginServer *server);
157 int process_buffer(VFrame **frame,
158 int64_t start_position,
160 void process_global();
161 void process_rotation();
162 void draw_vectors(VFrame *frame);
163 int is_multichannel();
165 void save_data(KeyFrame *keyframe);
166 void read_data(KeyFrame *keyframe);
168 // Calculate frame to copy from and frame to move
169 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
170 void allocate_temp(int w, int h, int color_model);
172 PLUGIN_CLASS_MEMBERS2(MotionConfig)
175 static void draw_pixel(VFrame *frame, int x, int y);
176 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
177 void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
179 // Number of the previous reference frame on the timeline.
180 int64_t previous_frame_number;
181 // The frame compared with the previous frame to get the motion.
182 // It is moved to compensate for motion and copied to the previous_frame.
185 RotateScan *motion_rotate;
186 OverlayFrame *overlayer;
187 AffineEngine *rotate_engine;
189 // Accumulation of all global tracks since the plugin start.
190 // Multiplied by OVERSAMPLE.
194 // Rotation motion tracking
197 // Current motion vector for drawing vectors
204 // Oversampled current frame for motion estimation
205 int32_t *search_area;
209 // The layer to track motion in.
211 // The layer to apply motion in.
214 // Pointer to the source and destination of each operation.
215 // These are fully allocated buffers.
217 // The previous reference frame for global motion tracking
218 VFrame *prev_global_ref;
219 // The current reference frame for global motion tracking
220 VFrame *current_global_ref;
221 // The input target frame for global motion tracking
222 VFrame *global_target_src;
223 // The output target frame for global motion tracking
224 VFrame *global_target_dst;
226 // The previous reference frame for rotation tracking
227 VFrame *prev_rotate_ref;
228 // The current reference frame for rotation tracking
229 VFrame *current_rotate_ref;
230 // The input target frame for rotation tracking.
231 VFrame *rotate_target_src;
232 // The output target frame for rotation tracking.
233 VFrame *rotate_target_dst;
235 // The output of process_buffer
236 VFrame *output_frame;
264 class RotateScanPackage : public LoadPackage
272 class RotateScanCache
275 RotateScanCache(float angle, int64_t difference);
280 class RotateScanUnit : public LoadClient
283 RotateScanUnit(RotateScan *server, MotionMain *plugin);
286 void process_package(LoadPackage *package);
290 AffineEngine *rotater;
294 class RotateScan : public LoadServer
297 RotateScan(MotionMain *plugin,
302 friend class RotateScanUnit;
304 void init_packages();
305 LoadClient* new_client();
306 LoadPackage* new_package();
308 // Invoke the motion engine for a search
309 // Frame before rotation
310 float scan_frame(VFrame *previous_frame,
311 // Frame after rotation
312 VFrame *current_frame,
316 int64_t get_cache(float angle);
317 void put_cache(float angle, int64_t difference);
324 VFrame *previous_frame;
325 // Frame after motion
326 VFrame *current_frame;
344 // Range of angles to compare
345 float scan_angle1, scan_angle2;
348 ArrayList<RotateScanCache*> cache;