add stacked edl editing, add sketcher/vframe line anti-aliasing
[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 };
113 class SketcherPoints : public ArrayList<SketcherPoint *>
114 {
115 public:
116         SketcherPoints() {}
117         ~SketcherPoints() { remove_all_objects(); }
118         void dump();
119 };
120
121
122 class SketcherCurve
123 {
124 public:
125         int id, pen, width, color;
126         static const char *pens[PEN_SZ];
127
128         SketcherPoints points;
129
130         void init(int id, int pen, int width, int color);
131         SketcherCurve(int id, int pen, int width, int color);
132         SketcherCurve(int id=-1);
133         ~SketcherCurve();
134         SketcherCurve(SketcherCurve &cv);
135         int equivalent(SketcherCurve &that);
136         void copy_from(SketcherCurve &that);
137         void save_data(FileXML &output);
138         void read_data(FileXML &input);
139         double nearest_point(int &pi, coord x, coord y);
140
141         SketcherVPen *new_vpen(VFrame *out);
142         void draw(VFrame *img, int flags);
143 };
144 class SketcherCurves : public ArrayList<SketcherCurve *>
145 {
146 public:
147         SketcherCurves() {}
148         ~SketcherCurves() { remove_all_objects(); }
149         void dump();
150 };
151
152 class SketcherConfig
153 {
154 public:
155         SketcherConfig();
156         ~SketcherConfig();
157
158         SketcherCurves curves;
159         int equivalent(SketcherConfig &that);
160         void copy_from(SketcherConfig &that);
161         void interpolate(SketcherConfig &prev, SketcherConfig &next,
162                 long prev_frame, long next_frame, long current_frame);
163         double nearest_point(int &ci, int &pi, coord x, coord y);
164         void limits();
165         void dump();
166
167         int drag;
168         int aliasing;
169         int cv_selected, pt_selected;
170 };
171
172 class Sketcher : public PluginVClient
173 {
174 public:
175         Sketcher(PluginServer *server);
176         ~Sketcher();
177         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
178         int is_realtime();
179         int is_synthesis();
180         void update_gui();
181         void save_data(KeyFrame *keyframe);
182         void read_data(KeyFrame *keyframe);
183         int new_curve(int pen, int width, int color);
184         int new_curve();
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);
190
191         VFrame *input, *output;
192         VFrame *img, *out;
193         OverlayFrame *overlay_frame;
194         int w, h, color_model, bpp, comp;
195         int is_yuv, is_float;
196 };
197
198 #endif