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/rotate"
74 int equivalent(MotionConfig &that);
75 void copy_from(MotionConfig &that);
76 void interpolate(MotionConfig &prev,
80 int64_t current_frame);
86 // Range of angles above and below center rotation angle to search
88 // Center angle of rotation search
93 int rotate_return_speed;
95 // Percent of image size
100 // Number of search positions in each refinement of the log search
101 int global_positions;
102 int rotate_positions;
103 // Block position in percentage 0 - 100
111 // Track or stabilize, single pixel, scan only, or nothing
113 // Recalculate, no calculate, save, or load coordinates from disk
115 // Track a single frame, previous frame, or previous frame same block
140 // Number of single frame to track relative to timeline start
143 int bottom_is_master;
149 class MotionMain : public PluginVClient
152 MotionMain(PluginServer *server);
155 int process_buffer(VFrame **frame,
156 int64_t start_position,
158 void process_global();
159 void process_rotation();
160 void draw_vectors(VFrame *frame);
161 int is_multichannel();
163 void save_data(KeyFrame *keyframe);
164 void read_data(KeyFrame *keyframe);
166 // Calculate frame to copy from and frame to move
167 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
168 void allocate_temp(int w, int h, int color_model);
170 PLUGIN_CLASS_MEMBERS2(MotionConfig)
173 static void draw_pixel(VFrame *frame, int x, int y);
174 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
175 void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
177 // Number of the previous reference frame on the timeline.
178 int64_t previous_frame_number;
179 // The frame compared with the previous frame to get the motion.
180 // It is moved to compensate for motion and copied to the previous_frame.
183 RotateScan *motion_rotate;
184 OverlayFrame *overlayer;
185 AffineEngine *rotate_engine;
187 // Accumulation of all global tracks since the plugin start.
188 // Multiplied by OVERSAMPLE.
192 // Rotation motion tracking
195 // Current motion vector for drawing vectors
202 // Oversampled current frame for motion estimation
203 int32_t *search_area;
207 // The layer to track motion in.
209 // The layer to apply motion in.
212 // Pointer to the source and destination of each operation.
213 // These are fully allocated buffers.
215 // The previous reference frame for global motion tracking
216 VFrame *prev_global_ref;
217 // The current reference frame for global motion tracking
218 VFrame *current_global_ref;
219 // The input target frame for global motion tracking
220 VFrame *global_target_src;
221 // The output target frame for global motion tracking
222 VFrame *global_target_dst;
224 // The previous reference frame for rotation tracking
225 VFrame *prev_rotate_ref;
226 // The current reference frame for rotation tracking
227 VFrame *current_rotate_ref;
228 // The input target frame for rotation tracking.
229 VFrame *rotate_target_src;
230 // The output target frame for rotation tracking.
231 VFrame *rotate_target_dst;
233 // The output of process_buffer
234 VFrame *output_frame;
262 class RotateScanPackage : public LoadPackage
270 class RotateScanCache
273 RotateScanCache(float angle, int64_t difference);
278 class RotateScanUnit : public LoadClient
281 RotateScanUnit(RotateScan *server, MotionMain *plugin);
284 void process_package(LoadPackage *package);
288 AffineEngine *rotater;
292 class RotateScan : public LoadServer
295 RotateScan(MotionMain *plugin,
300 friend class RotateScanUnit;
302 void init_packages();
303 LoadClient* new_client();
304 LoadPackage* new_package();
306 // Invoke the motion engine for a search
307 // Frame before rotation
308 float scan_frame(VFrame *previous_frame,
309 // Frame after rotation
310 VFrame *current_frame,
314 int64_t get_cache(float angle);
315 void put_cache(float angle, int64_t difference);
322 VFrame *previous_frame;
323 // Frame after motion
324 VFrame *current_frame;
342 // Range of angles to compare
343 float scan_angle1, scan_angle2;
346 ArrayList<RotateScanCache*> cache;