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"
34 #define MOTION_FILE "/tmp/m"
35 #define ROTATION_FILE "/tmp/r"
37 class MotionHVScanPackage : public LoadPackage
40 MotionHVScanPackage();
42 // For multiple blocks
43 // Position of stationary block after downsampling
44 int block_x1, block_y1, block_x2, block_y2;
45 // index of rotated frame
50 int64_t max_difference;
51 int64_t min_difference;
57 // Search position of current package to nearest pixel with downsampling
60 // Subpixel of search position
65 class MotionHVScanUnit : public LoadClient
68 MotionHVScanUnit(MotionHVScan *server);
71 void process_package(LoadPackage *package);
72 void subpixel(MotionHVScanPackage *pkg);
73 void single_pixel(MotionHVScanPackage *pkg);
78 class MotionHVScan : public LoadServer
81 MotionHVScan(int total_clients,
85 friend class MotionHVScanUnit;
88 LoadClient* new_client();
89 LoadPackage* new_package();
90 // Test for identical frames before scanning
91 void set_test_match(int value);
93 // Invoke the motion engine for a search
94 // Frame before motion
95 void scan_frame(VFrame *previous_frame,
96 VFrame *current_frame,
97 int global_range_w, // in pixels
99 int global_block_w, // in pixels
101 int block_x, // in pixels
109 int total_dx, // in pixels * OVERSAMPLE
111 int global_origin_x, // in pixels
115 double rotation_center, // in deg
116 double rotation_range);
118 static int64_t abs_diff(unsigned char *prev_ptr,
119 unsigned char *current_ptr,
124 static int64_t abs_diff_sub(unsigned char *prev_ptr,
125 unsigned char *current_ptr,
134 static void clamp_scan(int w,
146 // Change between previous frame and current frame multiplied by
180 void downsample_frame(VFrame *dst,
183 void pixel_search(int &x_result, int &y_result, double &r_result);
184 void subpixel_search(int &x_result, int &y_result);
185 double step_to_angle(int step, double center);
187 // double calculate_variance(unsigned char *current_ptr,
192 double calculate_range(unsigned char *current_ptr,
200 AffineEngine *rotater;
201 // Pointer to downsampled frame before motion
202 VFrame *previous_frame;
203 // Pointer to downsampled frame after motion
204 VFrame *current_frame;
205 // Frames passed from user
206 VFrame *previous_frame_arg;
207 VFrame *current_frame_arg;
208 // Downsampled frames
209 VFrame *downsampled_previous;
210 VFrame *downsampled_current;
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;