X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Fhistogram_bezier%2Fbistogramconfig.C;h=368cce72260ce1a8c787849999387aab06413fcb;hb=04031cc2a664d2a6d9d2a37954c55cc68742d78c;hp=d84550f80fe38a1427392ecc28991c1e3d35fb6f;hpb=30bdb85eb33a8ee7ba675038a86c6be59c43d7bd;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/plugins/histogram_bezier/bistogramconfig.C b/cinelerra-5.1/plugins/histogram_bezier/bistogramconfig.C index d84550f8..368cce72 100644 --- a/cinelerra-5.1/plugins/histogram_bezier/bistogramconfig.C +++ b/cinelerra-5.1/plugins/histogram_bezier/bistogramconfig.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 "clip.h" @@ -26,11 +26,14 @@ #include - - HistogramPoint::HistogramPoint() : ListItem() { + x = 0; y = 0; + xoffset_left = -0.05; + xoffset_right = 0.05; + gradient = 1.0; + } HistogramPoint::~HistogramPoint() @@ -39,28 +42,43 @@ HistogramPoint::~HistogramPoint() int HistogramPoint::equivalent(HistogramPoint *src) { - return EQUIV(x, src->x) && EQUIV(y, src->y) && EQUIV(gradient, src->gradient); + return EQUIV(x, src->x) && EQUIV(y, src->y) && + EQUIV(xoffset_left, src->xoffset_left) && + EQUIV(xoffset_right, src->xoffset_right) && + EQUIV(gradient, src->gradient); } +void HistogramPoint::copy_from(HistogramPoint *that) +{ + x = that->x; y = that->y; + xoffset_left = that->xoffset_left; + xoffset_right = that->xoffset_right; + gradient = that->gradient; +} HistogramPoints::HistogramPoints() : List() { + clear(); +} + +HistogramPoints::~HistogramPoints() +{ +} + +void HistogramPoints::clear() +{ + while( last ) delete last; insert(0.0,0.0); first->gradient = 1.0; first->xoffset_left = 0.0; first->xoffset_right = 0.05; insert(1.0,1.0); - last->gradient = 1.0; + last->gradient = 1.0; last->xoffset_left = -0.05; last->xoffset_right = 0.0; - -} - -HistogramPoints::~HistogramPoints() -{ } HistogramPoint* HistogramPoints::insert(float x, float y) @@ -68,40 +86,27 @@ HistogramPoint* HistogramPoints::insert(float x, float y) HistogramPoint *current = first; // Get existing point after new point - while(current) - { - if(current->x > x) - break; - else - current = NEXT; + while( current ) { + if( current->x > x ) break; + current = NEXT; } // Insert new point before current point HistogramPoint *new_point = new HistogramPoint; - if(current) - { + if( current ) insert_before(current, new_point); - } else -// Append new point to list - { append(new_point); - } new_point->x = x; new_point->y = y; - new_point->xoffset_left = -0.05; - new_point->xoffset_right = 0.05; - - return new_point; } void HistogramPoints::boundaries() { HistogramPoint *current = first; - while(current) - { + while( current ) { CLAMP(current->x, 0.0, 1.0); CLAMP(current->y, 0.0, 1.0); current = NEXT; @@ -112,14 +117,13 @@ int HistogramPoints::equivalent(HistogramPoints *src) { HistogramPoint *current_this = first; HistogramPoint *current_src = src->first; - while(current_this && current_src) - { + while( current_this && current_src ) { if(!current_this->equivalent(current_src)) return 0; current_this = current_this->next; current_src = current_src->next; } - return !current_this ^ !current_src ? 0 : 1; + return current_this || current_src ? 0 : 1; } void HistogramPoints::copy_from(HistogramPoints *src) @@ -127,48 +131,62 @@ void HistogramPoints::copy_from(HistogramPoints *src) while(last) delete last; HistogramPoint *current = src->first; - while(current) - { + while( current ) { HistogramPoint *new_point = new HistogramPoint; - new_point->x = current->x; - new_point->y = current->y; + new_point->copy_from(current); append(new_point); current = NEXT; } } -void HistogramPoints::interpolate(HistogramPoints *prev, - HistogramPoints *next, - double prev_scale, - double next_scale) +int HistogramPoints::cmprx(HistogramPoint *ap, HistogramPoint *bp) +{ + return ap->x < bp->x ? -1 : ap->x == bp->x ? 0 : 1; +} + +void HistogramPoints::interpolate(HistogramPoints *prev, HistogramPoints *next, + double prev_scale, double next_scale) { - HistogramPoint *current = first; HistogramPoint *current_prev = prev->first; HistogramPoint *current_next = next->first; - while(current && current_prev && current_next) - { - current->x = current_prev->x * prev_scale + - current_next->x * next_scale; - current->y = current_prev->y * prev_scale + - current_next->y * next_scale; - current = NEXT; - current_prev = current_prev->next; - current_next = current_next->next; + HistogramPoint *current = first; + while( current_prev || current_next ) { + if( !current ) { + current = new HistogramPoint; + append(current); + } + if( !current_next ) { + current->copy_from(current_prev); + current_prev = current_prev->next; + } + else if( !current_prev ) { + current->copy_from(current_next); + current_next = current_next->next; + } + else { + current->x = current_prev->x * prev_scale + + current_next->x * next_scale; + current->y = current_prev->y * prev_scale + + current_next->y * next_scale; + current->gradient = current_prev->gradient * prev_scale + + current_next->gradient * next_scale; + current->xoffset_left = current_prev->xoffset_left * prev_scale + + current_next->xoffset_left * next_scale; + current->xoffset_right = current_prev->xoffset_right * prev_scale + + current_next->xoffset_right * next_scale; + current_prev = current_prev->next; + current_next = current_next->next; + } + current = current->next; } -} - - - - - - - - - - - + while( current ) { + HistogramPoint *next_point = current->next; + delete current; current = next_point; + } + sort(cmprx); +} HistogramConfig::HistogramConfig() @@ -179,18 +197,14 @@ HistogramConfig::HistogramConfig() void HistogramConfig::reset(int do_mode) { reset_points(); - - - for(int i = 0; i < HISTOGRAM_MODES; i++) - { + for( int i = 0; i < HISTOGRAM_MODES; i++ ) { output_min[i] = 0.0; output_max[i] = 1.0; } - if(do_mode) - { + if( do_mode ) { automatic = 0; - threshold = 0.1; + threshold = 1.0; split = 0; smoothMode = 0; } @@ -198,21 +212,14 @@ void HistogramConfig::reset(int do_mode) void HistogramConfig::reset_points() { - for(int i = 0; i < HISTOGRAM_MODES; i++) - { - while(points[i].last) delete points[i].last; - points[i].insert(0.0,0.0); - points[i].last->gradient = 1.0; - points[i].insert(1.0,1.0); - points[i].last->gradient = 1.0; - } + for( int i=0; ipoints[j]; HistogramPoint *current = points->first; - while(current) - { - printf("%f,%f ", current->x, current->y); + while( current ) { + printf("%f,%f (@%f l%f,r%f)\n", current->x, current->y, + current->gradient, current->xoffset_left, current->xoffset_right); fflush(stdout); current = NEXT; } - printf("\n"); } } - -