d0429cb1ffcd0eb7c97f03ff0e6253e7ef3ca636
[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
28 class Sketcher;
29
30 enum { PT_ID, PT_X, PT_Y, PT_SZ };
31 enum { CV_ID, CV_TY, CV_RAD, CV_PEN, CV_CLR, CV_SZ };
32 enum { TYP_OFF, TYP_SKETCHER, TYP_SMOOTH, TYP_SZ };
33 enum { PEN_SQUARE, PEN_PLUS, PEN_SLANT, PEN_XLANT, PEN_SZ };
34
35 class SketcherVPen : public VFrame
36 {
37 public:
38         SketcherVPen(VFrame *vfrm, int n)
39          : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
40             vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
41             vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
42             vfrm->get_bytes_per_line()) {
43                 this->vfrm = vfrm;  this->n = n;
44         }
45         virtual int draw_pixel(int x, int y) = 0;
46         VFrame *vfrm;
47         int n;
48 };
49
50 class SketcherPenSquare : public SketcherVPen
51 {
52 public:
53         SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
54         int draw_pixel(int x, int y);
55 };
56 class SketcherPenPlus : public SketcherVPen
57 {
58 public:
59         SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
60         int draw_pixel(int x, int y);
61 };
62 class SketcherPenSlant : public SketcherVPen
63 {
64 public:
65         SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
66         int draw_pixel(int x, int y);
67 };
68 class SketcherPenXlant : public SketcherVPen
69 {
70 public:
71         SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
72         int draw_pixel(int x, int y);
73 };
74
75
76 class SketcherPoint
77 {
78 public:
79         int id;
80         int x, y;
81
82         void init(int id, int x, int y);
83         SketcherPoint(int id, int x, int y);
84         SketcherPoint(int id=-1);
85         SketcherPoint(SketcherPoint &pt);
86         ~SketcherPoint();
87         int equivalent(SketcherPoint &that);
88         void copy_from(SketcherPoint &that);
89         void save_data(FileXML &output);
90         void read_data(FileXML &input);
91 };
92 class SketcherPoints : public ArrayList<SketcherPoint *>
93 {
94 public:
95         SketcherPoints() {}
96         ~SketcherPoints() { remove_all_objects(); }
97         void dump();
98 };
99
100 #define cv_type SketcherCurve::types
101 #define cv_pen SketcherCurve::pens
102
103 class SketcherCurve
104 {
105 public:
106         int id, ty, radius, pen, color;
107         static const char *types[TYP_SZ];
108         static const char *pens[PEN_SZ];
109
110         SketcherPoints points;
111
112         void init(int id, int ty, int radius, int pen, int color);
113         SketcherCurve(int id, int ty, int radius, int pen, int color);
114         SketcherCurve(int id=-1);
115         ~SketcherCurve();
116         SketcherCurve(SketcherCurve &cv);
117         int equivalent(SketcherCurve &that);
118         void copy_from(SketcherCurve &that);
119         void save_data(FileXML &output);
120         void read_data(FileXML &input);
121         VFrame *new_vpen(VFrame *out);
122         void draw_line(VFrame *out);
123         void draw_smooth(VFrame *out);
124 };
125 class SketcherCurves : public ArrayList<SketcherCurve *>
126 {
127 public:
128         SketcherCurves() {}
129         ~SketcherCurves() { remove_all_objects(); }
130         void dump();
131 };
132
133 class SketcherConfig
134 {
135 public:
136         SketcherConfig();
137         ~SketcherConfig();
138
139         SketcherCurves curves;
140         int equivalent(SketcherConfig &that);
141         void copy_from(SketcherConfig &that);
142         void interpolate(SketcherConfig &prev, SketcherConfig &next,
143                 long prev_frame, long next_frame, long current_frame);
144         void limits();
145
146         int drag;
147         int cv_selected, pt_selected;
148 };
149
150 class Sketcher : public PluginVClient
151 {
152 public:
153         Sketcher(PluginServer *server);
154         ~Sketcher();
155 // required for all realtime plugins
156         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
157         int is_realtime();
158         void update_gui();
159         void save_data(KeyFrame *keyframe);
160         void read_data(KeyFrame *keyframe);
161         int new_curve(int ty, int radius, int pen, int color);
162         int new_curve();
163         int new_point(SketcherCurve *cv, int x, int y);
164         int new_point();
165         int process_realtime(VFrame *input, VFrame *output);
166         static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
167         void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
168
169         VFrame *input, *output;
170         int w, h, color_model, bpp, comp;
171         int is_yuv, is_float;
172 };
173
174 #endif