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);
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
98 // int rotation_block_w;
99 // int rotation_block_h;
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 int addtrackedframeoffset;
112 // Track or stabilize, single pixel, scan only, or nothing
114 // Recalculate, no calculate, save, or load coordinates from disk
116 // Track a single frame, previous frame, or previous frame same block
141 // Number of single frame to track relative to timeline start
144 int bottom_is_master;
150 class MotionMain : public PluginVClient
153 MotionMain(PluginServer *server);
156 int process_buffer(VFrame **frame,
157 int64_t start_position,
159 void process_global();
160 void process_rotation();
161 void draw_vectors(VFrame *frame);
162 int is_multichannel();
164 void save_data(KeyFrame *keyframe);
165 void read_data(KeyFrame *keyframe);
167 // Calculate frame to copy from and frame to move
168 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
169 void allocate_temp(int w, int h, int color_model);
171 PLUGIN_CLASS_MEMBERS2(MotionConfig)
174 static void draw_pixel(VFrame *frame, int x, int y);
175 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
176 void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
178 // Number of the previous reference frame on the timeline.
179 int64_t previous_frame_number;
180 // The frame compared with the previous frame to get the motion.
181 // It is moved to compensate for motion and copied to the previous_frame.
184 RotateScan *motion_rotate;
185 OverlayFrame *overlayer;
186 AffineEngine *rotate_engine;
188 // Accumulation of all global tracks since the plugin start.
189 // Multiplied by OVERSAMPLE.
193 // Rotation motion tracking
196 // Current motion vector for drawing vectors
203 // Oversampled current frame for motion estimation
204 int32_t *search_area;
208 // The layer to track motion in.
210 // The layer to apply motion in.
213 // Pointer to the source and destination of each operation.
214 // These are fully allocated buffers.
216 // The previous reference frame for global motion tracking
217 VFrame *prev_global_ref;
218 // The current reference frame for global motion tracking
219 VFrame *current_global_ref;
220 // The input target frame for global motion tracking
221 VFrame *global_target_src;
222 // The output target frame for global motion tracking
223 VFrame *global_target_dst;
225 // The previous reference frame for rotation tracking
226 VFrame *prev_rotate_ref;
227 // The current reference frame for rotation tracking
228 VFrame *current_rotate_ref;
229 // The input target frame for rotation tracking.
230 VFrame *rotate_target_src;
231 // The output target frame for rotation tracking.
232 VFrame *rotate_target_dst;
234 // The output of process_buffer
235 VFrame *output_frame;
263 class RotateScanPackage : public LoadPackage
271 class RotateScanCache
274 RotateScanCache(float angle, int64_t difference);
279 class RotateScanUnit : public LoadClient
282 RotateScanUnit(RotateScan *server, MotionMain *plugin);
285 void process_package(LoadPackage *package);
289 AffineEngine *rotater;
293 class RotateScan : public LoadServer
296 RotateScan(MotionMain *plugin,
301 friend class RotateScanUnit;
303 void init_packages();
304 LoadClient* new_client();
305 LoadPackage* new_package();
307 // Invoke the motion engine for a search
308 // Frame before rotation
309 float scan_frame(VFrame *previous_frame,
310 // Frame after rotation
311 VFrame *current_frame,
315 int64_t get_cache(float angle);
316 void put_cache(float angle, int64_t difference);
323 VFrame *previous_frame;
324 // Frame after motion
325 VFrame *current_frame;
343 // Range of angles to compare
344 float scan_angle1, scan_angle2;
347 ArrayList<RotateScanCache*> cache;