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 int draw_mask(int x, int y);
50 SketcherVPen(VFrame *vfrm, int n)
51 : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
52 vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
53 vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
54 vfrm->get_bytes_per_line()) {
55 this->vfrm = vfrm; this->n = n;
56 int sz = vfrm->get_w()*vfrm->get_h();
57 this->msk = (uint8_t*)memset(new uint8_t[sz],0,sz);
59 ~SketcherVPen() { delete [] msk; }
61 void draw_smooth(float x1, float y1, float x2, float y2, float x3, float y3) {
62 VFrame::draw_smooth(int(x1+.5f),int(y1+.5f),
63 int(x2+.5f),int(y2+.5f), int(x3+.5f),int(y3+.5f));
66 virtual int draw_pixel(float x, float y, float a) = 0;
67 int draw_pixel(float x, float y, float frac, int axis);
70 class SketcherPenSquare : public SketcherVPen
73 SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
74 int draw_pixel(float x, float y, float a);
76 class SketcherPenPlus : public SketcherVPen
79 SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
80 int draw_pixel(float x, float y, float a);
82 class SketcherPenSlant : public SketcherVPen
85 SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
86 int draw_pixel(float x, float y, float a);
88 class SketcherPenXlant : public SketcherVPen
91 SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
92 int draw_pixel(float x, float y, float a);
102 void init(int id, int arc, coord x, coord y);
103 SketcherPoint(int id, int arc, coord x, coord y);
104 SketcherPoint(int id=-1);
105 SketcherPoint(SketcherPoint &pt);
107 int equivalent(SketcherPoint &that);
108 void copy_from(SketcherPoint &that);
109 void save_data(FileXML &output);
110 void read_data(FileXML &input);
111 static const char *types[ARC_SZ];
112 void update_parameter(SketcherPoint *the, SketcherPoint *src);
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, int flags);
144 void update_parameter(SketcherCurve *the, SketcherCurve *src);
146 class SketcherCurves : public ArrayList<SketcherCurve *>
150 ~SketcherCurves() { remove_all_objects(); }
159 void read_data(KeyFrame *keyframe);
160 void save_data(KeyFrame *keyframe);
162 SketcherCurves curves;
163 int equivalent(SketcherConfig &that);
164 void copy_from(SketcherConfig &that);
165 void interpolate(SketcherConfig &prev, SketcherConfig &next,
166 long prev_frame, long next_frame, long current_frame);
167 double nearest_point(int &ci, int &pi, coord x, coord y);
168 int new_curve(int pen, int width, int color);
175 class Sketcher : public PluginVClient
178 Sketcher(PluginServer *server);
180 PLUGIN_CLASS_MEMBERS2(SketcherConfig)
184 void render_gui(void *data);
186 void save_data(KeyFrame *keyframe);
187 void read_data(KeyFrame *keyframe);
188 void span_keyframes(KeyFrame *src, int64_t start, int64_t end);
189 void update_parameter(SketcherConfig &prev_config, SketcherConfig &src_config,
191 int new_curve(int pen, int width, int color);
193 int new_point(SketcherCurve *cv, int arc, coord x, coord y, int idx=-1);
194 int new_point(int idx, int arc);
195 int process_realtime(VFrame *input, VFrame *output);
196 static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
197 void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
199 VFrame *input, *output;
201 OverlayFrame *overlay_frame;
202 int w, h, color_model, bpp, comp;
203 int is_yuv, is_float;
205 int cv_selected, pt_selected;