X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Finterpolatevideo%2Fopticflow.C;h=83414c07115f62db3c316d28634ed152f2de8444;hp=8335cc2e79855c89fb855b79e5b280daa8758d86;hb=9d832a1fff11b11aaa1108c460690ed05e2bdc05;hpb=5a1b2bb96f2bd6b7ef4f8031763683726c02219d diff --git a/cinelerra-5.1/plugins/interpolatevideo/opticflow.C b/cinelerra-5.1/plugins/interpolatevideo/opticflow.C index 8335cc2e..83414c07 100644 --- a/cinelerra-5.1/plugins/interpolatevideo/opticflow.C +++ b/cinelerra-5.1/plugins/interpolatevideo/opticflow.C @@ -1,12 +1,12 @@ /* * CINELERRA * Copyright (C) 1997-2011 Adam Williams - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -15,16 +15,17 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * */ - - + + #include "clip.h" #include "interpolatevideo.h" -#include "motionscan.h" +#include "motioncache-hv.h" +#include "motionscan-hv.h" #include "opticflow.h" #include @@ -87,14 +88,16 @@ void OpticFlowUnit::process_package(LoadPackage *package) { OpticFlowPackage *pkg = (OpticFlowPackage*)package; InterpolateVideo *plugin = server->plugin; - int w = plugin->frames[0]->get_w(); - int h = plugin->frames[0]->get_h(); + //int w = plugin->frames[0]->get_w(); + //int h = plugin->frames[0]->get_h(); struct timeval start_time; gettimeofday(&start_time, 0); - if(!motion) motion = new MotionScan(1, 1); + if(!motion) motion = new MotionHVScan(1, 1); motion->set_test_match(0); + motion->set_cache(server->downsample_cache); + // printf("OpticFlowUnit::process_package %d %d %d\n", // __LINE__, // pkg->macroblock0, @@ -103,6 +106,7 @@ void OpticFlowUnit::process_package(LoadPackage *package) for(int i = pkg->macroblock0; i < pkg->macroblock1; i++) { OpticFlowMacroblock *mb = plugin->macroblocks.get(i); +//printf("OpticFlowUnit::process_package %d i=%d x=%d y=%d\n", __LINE__, i, mb->x, mb->y); motion->scan_frame(plugin->frames[0], // Frame after motion plugin->frames[1], @@ -112,10 +116,10 @@ void OpticFlowUnit::process_package(LoadPackage *package) plugin->config.macroblock_size, mb->x, mb->y, - MotionScan::TRACK_PREVIOUS, - MotionScan::CALCULATE, + MotionHVScan::TRACK_PREVIOUS, + MotionHVScan::CALCULATE, // Get it to do the subpixel step - MotionScan::STABILIZE, + MotionHVScan::STABILIZE, 0, 0, 0, @@ -127,6 +131,7 @@ void OpticFlowUnit::process_package(LoadPackage *package) 0, 0, 0); +//printf("OpticFlowUnit::process_package 2\n", __LINE__); mb->dx = motion->dx_result; @@ -149,29 +154,47 @@ void OpticFlowUnit::process_package(LoadPackage *package) OpticFlow::OpticFlow(InterpolateVideo *plugin, - int total_clients, + int total_clients, int total_packages) -// : LoadServer(1, +// : LoadServer(1, // total_packages) - : LoadServer(total_clients, + : LoadServer(total_clients, total_packages) { this->plugin = plugin; + downsample_cache = 0; } OpticFlow::~OpticFlow() { + if(downsample_cache) + { +//printf("OpticFlow::~OpticFlow %d %p\n", __LINE__, downsample_cache); + delete downsample_cache; + } } void OpticFlow::init_packages() { -//printf("OpticFlow::init_packages %d %d\n", __LINE__, get_total_packages()); + if(!downsample_cache) + { + downsample_cache = new MotionHVCache(); + } + + downsample_cache->clear(); + for(int i = 0; i < get_total_packages(); i++) { OpticFlowPackage *pkg = (OpticFlowPackage*)get_package(i); pkg->macroblock0 = plugin->total_macroblocks * i / get_total_packages(); pkg->macroblock1 = plugin->total_macroblocks * (i + 1) / get_total_packages(); +// printf("OpticFlow::init_packages %d %d %d %d %d\n", +// __LINE__, +// plugin->total_macroblocks, +// get_total_packages(), +// pkg->macroblock0, +// pkg->macroblock1); } } @@ -286,10 +309,10 @@ void WarpUnit::process_package(LoadPackage *package) int x_macroblock2 = x_macroblock + 1; int y_macroblock2 = y_macroblock + 1; - + x_macroblock2 = MIN(x_macroblock2, plugin->x_macroblocks - 1); y_macroblock2 = MIN(y_macroblock2, plugin->y_macroblocks - 1); - + float x_fraction = (float)(j - x_macroblock * macroblock_size) / macroblock_size; float y_fraction = (float)(i - y_macroblock * macroblock_size) / macroblock_size; @@ -383,9 +406,9 @@ void WarpUnit::process_package(LoadPackage *package) Warp::Warp(InterpolateVideo *plugin, - int total_clients, + int total_clients, int total_packages) - : LoadServer(total_clients, + : LoadServer(total_clients, total_packages) { this->plugin = plugin; @@ -467,9 +490,9 @@ void BlendMacroblockUnit::process_package(LoadPackage *package) BlendMacroblock::BlendMacroblock(InterpolateVideo *plugin, - int total_clients, + int total_clients, int total_packages) - : LoadServer(total_clients, + : LoadServer(total_clients, total_packages) { this->plugin = plugin;