c8f3be5fda3ea5d15db5195397935491a3815a1d
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / sketcher / sketcher.h
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21
22
23 #ifndef __SKETCHERS_H__
24 #define __SKETCHERS_H__
25
26 #include "pluginvclient.h"
27 #include "overlayframe.inc"
28 #include "vframe.h"
29
30 class Sketcher;
31
32 #define pt_type SketcherPoint::types
33 #define cv_pen SketcherCurve::pens
34 #define CV_COLOR WHITE
35
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 };
40 typedef float coord;
41
42 class SketcherVPen : public VFrame
43 {
44 public:
45         VFrame *vfrm;
46         int n;
47         uint8_t *msk;
48
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);
58         }
59         ~SketcherVPen() { delete [] msk; }
60
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));
64         }
65
66         virtual int draw_pixel(float x, float y, float a) = 0;
67         int draw_pixel(float x, float y, float frac, int axis);
68 };
69
70 class SketcherPenSquare : public SketcherVPen
71 {
72 public:
73         SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
74         int draw_pixel(float x, float y, float a);
75 };
76 class SketcherPenPlus : public SketcherVPen
77 {
78 public:
79         SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
80         int draw_pixel(float x, float y, float a);
81 };
82 class SketcherPenSlant : public SketcherVPen
83 {
84 public:
85         SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
86         int draw_pixel(float x, float y, float a);
87 };
88 class SketcherPenXlant : public SketcherVPen
89 {
90 public:
91         SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
92         int draw_pixel(float x, float y, float a);
93 };
94
95
96 class SketcherPoint
97 {
98 public:
99         int id, arc;
100         coord x, y;
101
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);
106         ~SketcherPoint();
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);
113 };
114 class SketcherPoints : public ArrayList<SketcherPoint *>
115 {
116 public:
117         SketcherPoints() {}
118         ~SketcherPoints() { remove_all_objects(); }
119         void dump();
120 };
121
122
123 class SketcherCurve
124 {
125 public:
126         int id, pen, width, color;
127         static const char *pens[PEN_SZ];
128
129         SketcherPoints points;
130
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);
134         ~SketcherCurve();
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);
141
142         SketcherVPen *new_vpen(VFrame *out);
143         void draw(VFrame *img, int flags);
144         void update_parameter(SketcherCurve *the, SketcherCurve *src);
145 };
146 class SketcherCurves : public ArrayList<SketcherCurve *>
147 {
148 public:
149         SketcherCurves() {}
150         ~SketcherCurves() { remove_all_objects(); }
151         void dump();
152 };
153
154 class SketcherConfig
155 {
156 public:
157         SketcherConfig();
158         ~SketcherConfig();
159         void read_data(KeyFrame *keyframe);
160         void save_data(KeyFrame *keyframe);
161
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         void limits();
169         void dump();
170
171         int drag;
172         int aliasing;
173         int cv_selected, pt_selected;
174 };
175
176 class Sketcher : public PluginVClient
177 {
178 public:
179         Sketcher(PluginServer *server);
180         ~Sketcher();
181         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
182         int is_realtime();
183         int is_synthesis();
184         void update_gui();
185         void save_data(KeyFrame *keyframe);
186         void read_data(KeyFrame *keyframe);
187         void span_keyframes(KeyFrame *src, int64_t start, int64_t end);
188         void update_parameter(SketcherConfig &prev_config, SketcherConfig &src_config,
189                 KeyFrame *keyframe);
190         int new_curve(int pen, int width, int color);
191         int new_curve();
192         int new_point(SketcherCurve *cv, int arc, coord x, coord y, int idx=-1);
193         int new_point(int idx, int arc);
194         int process_realtime(VFrame *input, VFrame *output);
195         static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
196         void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
197
198         VFrame *input, *output;
199         VFrame *img, *out;
200         OverlayFrame *overlay_frame;
201         int w, h, color_model, bpp, comp;
202         int is_yuv, is_float;
203 };
204
205 #endif