4 * Copyright (C) 2012 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
23 #include "bcdisplayinfo.h"
26 #include "bcsignals.h"
32 #include "motionscan.h"
33 #include "motionwindow.h"
35 #include "overlayframe.h"
36 #include "rotateframe.h"
37 #include "transportque.h"
43 REGISTER_PLUGIN(MotionMain)
54 MotionConfig::MotionConfig()
61 global_block_w = MIN_BLOCK;
62 global_block_h = MIN_BLOCK;
63 // rotation_block_w = MIN_BLOCK;
64 // rotation_block_h = MIN_BLOCK;
67 global_positions = 256;
70 rotate_magnitude = 90;
72 rotate_return_speed = 0;
73 action_type = MotionScan::STABILIZE;
76 addtrackedframeoffset = 0;
77 tracking_type = MotionScan::NO_CALCULATE;
79 tracking_object = MotionScan::TRACK_SINGLE;
86 void MotionConfig::boundaries()
88 CLAMP(global_range_w, MIN_RADIUS, MAX_RADIUS);
89 CLAMP(global_range_h, MIN_RADIUS, MAX_RADIUS);
90 CLAMP(rotation_range, MIN_ROTATION, MAX_ROTATION);
91 CLAMP(rotation_center, -MAX_ROTATION, MAX_ROTATION);
92 CLAMP(block_count, MIN_BLOCKS, MAX_BLOCKS);
93 CLAMP(global_block_w, MIN_BLOCK, MAX_BLOCK);
94 CLAMP(global_block_h, MIN_BLOCK, MAX_BLOCK);
95 // CLAMP(rotation_block_w, MIN_BLOCK, MAX_BLOCK);
96 // CLAMP(rotation_block_h, MIN_BLOCK, MAX_BLOCK);
99 int MotionConfig::equivalent(MotionConfig &that)
101 return global_range_w == that.global_range_w &&
102 global_range_h == that.global_range_h &&
103 rotation_range == that.rotation_range &&
104 rotation_center == that.rotation_center &&
105 action_type == that.action_type &&
106 global == that.global &&
107 rotate == that.rotate &&
108 addtrackedframeoffset == that.addtrackedframeoffset &&
109 draw_vectors == that.draw_vectors &&
110 block_count == that.block_count &&
111 global_block_w == that.global_block_w &&
112 global_block_h == that.global_block_h &&
113 // rotation_block_w == that.rotation_block_w &&
114 // rotation_block_h == that.rotation_block_h &&
115 EQUIV(block_x, that.block_x) &&
116 EQUIV(block_y, that.block_y) &&
117 global_positions == that.global_positions &&
118 rotate_positions == that.rotate_positions &&
119 magnitude == that.magnitude &&
120 return_speed == that.return_speed &&
121 rotate_return_speed == that.rotate_return_speed &&
122 rotate_magnitude == that.rotate_magnitude &&
123 tracking_object == that.tracking_object &&
124 track_frame == that.track_frame &&
125 bottom_is_master == that.bottom_is_master &&
126 horizontal_only == that.horizontal_only &&
127 vertical_only == that.vertical_only;
130 void MotionConfig::copy_from(MotionConfig &that)
132 global_range_w = that.global_range_w;
133 global_range_h = that.global_range_h;
134 rotation_range = that.rotation_range;
135 rotation_center = that.rotation_center;
136 action_type = that.action_type;
137 global = that.global;
138 rotate = that.rotate;
139 addtrackedframeoffset = that.addtrackedframeoffset;
140 tracking_type = that.tracking_type;
141 draw_vectors = that.draw_vectors;
142 block_count = that.block_count;
143 block_x = that.block_x;
144 block_y = that.block_y;
145 global_positions = that.global_positions;
146 rotate_positions = that.rotate_positions;
147 global_block_w = that.global_block_w;
148 global_block_h = that.global_block_h;
149 // rotation_block_w = that.rotation_block_w;
150 // rotation_block_h = that.rotation_block_h;
151 magnitude = that.magnitude;
152 return_speed = that.return_speed;
153 rotate_magnitude = that.rotate_magnitude;
154 rotate_return_speed = that.rotate_return_speed;
155 tracking_object = that.tracking_object;
156 track_frame = that.track_frame;
157 bottom_is_master = that.bottom_is_master;
158 horizontal_only = that.horizontal_only;
159 vertical_only = that.vertical_only;
162 void MotionConfig::interpolate(MotionConfig &prev,
166 int64_t current_frame)
168 //double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
169 //double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
170 this->block_x = prev.block_x;
171 this->block_y = prev.block_y;
172 global_range_w = prev.global_range_w;
173 global_range_h = prev.global_range_h;
174 rotation_range = prev.rotation_range;
175 rotation_center = prev.rotation_center;
176 action_type = prev.action_type;
177 global = prev.global;
178 rotate = prev.rotate;
179 addtrackedframeoffset = prev.addtrackedframeoffset;
180 tracking_type = prev.tracking_type;
181 draw_vectors = prev.draw_vectors;
182 block_count = prev.block_count;
183 global_positions = prev.global_positions;
184 rotate_positions = prev.rotate_positions;
185 global_block_w = prev.global_block_w;
186 global_block_h = prev.global_block_h;
187 // rotation_block_w = prev.rotation_block_w;
188 // rotation_block_h = prev.rotation_block_h;
189 magnitude = prev.magnitude;
190 return_speed = prev.return_speed;
191 rotate_magnitude = prev.rotate_magnitude;
192 rotate_return_speed = prev.rotate_return_speed;
193 tracking_object = prev.tracking_object;
194 track_frame = prev.track_frame;
195 bottom_is_master = prev.bottom_is_master;
196 horizontal_only = prev.horizontal_only;
197 vertical_only = prev.vertical_only;
218 MotionMain::MotionMain(PluginServer *server)
219 : PluginVClient(server)
231 previous_frame_number = -1;
234 current_global_ref = 0;
235 global_target_src = 0;
236 global_target_dst = 0;
239 current_rotate_ref = 0;
240 rotate_target_src = 0;
241 rotate_target_dst = 0;
244 MotionMain::~MotionMain()
249 delete [] search_area;
251 delete rotate_engine;
252 delete motion_rotate;
255 delete prev_global_ref;
256 delete current_global_ref;
257 delete global_target_src;
258 delete global_target_dst;
260 delete prev_rotate_ref;
261 delete current_rotate_ref;
262 delete rotate_target_src;
263 delete rotate_target_dst;
266 const char* MotionMain::plugin_title() { return _("Motion"); }
267 int MotionMain::is_realtime() { return 1; }
268 int MotionMain::is_multichannel() { return 1; }
271 NEW_WINDOW_MACRO(MotionMain, MotionWindow)
273 LOAD_CONFIGURATION_MACRO(MotionMain, MotionConfig)
277 void MotionMain::update_gui()
281 if(load_configuration())
283 thread->window->lock_window("MotionMain::update_gui");
285 char string[BCTEXTLEN];
286 sprintf(string, "%d", config.global_positions);
287 ((MotionWindow*)thread->window)->global_search_positions->set_text(string);
288 sprintf(string, "%d", config.rotate_positions);
289 ((MotionWindow*)thread->window)->rotation_search_positions->set_text(string);
291 ((MotionWindow*)thread->window)->global_block_w->update(config.global_block_w);
292 ((MotionWindow*)thread->window)->global_block_h->update(config.global_block_h);
293 // ((MotionWindow*)thread->window)->rotation_block_w->update(config.rotation_block_w);
294 // ((MotionWindow*)thread->window)->rotation_block_h->update(config.rotation_block_h);
295 ((MotionWindow*)thread->window)->block_x->update(config.block_x);
296 ((MotionWindow*)thread->window)->block_y->update(config.block_y);
297 ((MotionWindow*)thread->window)->block_x_text->update((float)config.block_x);
298 ((MotionWindow*)thread->window)->block_y_text->update((float)config.block_y);
299 ((MotionWindow*)thread->window)->magnitude->update(config.magnitude);
300 ((MotionWindow*)thread->window)->return_speed->update(config.return_speed);
301 ((MotionWindow*)thread->window)->rotate_magnitude->update(config.rotate_magnitude);
302 ((MotionWindow*)thread->window)->rotate_return_speed->update(config.rotate_return_speed);
303 ((MotionWindow*)thread->window)->rotation_range->update(config.rotation_range);
304 ((MotionWindow*)thread->window)->rotation_center->update(config.rotation_center);
307 ((MotionWindow*)thread->window)->track_single->update(config.tracking_object == MotionScan::TRACK_SINGLE);
308 ((MotionWindow*)thread->window)->track_frame_number->update(config.track_frame);
309 ((MotionWindow*)thread->window)->track_previous->update(config.tracking_object == MotionScan::TRACK_PREVIOUS);
310 ((MotionWindow*)thread->window)->previous_same->update(config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK);
311 if(config.tracking_object != MotionScan::TRACK_SINGLE)
312 ((MotionWindow*)thread->window)->track_frame_number->disable();
314 ((MotionWindow*)thread->window)->track_frame_number->enable();
316 ((MotionWindow*)thread->window)->action_type->set_text(
317 ActionType::to_text(config.action_type));
318 ((MotionWindow*)thread->window)->tracking_type->set_text(
319 TrackingType::to_text(config.tracking_type));
320 ((MotionWindow*)thread->window)->track_direction->set_text(
321 TrackDirection::to_text(config.horizontal_only, config.vertical_only));
322 ((MotionWindow*)thread->window)->master_layer->set_text(
323 MasterLayer::to_text(config.bottom_is_master));
326 ((MotionWindow*)thread->window)->update_mode();
327 thread->window->unlock_window();
335 void MotionMain::save_data(KeyFrame *keyframe)
339 // cause data to be stored directly in text
340 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
341 output.tag.set_title("MOTION");
343 output.tag.set_property("BLOCK_COUNT", config.block_count);
344 output.tag.set_property("GLOBAL_POSITIONS", config.global_positions);
345 output.tag.set_property("ROTATE_POSITIONS", config.rotate_positions);
346 output.tag.set_property("GLOBAL_BLOCK_W", config.global_block_w);
347 output.tag.set_property("GLOBAL_BLOCK_H", config.global_block_h);
348 // output.tag.set_property("ROTATION_BLOCK_W", config.rotation_block_w);
349 // output.tag.set_property("ROTATION_BLOCK_H", config.rotation_block_h);
350 output.tag.set_property("BLOCK_X", config.block_x);
351 output.tag.set_property("BLOCK_Y", config.block_y);
352 output.tag.set_property("GLOBAL_RANGE_W", config.global_range_w);
353 output.tag.set_property("GLOBAL_RANGE_H", config.global_range_h);
354 output.tag.set_property("ROTATION_RANGE", config.rotation_range);
355 output.tag.set_property("ROTATION_CENTER", config.rotation_center);
356 output.tag.set_property("MAGNITUDE", config.magnitude);
357 output.tag.set_property("RETURN_SPEED", config.return_speed);
358 output.tag.set_property("ROTATE_MAGNITUDE", config.rotate_magnitude);
359 output.tag.set_property("ROTATE_RETURN_SPEED", config.rotate_return_speed);
360 output.tag.set_property("ACTION_TYPE", config.action_type);
361 output.tag.set_property("GLOBAL", config.global);
362 output.tag.set_property("ROTATE", config.rotate);
363 output.tag.set_property("ADDTRACKEDFRAMEOFFSET", config.addtrackedframeoffset);
364 output.tag.set_property("TRACKING_TYPE", config.tracking_type);
365 output.tag.set_property("DRAW_VECTORS", config.draw_vectors);
366 output.tag.set_property("TRACKING_OBJECT", config.tracking_object);
367 output.tag.set_property("TRACK_FRAME", config.track_frame);
368 output.tag.set_property("BOTTOM_IS_MASTER", config.bottom_is_master);
369 output.tag.set_property("HORIZONTAL_ONLY", config.horizontal_only);
370 output.tag.set_property("VERTICAL_ONLY", config.vertical_only);
372 output.tag.set_title("/MOTION");
374 output.terminate_string();
377 void MotionMain::read_data(KeyFrame *keyframe)
381 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
387 result = input.read_tag();
391 if(input.tag.title_is("MOTION"))
393 config.block_count = input.tag.get_property("BLOCK_COUNT", config.block_count);
394 config.global_positions = input.tag.get_property("GLOBAL_POSITIONS", config.global_positions);
395 config.rotate_positions = input.tag.get_property("ROTATE_POSITIONS", config.rotate_positions);
396 config.global_block_w = input.tag.get_property("GLOBAL_BLOCK_W", config.global_block_w);
397 config.global_block_h = input.tag.get_property("GLOBAL_BLOCK_H", config.global_block_h);
398 // config.rotation_block_w = input.tag.get_property("ROTATION_BLOCK_W", config.rotation_block_w);
399 // config.rotation_block_h = input.tag.get_property("ROTATION_BLOCK_H", config.rotation_block_h);
400 config.block_x = input.tag.get_property("BLOCK_X", config.block_x);
401 config.block_y = input.tag.get_property("BLOCK_Y", config.block_y);
402 config.global_range_w = input.tag.get_property("GLOBAL_RANGE_W", config.global_range_w);
403 config.global_range_h = input.tag.get_property("GLOBAL_RANGE_H", config.global_range_h);
404 config.rotation_range = input.tag.get_property("ROTATION_RANGE", config.rotation_range);
405 config.rotation_center = input.tag.get_property("ROTATION_CENTER", config.rotation_center);
406 config.magnitude = input.tag.get_property("MAGNITUDE", config.magnitude);
407 config.return_speed = input.tag.get_property("RETURN_SPEED", config.return_speed);
408 config.rotate_magnitude = input.tag.get_property("ROTATE_MAGNITUDE", config.rotate_magnitude);
409 config.rotate_return_speed = input.tag.get_property("ROTATE_RETURN_SPEED", config.rotate_return_speed);
410 config.action_type = input.tag.get_property("ACTION_TYPE", config.action_type);
411 config.global = input.tag.get_property("GLOBAL", config.global);
412 config.rotate = input.tag.get_property("ROTATE", config.rotate);
413 config.addtrackedframeoffset = input.tag.get_property("ADDTRACKEDFRAMEOFFSET", config.addtrackedframeoffset);
414 config.tracking_type = input.tag.get_property("TRACKING_TYPE", config.tracking_type);
415 config.draw_vectors = input.tag.get_property("DRAW_VECTORS", config.draw_vectors);
416 config.tracking_object = input.tag.get_property("TRACKING_OBJECT", config.tracking_object);
417 config.track_frame = input.tag.get_property("TRACK_FRAME", config.track_frame);
418 config.bottom_is_master = input.tag.get_property("BOTTOM_IS_MASTER", config.bottom_is_master);
419 config.horizontal_only = input.tag.get_property("HORIZONTAL_ONLY", config.horizontal_only);
420 config.vertical_only = input.tag.get_property("VERTICAL_ONLY", config.vertical_only);
435 void MotionMain::allocate_temp(int w, int h, int color_model)
438 (temp_frame->get_w() != w ||
439 temp_frame->get_h() != h))
445 temp_frame = new VFrame(w, h, color_model);
449 void MotionMain::process_global()
452 if(!engine) engine = new MotionScan(PluginClient::get_project_smp() + 1,
453 PluginClient::get_project_smp() + 1);
455 // Determine if frames changed
456 engine->scan_frame(current_global_ref,
458 config.global_range_w,
459 config.global_range_h,
460 config.global_block_w,
461 config.global_block_h,
464 config.tracking_object,
465 config.tracking_type,
467 config.horizontal_only,
468 config.vertical_only,
469 get_source_position(),
470 config.global_positions,
475 current_dx = engine->dx_result;
476 current_dy = engine->dy_result;
478 // Add current motion vector to accumulation vector.
479 if(config.tracking_object != MotionScan::TRACK_SINGLE)
482 total_dx = (int64_t)total_dx * (100 - config.return_speed) / 100;
483 total_dy = (int64_t)total_dy * (100 - config.return_speed) / 100;
484 total_dx += engine->dx_result;
485 total_dy += engine->dy_result;
486 // printf("MotionMain::process_global total_dx=%d engine->dx_result=%d\n",
488 // engine->dx_result);
491 // Make accumulation vector current
493 total_dx = engine->dx_result;
494 total_dy = engine->dy_result;
497 // Clamp accumulation vector
498 if(config.magnitude < 100)
500 //int block_w = (int64_t)config.global_block_w *
501 // current_global_ref->get_w() / 100;
502 //int block_h = (int64_t)config.global_block_h *
503 // current_global_ref->get_h() / 100;
504 int block_x_orig = (int64_t)(config.block_x *
505 current_global_ref->get_w() /
507 int block_y_orig = (int64_t)(config.block_y *
508 current_global_ref->get_h() /
511 int max_block_x = (int64_t)(current_global_ref->get_w() - block_x_orig) *
515 int max_block_y = (int64_t)(current_global_ref->get_h() - block_y_orig) *
519 int min_block_x = (int64_t)-block_x_orig *
523 int min_block_y = (int64_t)-block_y_orig *
528 CLAMP(total_dx, min_block_x, max_block_x);
529 CLAMP(total_dy, min_block_y, max_block_y);
533 printf("MotionMain::process_global 2 total_dx=%.02f total_dy=%.02f\n",
534 (float)total_dx / OVERSAMPLE,
535 (float)total_dy / OVERSAMPLE);
538 if(config.tracking_object != MotionScan::TRACK_SINGLE && !config.rotate)
540 // Transfer current reference frame to previous reference frame and update
541 // counter. Must wait for rotate to compare.
542 prev_global_ref->copy_from(current_global_ref);
543 previous_frame_number = get_source_position();
546 // Decide what to do with target based on requested operation
547 int interpolation = NEAREST_NEIGHBOR;
550 switch(config.action_type)
552 case MotionScan::NOTHING:
553 global_target_dst->copy_from(global_target_src);
555 case MotionScan::TRACK_PIXEL:
556 interpolation = NEAREST_NEIGHBOR;
557 dx = (int)(total_dx / OVERSAMPLE);
558 dy = (int)(total_dy / OVERSAMPLE);
560 case MotionScan::STABILIZE_PIXEL:
561 interpolation = NEAREST_NEIGHBOR;
562 dx = -(int)(total_dx / OVERSAMPLE);
563 dy = -(int)(total_dy / OVERSAMPLE);
566 case MotionScan::TRACK:
567 interpolation = CUBIC_LINEAR;
568 dx = (float)total_dx / OVERSAMPLE;
569 dy = (float)total_dy / OVERSAMPLE;
571 case MotionScan::STABILIZE:
572 interpolation = CUBIC_LINEAR;
573 dx = -(float)total_dx / OVERSAMPLE;
574 dy = -(float)total_dy / OVERSAMPLE;
579 if(config.action_type != MotionScan::NOTHING)
582 overlayer = new OverlayFrame(PluginClient::get_project_smp() + 1);
583 global_target_dst->clear_frame();
584 overlayer->overlay(global_target_dst,
588 global_target_src->get_w(),
589 global_target_src->get_h(),
592 (float)global_target_src->get_w() + dx,
593 (float)global_target_src->get_h() + dy,
602 void MotionMain::process_rotation()
607 // Convert the previous global reference into the previous rotation reference.
608 // Convert global target destination into rotation target source.
612 overlayer = new OverlayFrame(PluginClient::get_project_smp() + 1);
615 if(config.tracking_object == MotionScan::TRACK_SINGLE)
617 dx = (float)total_dx / OVERSAMPLE;
618 dy = (float)total_dy / OVERSAMPLE;
622 dx = (float)current_dx / OVERSAMPLE;
623 dy = (float)current_dy / OVERSAMPLE;
626 prev_rotate_ref->clear_frame();
627 overlayer->overlay(prev_rotate_ref,
631 prev_global_ref->get_w(),
632 prev_global_ref->get_h(),
635 (float)prev_global_ref->get_w() + dx,
636 (float)prev_global_ref->get_h() + dy,
640 // Pivot is destination global position
641 block_x = (int)(prev_rotate_ref->get_w() *
646 block_y = (int)(prev_rotate_ref->get_h() *
651 // Use the global target output as the rotation target input
652 rotate_target_src->copy_from(global_target_dst);
653 // Transfer current reference frame to previous reference frame for global.
654 if(config.tracking_object != MotionScan::TRACK_SINGLE)
656 prev_global_ref->copy_from(current_global_ref);
657 previous_frame_number = get_source_position();
663 block_x = (int)(prev_rotate_ref->get_w() *
666 block_y = (int)(prev_rotate_ref->get_h() *
675 motion_rotate = new RotateScan(this,
676 get_project_smp() + 1,
677 get_project_smp() + 1);
679 current_angle = motion_rotate->scan_frame(prev_rotate_ref,
686 // Add current rotation to accumulation
687 if(config.tracking_object != MotionScan::TRACK_SINGLE)
690 total_angle = total_angle * (100 - config.rotate_return_speed) / 100;
691 // Accumulate current rotation
692 total_angle += current_angle;
694 // Clamp rotation accumulation
695 if(config.rotate_magnitude < 90)
697 CLAMP(total_angle, -config.rotate_magnitude, config.rotate_magnitude);
702 // Transfer current reference frame to previous reference frame and update
704 prev_rotate_ref->copy_from(current_rotate_ref);
705 previous_frame_number = get_source_position();
710 total_angle = current_angle;
714 printf("MotionMain::process_rotation total_angle=%f\n", total_angle);
718 // Calculate rotation parameters based on requested operation
720 switch(config.action_type)
722 case MotionScan::NOTHING:
723 rotate_target_dst->copy_from(rotate_target_src);
725 case MotionScan::TRACK:
726 case MotionScan::TRACK_PIXEL:
729 case MotionScan::STABILIZE:
730 case MotionScan::STABILIZE_PIXEL:
731 angle = -total_angle;
737 if(config.action_type != MotionScan::NOTHING)
740 rotate_engine = new AffineEngine(PluginClient::get_project_smp() + 1,
741 PluginClient::get_project_smp() + 1);
743 rotate_target_dst->clear_frame();
745 // Determine pivot based on a number of factors.
746 switch(config.action_type)
748 case MotionScan::TRACK:
749 case MotionScan::TRACK_PIXEL:
750 // Use destination of global tracking.
751 // rotate_engine->set_pivot(block_x, block_y);
752 rotate_engine->set_in_pivot(block_x, block_y);
753 rotate_engine->set_out_pivot(block_x, block_y);
756 case MotionScan::STABILIZE:
757 case MotionScan::STABILIZE_PIXEL:
760 // Use origin of global stabilize operation
761 // rotate_engine->set_pivot((int)(rotate_target_dst->get_w() *
764 // (int)(rotate_target_dst->get_h() *
767 rotate_engine->set_in_pivot((int)(rotate_target_dst->get_w() *
770 (int)(rotate_target_dst->get_h() *
773 rotate_engine->set_out_pivot((int)(rotate_target_dst->get_w() *
776 (int)(rotate_target_dst->get_h() *
784 // rotate_engine->set_pivot(block_x, block_y);
785 rotate_engine->set_in_pivot(block_x, block_y);
786 rotate_engine->set_out_pivot(block_x, block_y);
792 rotate_engine->rotate(rotate_target_dst, rotate_target_src, angle);
793 // overlayer->overlay(rotate_target_dst,
797 // prev_rotate_ref->get_w(),
798 // prev_rotate_ref->get_h(),
801 // prev_rotate_ref->get_w(),
802 // prev_rotate_ref->get_h(),
806 // overlayer->overlay(rotate_target_dst,
807 // current_rotate_ref,
810 // prev_rotate_ref->get_w(),
811 // prev_rotate_ref->get_h(),
814 // prev_rotate_ref->get_w(),
815 // prev_rotate_ref->get_h(),
834 int MotionMain::process_buffer(VFrame **frame,
835 int64_t start_position,
838 int need_reconfigure = load_configuration();
839 int color_model = frame[0]->get_color_model();
840 w = frame[0]->get_w();
841 h = frame[0]->get_h();
845 printf("MotionMain::process_buffer %d start_position=%lld\n", __LINE__, start_position);
849 // Calculate the source and destination pointers for each of the operations.
850 // Get the layer to track motion in.
851 reference_layer = config.bottom_is_master ?
852 PluginClient::total_in_buffers - 1 :
854 // Get the layer to apply motion in.
855 target_layer = config.bottom_is_master ?
857 PluginClient::total_in_buffers - 1;
860 output_frame = frame[target_layer];
863 // Get the position of previous reference frame.
864 int64_t actual_previous_number;
865 // Skip if match frame not available
866 int skip_current = 0;
869 if(config.tracking_object == MotionScan::TRACK_SINGLE)
871 actual_previous_number = config.track_frame;
872 if(get_direction() == PLAY_REVERSE)
873 actual_previous_number++;
874 if(actual_previous_number == start_position)
879 actual_previous_number = start_position;
880 if(get_direction() == PLAY_FORWARD)
882 actual_previous_number--;
883 if(actual_previous_number < get_source_start())
887 KeyFrame *keyframe = get_prev_keyframe(start_position, 1);
888 if(keyframe->position > 0 &&
889 actual_previous_number < keyframe->position)
895 actual_previous_number++;
896 if(actual_previous_number >= get_source_start() + get_total_len())
900 KeyFrame *keyframe = get_next_keyframe(start_position, 1);
901 if(keyframe->position > 0 &&
902 actual_previous_number >= keyframe->position)
907 // Only count motion since last keyframe
913 if(!config.global && !config.rotate) skip_current = 1;
918 // printf("process_realtime %d %lld %lld\n",
920 // previous_frame_number,
921 // actual_previous_number);
922 // Load match frame and reset vectors
923 int need_reload = !skip_current &&
924 (previous_frame_number != actual_previous_number ||
931 previous_frame_number = actual_previous_number;
948 // Get the global pointers. Here we walk through the sequence of events.
951 // Assume global only. Global reads previous frame and compares
952 // with current frame to get the current translation.
953 // The center of the search area is fixed in compensate mode or
954 // the user value + the accumulation vector in track mode.
956 prev_global_ref = new VFrame(w, h, color_model);
957 if(!current_global_ref)
958 current_global_ref = new VFrame(w, h, color_model);
960 // Global loads the current target frame into the src and
961 // writes it to the dst frame with desired translation.
962 if(!global_target_src)
963 global_target_src = new VFrame(w, h, color_model);
964 if(!global_target_dst)
965 global_target_dst = new VFrame(w, h, color_model);
968 // Load the global frames
971 read_frame(prev_global_ref,
973 previous_frame_number,
978 read_frame(current_global_ref,
983 read_frame(global_target_src,
991 // Global followed by rotate
994 // Must translate the previous global reference by the current global
995 // accumulation vector to match the current global reference.
996 // The center of the search area is always the user value + the accumulation
999 prev_rotate_ref = new VFrame(w, h, color_model);
1000 // The current global reference is the current rotation reference.
1001 if(!current_rotate_ref)
1002 current_rotate_ref = new VFrame(w, h, color_model);
1003 current_rotate_ref->copy_from(current_global_ref);
1005 // The global target destination is copied to the rotation target source
1006 // then written to the rotation output with rotation.
1007 // The pivot for the rotation is the center of the search area
1008 // if we're tracking.
1009 // The pivot is fixed to the user position if we're compensating.
1010 if(!rotate_target_src)
1011 rotate_target_src = new VFrame(w, h, color_model);
1012 if(!rotate_target_dst)
1013 rotate_target_dst = new VFrame(w, h, color_model);
1020 // Rotation reads the previous reference frame and compares it with current
1022 if(!prev_rotate_ref)
1023 prev_rotate_ref = new VFrame(w, h, color_model);
1024 if(!current_rotate_ref)
1025 current_rotate_ref = new VFrame(w, h, color_model);
1027 // Rotation loads target frame to temporary, rotates it, and writes it to the
1028 // target frame. The pivot is always fixed.
1029 if(!rotate_target_src)
1030 rotate_target_src = new VFrame(w, h, color_model);
1031 if(!rotate_target_dst)
1032 rotate_target_dst = new VFrame(w, h, color_model);
1035 // Load the rotate frames
1038 read_frame(prev_rotate_ref,
1040 previous_frame_number,
1044 read_frame(current_rotate_ref,
1049 read_frame(rotate_target_src,
1067 // Get position change from previous frame to current frame
1068 if(config.global) process_global();
1069 // Get rotation change from previous frame to current frame
1070 if(config.rotate) process_rotation();
1071 //frame[target_layer]->copy_from(prev_rotate_ref);
1072 //frame[target_layer]->copy_from(current_rotate_ref);
1080 // Transfer the relevant target frame to the output
1085 frame[target_layer]->copy_from(rotate_target_dst);
1089 frame[target_layer]->copy_from(global_target_dst);
1093 // Read the target destination directly
1095 read_frame(frame[target_layer],
1102 if(config.draw_vectors)
1104 draw_vectors(frame[target_layer]);
1108 printf("MotionMain::process_buffer %d\n", __LINE__);
1115 void MotionMain::draw_vectors(VFrame *frame)
1117 int w = frame->get_w();
1118 int h = frame->get_h();
1119 int global_x1, global_y1;
1120 int global_x2, global_y2;
1121 int block_x, block_y;
1122 int block_w, block_h;
1123 int block_x1, block_y1;
1124 int block_x2, block_y2;
1125 int block_x3, block_y3;
1126 int block_x4, block_y4;
1127 int search_w, search_h;
1128 int search_x1, search_y1;
1129 int search_x2, search_y2;
1135 // Start of vector is center of previous block.
1136 // End of vector is total accumulation.
1137 if(config.tracking_object == MotionScan::TRACK_SINGLE)
1139 global_x1 = (int64_t)(config.block_x *
1142 global_y1 = (int64_t)(config.block_y *
1145 global_x2 = global_x1 + total_dx / OVERSAMPLE;
1146 global_y2 = global_y1 + total_dy / OVERSAMPLE;
1147 //printf("MotionMain::draw_vectors %d %d %d %d %d %d\n", total_dx, total_dy, global_x1, global_y1, global_x2, global_y2);
1150 // Start of vector is center of previous block.
1151 // End of vector is current change.
1152 if(config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK)
1154 global_x1 = (int64_t)(config.block_x *
1157 global_y1 = (int64_t)(config.block_y *
1160 global_x2 = global_x1 + current_dx / OVERSAMPLE;
1161 global_y2 = global_y1 + current_dy / OVERSAMPLE;
1165 global_x1 = (int64_t)(config.block_x *
1168 (total_dx - current_dx) /
1170 global_y1 = (int64_t)(config.block_y *
1173 (total_dy - current_dy) /
1175 global_x2 = (int64_t)(config.block_x *
1180 global_y2 = (int64_t)(config.block_y *
1187 block_x = global_x1;
1188 block_y = global_y1;
1189 block_w = config.global_block_w * w / 100;
1190 block_h = config.global_block_h * h / 100;
1191 block_x1 = block_x - block_w / 2;
1192 block_y1 = block_y - block_h / 2;
1193 block_x2 = block_x + block_w / 2;
1194 block_y2 = block_y + block_h / 2;
1195 search_w = config.global_range_w * w / 100;
1196 search_h = config.global_range_h * h / 100;
1197 search_x1 = block_x1 - search_w / 2;
1198 search_y1 = block_y1 - search_h / 2;
1199 search_x2 = block_x2 + search_w / 2;
1200 search_y2 = block_y2 + search_h / 2;
1202 // printf("MotionMain::draw_vectors %d %d %d %d %d %d %d %d %d %d %d %d\n",
1216 MotionScan::clamp_scan(w,
1229 draw_arrow(frame, global_x1, global_y1, global_x2, global_y2);
1232 draw_line(frame, block_x1, block_y1, block_x2, block_y1);
1233 draw_line(frame, block_x2, block_y1, block_x2, block_y2);
1234 draw_line(frame, block_x2, block_y2, block_x1, block_y2);
1235 draw_line(frame, block_x1, block_y2, block_x1, block_y1);
1239 draw_line(frame, search_x1, search_y1, search_x2, search_y1);
1240 draw_line(frame, search_x2, search_y1, search_x2, search_y2);
1241 draw_line(frame, search_x2, search_y2, search_x1, search_y2);
1242 draw_line(frame, search_x1, search_y2, search_x1, search_y1);
1244 // Block should be endpoint of motion
1247 block_x = global_x2;
1248 block_y = global_y2;
1253 block_x = (int64_t)(config.block_x * w / 100);
1254 block_y = (int64_t)(config.block_y * h / 100);
1257 block_w = config.global_block_w * w / 100;
1258 block_h = config.global_block_h * h / 100;
1261 float angle = total_angle * 2 * M_PI / 360;
1262 double base_angle1 = atan((float)block_h / block_w);
1263 double base_angle2 = atan((float)block_w / block_h);
1264 double target_angle1 = base_angle1 + angle;
1265 double target_angle2 = base_angle2 + angle;
1266 double radius = sqrt(block_w * block_w + block_h * block_h) / 2;
1267 block_x1 = (int)(block_x - cos(target_angle1) * radius);
1268 block_y1 = (int)(block_y - sin(target_angle1) * radius);
1269 block_x2 = (int)(block_x + sin(target_angle2) * radius);
1270 block_y2 = (int)(block_y - cos(target_angle2) * radius);
1271 block_x3 = (int)(block_x - sin(target_angle2) * radius);
1272 block_y3 = (int)(block_y + cos(target_angle2) * radius);
1273 block_x4 = (int)(block_x + cos(target_angle1) * radius);
1274 block_y4 = (int)(block_y + sin(target_angle1) * radius);
1276 draw_line(frame, block_x1, block_y1, block_x2, block_y2);
1277 draw_line(frame, block_x2, block_y2, block_x4, block_y4);
1278 draw_line(frame, block_x4, block_y4, block_x3, block_y3);
1279 draw_line(frame, block_x3, block_y3, block_x1, block_y1);
1285 draw_line(frame, block_x, block_y - 5, block_x, block_y + 6);
1286 draw_line(frame, block_x - 5, block_y, block_x + 6, block_y);
1293 void MotionMain::draw_pixel(VFrame *frame, int x, int y)
1295 if(!(x >= 0 && y >= 0 && x < frame->get_w() && y < frame->get_h())) return;
1297 #define DRAW_PIXEL(x, y, components, do_yuv, max, type) \
1299 type **rows = (type**)frame->get_rows(); \
1300 rows[y][x * components] = max - rows[y][x * components]; \
1303 rows[y][x * components + 1] = max - rows[y][x * components + 1]; \
1304 rows[y][x * components + 2] = max - rows[y][x * components + 2]; \
1308 rows[y][x * components + 1] = (max / 2 + 1) - rows[y][x * components + 1]; \
1309 rows[y][x * components + 2] = (max / 2 + 1) - rows[y][x * components + 2]; \
1311 if(components == 4) \
1312 rows[y][x * components + 3] = max; \
1316 switch(frame->get_color_model())
1319 DRAW_PIXEL(x, y, 3, 0, 0xff, unsigned char);
1322 DRAW_PIXEL(x, y, 4, 0, 0xff, unsigned char);
1325 DRAW_PIXEL(x, y, 3, 0, 1.0, float);
1328 DRAW_PIXEL(x, y, 4, 0, 1.0, float);
1331 DRAW_PIXEL(x, y, 3, 1, 0xff, unsigned char);
1334 DRAW_PIXEL(x, y, 4, 1, 0xff, unsigned char);
1337 DRAW_PIXEL(x, y, 3, 0, 0xffff, uint16_t);
1340 DRAW_PIXEL(x, y, 3, 1, 0xffff, uint16_t);
1342 case BC_RGBA16161616:
1343 DRAW_PIXEL(x, y, 4, 0, 0xffff, uint16_t);
1345 case BC_YUVA16161616:
1346 DRAW_PIXEL(x, y, 4, 1, 0xffff, uint16_t);
1352 void MotionMain::draw_line(VFrame *frame, int x1, int y1, int x2, int y2)
1354 int w = labs(x2 - x1);
1355 int h = labs(y2 - y1);
1356 //printf("MotionMain::draw_line 1 %d %d %d %d\n", x1, y1, x2, y2);
1360 draw_pixel(frame, x1, y1);
1365 // Flip coordinates so x1 < x2
1375 int numerator = y2 - y1;
1376 int denominator = x2 - x1;
1377 for(int i = x1; i < x2; i++)
1379 int y = y1 + (int64_t)(i - x1) * (int64_t)numerator / (int64_t)denominator;
1380 draw_pixel(frame, i, y);
1385 // Flip coordinates so y1 < y2
1395 int numerator = x2 - x1;
1396 int denominator = y2 - y1;
1397 for(int i = y1; i < y2; i++)
1399 int x = x1 + (int64_t)(i - y1) * (int64_t)numerator / (int64_t)denominator;
1400 draw_pixel(frame, x, i);
1403 //printf("MotionMain::draw_line 2\n");
1406 #define ARROW_SIZE 10
1407 void MotionMain::draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2)
1409 double angle = atan((float)(y2 - y1) / (float)(x2 - x1));
1410 double angle1 = angle + (float)145 / 360 * 2 * 3.14159265;
1411 double angle2 = angle - (float)145 / 360 * 2 * 3.14159265;
1418 x3 = x2 - (int)(ARROW_SIZE * cos(angle1));
1419 y3 = y2 - (int)(ARROW_SIZE * sin(angle1));
1420 x4 = x2 - (int)(ARROW_SIZE * cos(angle2));
1421 y4 = y2 - (int)(ARROW_SIZE * sin(angle2));
1425 x3 = x2 + (int)(ARROW_SIZE * cos(angle1));
1426 y3 = y2 + (int)(ARROW_SIZE * sin(angle1));
1427 x4 = x2 + (int)(ARROW_SIZE * cos(angle2));
1428 y4 = y2 + (int)(ARROW_SIZE * sin(angle2));
1432 draw_line(frame, x1, y1, x2, y2);
1433 // draw_line(frame, x1, y1 + 1, x2, y2 + 1);
1436 if(abs(y2 - y1) || abs(x2 - x1)) draw_line(frame, x2, y2, x3, y3);
1437 // draw_line(frame, x2, y2 + 1, x3, y3 + 1);
1439 if(abs(y2 - y1) || abs(x2 - x1)) draw_line(frame, x2, y2, x4, y4);
1440 // draw_line(frame, x2, y2 + 1, x4, y4 + 1);
1458 RotateScanPackage::RotateScanPackage()
1463 RotateScanUnit::RotateScanUnit(RotateScan *server, MotionMain *plugin)
1464 : LoadClient(server)
1466 this->server = server;
1467 this->plugin = plugin;
1472 RotateScanUnit::~RotateScanUnit()
1478 void RotateScanUnit::process_package(LoadPackage *package)
1480 if(server->skip) return;
1481 RotateScanPackage *pkg = (RotateScanPackage*)package;
1483 if((pkg->difference = server->get_cache(pkg->angle)) < 0)
1485 //printf("RotateScanUnit::process_package %d\n", __LINE__);
1486 int color_model = server->previous_frame->get_color_model();
1487 int pixel_size = BC_CModels::calculate_pixelsize(color_model);
1488 int row_bytes = server->previous_frame->get_bytes_per_line();
1491 rotater = new AffineEngine(1, 1);
1492 if(!temp) temp = new VFrame(0,
1494 server->previous_frame->get_w(),
1495 server->previous_frame->get_h(),
1498 //printf("RotateScanUnit::process_package %d\n", __LINE__);
1501 // Rotate original block size
1502 // rotater->set_viewport(server->block_x1,
1503 // server->block_y1,
1504 // server->block_x2 - server->block_x1,
1505 // server->block_y2 - server->block_y1);
1506 rotater->set_in_viewport(server->block_x1,
1508 server->block_x2 - server->block_x1,
1509 server->block_y2 - server->block_y1);
1510 rotater->set_out_viewport(server->block_x1,
1512 server->block_x2 - server->block_x1,
1513 server->block_y2 - server->block_y1);
1514 // rotater->set_pivot(server->block_x, server->block_y);
1515 rotater->set_in_pivot(server->block_x, server->block_y);
1516 rotater->set_out_pivot(server->block_x, server->block_y);
1517 //printf("RotateScanUnit::process_package %d\n", __LINE__);
1518 rotater->rotate(temp,
1519 server->previous_frame,
1522 // Scan reduced block size
1523 //plugin->output_frame->copy_from(server->current_frame);
1524 //plugin->output_frame->copy_from(temp);
1525 // printf("RotateScanUnit::process_package %d %d %d %d %d\n",
1531 // Clamp coordinates
1532 int x1 = server->scan_x;
1533 int y1 = server->scan_y;
1534 int x2 = x1 + server->scan_w;
1535 int y2 = y1 + server->scan_h;
1536 x2 = MIN(temp->get_w(), x2);
1537 y2 = MIN(temp->get_h(), y2);
1538 x2 = MIN(server->current_frame->get_w(), x2);
1539 y2 = MIN(server->current_frame->get_h(), y2);
1543 if(x2 > x1 && y2 > y1)
1545 pkg->difference = MotionScan::abs_diff(
1546 temp->get_rows()[y1] + x1 * pixel_size,
1547 server->current_frame->get_rows()[y1] + x1 * pixel_size,
1552 //printf("RotateScanUnit::process_package %d\n", __LINE__);
1553 server->put_cache(pkg->angle, pkg->difference);
1556 // printf("RotateScanUnit::process_package 10 x=%d y=%d w=%d h=%d block_x=%d block_y=%d angle=%f scan_w=%d scan_h=%d diff=%lld\n",
1557 // server->block_x1,
1558 // server->block_y1,
1559 // server->block_x2 - server->block_x1,
1560 // server->block_y2 - server->block_y1,
1566 // pkg->difference);
1591 RotateScan::RotateScan(MotionMain *plugin,
1596 total_clients, total_packages
1599 this->plugin = plugin;
1600 cache_lock = new Mutex("RotateScan::cache_lock");
1604 RotateScan::~RotateScan()
1609 void RotateScan::init_packages()
1611 for(int i = 0; i < get_total_packages(); i++)
1613 RotateScanPackage *pkg = (RotateScanPackage*)get_package(i);
1615 (scan_angle2 - scan_angle1) /
1621 LoadClient* RotateScan::new_client()
1623 return new RotateScanUnit(this, plugin);
1626 LoadPackage* RotateScan::new_package()
1628 return new RotateScanPackage;
1632 float RotateScan::scan_frame(VFrame *previous_frame,
1633 VFrame *current_frame,
1638 this->block_x = block_x;
1639 this->block_y = block_y;
1641 //printf("RotateScan::scan_frame %d\n", __LINE__);
1642 switch(plugin->config.tracking_type)
1644 case MotionScan::NO_CALCULATE:
1645 result = plugin->config.rotation_center;
1649 case MotionScan::LOAD:
1651 char string[BCTEXTLEN];
1652 sprintf(string, "%s" _LDv(06),
1653 ROTATION_FILE, plugin->get_source_position());
1654 FILE *input = fopen(string, "r");
1657 fscanf(input, "%f", &result);
1663 perror("RotateScan::scan_frame LOAD");
1676 this->previous_frame = previous_frame;
1677 this->current_frame = current_frame;
1678 int w = current_frame->get_w();
1679 int h = current_frame->get_h();
1680 int block_w = w * plugin->config.global_block_w / 100;
1681 int block_h = h * plugin->config.global_block_h / 100;
1683 if(this->block_x - block_w / 2 < 0) block_w = this->block_x * 2;
1684 if(this->block_y - block_h / 2 < 0) block_h = this->block_y * 2;
1685 if(this->block_x + block_w / 2 > w) block_w = (w - this->block_x) * 2;
1686 if(this->block_y + block_h / 2 > h) block_h = (h - this->block_y) * 2;
1688 block_x1 = this->block_x - block_w / 2;
1689 block_x2 = this->block_x + block_w / 2;
1690 block_y1 = this->block_y - block_h / 2;
1691 block_y2 = this->block_y + block_h / 2;
1693 // Calculate the maximum area available to scan after rotation.
1694 // Must be calculated from the starting range because of cache.
1695 // Get coords of rectangle after rotation.
1696 double center_x = this->block_x;
1697 double center_y = this->block_y;
1698 double max_angle = plugin->config.rotation_range;
1699 double base_angle1 = atan((float)block_h / block_w);
1700 double base_angle2 = atan((float)block_w / block_h);
1701 double target_angle1 = base_angle1 + max_angle * 2 * M_PI / 360;
1702 double target_angle2 = base_angle2 + max_angle * 2 * M_PI / 360;
1703 double radius = sqrt(block_w * block_w + block_h * block_h) / 2;
1704 double x1 = center_x - cos(target_angle1) * radius;
1705 double y1 = center_y - sin(target_angle1) * radius;
1706 double x2 = center_x + sin(target_angle2) * radius;
1707 double y2 = center_y - cos(target_angle2) * radius;
1708 double x3 = center_x - sin(target_angle2) * radius;
1709 double y3 = center_y + cos(target_angle2) * radius;
1711 // Track top edge to find greatest area.
1712 double max_area1 = 0;
1713 //double max_x1 = 0;
1715 for(double x = x1; x < x2; x++)
1717 double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
1718 if(x >= center_x && x < block_x2 && y >= block_y1 && y < center_y)
1720 double area = fabs(x - center_x) * fabs(y - center_y);
1721 if(area > max_area1)
1730 // Track left edge to find greatest area.
1731 double max_area2 = 0;
1733 //double max_y2 = 0;
1734 for(double y = y1; y < y3; y++)
1736 double x = x1 + (x3 - x1) * (y - y1) / (y3 - y1);
1737 if(x >= block_x1 && x < center_x && y >= block_y1 && y < center_y)
1739 double area = fabs(x - center_x) * fabs(y - center_y);
1740 if(area > max_area2)
1749 double max_x, max_y;
1753 // Get reduced scan coords
1754 scan_w = (int)(fabs(max_x - center_x) * 2);
1755 scan_h = (int)(fabs(max_y - center_y) * 2);
1756 scan_x = (int)(center_x - scan_w / 2);
1757 scan_y = (int)(center_y - scan_h / 2);
1758 // printf("RotateScan::scan_frame center=%d,%d scan=%d,%d %dx%d\n",
1759 // this->block_x, this->block_y, scan_x, scan_y, scan_w, scan_h);
1760 // printf(" angle_range=%f block= %d,%d,%d,%d\n", max_angle, block_x1, block_y1, block_x2, block_y2);
1762 // Determine min angle from size of block
1763 double angle1 = atan((double)block_h / block_w);
1764 double angle2 = atan((double)(block_h - 1) / (block_w + 1));
1765 double min_angle = fabs(angle2 - angle1) / OVERSAMPLE;
1766 min_angle = MAX(min_angle, MIN_ANGLE);
1768 //printf("RotateScan::scan_frame %d min_angle=%f\n", __LINE__, min_angle * 360 / 2 / M_PI);
1770 cache.remove_all_objects();
1775 if(previous_frame->data_matches(current_frame))
1777 //printf("RotateScan::scan_frame: frames match. Skipping.\n");
1778 result = plugin->config.rotation_center;
1785 // Initial search range
1786 float angle_range = max_angle;
1787 result = plugin->config.rotation_center;
1788 total_steps = plugin->config.rotate_positions;
1791 while(angle_range >= min_angle * total_steps)
1793 scan_angle1 = result - angle_range;
1794 scan_angle2 = result + angle_range;
1797 set_package_count(total_steps);
1798 //set_package_count(1);
1801 int64_t min_difference = -1;
1802 for(int i = 0; i < get_total_packages(); i++)
1804 RotateScanPackage *pkg = (RotateScanPackage*)get_package(i);
1805 if(pkg->difference < min_difference || min_difference == -1)
1807 min_difference = pkg->difference;
1808 result = pkg->angle;
1819 //printf("RotateScan::scan_frame %d\n", __LINE__);
1821 if(!skip && plugin->config.tracking_type == MotionScan::SAVE)
1823 char string[BCTEXTLEN];
1824 sprintf(string, "%s" _LDv(06),
1825 ROTATION_FILE, plugin->get_source_position());
1826 FILE *output = fopen(string, "w");
1829 fprintf(output, "%f\n", result);
1834 perror("RotateScan::scan_frame SAVE");
1838 //printf("RotateScan::scan_frame %d angle=%f\n", __LINE__, result);
1845 int64_t RotateScan::get_cache(float angle)
1847 int64_t result = -1;
1848 cache_lock->lock("RotateScan::get_cache");
1849 for(int i = 0; i < cache.total; i++)
1851 RotateScanCache *ptr = cache.values[i];
1852 if(fabs(ptr->angle - angle) <= MIN_ANGLE)
1854 result = ptr->difference;
1858 cache_lock->unlock();
1862 void RotateScan::put_cache(float angle, int64_t difference)
1864 RotateScanCache *ptr = new RotateScanCache(angle, difference);
1865 cache_lock->lock("RotateScan::put_cache");
1867 cache_lock->unlock();
1878 RotateScanCache::RotateScanCache(float angle, int64_t difference)
1880 this->angle = angle;
1881 this->difference = difference;