]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
End of line normalization
[vompclient.git] / osdvector.h
1 /*
2     Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef OSDVECTOR_H
22 #define OSDVECTOR_H
23 #include "osd.h"
24 #include "mutex.h"
25 #include "colour.h"
26 #include <list>
27 #include <map>
28 #include <string>
29
30 #include "teletextdecodervbiebu.h"
31
32 enum SVGCommandInstr {
33         DrawPath,
34         DrawGlyph,
35         DrawImage,
36         DrawTTchar
37 };
38 enum PathIndex {
39         HorzLine,
40         VertLine,
41         Rectangle,
42         Point
43 };
44
45 typedef  unsigned int ImageIndex;
46
47 class SVGCommand
48 {
49 public:
50         SVGCommand(float ix, float iy,float iw,float ih,PathIndex path,unsigned int ref)
51         {
52                 instr=DrawPath;
53                 x=ix;
54                 y=iy;
55                 w=iw;
56                 h=ih;
57                 target.path_index=path;
58                 reference=ref;
59         };
60         SVGCommand(float ix, float iy,float iw,float ih,ImageIndex image_in,unsigned int ref)
61         {
62                 instr=DrawImage;
63                 x=ix;
64                 y=iy;
65                 w=iw;
66                 h=ih;
67                 target.image=image_in;
68                 reference=ref;
69         };
70         SVGCommand(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
71         {
72                 instr=DrawTTchar;
73                 x=ix;
74                 y=iy;
75                 w=iw;
76                 h=ih;
77                 reference=0;
78                 target.ttchar=ttchar_in;
79         };
80         SVGCommand(float ix, float iy,wchar_t char_in,unsigned int ref)
81         {
82                 instr=DrawGlyph;
83                 x=ix;
84                 y=iy;
85                 w=0;
86                 h=0;
87                 reference=ref;
88                 target.textchar=char_in;
89         };
90
91         bool Test(float tx,float ty,float tw, float th)
92         {
93                 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
94         }
95         bool TTTest(float tox,float toy,float tx, float ty)
96         {
97                 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
98         }
99         unsigned int getRef(){return reference;};
100         ImageIndex getImageIndex() {
101                 if (instr!=DrawImage) return 0;
102                 else return target.image;
103         };
104         SVGCommandInstr instr;
105         float x,y,w,h;
106         unsigned int reference;
107         union {
108                 PathIndex path_index; //path_index
109                 wchar_t textchar;
110                 ImageIndex image;
111                 unsigned int ttchar;
112         } target;
113 };
114
115 class SurfaceVector;
116
117 struct SurfaceCommands{
118         const SurfaceVector* surf;
119         list<SVGCommand> commands;
120         float x,y,w,h;
121 };
122
123
124 class OsdVector : public Osd
125 {
126   public:
127     OsdVector();
128     virtual ~OsdVector();
129
130
131     int restore();
132
133     int getFD();
134
135     void screenShot(const char* fileName);
136
137     Surface * createNewSurface();
138         void BeginPainting();
139         void EndPainting();
140
141         void Blank();
142
143         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
144                         list<SVGCommand>& commands);
145         void removeSurface(const SurfaceVector *surf);
146
147         virtual float getFontHeight()=0;
148         virtual float getCharWidth(wchar_t c)=0;
149
150         virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
151         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
152         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
153         virtual void imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)=0;
154         void removeImageRef(const ImageIndex ref);
155         unsigned int getColorRef(const Colour &c); //internally this is the same as getStyleRef
156         unsigned int getStyleRef(const DrawStyle &c);
157         virtual void removeStyleRef(unsigned int ref);
158
159
160     int charSet() {return 2;}; //UTF-8
161
162
163
164 protected:
165
166         void incImageRef(ImageIndex index);
167         unsigned int getImageRef(ImageIndex index);
168         virtual void destroyImageRef(ImageIndex index)=0;
169         virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
170         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
171         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
172
173         map<ImageIndex,unsigned int> images_ref;
174         map<void *,ImageIndex> monobitmaps;
175         map<string,ImageIndex> jpegs;
176
177         void incStyleRef(unsigned int index);
178         unsigned int getStyleRef(ImageIndex index);
179         virtual void destroyStyleRef(unsigned int index)=0;
180         map<pair<Colour*,unsigned int>,unsigned int> styles;
181         map<unsigned int,unsigned int> styles_ref;
182         virtual unsigned int createStyleRef(const DrawStyle &c)=0;
183         virtual unsigned int createColorRef(const Colour &c)=0;
184
185         void dereferenceSVGCommand(list<SVGCommand>& commands );
186         void referenceSVGCommand(list<SVGCommand>& commands );
187         void cleanupOrphanedRefs();
188
189
190
191         virtual void drawSetTrans(SurfaceCommands & sc)=0;
192         virtual void executeDrawCommand(SVGCommand & command)=0;
193
194
195
196
197         list<SurfaceCommands> scommands;
198
199         Mutex surfaces_mutex;
200
201         void drawSurfaces();
202 };
203
204
205
206
207 #endif