X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fmaskengine.C;h=ed7cbaaebdbddfafcf72709f205eb891f5542e42;hb=8aa6d71ebd2c65785a8b553fc6fc38ac19041ce0;hp=9f2861feae44c6dd580ecfb04dda7a9c5384e217;hpb=dab459d8fcf93c377836bc30a1c4bc5505b79323;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/maskengine.C b/cinelerra-5.1/cinelerra/maskengine.C index 9f2861fe..ed7cbaae 100644 --- a/cinelerra-5.1/cinelerra/maskengine.C +++ b/cinelerra-5.1/cinelerra/maskengine.C @@ -2,21 +2,21 @@ /* * CINELERRA * Copyright (C) 2008 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 * GNU General Public License for more details. - * + * * 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 "bcsignals.h" @@ -63,78 +63,7 @@ MaskUnit::~MaskUnit() #define OVERSAMPLE 8 -#if 1 -// Bresenham's void MaskUnit::draw_line_clamped(VFrame *frame, - int x1,int y1, int x2,int y2, unsigned char k) -{ - int w = frame->get_w(), h = frame->get_h(); - unsigned char **rows = (unsigned char**)frame->get_rows(); - int dx = x2-x1, dy = y2-y1; -//printf("MaskUnit::draw_line_clamped(%d,%d -> %d,%d, 0x%02x\n", x1,y1, x2,y2, k); - - int ax = 2*abs(dx), ay = 2*abs(dy); - - if( ax > ay ) { /* x dominant */ - if( dx == 0 ) return; - if( x1 > x2 ) { - int xx = x2; x2 = x1; x1 = xx; - int yy = y2; y2 = y1; y1 = yy; - } - if( x1 >= w || x2 < 0 ) return; - if( dx < 0 ) { dx = -dx; dy = -dy; } - int x = x1, y = y1, d = dx; - int sy = dy < 0 ? -1 : 1; - if( x1 < 0 ) { - double py = -(double)dy/dx * x1 + y1 + 0.5; - x = 0; y = py; - d = (py - y) * ay; - } - - for( int y0=-1;;) { - if( x >= w ) return; - if( y != y0 && y >= 0 && y < h ) { - y0 = y; - unsigned char *bp = rows[y] + x; - *bp = *bp == k ? 0 : k; - } - if( x == x2 ) return; - if( d < 0 ) { d += ax; y += sy; } - d -= ay; ++x; - } - } - else { /* y dominant */ - if( dy == 0 ) return; - if( y1 > y2 ) { - int xx = x2; x2 = x1; x1 = xx; - int yy = y2; y2 = y1; y1 = yy; - } - if( y1 >= h || y2 < 0 ) return; - if( dy < 0 ) { dx = -dx; dy = -dy; } - int x = x1, y = y1, d = dy; - int sx = dx < 0 ? -1 : 1; - if( y1 < 0 ) { - double px = -(double)dx/dy * y1 + x1 + 0.5; - x = px; y = 0; - d = (px - x) * ax; - } - - for(;;) { - if( y >= h ) return; - if( x >= 0 && x < w ) { - unsigned char *bp = rows[y] + x; - *bp = *bp == k ? 0 : k; - } - if( y == y2 ) return; - if( d < 0 ) { d += ay; x += sx; } - d -= ax; ++y; - } - } -} - -#else - -void MaskUnit::draw_line_clamped(VFrame *frame, int x1, int y1, int x2, int y2, unsigned char k) { int draw_x1, draw_y1; @@ -171,12 +100,10 @@ void MaskUnit::draw_line_clamped(VFrame *frame, } } -#endif - -void MaskUnit::blur_strip(double *val_p, - double *val_m, - double *dst, - double *src, +void MaskUnit::blur_strip(double *val_p, + double *val_m, + double *dst, + double *src, int size, int max) { @@ -218,11 +145,11 @@ void MaskUnit::blur_strip(double *val_p, } void MaskUnit::do_feather(VFrame *output, - VFrame *input, - double feather, - int start_y, - int end_y, - int start_x, + VFrame *input, + double feather, + int start_y, + int end_y, + int start_x, int end_x) { //printf("MaskUnit::do_feather %f\n", feather); @@ -249,18 +176,18 @@ void MaskUnit::do_feather(VFrame *output, (2 * constants[6] + constants[4]) * cos(constants[2])); n_p[2] = 2 * exp(constants[0] + constants[1]) * - ((constants[4] + constants[6]) * cos(constants[3]) * - cos(constants[2]) - constants[5] * + ((constants[4] + constants[6]) * cos(constants[3]) * + cos(constants[2]) - constants[5] * cos(constants[3]) * sin(constants[2]) - constants[7] * cos(constants[2]) * sin(constants[3])) + constants[6] * exp(2 * constants[0]) + constants[4] * exp(2 * constants[1]); n_p[3] = exp(constants[1] + 2 * constants[0]) * - (constants[7] * sin(constants[3]) - + (constants[7] * sin(constants[3]) - constants[6] * cos(constants[3])) + exp(constants[0] + 2 * constants[1]) * - (constants[5] * sin(constants[2]) - constants[4] * + (constants[5] * sin(constants[2]) - constants[4] * cos(constants[2])); n_p[4] = 0.0; @@ -268,7 +195,7 @@ void MaskUnit::do_feather(VFrame *output, d_p[1] = -2 * exp(constants[1]) * cos(constants[3]) - 2 * exp(constants[0]) * cos(constants[2]); - d_p[2] = 4 * cos(constants[3]) * cos(constants[2]) * + d_p[2] = 4 * cos(constants[3]) * cos(constants[2]) * exp(constants[0] + constants[1]) + exp(2 * constants[1]) + exp (2 * constants[0]); @@ -404,11 +331,11 @@ void MaskUnit::do_feather(VFrame *output, case BC_A8: DO_FEATHER(unsigned char, 0xff); break; - + case BC_A16: DO_FEATHER(uint16_t, 0xffff); break; - + case BC_A_FLOAT: DO_FEATHER(float, 1); break; @@ -423,11 +350,11 @@ void MaskUnit::process_package(LoadPackage *package) { MaskPackage *ptr = (MaskPackage*)package; - if(engine->recalculate && + if(engine->recalculate && engine->step == DO_MASK) { VFrame *mask; - if(engine->feather > 0) + if(engine->feather > 0) mask = engine->temp_mask; else mask = engine->mask; @@ -441,24 +368,16 @@ SET_TRACE //printf("MaskUnit::process_package 1\n"); SET_TRACE - if(temp && + if(temp && (temp->get_w() != oversampled_package_w || - temp->get_h() != oversampled_package_h)) - { - delete temp; - temp = 0; + temp->get_h() != oversampled_package_h)) { + delete temp; temp = 0; } //printf("MaskUnit::process_package 1\n"); SET_TRACE - if(!temp) - { - temp = new VFrame(0, - -1, - oversampled_package_w, - oversampled_package_h, - BC_A8, - -1); + if(!temp) { + temp = new VFrame(oversampled_package_w, oversampled_package_h, BC_A8, 0); } SET_TRACE @@ -479,8 +398,8 @@ SET_TRACE for(int i = 0; i < points->total; i++) { MaskPoint *point1 = points->values[i]; - MaskPoint *point2 = (i >= points->total - 1) ? - points->values[0] : + MaskPoint *point2 = (i >= points->total - 1) ? + points->values[0] : points->values[i + 1]; float x, y; @@ -510,11 +429,11 @@ SET_TRACE x = ( invtpow3 * x0 + 3 * t * invtpow2 * x1 - + 3 * tpow2 * invt * x2 + + 3 * tpow2 * invt * x2 + tpow3 * x3); - y = ( invtpow3 * y0 + y = ( invtpow3 * y0 + 3 * t * invtpow2 * y1 - + 3 * tpow2 * invt * y2 + + 3 * tpow2 * invt * y2 + tpow3 * y3); y -= ptr->start_y; @@ -646,10 +565,10 @@ SET_TRACE if(engine->recalculate) { // Feather polygon - if(engine->feather > 0) do_feather(engine->mask, - engine->temp_mask, - engine->feather, - ptr->start_y, + if(engine->feather > 0) do_feather(engine->mask, + engine->temp_mask, + engine->feather, + ptr->start_y, ptr->end_y, 0, 0); @@ -662,10 +581,10 @@ SET_TRACE if(engine->recalculate) { // Feather polygon - if(engine->feather > 0) do_feather(engine->mask, - engine->temp_mask, - engine->feather, - 0, + if(engine->feather > 0) do_feather(engine->mask, + engine->temp_mask, + engine->feather, + 0, 0, ptr->start_x, ptr->end_x); @@ -831,7 +750,7 @@ MaskEngine::MaskEngine(int cpus) MaskEngine::~MaskEngine() { - if(mask) + if(mask) { delete mask; delete temp_mask; @@ -845,23 +764,23 @@ MaskEngine::~MaskEngine() point_sets.remove_all_objects(); } -int MaskEngine::points_equivalent(ArrayList *new_points, +int MaskEngine::points_equivalent(ArrayList *new_points, ArrayList *points) { //printf("MaskEngine::points_equivalent %d %d\n", new_points->total, points->total); if(new_points->total != points->total) return 0; - + for(int i = 0; i < new_points->total; i++) { if(!(*new_points->values[i] == *points->values[i])) return 0; } - + return 1; } -void MaskEngine::do_mask(VFrame *output, +void MaskEngine::do_mask(VFrame *output, int64_t start_position_project, - MaskAutos *keyframe_set, + MaskAutos *keyframe_set, MaskAuto *keyframe, MaskAuto *default_auto) { @@ -893,7 +812,7 @@ void MaskEngine::do_mask(VFrame *output, // Determine if recalculation is needed SET_TRACE - if(mask && + if(mask && (mask->get_w() != output->get_w() || mask->get_h() != output->get_h() || mask->get_color_model() != new_color_model)) @@ -906,22 +825,22 @@ SET_TRACE if(!recalculate) { - if(point_sets.total != keyframe_set->total_submasks(start_position_project, + if(point_sets.total != keyframe_set->total_submasks(start_position_project, PLAY_FORWARD)) recalculate = 1; } if(!recalculate) { - for(int i = 0; - i < keyframe_set->total_submasks(start_position_project, - PLAY_FORWARD) && !recalculate; + for(int i = 0; + i < keyframe_set->total_submasks(start_position_project, + PLAY_FORWARD) && !recalculate; i++) { ArrayList *new_points = new ArrayList; - keyframe_set->get_points(new_points, - i, - start_position_project, + keyframe_set->get_points(new_points, + i, + start_position_project, PLAY_FORWARD); if(!points_equivalent(new_points, point_sets.values[i])) recalculate = 1; new_points->remove_all_objects(); @@ -929,9 +848,9 @@ SET_TRACE } } - int new_value = keyframe_set->get_value(start_position_project, + int new_value = keyframe_set->get_value(start_position_project, PLAY_FORWARD); - float new_feather = keyframe_set->get_feather(start_position_project, + float new_feather = keyframe_set->get_feather(start_position_project, PLAY_FORWARD); if(recalculate || @@ -939,20 +858,12 @@ SET_TRACE !EQUIV(new_value, value)) { recalculate = 1; - if(!mask) + if(!mask) { - mask = new VFrame(0, - -1, - output->get_w(), - output->get_h(), - new_color_model, - -1); - temp_mask = new VFrame(0, - -1, - output->get_w(), - output->get_h(), - new_color_model, - -1); + mask = new VFrame(output->get_w(), output->get_h(), + new_color_model, 0); + temp_mask = new VFrame(output->get_w(), output->get_h(), + new_color_model, 0); } if(new_feather > 0) temp_mask->clear_frame(); @@ -966,15 +877,15 @@ SET_TRACE } point_sets.remove_all_objects(); - for(int i = 0; - i < keyframe_set->total_submasks(start_position_project, - PLAY_FORWARD); + for(int i = 0; + i < keyframe_set->total_submasks(start_position_project, + PLAY_FORWARD); i++) { ArrayList *new_points = new ArrayList; - keyframe_set->get_points(new_points, - i, - start_position_project, + keyframe_set->get_points(new_points, + i, + start_position_project, PLAY_FORWARD); point_sets.append(new_points); } @@ -1007,19 +918,15 @@ void MaskEngine::init_packages() { SET_TRACE //printf("MaskEngine::init_packages 1\n"); - int division = (int)((float)output->get_h() / (get_total_packages() / 2) + 0.5); - if(division < 1) division = 1; - + int x0 = 0, y0 = 0, i = 0, n = get_total_packages(); + int out_w = output->get_w(), out_h = output->get_h(); SET_TRACE - for(int i = 0; i < get_total_packages(); i++) - { - MaskPackage *ptr = (MaskPackage*)get_package(i); - - ptr->start_y = output->get_h() * i / get_total_packages(); - ptr->end_y = output->get_h() * (i + 1) / get_total_packages(); - - ptr->start_x = output->get_w() * i / get_total_packages(); - ptr->end_x = output->get_w() * (i + 1) / get_total_packages(); + while( i < n ) { + MaskPackage *ptr = (MaskPackage*)get_package(i++); + int x1 = (out_w * i) / n, y1 = (out_h * i) / n; + ptr->start_x = x0; ptr->end_x = x1; + ptr->start_y = y0; ptr->end_y = y1; + x0 = x1; y0 = y1; } SET_TRACE //printf("MaskEngine::init_packages 2\n");