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
26 #include "arraylist.h"
27 //#include "../downsample/downsampleengine.inc"
28 #include "loadbalance.h"
36 class MotionScanPackage : public LoadPackage
41 // For multiple blocks
42 // Position of stationary block
43 int block_x1, block_y1, block_x2, block_y2;
44 // Range of positions to scan
45 int scan_x1, scan_y1, scan_x2, scan_y2;
48 int64_t max_difference;
49 int64_t min_difference;
57 // Search position to nearest pixel
60 // Subpixel of search position
68 MotionScanCache(int x, int y, int64_t difference);
73 class MotionScanUnit : public LoadClient
76 MotionScanUnit(MotionScan *server);
79 void process_package(LoadPackage *package);
80 int64_t get_cache(int x, int y);
81 void put_cache(int x, int y, int64_t difference);
85 ArrayList<MotionScanCache*> cache;
89 class MotionScan : public LoadServer
92 MotionScan(int total_clients,
96 friend class MotionScanUnit;
99 LoadClient* new_client();
100 LoadPackage* new_package();
101 // Test for identical frames before scanning
102 void set_test_match(int value);
104 // Invoke the motion engine for a search
105 void scan_frame(VFrame *previous_frame, // Frame before motion
106 VFrame *current_frame, // Frame after motion
107 int global_range_w, int global_range_h, int global_block_w, int global_block_h,
108 double block_x, double block_y, int frame_type, int tracking_type, int action_type,
109 int horizontal_only, int vertical_only, int source_position, int total_steps,
110 int total_dx, int total_dy, int global_origin_x, int global_origin_y,
111 int load_ok=0, int load_dx=0, int load_dy=0);
112 int64_t get_cache(int x, int y);
113 void put_cache(int x, int y, int64_t difference);
115 static int64_t abs_diff(unsigned char *prev_ptr, unsigned char *current_ptr,
116 int row_bytes, int w, int h, int color_model);
117 static int64_t abs_diff_sub(unsigned char *prev_ptr, unsigned char *current_ptr,
118 int row_bytes, int w, int h, int color_model, int sub_x, int sub_y);
120 static void clamp_scan(int w, int h,
121 int *block_x1, int *block_y1, int *block_x2, int *block_y2,
122 int *scan_x1, int *scan_y1, int *scan_x2, int *scan_y2,
125 // Change between previous frame and current frame multiplied by
127 int dx_result, dy_result;
129 enum { // action_type
137 enum { // tracking_type
151 // Pointer to downsampled frame before motion
152 VFrame *previous_frame;
153 // Pointer to downsampled frame after motion
154 VFrame *current_frame;
155 // Frames passed from user
156 VFrame *previous_frame_arg;
157 VFrame *current_frame_arg;
158 // Downsampled frames
159 VFrame *downsampled_previous;
160 VFrame *downsampled_current;
161 // Test for identical frames before processing
162 // Faster to skip it if the frames are usually different
185 ArrayList<MotionScanCache*> cache;
187 // DownSampleServer *downsample;