443e8e9134abc8f25826566236a713233d7735a9
[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_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 };
40
41 class SketcherVPen : public VFrame
42 {
43 public:
44         VFrame *vfrm;
45         int n;
46         uint8_t *msk;
47
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);
56         }
57         ~SketcherVPen() { delete [] msk; }
58
59         virtual int draw_pixel(int x, int y) = 0;
60 };
61
62 class SketcherPenSquare : public SketcherVPen
63 {
64 public:
65         SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
66         int draw_pixel(int x, int y);
67 };
68 class SketcherPenPlus : public SketcherVPen
69 {
70 public:
71         SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
72         int draw_pixel(int x, int y);
73 };
74 class SketcherPenSlant : public SketcherVPen
75 {
76 public:
77         SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
78         int draw_pixel(int x, int y);
79 };
80 class SketcherPenXlant : public SketcherVPen
81 {
82 public:
83         SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
84         int draw_pixel(int x, int y);
85 };
86
87
88 class SketcherPoint
89 {
90 public:
91         int id, pty;
92         int x, y;
93
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);
98         ~SketcherPoint();
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];
104 };
105 class SketcherPoints : public ArrayList<SketcherPoint *>
106 {
107 public:
108         SketcherPoints() {}
109         ~SketcherPoints() { remove_all_objects(); }
110         void dump();
111 };
112
113
114 class SketcherCurve
115 {
116 public:
117         int id, pen, radius, color;
118         static const char *pens[PEN_SZ];
119
120         SketcherPoints points;
121
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);
125         ~SketcherCurve();
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);
132
133         SketcherVPen *new_vpen(VFrame *out);
134         void draw(VFrame *img);
135 };
136 class SketcherCurves : public ArrayList<SketcherCurve *>
137 {
138 public:
139         SketcherCurves() {}
140         ~SketcherCurves() { remove_all_objects(); }
141         void dump();
142 };
143
144 class SketcherConfig
145 {
146 public:
147         SketcherConfig();
148         ~SketcherConfig();
149
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);
156         void limits();
157         void dump();
158
159         int drag;
160         int cv_selected, pt_selected;
161 };
162
163 class Sketcher : public PluginVClient
164 {
165 public:
166         Sketcher(PluginServer *server);
167         ~Sketcher();
168         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
169         int is_realtime();
170         void update_gui();
171         void save_data(KeyFrame *keyframe);
172         void read_data(KeyFrame *keyframe);
173         int new_curve(int pen, int radius, int color);
174         int new_curve();
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);
180
181         VFrame *input, *output;
182         VFrame *img, *out;
183         OverlayFrame *overlay_frame;
184         int w, h, color_model, bpp, comp;
185         int is_yuv, is_float;
186 };
187
188 #endif