X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Fsketcher%2Fsketcher.C;h=2b392327176b85cdb35e3a22cd8283dd6ff85d3c;hb=HEAD;hp=70da9eb25ebf87aafddb0b382cc7ab6871098621;hpb=4645b3c0b7256990cf4f1c808ff37217f0db3fc9;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/plugins/sketcher/sketcher.C b/cinelerra-5.1/plugins/sketcher/sketcher.C index 70da9eb2..151b42e1 100644 --- a/cinelerra-5.1/plugins/sketcher/sketcher.C +++ b/cinelerra-5.1/plugins/sketcher/sketcher.C @@ -27,13 +27,16 @@ #include "bccmodels.h" #include "bccolors.h" #include "clip.h" +#include "edl.h" #include "edlsession.h" #include "filexml.h" +#include "keyframes.h" #include "overlayframe.h" #include "pluginserver.h" #include "preferences.h" #include "sketcher.h" #include "sketcherwindow.h" +#include "transportque.inc" #include "language.h" #include "vframe.h" @@ -162,20 +165,24 @@ void SketcherCurve::read_data(FileXML &input) bclamp(pen, 0, PEN_SZ-1); } -int Sketcher::new_curve(int pen, int width, int color) +int SketcherConfig::new_curve(int pen, int width, int color) { - SketcherCurves &curves = config.curves; int k = curves.size(), id = 1; for( int i=k; --i>=0; ) { - int n = config.curves[i]->id; + int n = curves[i]->id; if( n >= id ) id = n + 1; } SketcherCurve *cv = new SketcherCurve(id, pen, width, color); curves.append(cv); - config.cv_selected = k; return k; } +int Sketcher::new_curve(int pen, int width, int color) +{ + cv_selected = config.new_curve(pen, width, color); + return cv_selected; +} + int Sketcher::new_curve() { return new_curve(PEN_XLANT, 1, CV_COLOR); @@ -197,11 +204,11 @@ int Sketcher::new_point(SketcherCurve *cv, int arc, coord x, coord y, int idx) int Sketcher::new_point(int idx, int arc) { - int ci = config.cv_selected; + int ci = cv_selected; if( ci < 0 || ci >= config.curves.size() ) return -1; SketcherCurve *cv = config.curves[ci]; - EDLSession *session = get_edlsession(); + EDLSession *session = get_edl()->session; coord x = !session ? 0.f : session->output_w / 2.f; coord y = !session ? 0.f : session->output_h / 2.f; return new_point(cv, arc, x, y, idx); @@ -240,9 +247,7 @@ REGISTER_PLUGIN(Sketcher) SketcherConfig::SketcherConfig() { - drag = 1; - cv_selected = 0; - pt_selected = 0; + aliasing = 0; } SketcherConfig::~SketcherConfig() { @@ -250,9 +255,7 @@ SketcherConfig::~SketcherConfig() int SketcherConfig::equivalent(SketcherConfig &that) { - if( this->drag != that.drag ) return 0; - if( this->cv_selected != that.cv_selected ) return 0; - if( this->pt_selected != that.pt_selected ) return 0; + if( this->aliasing != that.aliasing ) return 0; if( this->curves.size() != that.curves.size() ) return 0; for( int i=0, n=curves.size(); iequivalent(*that.curves[i]) ) return 0; @@ -262,9 +265,7 @@ int SketcherConfig::equivalent(SketcherConfig &that) void SketcherConfig::copy_from(SketcherConfig &that) { - this->drag = that.drag; - this->cv_selected = that.cv_selected; - this->pt_selected = that.pt_selected; + this->aliasing = that.aliasing; int m = curves.size(), n = that.curves.size(); while( m > n ) curves.remove_object_number(--m); while( m < n ) { curves.append(new SketcherCurve()); ++m; } @@ -274,9 +275,7 @@ void SketcherConfig::copy_from(SketcherConfig &that) void SketcherConfig::interpolate(SketcherConfig &prev, SketcherConfig &next, long prev_frame, long next_frame, long current_frame) { - this->cv_selected = prev.cv_selected; - this->pt_selected = prev.pt_selected; - this->drag = prev.drag; + this->aliasing = prev.aliasing; double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame); double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame); @@ -335,6 +334,10 @@ Sketcher::Sketcher(PluginServer *server) img = 0; out = 0; overlay_frame = 0; + + drag = 1; + cv_selected = 0; + pt_selected = 0; } Sketcher::~Sketcher() @@ -351,20 +354,36 @@ int Sketcher::is_synthesis() { return 1; } NEW_WINDOW_MACRO(Sketcher, SketcherWindow); LOAD_CONFIGURATION_MACRO(Sketcher, SketcherConfig) -void Sketcher::save_data(KeyFrame *keyframe) +void Sketcher::render_gui(void *data) +{ + Sketcher *sketcher = (Sketcher *)data; + sketcher->drag = drag; + sketcher->cv_selected = cv_selected; + sketcher->pt_selected = pt_selected; +} + +int Sketcher::is_dragging() +{ + drag = 0; + cv_selected = -1; + pt_selected = -1; + send_render_gui(this); + return drag; +} + + +void SketcherConfig::save_data(KeyFrame *keyframe) { FileXML output; // cause data to be stored directly in text output.set_shared_output(keyframe->xbuf); output.tag.set_title("SKETCHER"); - output.tag.set_property("DRAG", config.drag); - output.tag.set_property("CV_SELECTED", config.cv_selected); - output.tag.set_property("PT_SELECTED", config.pt_selected); + output.tag.set_property("ALIASING", aliasing); output.append_tag(); output.append_newline(); - for( int i=0,n=config.curves.size(); isave_data(output); + for( int i=0,n=curves.size(); isave_data(output); } output.tag.set_title("/SKETCHER"); output.append_tag(); @@ -372,24 +391,27 @@ void Sketcher::save_data(KeyFrame *keyframe) output.terminate_string(); } -void Sketcher::read_data(KeyFrame *keyframe) +void Sketcher::save_data(KeyFrame *keyframe) +{ + config.save_data(keyframe); +} + +void SketcherConfig::read_data(KeyFrame *keyframe) { FileXML input; input.set_shared_input(keyframe->xbuf); - config.curves.remove_all_objects(); + curves.remove_all_objects(); int result = 0; SketcherCurve *cv = 0; while( !(result=input.read_tag()) ) { if( input.tag.title_is("SKETCHER") ) { - config.drag = input.tag.get_property("DRAG", config.drag); - config.cv_selected = input.tag.get_property("CV_SELECTED", 0); - config.pt_selected = input.tag.get_property("PT_SELECTED", 0); + aliasing = input.tag.get_property("ALIASING", aliasing); } else if( !strncmp(input.tag.get_title(),"CURVE_",6) ) { cv = new SketcherCurve(); cv->read_data(input); - config.curves.append(cv); + curves.append(cv); } else if( !strncmp(input.tag.get_title(),"/CURVE_",7) ) cv = 0; @@ -400,13 +422,79 @@ void Sketcher::read_data(KeyFrame *keyframe) cv->points.append(pt); } else - printf("Sketcher::read_data: no curve for point\n"); + printf("SketcherConfig::read_data: no curve for point\n"); } } + limits(); +} + +void Sketcher::read_data(KeyFrame *keyframe) +{ + config.read_data(keyframe); if( !config.curves.size() ) new_curve(); - config.limits(); +} + +void SketcherPoint::update_parameter(SketcherPoint *prev, SketcherPoint *src) +{ + if( prev->arc != src->arc ) arc = src->arc; + if( prev->x != src->x ) x = src->x; + if( prev->y != src->y ) y = src->y; +} + +void SketcherCurve::update_parameter(SketcherCurve *prev, SketcherCurve *src) +{ + if( prev->pen != src->pen ) pen = src->pen; + if( prev->width != src->width ) width = src->width; + if( prev->color != src->color ) color = src->color; + int prev_points = prev->points.size(); + int src_points = src->points.size(); + int dst_points = this->points.size(); + int npoints = bmin(prev_points, bmin(src_points, dst_points)); + for( int i=0; ipoints[i]; + SketcherPoint *src_point = src->points[i]; + SketcherPoint *dst_point = this->points[i]; + dst_point->update_parameter(prev_point, src_point); + } +} + +void Sketcher::span_keyframes(KeyFrame *src, int64_t start, int64_t end) +{ + SketcherConfig src_config; + src_config.read_data(src); + KeyFrames *keyframes = (KeyFrames *)src->autos; + KeyFrame *prev = keyframes->get_prev_keyframe(start, PLAY_FORWARD); + SketcherConfig prev_config; + prev_config.read_data(prev); +// Always update the first one + update_parameter(prev_config, src_config, prev); + KeyFrame *curr = (KeyFrame*)prev->next; + while( curr && curr->position < end ) { + update_parameter(prev_config, src_config, curr); + curr = (KeyFrame*)curr->next; + } +} + +void Sketcher::update_parameter(SketcherConfig &prev_config, SketcherConfig &src_config, + KeyFrame *keyframe) +{ + SketcherConfig dst_config; + dst_config.read_data(keyframe); + if( prev_config.aliasing != src_config.aliasing ) + dst_config.aliasing = src_config.aliasing; + int src_curves = src_config.curves.size(); + int dst_curves = dst_config.curves.size(); + int prev_curves = prev_config.curves.size(); + int ncurves = bmin(prev_curves, bmin(src_curves, dst_curves)); + for( int i=0; iupdate_parameter(prev_curve, src_curve); + } + dst_config.save_data(keyframe); } void Sketcher::update_gui() @@ -437,47 +525,58 @@ void Sketcher::draw_point(VFrame *vfrm, SketcherPoint *pt, int color) } -int SketcherVPen::draw_pixel(int x, int y) +int SketcherVPen::draw_mask(int x, int y) { - if( x >= 0 && x < vfrm->get_w() && - y >= 0 && y < vfrm->get_h() ) - msk[vfrm->get_w()*y + x] = 0xff; + int w = vfrm->get_w(), h = vfrm->get_h(); + if( x < 0 || x >= w ) return 1; + if( y < 0 || y >= h ) return 1; + msk[w * y + x] = 0xff; return 0; } -int SketcherPenSquare::draw_pixel(int x, int y) +int SketcherVPen::draw_pixel(float x, float y, float frac, int axis) +{ + draw_mask(x, y); + return VFrame::draw_pixel(x, y, frac, axis); +} + +int SketcherPenSquare::draw_pixel(float x, float y, float a) { + vfrm->set_draw_alpha(a); vfrm->draw_line(x-n, y, x+n, y); for( int i=-n; idraw_line(x-n, y+i, x+n, y+i); - return SketcherVPen::draw_pixel(x, y); + return 0; } -int SketcherPenPlus::draw_pixel(int x, int y) +int SketcherPenPlus::draw_pixel(float x, float y, float a) { + vfrm->set_draw_alpha(a); if( n > 1 ) { vfrm->draw_line(x-n, y, x+n, y); vfrm->draw_line(x, y-n, x, y+n); } else vfrm->draw_pixel(x, y); - return SketcherVPen::draw_pixel(x, y); + return 0; } -int SketcherPenSlant::draw_pixel(int x, int y) +int SketcherPenSlant::draw_pixel(float x, float y, float a) { + vfrm->set_draw_alpha(a); vfrm->draw_line(x-n, y+n, x+n, y-n); vfrm->draw_line(x-n+1, y+n, x+n+1, y-n); vfrm->draw_line(x-n, y+n+1, x+n, y-n+1); - return SketcherVPen::draw_pixel(x, y); + return 0; } -int SketcherPenXlant::draw_pixel(int x, int y) +int SketcherPenXlant::draw_pixel(float x, float y, float a) { + vfrm->set_draw_alpha(a); vfrm->draw_line(x-n, y+n, x+n, y-n); vfrm->draw_line(x-n+1, y+n, x+n+1, y-n); vfrm->draw_line(x-n, y+n+1, x+n, y-n+1); vfrm->draw_line(x-n, y-n, x+n, y+n); vfrm->draw_line(x-n+1, y-n, x+n+1, y+n); vfrm->draw_line(x-n, y-n+1, x+n, y-n+1); - return SketcherVPen::draw_pixel(x, y); + return 0; } @@ -562,6 +661,7 @@ class FillRegion public: SketcherPoint *next(); bool exists() { return stack.size() > 0; } + void draw_pixel(int x, int y) { img->draw_pixel(x, y); } void start_at(int x, int y); void run(); FillRegion(SketcherPoints &pts, SketcherVPen *vpen); @@ -590,25 +690,26 @@ void FillRegion::start_at(int x, int y) void FillRegion::run() { + img->set_draw_alpha(1); while( stack.size() > 0 ) { int y, ilt, irt; pop(y, ilt, irt); int ofs = y*w + ilt; for( int x=ilt; x<=irt; ++x,++ofs ) { + draw_pixel(x, y); if( msk[ofs] ) continue; msk[ofs] = 0xff; - img->draw_pixel(x, y); int lt = x, rt = x; int lofs = ofs; for( int i=lt; --i>=0; ) { + draw_pixel(i, y); if( msk[--lofs] ) break; - img->draw_pixel(i, y); msk[lofs] = 0xff; lt = i; } int rofs = ofs; for( int i=rt; ++i< w; ) { + draw_pixel(i, y); if( msk[++rofs] ) break; - img->draw_pixel(i, y); msk[rofs] = 0xff; rt = i; } if( y+1 < h ) push(y+1, lt, rt); @@ -628,12 +729,13 @@ SketcherPoint *FillRegion::next() return 0; } - -void SketcherCurve::draw(VFrame *img) +void SketcherCurve::draw(VFrame *img, int alias) { if( !points.size() ) return; + img->set_pixel_color(color, (~color>>24)&0xff); const float fmx = 16383; SketcherVPen *vpen = new_vpen(img); + vpen->set_draw_flags(alias); FillRegion fill(points, vpen); SketcherPoint *pnt0 = fill.next(); SketcherPoint *pnt1 = pnt0 ? fill.next() : 0; @@ -693,7 +795,7 @@ void SketcherCurve::draw(VFrame *img) vpen->draw_line(pnt0->x, pnt0->y, pnt1->x, pnt1->y); } else if( pnt0 ) { - vpen->draw_pixel(pnt0->x, pnt0->y); + vpen->draw_pixel(pnt0->x, pnt0->y, 1); } delete vpen; } @@ -739,17 +841,18 @@ int Sketcher::process_realtime(VFrame *input, VFrame *output) int m = cv->points.size(); if( !m ) continue; img->clear_frame(); - img->set_pixel_color(cv->color, (~cv->color>>24)&0xff); - cv->draw(img); + int alias = config.aliasing < 0 ? ALIAS_OFF : + config.aliasing > 0 ? ALIAS_DBL : ALIAS_NRM; + cv->draw(img, alias); overlay_frame->overlay(out, img, 0,0,w,h, 0,0,w,h, - 1.f, TRANSFER_NORMAL, NEAREST_NEIGHBOR); + 1.f, TRANSFER_SRC_OVER, NEAREST_NEIGHBOR); } - if( config.drag ) { + if( is_dragging() ) { for( int ci=0, n=config.curves.size(); cipoints.size(); picolor ; draw_point(out, cv->points[pi], color); } @@ -785,8 +888,7 @@ void SketcherCurves::dump() } void SketcherConfig::dump() { - printf("Config drag=%d, cv_selected=%d, pt_selected=%d %d curves\n", - drag, cv_selected, pt_selected, curves.size()); + printf("Config %d curves\n", curves.size()); curves.dump(); }