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(MotionMain *plugin,
97 friend class MotionScanUnit;
100 LoadClient* new_client();
101 LoadPackage* new_package();
102 // Test for identical frames before scanning
103 void set_test_match(int value);
105 // Invoke the motion engine for a search
106 void scan_frame(VFrame *previous_frame, // Frame before motion
107 VFrame *current_frame, // Frame after motion
108 int global_range_w, int global_range_h, int global_block_w, int global_block_h,
109 double block_x, double block_y, int frame_type, int tracking_type, int action_type,
110 int horizontal_only, int vertical_only, int source_position, int total_steps,
111 int total_dx, int total_dy, int global_origin_x, int global_origin_y, int passno,
112 int load_ok=0, int load_dx=0, int load_dy=0);
113 int64_t get_cache(int x, int y);
114 void put_cache(int x, int y, int64_t difference);
116 static int64_t abs_diff(unsigned char *prev_ptr, unsigned char *current_ptr,
117 int row_bytes, int w, int h, int color_model);
118 static int64_t abs_diff_sub(unsigned char *prev_ptr, unsigned char *current_ptr,
119 int row_bytes, int w, int h, int color_model, int sub_x, int sub_y);
121 static void clamp_scan(int w, int h,
122 int *block_x1, int *block_y1, int *block_x2, int *block_y2,
123 int *scan_x1, int *scan_y1, int *scan_x2, int *scan_y2,
126 // Change between previous frame and current frame multiplied by
128 int dx_result, dy_result;
130 // Currently best expected location of scan block
131 int x_result, y_result;
133 enum { // action_type
141 enum { // tracking_type
155 // Pointer to downsampled frame before motion
156 VFrame *previous_frame;
157 // Pointer to downsampled frame after motion
158 VFrame *current_frame;
159 // Frames passed from user
160 VFrame *previous_frame_arg;
161 VFrame *current_frame_arg;
162 // Downsampled frames
163 VFrame *downsampled_previous;
164 VFrame *downsampled_current;
166 // Test for identical frames before processing
167 // Faster to skip it if the frames are usually different
190 ArrayList<MotionScanCache*> cache;
192 // DownSampleServer *downsample;