]> git.vomp.tv Git - vompclient.git/blob - teletextdecodervbiebu.h
10 CWFs
[vompclient.git] / teletextdecodervbiebu.h
1 /*
2     Copyright 2008 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, see <https://www.gnu.org/licenses/>.
18 */
19 /* Portions from vdr osdteletext plugin "txtrender.c": */
20 /***************************************************************************
21  *                                                                         *
22  *   txtrender.h - Teletext display abstraction and teletext code          *
23  *                 renderer                                                *
24  *                                                                         *
25  *   This program is free software; you can redistribute it and/or modify  *
26  *   it under the terms of the GNU General Public License as published by  *
27  *   the Free Software Foundation; either version 2 of the License, or     *
28  *   (at your option) any later version.                                   *
29  *                                                                         *
30  *   Changelog:                                                            *
31  *     2005-03    initial version (c) Udo Richter                          *
32  *                                                                         *
33  ***************************************************************************/
34
35 #ifndef TXTDECVBIEBU_H
36 #define TXTDECVBIEBU_H
37
38 #include "draintarget.h"
39 #include "log.h"
40
41 /* from osdteletext begin */
42
43 // Teletext character sets
44 enum enumCharsets {
45     CHARSET_LATIN_G0          = 0x0000, // native latin (partially todo)
46     CHARSET_LATIN_G0_CZ_SK    = 0x0100, // Czech/Slovak (todo)
47     CHARSET_LATIN_G0_EN       = 0x0200, // English
48     CHARSET_LATIN_G0_EE       = 0x0300, // Estonian (todo)
49     CHARSET_LATIN_G0_FR       = 0x0400, // French
50     CHARSET_LATIN_G0_DE       = 0x0500, // German
51     CHARSET_LATIN_G0_IT       = 0x0600, // Italian
52     CHARSET_LATIN_G0_LV_LT    = 0x0700, // Lettish/Lithuanian (todo)
53     CHARSET_LATIN_G0_PL       = 0x0800, // Polish (todo)
54     CHARSET_LATIN_G0_PT_ES    = 0x0900, // Portugese/Spanish
55     CHARSET_LATIN_G0_RO       = 0x0A00, // Romanian (todo)
56     CHARSET_LATIN_G0_SR_HR_SL = 0x0B00, // Serbian/Croatian/Slovenian (todo)
57     CHARSET_LATIN_G0_SV_FI    = 0x0C00, // Swedish/Finnish
58     CHARSET_LATIN_G0_TR       = 0x0D00, // Turkish (todo)
59     CHARSET_LATIN_G2          = 0x0E00, // Latin G2 supplementary set (todo)
60     CHARSET_CYRILLIC_G0_SR_HR = 0x0F00, // Serbian/Croatian (todo)
61     CHARSET_CYRILLIC_G0_RU_BG = 0x1000, // Russian/Bulgarian (todo)
62     CHARSET_CYRILLIC_G0_UK    = 0x1100, // Ukrainian (todo)
63     CHARSET_CYRILLIC_G2       = 0x1200, // Cyrillic G2 Supplementary (todo)
64     CHARSET_GREEK_G0          = 0x1300, // Greek G0 (todo)
65     CHARSET_GREEK_G2          = 0x1400, // Greeek G2 (todo)
66     CHARSET_ARABIC_G0         = 0x1500, // Arabic G0 (todo)
67     CHARSET_ARABIC_G2         = 0x1600, // Arabic G2 (todo)
68     CHARSET_HEBREW_G0         = 0x1700, // Hebrew G0 (todo)
69     CHARSET_GRAPHICS_G1       = 0x1800, // G1 graphics set
70     CHARSET_GRAPHICS_G1_SEP   = 0x1900, // G1 graphics set, separated
71     CHARSET_GRAPHICS_G3       = 0x1A00, // G3 graphics set (todo)
72     CHARSET_INVALID           = 0x1F00  // no charset defined
73 };
74
75 // Macro to get the lowest non-0 bit position from a bit mask
76 // Should evaluate to const on a const mask
77 #define LowestSet2Bit(mask) ((mask)&0x0001?0:1)
78 #define LowestSet4Bit(mask) ((mask)&0x0003?LowestSet2Bit(mask):LowestSet2Bit((mask)>>2)+2)
79 #define LowestSet8Bit(mask) ((mask)&0x000f?LowestSet4Bit(mask):LowestSet4Bit((mask)>>4)+4)
80 #define LowestSet16Bit(mask) ((mask)&0x00ff?LowestSet8Bit(mask):LowestSet8Bit((mask)>>8)+8)
81 #define LowestSet32Bit(mask) ((mask)&0xffff?LowestSet16Bit(mask):LowestSet16Bit((mask)>>16)+16)
82
83
84 // Character modifcation double height:
85 enum enumDblHeight {
86     dblh_Normal=0x00000000, // normal height
87     dblh_Top   =0x04000000, // upper half character
88     dblh_Bottom=0x08000000  // lower half character
89 };
90 // Character modifcation double width:
91 enum enumDblWidth {
92     dblw_Normal=0x00000000, // normal width
93     dblw_Left  =0x10000000, // left half character
94     dblw_Right =0x20000000  // right half character
95 };
96
97 // Teletext colors
98 enum enumTeletextColor {
99     // level 1:
100     ttcBlack=0,
101     ttcRed=1,
102     ttcGreen=2,
103     ttcYellow=3,
104     ttcBlue=4,
105     ttcMagenta=5,
106     ttcCyan=6,
107     ttcWhite=7,
108     // level 2.5:
109     ttcTransparent=8,
110     ttcHalfRed=9,
111     ttcHalfGreen=10,
112     ttcHalfYellow=11,
113     ttcHalfBlue=12,
114     ttcHalfMagenta=13,
115     ttcHalfCyan=14,
116     ttcGrey=15,
117     // unnamed, level 2.5:
118     ttcColor16=16, ttcColor17=17, ttcColor18=18, ttcColor19=19,
119     ttcColor20=20, ttcColor21=21, ttcColor22=22, ttcColor23=23,
120     ttcColor24=24, ttcColor25=25, ttcColor26=26, ttcColor27=27,
121     ttcColor28=28, ttcColor29=29, ttcColor30=30, ttcColor31=31,
122     
123     ttcFirst=0, ttcLast=31
124 };
125 inline enumTeletextColor& operator++(enumTeletextColor& c) { return c=enumTeletextColor(int(c)+1); }
126 inline enumTeletextColor operator++(enumTeletextColor& c, int) { enumTeletextColor tmp(c); ++c; return tmp; }
127     
128 class cTeletextChar {
129     // Wrapper class that represents a teletext character,
130     // including colors and effects. Should optimize back
131     // to 4 byte unsigned int on compile.
132     
133 protected:
134     unsigned int c;
135
136     static const unsigned int CHAR             = 0x000000FF;
137     // character code
138     static const unsigned int CHARSET          = 0x00001F00;
139     // character set code, see below
140     static const unsigned int BOXOUT           = 0x00004000;
141     // 'boxed' mode hidden area
142     static const unsigned int DIRTY            = 0x00008000;
143     // 'dirty' bit - internal marker only
144     static const unsigned int FGCOLOR          = 0x001F0000;
145     // 5-bit foreground color code, 3 bit used for now
146     static const unsigned int BGCOLOR          = 0x03E00000;
147     // 5-bit background color code, 3 bit used for now
148     static const unsigned int DBLHEIGHT        = 0x0C000000;
149     // show double height
150     static const unsigned int DBLWIDTH         = 0x30000000;
151     // show double width (todo)
152     static const unsigned int CONCEAL          = 0x40000000;
153     // character concealed
154     static const unsigned int BLINK            = 0x80000000;
155     // blinking character
156
157     cTeletextChar(unsigned int cc) { c=cc; }
158
159 public:
160     cTeletextChar() { c=0; }
161     
162     // inline helper functions:
163     // For each parameter encoded into the 32-bit int, there is
164     // a Get...() to read, a Set...() to write, and a To...() to
165     // return a modified copy
166     
167     inline unsigned char GetChar() 
168         { return c&CHAR; }
169     inline void SetChar(unsigned char chr)
170         { c=(c&~CHAR)|chr; }
171     inline cTeletextChar ToChar(unsigned char chr)
172         { return cTeletextChar((c&~CHAR)|chr); }
173         
174     inline enumCharsets GetCharset() 
175         { return static_cast<enumCharsets>(c&CHARSET); }
176     inline void SetCharset(enumCharsets charset) 
177         { c=(c&~CHARSET)|charset; }
178     inline cTeletextChar ToCharset(enumCharsets charset) 
179         { return cTeletextChar((c&~CHARSET)|charset); }
180     
181     inline enumTeletextColor GetFGColor() 
182         { return static_cast<enumTeletextColor>((c&FGCOLOR) >> LowestSet32Bit(FGCOLOR)); }
183     inline void SetFGColor(enumTeletextColor fgc) 
184         { c=(c&~FGCOLOR) | (fgc << LowestSet32Bit(FGCOLOR)); }
185     inline cTeletextChar ToFGColor(enumTeletextColor fgc) 
186         { return cTeletextChar((c&~FGCOLOR) | (fgc << LowestSet32Bit(FGCOLOR))); }
187     
188     inline enumTeletextColor GetBGColor() 
189         { return static_cast<enumTeletextColor>((c&BGCOLOR) >> LowestSet32Bit(BGCOLOR)); }
190     inline void SetBGColor(enumTeletextColor bgc) 
191         { c=(c&~BGCOLOR) | (bgc << LowestSet32Bit(BGCOLOR)); }
192     inline cTeletextChar ToBGColor(enumTeletextColor bgc) 
193         { return cTeletextChar((c&~BGCOLOR) | (bgc << LowestSet32Bit(BGCOLOR))); }
194     
195     inline bool GetBoxedOut() 
196         { return c&BOXOUT; }
197     inline void SetBoxedOut(bool BoxedOut) 
198         { c=(BoxedOut)?(c|BOXOUT):(c&~BOXOUT); }
199     inline cTeletextChar ToBoxedOut(bool BoxedOut) 
200         { return cTeletextChar((BoxedOut)?(c|BOXOUT):(c&~BOXOUT)); }
201     
202     inline bool GetDirty() 
203         { return c&DIRTY; }
204     inline void SetDirty(bool Dirty) 
205         { c=(Dirty)?(c|DIRTY):(c&~DIRTY); }
206     inline cTeletextChar ToDirty(bool Dirty) 
207         { return cTeletextChar((Dirty)?(c|DIRTY):(c&~DIRTY)); }
208     
209     inline enumDblHeight GetDblHeight() 
210         { return static_cast<enumDblHeight>(c&DBLHEIGHT); }
211     inline void SetDblHeight(enumDblHeight dh) 
212         { c=(c&~(DBLHEIGHT)) | dh; }
213     inline cTeletextChar ToDblHeight(enumDblHeight dh) 
214         { return cTeletextChar((c&~(DBLHEIGHT)) | dh); }
215     
216     inline enumDblWidth GetDblWidth() 
217         { return static_cast<enumDblWidth>(c&DBLWIDTH); }
218     inline void SetDblWidth(enumDblWidth dw) 
219         { c=(c&~(DBLWIDTH)) | dw; }
220     inline cTeletextChar ToDblWidth(enumDblWidth dw) 
221         { return cTeletextChar((c&~(DBLWIDTH)) | dw); }
222     
223     inline bool GetConceal() 
224         { return c&CONCEAL; }
225     inline void SetConceal(bool Conceal) 
226         { c=(Conceal)?(c|CONCEAL):(c&~CONCEAL); }
227     inline cTeletextChar ToConceal(bool Conceal) 
228         { return cTeletextChar((Conceal)?(c|CONCEAL):(c&~CONCEAL)); }
229     
230     inline bool GetBlink() 
231         { return c&BLINK; }
232     inline void SetBlink(bool Blink) 
233         { c=(Blink)?(c|BLINK):(c&~BLINK); }
234     inline cTeletextChar ToBlink(bool Blink) 
235         { return cTeletextChar((Blink)?(c|BLINK):(c&~BLINK)); }
236     inline unsigned int getGlyphIndex() {
237         return c & (CHAR | CHARSET | DBLHEIGHT | DBLWIDTH);
238     };
239
240     inline void setInternal(unsigned int cc) {c=cc;};
241     inline unsigned int getInternal() {return c;};
242         
243     bool operator==(cTeletextChar &chr) { return c==chr.c; }
244     bool operator!=(cTeletextChar &chr) { return c!=chr.c; }
245 };
246 /* from osdteletext end*/
247
248 class VTeletextView;
249
250 /* Decoder of teletext matrial present in Data stream for VBI reinsertion more or less according to EBU specs*/ 
251 class TeletextDecoderVBIEBU: public DrainTarget {
252 public:
253     TeletextDecoderVBIEBU();
254     virtual ~TeletextDecoderVBIEBU();
255
256     virtual long long SetStartOffset(long long curreftime, bool *rsync);
257     virtual void ResetTimeOffsets();
258
259     void ResetDecoder();
260     void setKeyinDigits(char digits[3],bool inKeying);
261     void setPage(unsigned int newpage);
262     int getPage() {return selectedpage;};
263     void setRecordigMode(bool isrecord) {isrecording=isrecord;};
264     int *getSubtitlePages() {return record_pages;};
265
266
267     virtual void PrepareMediaSample(const MediaPacketList& mplist, UINT samplepos);
268     virtual UINT DeliverMediaSample(UCHAR* buffer, UINT *samplepos);
269
270     void registerTeletextView(VTeletextView* view) {txtview=view;};
271     void unRegisterTeletextView(VTeletextView* view) {if (txtview==view) txtview=NULL;};
272     VTeletextView* getTeletxtView() {return txtview;};
273
274     cTeletextChar getChar(int x, int y) {
275         // Read character content from page
276         if (x<0 || x>=40 || y<0 || y>=25) {
277             Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds read access to teletext page");
278             return cTeletextChar();
279         }
280         return Page[x][y].ToDirty(false);
281     }
282     bool isDirty(int x, int y) {
283         if (x<0 || x>=40 || y<0 || y>=25) {
284             Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds dirty access to teletext page");
285             return false;
286         }
287         return Page[x][y].GetDirty();
288     }
289     void setChar(int x, int y, cTeletextChar c) {
290         // Set character at given location
291         
292         if (x<0 || x>=40 || y<0 || y>=25) {
293             Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds write access to teletext page");
294             return;
295         }
296         if (getChar(x,y) != c) {
297             Page[x][y]=c.ToDirty(true);
298             dirty=true; 
299         }           
300     }
301
302
303 protected:
304     void DecodeTeletext(const UCHAR* buffer, unsigned int field);
305     void RenderTeletextCode(bool renderfirstlineonly);
306     void CleanPage();
307
308     int selectedpage;
309     int lang;
310     int flags;
311     UCHAR curpage[25][40]; //Line DataCache
312     cTeletextChar Page[40][25];
313     char keyindigits[3];
314
315
316     // Font Code pages
317     int FirstG0CodePage;  // 7-bit number, lower 3 bits ignored
318     int SecondG0CodePage; // 7-bit number
319  
320     bool ourpage;
321     bool dirty;
322     bool gotcha;
323     bool inkeying;
324     bool isrecording;
325     int record_pages[10];//Only 10 Pages per record;
326     unsigned int firstlineupdate;
327     VTeletextView *txtview;
328 private:
329     MediaPacket mediapacket;
330     
331     
332
333 };
334
335 #endif