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-hv.inc"
35 #include "motionwindow-hv.inc"
36 #include "overlayframe.inc"
37 #include "pluginvclient.h"
46 // Limits of global range in percent
48 #define MAX_RADIUS 100
50 // Limits of rotation range in degrees
51 #define MIN_ROTATION 1
52 #define MAX_ROTATION 25
54 // Limits of block size in percent.
58 // Limits of block count
60 #define MAX_BLOCKS 200
62 // Precision of rotation
63 #define MIN_ANGLE 0.0001
71 int equivalent(MotionHVConfig &that);
72 void copy_from(MotionHVConfig &that);
73 void interpolate(MotionHVConfig &prev,
77 int64_t current_frame);
83 // Range of angles above and below center rotation angle to search
85 // Center angle of rotation search
90 int rotate_return_speed;
92 // Percent of image size
95 // int rotation_block_w;
96 // int rotation_block_h;
97 // Number of search positions in each refinement of the log search
98 // int global_positions;
99 // int rotate_positions;
100 // Block position in percentage 0 - 100
108 // Track or stabilize, single pixel, scan only, or nothing
110 // Recalculate, no calculate, save, or load coordinates from disk
112 // Track a single frame, previous frame, or previous frame same block
137 // Number of single frame to track relative to timeline start
140 int bottom_is_master;
146 class MotionHVMain : public PluginVClient
149 MotionHVMain(PluginServer *server);
152 int process_buffer(VFrame **frame,
153 int64_t start_position,
155 void process_global();
156 void process_rotation();
157 void draw_vectors(VFrame *frame);
158 int is_multichannel();
160 void save_data(KeyFrame *keyframe);
161 void read_data(KeyFrame *keyframe);
163 // Calculate frame to copy from and frame to move
164 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
165 void allocate_temp(int w, int h, int color_model);
167 PLUGIN_CLASS_MEMBERS2(MotionHVConfig)
170 static void draw_pixel(VFrame *frame, int x, int y);
171 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
172 void draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2);
174 // Number of the previous reference frame on the timeline.
175 int64_t previous_frame_number;
176 // The frame compared with the previous frame to get the motion.
177 // It is moved to compensate for motion and copied to the previous_frame.
179 MotionHVScan *engine;
180 // RotateScan *motion_rotate;
181 OverlayFrame *overlayer;
182 AffineEngine *rotate_engine;
184 // Accumulation of all global tracks since the plugin start.
185 // Multiplied by OVERSAMPLE.
189 // Rotation motion tracking
192 // Current motion vector for drawing vectors
199 // Oversampled current frame for motion estimation
200 int32_t *search_area;
204 // The layer to track motion in.
206 // The layer to apply motion in.
209 // Pointer to the source and destination of each operation.
210 // These are fully allocated buffers.
212 // The previous reference frame for global motion tracking
213 VFrame *prev_global_ref;
214 // The current reference frame for global motion tracking
215 VFrame *current_global_ref;
216 // The input target frame for global motion tracking
217 VFrame *global_target_src;
218 // The output target frame for global motion tracking
219 VFrame *global_target_dst;
221 // The previous reference frame for rotation tracking
222 VFrame *prev_rotate_ref;
223 // The current reference frame for rotation tracking
224 VFrame *current_rotate_ref;
225 // The input target frame for rotation tracking.
226 VFrame *rotate_target_src;
227 // The output target frame for rotation tracking.
228 VFrame *rotate_target_dst;
230 // The output of process_buffer
231 VFrame *output_frame;
237 class MotionHvVVFrame : public VFrame
240 MotionHvVVFrame(VFrame *vfrm, int n);
241 int draw_pixel(int x, int y);