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
27 #include "loadbalance.h"
28 #include "motioncache-hv.inc"
35 #define MOTION_FILE "/tmp/m"
36 #define ROTATION_FILE "/tmp/r"
38 class MotionHVScanPackage : public LoadPackage
41 MotionHVScanPackage();
43 // For multiple blocks
44 // Position of stationary block after downsampling
45 int block_x1, block_y1, block_x2, block_y2;
46 // index of rotated frame
51 int64_t max_difference;
52 int64_t min_difference;
58 // Search position of current package to nearest pixel with downsampling
61 // Subpixel of search position
66 class MotionHVScanUnit : public LoadClient
69 MotionHVScanUnit(MotionHVScan *server);
72 void process_package(LoadPackage *package);
73 void subpixel(MotionHVScanPackage *pkg);
74 void single_pixel(MotionHVScanPackage *pkg);
79 class MotionHVScan : public LoadServer
82 MotionHVScan(int total_clients,
86 friend class MotionHVScanUnit;
89 LoadClient* new_client();
90 LoadPackage* new_package();
91 // Test for identical frames before scanning
92 void set_test_match(int value);
93 void set_cache(MotionHVCache *cache);
95 // Invoke the motion engine for a search
96 // Frame before motion
97 void scan_frame(VFrame *previous_frame,
98 VFrame *current_frame,
99 int global_range_w, // in pixels
101 int global_block_w, // in pixels
103 int block_x, // in pixels
111 int total_dx, // in pixels * OVERSAMPLE
113 int global_origin_x, // in pixels
117 double rotation_center, // in deg
118 double rotation_range);
120 static int64_t abs_diff(unsigned char *prev_ptr,
121 unsigned char *current_ptr,
126 static int64_t abs_diff_sub(unsigned char *prev_ptr,
127 unsigned char *current_ptr,
136 static void clamp_scan(int w,
148 // Change between previous frame and current frame multiplied by
182 void downsample_frame(VFrame *dst,
185 void pixel_search(int &x_result, int &y_result, double &r_result);
186 void subpixel_search(int &x_result, int &y_result);
187 double step_to_angle(int step, double center);
189 // double calculate_variance(unsigned char *current_ptr,
194 double calculate_range(unsigned char *current_ptr,
201 MotionHVCache *downsample_cache;
202 int shared_downsample;
203 AffineEngine *rotater;
204 // Pointer to downsampled frame before motion
205 VFrame *previous_frame;
206 // Pointer to downsampled frame after motion
207 VFrame *current_frame;
208 // Frames passed from user
209 VFrame *previous_frame_arg;
210 VFrame *current_frame_arg;
211 // rotated versions of current_frame
212 VFrame **rotated_current;
213 // allocation of rotated_current array, a copy of angle_steps
215 // Test for identical frames before processing
216 // Faster to skip it if the frames are usually different
219 // macroblocks didn't have enough data
232 double scan_angle1, scan_angle2;
244 int current_downsample;
252 double rotation_center;
253 double rotation_range;