3 * Copyright (C) 1997-2015 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "arraylist.h"
27 #include "bccmodels.h"
31 #include "edlsession.h"
33 #include "overlayframe.h"
34 #include "pluginserver.h"
35 #include "preferences.h"
37 #include "sketcherwindow.h"
41 void SketcherPoint::init(int id, int arc, coord x, coord y)
43 this->id = id; this->arc = arc;
44 this->x = x; this->y = y;
46 SketcherPoint::SketcherPoint(int id)
48 init(id, ARC_LINE, 0, 0);
50 SketcherPoint::SketcherPoint(int id, int arc, coord x, coord y)
54 SketcherPoint::~SketcherPoint()
57 SketcherPoint::SketcherPoint(SketcherPoint &pt)
61 int SketcherPoint::equivalent(SketcherPoint &that)
63 return this->id == that.id &&
64 this->arc == that.arc &&
65 EQUIV(this->x, that.x) &&
66 EQUIV(this->y, that.y) ? 1 : 0;
68 void SketcherPoint::copy_from(SketcherPoint &that)
70 this->id = that.id; this->arc = that.arc;
71 this->x = that.x; this->y = that.y;
73 void SketcherPoint::save_data(FileXML &output)
76 sprintf(point,"/POINT_%d",id);
77 output.tag.set_title(point+1);
78 output.tag.set_property("TYPE", arc);
79 output.tag.set_property("X", x);
80 output.tag.set_property("Y", y);
82 output.tag.set_title(point+0);
84 output.append_newline();
86 void SketcherPoint::read_data(FileXML &input)
88 id = atoi(input.tag.get_title() + 6);
89 arc = input.tag.get_property("TYPE", ARC_OFF);
90 x = input.tag.get_property("X", (coord)0);
91 y = input.tag.get_property("Y", (coord)0);
92 bclamp(arc, 0, ARC_SZ-1);
95 void SketcherCurve::init(int id, int pen, int width, int color)
102 SketcherCurve::SketcherCurve(int id)
104 init(id, 1, PEN_SQUARE, CV_COLOR);
106 SketcherCurve::SketcherCurve(int id, int pen, int width, int color)
108 init(id, pen, width, color);
110 SketcherCurve::~SketcherCurve()
113 SketcherCurve::SketcherCurve(SketcherCurve &cv)
117 int SketcherCurve::equivalent(SketcherCurve &that)
119 if( this->id != that.id ) return 0;
120 if( this->pen != that.pen ) return 0;
121 if( this->width != that.width ) return 0;
122 if( this->color != that.color ) return 0;
123 int n = this->points.size();
124 if( n != that.points.size() ) return 0;
125 for( int i=0; i<n; ++i ) {
126 if( !points[i]->equivalent(*that.points[i]) ) return 0;
130 void SketcherCurve::copy_from(SketcherCurve &that)
133 this->pen = that.pen;
134 this->width = that.width;
135 this->color = that.color;
136 int m = points.size(), n = that.points.size();
137 while( m > n ) points.remove_object_number(--m);
138 while( m < n ) { points.append(new SketcherPoint()); ++m; }
139 for( int i=0; i<n; ++i ) points[i]->copy_from(*that.points[i]);
141 void SketcherCurve::save_data(FileXML &output)
143 char curve[BCSTRLEN];
144 sprintf(curve,"/CURVE_%d",id);
145 output.tag.set_title(curve+1);
146 output.tag.set_property("PEN", pen);
147 output.tag.set_property("RADIUS", width);
148 output.tag.set_property("COLOR", color);
150 output.append_newline();
151 for( int i=0,n=points.size(); i<n; ++i )
152 points[i]->save_data(output);
153 output.tag.set_title(curve+0);
155 output.append_newline();
157 void SketcherCurve::read_data(FileXML &input)
159 id = atoi(input.tag.get_title() + 6);
160 pen = input.tag.get_property("PEN", PEN_OFF);
161 width = input.tag.get_property("RADIUS", 1.);
162 color = input.tag.get_property("COLOR", CV_COLOR);
163 bclamp(pen, 0, PEN_SZ-1);
166 int Sketcher::new_curve(int pen, int width, int color)
168 SketcherCurves &curves = config.curves;
169 int k = curves.size(), id = 1;
170 for( int i=k; --i>=0; ) {
171 int n = config.curves[i]->id;
172 if( n >= id ) id = n + 1;
174 SketcherCurve *cv = new SketcherCurve(id, pen, width, color);
176 config.cv_selected = k;
180 int Sketcher::new_curve()
182 return new_curve(PEN_XLANT, 1, CV_COLOR);
185 int Sketcher::new_point(SketcherCurve *cv, int arc, coord x, coord y, int idx)
188 for( int i=cv->points.size(); --i>=0; ) {
189 int n = cv->points[i]->id;
190 if( n >= id ) id = n + 1;
192 SketcherPoint *pt = new SketcherPoint(id, arc, x, y);
193 int n = cv->points.size();
194 if( idx < 0 || idx > n ) idx = n;
195 cv->points.insert(pt, idx);
199 int Sketcher::new_point(int idx, int arc)
201 int ci = config.cv_selected;
202 if( ci < 0 || ci >= config.curves.size() )
204 SketcherCurve *cv = config.curves[ci];
205 EDLSession *session = get_edl()->session;
206 coord x = !session ? 0.f : session->output_w / 2.f;
207 coord y = !session ? 0.f : session->output_h / 2.f;
208 return new_point(cv, arc, x, y, idx);
211 double SketcherCurve::nearest_point(int &pi, coord x, coord y)
214 double dist = DBL_MAX;
215 for( int i=0; i<points.size(); ++i ) {
216 SketcherPoint *p = points[i];
217 double d = DISTANCE(x,y, p->x,p->y);
218 if( d < dist ) { dist = d; pi = i; }
220 return pi >= 0 ? dist : -1.;
223 double SketcherConfig::nearest_point(int &ci, int &pi, coord x, coord y)
225 double dist = DBL_MAX;
227 for( int i=0; i<curves.size(); ++i ) {
228 SketcherCurve *crv = curves[i];
229 SketcherPoints &points = crv->points;
230 for( int k=0; k<points.size(); ++k ) {
231 SketcherPoint *p = points[k];
232 double d = DISTANCE(x,y, p->x,p->y);
233 if( d < dist ) { dist = d; ci = i; pi = k; }
236 return pi >= 0 ? dist : -1.;
240 REGISTER_PLUGIN(Sketcher)
242 SketcherConfig::SketcherConfig()
249 SketcherConfig::~SketcherConfig()
253 int SketcherConfig::equivalent(SketcherConfig &that)
255 if( this->drag != that.drag ) return 0;
256 if( this->aliasing != that.aliasing ) return 0;
257 if( this->cv_selected != that.cv_selected ) return 0;
258 if( this->pt_selected != that.pt_selected ) return 0;
259 if( this->curves.size() != that.curves.size() ) return 0;
260 for( int i=0, n=curves.size(); i<n; ++i ) {
261 if( !curves[i]->equivalent(*that.curves[i]) ) return 0;
266 void SketcherConfig::copy_from(SketcherConfig &that)
268 this->drag = that.drag;
269 this->aliasing = that.aliasing;
270 this->cv_selected = that.cv_selected;
271 this->pt_selected = that.pt_selected;
272 int m = curves.size(), n = that.curves.size();
273 while( m > n ) curves.remove_object_number(--m);
274 while( m < n ) { curves.append(new SketcherCurve()); ++m; }
275 for( int i=0; i<n; ++i ) curves[i]->copy_from(*that.curves[i]);
278 void SketcherConfig::interpolate(SketcherConfig &prev, SketcherConfig &next,
279 long prev_frame, long next_frame, long current_frame)
281 this->cv_selected = prev.cv_selected;
282 this->pt_selected = prev.pt_selected;
283 this->drag = prev.drag;
284 this->aliasing = prev.aliasing;
286 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
287 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
289 curves.remove_all_objects();
290 int prev_cv_sz = prev.curves.size();
291 int next_cv_sz = next.curves.size();
292 for( int i=0; i<prev_cv_sz; ++i ) {
293 SketcherCurve *pcv = prev.curves[i], *ncv = 0;
294 SketcherCurve *cv = curves.append(new SketcherCurve());
295 int k = next_cv_sz; // associated by id in next
296 while( --k >= 0 && pcv->id != (ncv=next.curves[k])->id );
300 cv->width = pcv->width == ncv->width ? pcv->width :
301 pcv->width*prev_scale + ncv->width*next_scale + 0.5;
302 int pr = (pcv->color>>16)&0xff, nr = (ncv->color>>16)&0xff;
303 int pg = (pcv->color>> 8)&0xff, ng = (ncv->color>> 8)&0xff;
304 int pb = (pcv->color>> 0)&0xff, nb = (ncv->color>> 0)&0xff;
305 int pa = (~pcv->color>>24)&0xff, na = (~ncv->color>>24)&0xff;
306 int r = pr == nr ? pr : pr*prev_scale + nr*next_scale + 0.5;
307 int g = pg == ng ? pg : pg*prev_scale + ng*next_scale + 0.5;
308 int b = pb == nb ? pb : pb*prev_scale + nb*next_scale + 0.5;
309 int a = pa == na ? pa : pa*prev_scale + na*next_scale + 0.5;
310 bclamp(r,0,255); bclamp(g,0,255); bclamp(b,0,255); bclamp(a,0,255);
311 cv->color = (~a<<24) | (r<<16) | (g<<8) | (b<<0);
312 int prev_pt_sz = pcv->points.size(), next_pt_sz = ncv->points.size();
313 for( int j=0; j<prev_pt_sz; ++j ) {
314 SketcherPoint &pt = *pcv->points[j], *nt = 0;
315 k = next_pt_sz; // associated by id in next
316 while( --k >= 0 && pt.id != (nt=ncv->points[k])->id );
317 coord x = pt.x, y = pt.y;
320 x = x * prev_scale + nt->x * next_scale;
322 y = y * prev_scale + nt->y * next_scale;
324 cv->points.append(new SketcherPoint(pt.id, pt.arc, x, y));
332 void SketcherConfig::limits()
337 Sketcher::Sketcher(PluginServer *server)
338 : PluginVClient(server)
345 Sketcher::~Sketcher()
349 delete overlay_frame;
352 const char* Sketcher::plugin_title() { return N_("Sketcher"); }
353 int Sketcher::is_realtime() { return 1; }
354 int Sketcher::is_synthesis() { return 1; }
356 NEW_WINDOW_MACRO(Sketcher, SketcherWindow);
357 LOAD_CONFIGURATION_MACRO(Sketcher, SketcherConfig)
359 void Sketcher::save_data(KeyFrame *keyframe)
362 // cause data to be stored directly in text
363 output.set_shared_output(keyframe->xbuf);
365 output.tag.set_title("SKETCHER");
366 output.tag.set_property("DRAG", config.drag);
367 output.tag.set_property("ALIASING", config.aliasing);
368 output.tag.set_property("CV_SELECTED", config.cv_selected);
369 output.tag.set_property("PT_SELECTED", config.pt_selected);
371 output.append_newline();
372 for( int i=0,n=config.curves.size(); i<n; ++i ) {
373 config.curves[i]->save_data(output);
375 output.tag.set_title("/SKETCHER");
377 output.append_newline();
378 output.terminate_string();
381 void Sketcher::read_data(KeyFrame *keyframe)
384 input.set_shared_input(keyframe->xbuf);
385 config.curves.remove_all_objects();
387 SketcherCurve *cv = 0;
389 while( !(result=input.read_tag()) ) {
390 if( input.tag.title_is("SKETCHER") ) {
391 config.drag = input.tag.get_property("DRAG", config.drag);
392 config.aliasing = input.tag.get_property("ALIASING", config.aliasing);
393 config.cv_selected = input.tag.get_property("CV_SELECTED", 0);
394 config.pt_selected = input.tag.get_property("PT_SELECTED", 0);
396 else if( !strncmp(input.tag.get_title(),"CURVE_",6) ) {
397 cv = new SketcherCurve();
398 cv->read_data(input);
399 config.curves.append(cv);
401 else if( !strncmp(input.tag.get_title(),"/CURVE_",7) )
403 else if( !strncmp(input.tag.get_title(),"POINT_",6) ) {
405 SketcherPoint *pt = new SketcherPoint();
406 pt->read_data(input);
407 cv->points.append(pt);
410 printf("Sketcher::read_data: no curve for point\n");
414 if( !config.curves.size() )
419 void Sketcher::update_gui()
421 if( !thread ) return;
422 thread->window->lock_window("Sketcher::update_gui");
423 if( load_configuration() ) {
424 SketcherWindow *window = (SketcherWindow*)thread->window;
425 window->update_gui();
428 thread->window->unlock_window();
431 void Sketcher::draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d)
433 int r = d/2+1, x = pt->x, y = pt->y;
434 vfrm->set_pixel_color(color);
435 vfrm->draw_smooth(x-r,y+0, x-r, y-r, x+0,y-r);
436 vfrm->draw_smooth(x+0,y-r, x+r, y-r, x+r,y+0);
437 vfrm->draw_smooth(x+r,y+0, x+r, y+r, x+0,y+r);
438 vfrm->draw_smooth(x+0,y+r, x-r, y+r, x-r,y+0);
439 vfrm->draw_x(pt->x, pt->y, d);
441 void Sketcher::draw_point(VFrame *vfrm, SketcherPoint *pt, int color)
443 draw_point(vfrm, pt, color, bmax(w,h)/200 + 2);
447 int SketcherVPen::draw_mask(int x, int y)
449 int w = vfrm->get_w(), h = vfrm->get_h();
450 if( x < 0 || x >= w ) return 1;
451 if( y < 0 || y >= h ) return 1;
452 msk[w * y + x] = 0xff;
456 int SketcherVPen::draw_pixel(float x, float y, float frac, int axis)
459 return VFrame::draw_pixel(x, y, frac, axis);
462 int SketcherPenSquare::draw_pixel(float x, float y, float a)
464 vfrm->set_draw_alpha(a);
465 vfrm->draw_line(x-n, y, x+n, y);
466 for( int i=-n; i<n; ++i )
467 vfrm->draw_line(x-n, y+i, x+n, y+i);
470 int SketcherPenPlus::draw_pixel(float x, float y, float a)
472 vfrm->set_draw_alpha(a);
474 vfrm->draw_line(x-n, y, x+n, y);
475 vfrm->draw_line(x, y-n, x, y+n);
478 vfrm->draw_pixel(x, y);
481 int SketcherPenSlant::draw_pixel(float x, float y, float a)
483 vfrm->set_draw_alpha(a);
484 vfrm->draw_line(x-n, y+n, x+n, y-n);
485 vfrm->draw_line(x-n+1, y+n, x+n+1, y-n);
486 vfrm->draw_line(x-n, y+n+1, x+n, y-n+1);
489 int SketcherPenXlant::draw_pixel(float x, float y, float a)
491 vfrm->set_draw_alpha(a);
492 vfrm->draw_line(x-n, y+n, x+n, y-n);
493 vfrm->draw_line(x-n+1, y+n, x+n+1, y-n);
494 vfrm->draw_line(x-n, y+n+1, x+n, y-n+1);
495 vfrm->draw_line(x-n, y-n, x+n, y+n);
496 vfrm->draw_line(x-n+1, y-n, x+n+1, y+n);
497 vfrm->draw_line(x-n, y-n+1, x+n, y-n+1);
502 SketcherVPen *SketcherCurve::new_vpen(VFrame *out)
505 case PEN_SQUARE: return new SketcherPenSquare(out, width);
506 case PEN_PLUS: return new SketcherPenPlus(out, width);
507 case PEN_SLANT: return new SketcherPenSlant(out, width);
508 case PEN_XLANT: return new SketcherPenXlant(out, width);
513 static int intersects_at(float &x, float &y,
514 float ax,float ay, float bx, float by, float cx,float cy, // line slope ab thru c
515 float dx,float dy, float ex, float ey, float fx,float fy, // line slope de thru f
518 float badx = bx - ax, bady = by - ay;
519 float eddx = ex - dx, eddy = ey - dy;
520 float d = badx*eddy - bady*eddx;
522 if( fabsf(d) < 1 ) { ret = 1; d = signbit(d) ? -1 : 1; }
523 x = (badx*cy*eddx - badx*eddx*fy + badx*eddy*fx - bady*cx*eddx) / d;
524 y = (badx*cy*eddy - bady*cx*eddy - bady*eddx*fy + bady*eddy*fx) / d;
525 if( mx > 0 ) { bclamp(x, -mx,mx); bclamp(y, -mx,mx); }
529 static void smooth_axy(float &ax, float &ay,
530 float bx, float by, float cx, float cy, float dx, float dy)
532 //middle of bd reflected around ctr
533 // point ctr = (b+d)/2, dv=c-ctr, a=ctr-dv;
534 float xc = (bx+dx)*.5f, yc = (by+dy)*.5f;
535 float xd = cx - xc, yd = cy - yc;
536 ax = xc - xd; ay = yc - yd;
538 static void smooth_dxy(float &dx, float &dy,
539 float ax, float ay, float bx, float by, float cx, float cy)
541 //middle of ac reflected around ctr
542 // point ctr = (a+c)/2, dv=c-ctr, d=ctr-dv;
543 float xc = (ax+cx)*.5f, yc = (ay+cy)*.5f;
544 float xd = bx - xc, yd = by - yc;
545 dx = xc - xd; dy = yc - yd;
548 static int convex(float ax,float ay, float bx,float by,
549 float cx,float cy, float dx,float dy)
551 float abdx = bx-ax, abdy = by-ay;
552 float acdx = cx-ax, acdy = cy-ay;
553 float bcdx = cx-bx, bcdy = cy-by;
554 float bddx = dx-bx, bddy = dy-by;
555 float abc = abdx*acdy - abdy*acdx;
556 float bcd = bcdx*bddy - bcdy*bddx;
558 return !v ? 0 : v>0 ? 1 : -1;
563 class segment { public: int y, lt, rt; };
564 ArrayList<segment> stack;
566 void push(int y, int lt, int rt) {
567 segment &seg = stack.append();
568 seg.y = y; seg.lt = lt; seg.rt = rt;
570 void pop(int &y, int <, int &rt) {
571 segment &seg = stack.last();
572 y = seg.y; lt = seg.lt; rt = seg.rt;
579 SketcherPoints &points;
581 SketcherPoint *next();
582 bool exists() { return stack.size() > 0; }
583 void draw_pixel(int x, int y) { img->draw_pixel(x, y); }
584 void start_at(int x, int y);
586 FillRegion(SketcherPoints &pts, SketcherVPen *vpen);
590 FillRegion::FillRegion(SketcherPoints &pts, SketcherVPen *vpen)
593 this->img = vpen->vfrm;
594 this->msk = vpen->msk;
595 this->w = img->get_w();
596 this->h = img->get_h();
599 FillRegion::~FillRegion()
603 void FillRegion::start_at(int x, int y)
610 void FillRegion::run()
612 img->set_draw_alpha(1);
613 while( stack.size() > 0 ) {
617 for( int x=ilt; x<=irt; ++x,++ofs ) {
619 if( msk[ofs] ) continue;
623 for( int i=lt; --i>=0; ) {
625 if( msk[--lofs] ) break;
626 msk[lofs] = 0xff; lt = i;
629 for( int i=rt; ++i< w; ) {
631 if( msk[++rofs] ) break;
632 msk[rofs] = 0xff; rt = i;
634 if( y+1 < h ) push(y+1, lt, rt);
635 if( y-1 >= 0 ) push(y-1, lt, rt);
640 SketcherPoint *FillRegion::next()
642 while( nxt < points.size() ) {
643 SketcherPoint *pt = points[nxt++];
644 if( pt->arc == ARC_OFF ) continue;
645 if( pt->arc != ARC_FILL ) return pt;
646 start_at(pt->x, pt->y);
651 void SketcherCurve::draw(VFrame *img, int alias)
653 if( !points.size() ) return;
654 img->set_pixel_color(color, (~color>>24)&0xff);
655 const float fmx = 16383;
656 SketcherVPen *vpen = new_vpen(img);
657 vpen->set_draw_flags(alias);
658 FillRegion fill(points, vpen);
659 SketcherPoint *pnt0 = fill.next();
660 SketcherPoint *pnt1 = pnt0 ? fill.next() : 0;
661 SketcherPoint *pnt2 = pnt1 ? fill.next() : 0;
662 if( pnt0 && pnt1 && pnt2 ) {
663 SketcherPoint *pt0 = pnt0, *pt1 = pnt1, *pt2 = pnt2;
664 float ax,ay, bx,by, cx,cy, dx,dy, sx,sy;
665 bx = pt0->x; by = pt0->y;
666 cx = pt1->x; cy = pt1->y;
667 dx = pt2->x; dy = pt2->y;
668 smooth_axy(ax,ay, bx,by, cx,cy, dx,dy);
670 dx = pt2->x; dy = pt2->y;
673 if( convex(ax,ay, bx,by, cx,cy, dx,dy) >= 0 ) {
674 // s = ac thru b x bd thru c
675 intersects_at(sx,sy, ax,ay,cx,cy,bx,by, bx,by,dx,dy,cx,cy,fmx);
676 vpen->draw_smooth(bx,by, sx,sy, cx,cy);
680 vpen->draw_line(bx, by, cx, cy);
683 ax = bx; ay = by; pt0 = pt1;
684 bx = cx; by = cy; pt1 = pt2;
685 cx = dx; cy = dy; pt2 = fill.next();
689 vpen->draw_line(bx, by, cx, cy);
690 if( fill.exists() ) {
691 dx = pnt0->x; dy = pnt0->y;
692 vpen->draw_line(cx,cy, dx,dy);
696 if( fill.exists() ) {
697 dx = pnt0->x; dy = pnt0->y;
698 intersects_at(sx,sy, ax,ay,cx,cy,bx,by, bx,by,dx,dy,cx,cy,fmx);
699 vpen->draw_smooth(bx,by, sx,sy, cx,cy);
703 dx = pnt1->x; dy = pnt1->y;
706 smooth_dxy(dx,dy, ax,ay, bx,by, cx,cy);
707 intersects_at(sx,sy, ax,ay,cx,cy,bx,by, bx,by,dx,dy,cx,cy,fmx);
708 vpen->draw_smooth(bx,by, sx,sy, cx,cy);
713 else if( pnt0 && pnt1 ) {
714 vpen->draw_line(pnt0->x, pnt0->y, pnt1->x, pnt1->y);
717 vpen->draw_pixel(pnt0->x, pnt0->y, 1);
722 int Sketcher::process_realtime(VFrame *input, VFrame *output)
724 this->input = input; this->output = output;
725 w = output->get_w(); h = output->get_h();
727 load_configuration();
729 int out_color_model = output->get_color_model();
730 int color_model = out_color_model;
731 switch( color_model ) { // add alpha if needed
732 case BC_RGB888: color_model = BC_RGBA8888; break;
733 case BC_YUV888: color_model = BC_YUVA8888; break;
734 case BC_RGB161616: color_model = BC_RGBA16161616; break;
735 case BC_YUV161616: color_model = BC_YUVA16161616; break;
736 case BC_RGB_FLOAT: color_model = BC_RGBA_FLOAT; break;
737 case BC_RGB_FLOATP: color_model = BC_RGBA_FLOATP; break;
739 if( color_model == out_color_model ) {
740 delete out; out = output;
741 if( output != input )
742 output->transfer_from(input);
745 VFrame::get_temp(out, w, h, color_model);
746 out->transfer_from(input);
748 VFrame::get_temp(img, w, h, color_model);
750 if( !overlay_frame ) {
751 int cpus = server->preferences->project_smp;
752 int max = (w*h)/0x80000 + 2;
753 if( cpus > max ) cpus = max;
754 overlay_frame = new OverlayFrame(cpus);
757 for( int ci=0, n=config.curves.size(); ci<n; ++ci ) {
758 SketcherCurve *cv = config.curves[ci];
759 if( cv->pen == PEN_OFF ) continue;
760 int m = cv->points.size();
763 int alias = config.aliasing < 0 ? ALIAS_OFF :
764 config.aliasing > 0 ? ALIAS_DBL : ALIAS_NRM;
765 cv->draw(img, alias);
766 overlay_frame->overlay(out, img, 0,0,w,h, 0,0,w,h,
767 1.f, TRANSFER_SRC_OVER, NEAREST_NEIGHBOR);
771 for( int ci=0, n=config.curves.size(); ci<n; ++ci ) {
772 SketcherCurve *cv = config.curves[ci];
773 for( int pi=0,m=cv->points.size(); pi<m; ++pi ) {
774 int color = pi==config.pt_selected && ci==config.cv_selected ?
776 draw_point(out, cv->points[pi], color);
782 output->transfer_from(out);
789 void SketcherPoints::dump()
791 for( int i=0; i<size(); ++i ) {
792 SketcherPoint *pt = get(i);
793 printf(" Pt %d, id=%d, arc=%s, x=%0.1f, y=%0.1f\n",
794 i, pt->id, pt_type[pt->arc], pt->x, pt->y);
797 void SketcherCurves::dump()
799 for( int i=0; i<size(); ++i ) {
800 SketcherCurve *cv = get(i);
801 printf("Curve %d, id=%d, pen=%s, r=%d, color=%02x%02x%02x%02x, %d points\n",
802 i, cv->id, cv_pen[cv->pen], cv->width, (~cv->color>>24)&0xff,
803 (cv->color>>16)&0xff, (cv->color>>8)&0xff, (cv->color>>0)&0xff,
808 void SketcherConfig::dump()
810 printf("Config drag=%d, cv_selected=%d, pt_selected=%d %d curves\n",
811 drag, cv_selected, pt_selected, curves.size());