3 * Copyright (C) 1997-2014 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
23 #ifndef __SKETCHERS_H__
24 #define __SKETCHERS_H__
26 #include "pluginvclient.h"
27 #include "overlayframe.inc"
32 #define pt_type SketcherPoint::types
33 #define cv_pen SketcherCurve::pens
34 #define CV_COLOR WHITE
36 enum { PT_ID, PT_TY, PT_X, PT_Y, PT_SZ };
37 enum { CV_ID, CV_RAD, CV_PEN, CV_CLR, CV_SZ };
38 enum { PTY_OFF, PTY_LINE, PTY_CURVE, PTY_FILL, PTY_SZ };
39 enum { PEN_OFF, PEN_SQUARE, PEN_PLUS, PEN_SLANT, PEN_XLANT, PEN_SZ };
41 class SketcherVPen : public VFrame
48 SketcherVPen(VFrame *vfrm, int n)
49 : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
50 vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
51 vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
52 vfrm->get_bytes_per_line()) {
53 this->vfrm = vfrm; this->n = n;
54 int sz = vfrm->get_w()*vfrm->get_h();
55 this->msk = (uint8_t*)memset(new uint8_t[sz],0,sz);
57 ~SketcherVPen() { delete [] msk; }
59 virtual int draw_pixel(int x, int y) = 0;
62 class SketcherPenSquare : public SketcherVPen
65 SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
66 int draw_pixel(int x, int y);
68 class SketcherPenPlus : public SketcherVPen
71 SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
72 int draw_pixel(int x, int y);
74 class SketcherPenSlant : public SketcherVPen
77 SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
78 int draw_pixel(int x, int y);
80 class SketcherPenXlant : public SketcherVPen
83 SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
84 int draw_pixel(int x, int y);
94 void init(int id, int pty, int x, int y);
95 SketcherPoint(int id, int pty, int x, int y);
96 SketcherPoint(int id=-1);
97 SketcherPoint(SketcherPoint &pt);
99 int equivalent(SketcherPoint &that);
100 void copy_from(SketcherPoint &that);
101 void save_data(FileXML &output);
102 void read_data(FileXML &input);
103 static const char *types[PTY_SZ];
105 class SketcherPoints : public ArrayList<SketcherPoint *>
109 ~SketcherPoints() { remove_all_objects(); }
117 int id, pen, radius, color;
118 static const char *pens[PEN_SZ];
120 SketcherPoints points;
122 void init(int id, int pen, int radius, int color);
123 SketcherCurve(int id, int pen, int radius, int color);
124 SketcherCurve(int id=-1);
126 SketcherCurve(SketcherCurve &cv);
127 int equivalent(SketcherCurve &that);
128 void copy_from(SketcherCurve &that);
129 void save_data(FileXML &output);
130 void read_data(FileXML &input);
131 double nearest_point(int &pi, float x, float y);
133 SketcherVPen *new_vpen(VFrame *out);
134 void draw(VFrame *img);
136 class SketcherCurves : public ArrayList<SketcherCurve *>
140 ~SketcherCurves() { remove_all_objects(); }
150 SketcherCurves curves;
151 int equivalent(SketcherConfig &that);
152 void copy_from(SketcherConfig &that);
153 void interpolate(SketcherConfig &prev, SketcherConfig &next,
154 long prev_frame, long next_frame, long current_frame);
155 double nearest_point(int &ci, int &pi, float x, float y);
160 int cv_selected, pt_selected;
163 class Sketcher : public PluginVClient
166 Sketcher(PluginServer *server);
168 PLUGIN_CLASS_MEMBERS2(SketcherConfig)
171 void save_data(KeyFrame *keyframe);
172 void read_data(KeyFrame *keyframe);
173 int new_curve(int pen, int radius, int color);
175 int new_point(SketcherCurve *cv, int pty, int x, int y, int idx=-1);
176 int new_point(int idx=-1);
177 int process_realtime(VFrame *input, VFrame *output);
178 static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
179 void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
181 VFrame *input, *output;
183 OverlayFrame *overlay_frame;
184 int w, h, color_model, bpp, comp;
185 int is_yuv, is_float;