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_ALP, CV_SZ };
38 enum { ARC_OFF, ARC_LINE, ARC_CURVE, ARC_FILL, ARC_SZ };
39 enum { PEN_OFF, PEN_SQUARE, PEN_PLUS, PEN_SLANT, PEN_XLANT, PEN_SZ };
42 class SketcherVPen : public VFrame
49 SketcherVPen(VFrame *vfrm, int n)
50 : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
51 vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
52 vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
53 vfrm->get_bytes_per_line()) {
54 this->vfrm = vfrm; this->n = n;
55 int sz = vfrm->get_w()*vfrm->get_h();
56 this->msk = (uint8_t*)memset(new uint8_t[sz],0,sz);
58 ~SketcherVPen() { delete [] msk; }
60 void draw_line(float x1, float y1, float x2, float y2) {
61 VFrame::draw_line(int(x1+.5f),int(y1+.5f), int(x2+.5f),int(y2+.5f));
63 void draw_smooth(float x1, float y1, float x2, float y2, float x3, float y3) {
64 VFrame::draw_smooth(int(x1+.5f),int(y1+.5f),
65 int(x2+.5f),int(y2+.5f), int(x3+.5f),int(y3+.5f));
68 virtual int draw_pixel(int x, int y) = 0;
71 class SketcherPenSquare : public SketcherVPen
74 SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
75 int draw_pixel(int x, int y);
77 class SketcherPenPlus : public SketcherVPen
80 SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
81 int draw_pixel(int x, int y);
83 class SketcherPenSlant : public SketcherVPen
86 SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
87 int draw_pixel(int x, int y);
89 class SketcherPenXlant : public SketcherVPen
92 SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
93 int draw_pixel(int x, int y);
103 void init(int id, int arc, coord x, coord y);
104 SketcherPoint(int id, int arc, coord x, coord y);
105 SketcherPoint(int id=-1);
106 SketcherPoint(SketcherPoint &pt);
108 int equivalent(SketcherPoint &that);
109 void copy_from(SketcherPoint &that);
110 void save_data(FileXML &output);
111 void read_data(FileXML &input);
112 static const char *types[ARC_SZ];
114 class SketcherPoints : public ArrayList<SketcherPoint *>
118 ~SketcherPoints() { remove_all_objects(); }
126 int id, pen, width, color;
127 static const char *pens[PEN_SZ];
129 SketcherPoints points;
131 void init(int id, int pen, int width, int color);
132 SketcherCurve(int id, int pen, int width, int color);
133 SketcherCurve(int id=-1);
135 SketcherCurve(SketcherCurve &cv);
136 int equivalent(SketcherCurve &that);
137 void copy_from(SketcherCurve &that);
138 void save_data(FileXML &output);
139 void read_data(FileXML &input);
140 double nearest_point(int &pi, coord x, coord y);
142 SketcherVPen *new_vpen(VFrame *out);
143 void draw(VFrame *img);
145 class SketcherCurves : public ArrayList<SketcherCurve *>
149 ~SketcherCurves() { remove_all_objects(); }
159 SketcherCurves curves;
160 int equivalent(SketcherConfig &that);
161 void copy_from(SketcherConfig &that);
162 void interpolate(SketcherConfig &prev, SketcherConfig &next,
163 long prev_frame, long next_frame, long current_frame);
164 double nearest_point(int &ci, int &pi, coord x, coord y);
169 int cv_selected, pt_selected;
172 class Sketcher : public PluginVClient
175 Sketcher(PluginServer *server);
177 PLUGIN_CLASS_MEMBERS2(SketcherConfig)
181 void save_data(KeyFrame *keyframe);
182 void read_data(KeyFrame *keyframe);
183 int new_curve(int pen, int width, int color);
185 int new_point(SketcherCurve *cv, int arc, coord x, coord y, int idx=-1);
186 int new_point(int idx, int arc);
187 int process_realtime(VFrame *input, VFrame *output);
188 static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
189 void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
191 VFrame *input, *output;
193 OverlayFrame *overlay_frame;
194 int w, h, color_model, bpp, comp;
195 int is_yuv, is_float;