4 * Copyright (C) 2016 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 "rotatescan.inc"
47 // Limits of global range in percent
49 #define MAX_RADIUS 100
51 // Limits of rotation range in degrees
52 #define MIN_ROTATION 1
53 #define MAX_ROTATION 25
55 // Limits of block size in percent.
59 // Limits of block count
61 #define MAX_BLOCKS 200
63 // Precision of rotation
64 #define MIN_ANGLE 0.0001
72 int equivalent(MotionConfig &that);
73 void copy_from(MotionConfig &that);
74 void interpolate(MotionConfig &prev,
78 int64_t current_frame);
84 // Range of angles above and below center rotation angle to search
86 // Center angle of rotation search
91 int rotate_return_speed;
93 // Percent of image size
96 // int rotation_block_w;
97 // int rotation_block_h;
98 // Number of search positions in each refinement of the log search
99 // int global_positions;
100 // int rotate_positions;
101 // Block position in percentage 0 - 100
109 // Track or stabilize, single pixel, scan only, or nothing
111 // Recalculate, no calculate, save, or load coordinates from disk
113 // Track a single frame, previous frame, or previous frame same block
138 // Number of single frame to track relative to timeline start
141 int bottom_is_master;
147 class MotionMain : public PluginVClient
150 MotionMain(PluginServer *server);
153 int process_buffer(VFrame **frame,
154 int64_t start_position,
156 void process_global();
157 void process_rotation();
158 void draw_vectors(VFrame *frame);
159 int is_multichannel();
161 void save_data(KeyFrame *keyframe);
162 void read_data(KeyFrame *keyframe);
164 // Calculate frame to copy from and frame to move
165 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
166 void allocate_temp(int w, int h, int color_model);
168 PLUGIN_CLASS_MEMBERS2(MotionConfig)
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;