2 Copyright 2008 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 /* Portions from vdr osdteletext plugin "txtrender.c": */
\r
21 /***************************************************************************
\r
23 * txtrender.h - Teletext display abstraction and teletext code *
\r
26 * This program is free software; you can redistribute it and/or modify *
\r
27 * it under the terms of the GNU General Public License as published by *
\r
28 * the Free Software Foundation; either version 2 of the License, or *
\r
29 * (at your option) any later version. *
\r
32 * 2005-03 initial version (c) Udo Richter *
\r
34 ***************************************************************************/
\r
36 #ifndef TXTDECVBIEBU_H
\r
37 #define TXTDECVBIEBU_H
\r
39 #include "draintarget.h"
\r
42 /* from osdteletext begin */
\r
44 // Teletext character sets
\r
46 CHARSET_LATIN_G0 = 0x0000, // native latin (partially todo)
\r
47 CHARSET_LATIN_G0_CZ_SK = 0x0100, // Czech/Slovak (todo)
\r
48 CHARSET_LATIN_G0_EN = 0x0200, // English
\r
49 CHARSET_LATIN_G0_EE = 0x0300, // Estonian (todo)
\r
50 CHARSET_LATIN_G0_FR = 0x0400, // French
\r
51 CHARSET_LATIN_G0_DE = 0x0500, // German
\r
52 CHARSET_LATIN_G0_IT = 0x0600, // Italian
\r
53 CHARSET_LATIN_G0_LV_LT = 0x0700, // Lettish/Lithuanian (todo)
\r
54 CHARSET_LATIN_G0_PL = 0x0800, // Polish (todo)
\r
55 CHARSET_LATIN_G0_PT_ES = 0x0900, // Portugese/Spanish
\r
56 CHARSET_LATIN_G0_RO = 0x0A00, // Romanian (todo)
\r
57 CHARSET_LATIN_G0_SR_HR_SL = 0x0B00, // Serbian/Croatian/Slovenian (todo)
\r
58 CHARSET_LATIN_G0_SV_FI = 0x0C00, // Swedish/Finnish
\r
59 CHARSET_LATIN_G0_TR = 0x0D00, // Turkish (todo)
\r
60 CHARSET_LATIN_G2 = 0x0E00, // Latin G2 supplementary set (todo)
\r
61 CHARSET_CYRILLIC_G0_SR_HR = 0x0F00, // Serbian/Croatian (todo)
\r
62 CHARSET_CYRILLIC_G0_RU_BG = 0x1000, // Russian/Bulgarian (todo)
\r
63 CHARSET_CYRILLIC_G0_UK = 0x1100, // Ukrainian (todo)
\r
64 CHARSET_CYRILLIC_G2 = 0x1200, // Cyrillic G2 Supplementary (todo)
\r
65 CHARSET_GREEK_G0 = 0x1300, // Greek G0 (todo)
\r
66 CHARSET_GREEK_G2 = 0x1400, // Greeek G2 (todo)
\r
67 CHARSET_ARABIC_G0 = 0x1500, // Arabic G0 (todo)
\r
68 CHARSET_ARABIC_G2 = 0x1600, // Arabic G2 (todo)
\r
69 CHARSET_HEBREW_G0 = 0x1700, // Hebrew G0 (todo)
\r
70 CHARSET_GRAPHICS_G1 = 0x1800, // G1 graphics set
\r
71 CHARSET_GRAPHICS_G1_SEP = 0x1900, // G1 graphics set, separated
\r
72 CHARSET_GRAPHICS_G3 = 0x1A00, // G3 graphics set (todo)
\r
73 CHARSET_INVALID = 0x1F00 // no charset defined
\r
76 // Macro to get the lowest non-0 bit position from a bit mask
\r
77 // Should evaluate to const on a const mask
\r
78 #define LowestSet2Bit(mask) ((mask)&0x0001?0:1)
\r
79 #define LowestSet4Bit(mask) ((mask)&0x0003?LowestSet2Bit(mask):LowestSet2Bit((mask)>>2)+2)
\r
80 #define LowestSet8Bit(mask) ((mask)&0x000f?LowestSet4Bit(mask):LowestSet4Bit((mask)>>4)+4)
\r
81 #define LowestSet16Bit(mask) ((mask)&0x00ff?LowestSet8Bit(mask):LowestSet8Bit((mask)>>8)+8)
\r
82 #define LowestSet32Bit(mask) ((mask)&0xffff?LowestSet16Bit(mask):LowestSet16Bit((mask)>>16)+16)
\r
85 // Character modifcation double height:
\r
86 enum enumDblHeight {
\r
87 dblh_Normal=0x00000000, // normal height
\r
88 dblh_Top =0x04000000, // upper half character
\r
89 dblh_Bottom=0x08000000 // lower half character
\r
91 // Character modifcation double width:
\r
93 dblw_Normal=0x00000000, // normal width
\r
94 dblw_Left =0x10000000, // left half character
\r
95 dblw_Right =0x20000000 // right half character
\r
99 enum enumTeletextColor {
\r
118 // unnamed, level 2.5:
\r
119 ttcColor16=16, ttcColor17=17, ttcColor18=18, ttcColor19=19,
\r
120 ttcColor20=20, ttcColor21=21, ttcColor22=22, ttcColor23=23,
\r
121 ttcColor24=24, ttcColor25=25, ttcColor26=26, ttcColor27=27,
\r
122 ttcColor28=28, ttcColor29=29, ttcColor30=30, ttcColor31=31,
\r
124 ttcFirst=0, ttcLast=31
\r
126 inline enumTeletextColor& operator++(enumTeletextColor& c) { return c=enumTeletextColor(int(c)+1); }
\r
127 inline enumTeletextColor operator++(enumTeletextColor& c, int) { enumTeletextColor tmp(c); ++c; return tmp; }
\r
129 class cTeletextChar {
\r
130 // Wrapper class that represents a teletext character,
\r
131 // including colors and effects. Should optimize back
\r
132 // to 4 byte unsigned int on compile.
\r
137 static const unsigned int CHAR = 0x000000FF;
\r
139 static const unsigned int CHARSET = 0x00001F00;
\r
140 // character set code, see below
\r
141 static const unsigned int BOXOUT = 0x00004000;
\r
142 // 'boxed' mode hidden area
\r
143 static const unsigned int DIRTY = 0x00008000;
\r
144 // 'dirty' bit - internal marker only
\r
145 static const unsigned int FGCOLOR = 0x001F0000;
\r
146 // 5-bit foreground color code, 3 bit used for now
\r
147 static const unsigned int BGCOLOR = 0x03E00000;
\r
148 // 5-bit background color code, 3 bit used for now
\r
149 static const unsigned int DBLHEIGHT = 0x0C000000;
\r
150 // show double height
\r
151 static const unsigned int DBLWIDTH = 0x30000000;
\r
152 // show double width (todo)
\r
153 static const unsigned int CONCEAL = 0x40000000;
\r
154 // character concealed
\r
155 static const unsigned int BLINK = 0x80000000;
\r
156 // blinking character
\r
158 cTeletextChar(unsigned int cc) { c=cc; }
\r
161 cTeletextChar() { c=0; }
\r
163 // inline helper functions:
\r
164 // For each parameter encoded into the 32-bit int, there is
\r
165 // a Get...() to read, a Set...() to write, and a To...() to
\r
166 // return a modified copy
\r
168 inline unsigned char GetChar()
\r
170 inline void SetChar(unsigned char chr)
\r
171 { c=(c&~CHAR)|chr; }
\r
172 inline cTeletextChar ToChar(unsigned char chr)
\r
173 { return cTeletextChar((c&~CHAR)|chr); }
\r
175 inline enumCharsets GetCharset()
\r
176 { return (enumCharsets)(c&CHARSET); }
\r
177 inline void SetCharset(enumCharsets charset)
\r
178 { c=(c&~CHARSET)|charset; }
\r
179 inline cTeletextChar ToCharset(enumCharsets charset)
\r
180 { return cTeletextChar((c&~CHARSET)|charset); }
\r
182 inline enumTeletextColor GetFGColor()
\r
183 { return (enumTeletextColor)((c&FGCOLOR) >> LowestSet32Bit(FGCOLOR)); }
\r
184 inline void SetFGColor(enumTeletextColor fgc)
\r
185 { c=(c&~FGCOLOR) | (fgc << LowestSet32Bit(FGCOLOR)); }
\r
186 inline cTeletextChar ToFGColor(enumTeletextColor fgc)
\r
187 { return cTeletextChar((c&~FGCOLOR) | (fgc << LowestSet32Bit(FGCOLOR))); }
\r
189 inline enumTeletextColor GetBGColor()
\r
190 { return (enumTeletextColor)((c&BGCOLOR) >> LowestSet32Bit(BGCOLOR)); }
\r
191 inline void SetBGColor(enumTeletextColor bgc)
\r
192 { c=(c&~BGCOLOR) | (bgc << LowestSet32Bit(BGCOLOR)); }
\r
193 inline cTeletextChar ToBGColor(enumTeletextColor bgc)
\r
194 { return cTeletextChar((c&~BGCOLOR) | (bgc << LowestSet32Bit(BGCOLOR))); }
\r
196 inline bool GetBoxedOut()
\r
197 { return c&BOXOUT; }
\r
198 inline void SetBoxedOut(bool BoxedOut)
\r
199 { c=(BoxedOut)?(c|BOXOUT):(c&~BOXOUT); }
\r
200 inline cTeletextChar ToBoxedOut(bool BoxedOut)
\r
201 { return cTeletextChar((BoxedOut)?(c|BOXOUT):(c&~BOXOUT)); }
\r
203 inline bool GetDirty()
\r
204 { return c&DIRTY; }
\r
205 inline void SetDirty(bool Dirty)
\r
206 { c=(Dirty)?(c|DIRTY):(c&~DIRTY); }
\r
207 inline cTeletextChar ToDirty(bool Dirty)
\r
208 { return cTeletextChar((Dirty)?(c|DIRTY):(c&~DIRTY)); }
\r
210 inline enumDblHeight GetDblHeight()
\r
211 { return (enumDblHeight)(c&DBLHEIGHT); }
\r
212 inline void SetDblHeight(enumDblHeight dh)
\r
213 { c=(c&~(DBLHEIGHT)) | dh; }
\r
214 inline cTeletextChar ToDblHeight(enumDblHeight dh)
\r
215 { return cTeletextChar((c&~(DBLHEIGHT)) | dh); }
\r
217 inline enumDblWidth GetDblWidth()
\r
218 { return (enumDblWidth)(c&DBLWIDTH); }
\r
219 inline void SetDblWidth(enumDblWidth dw)
\r
220 { c=(c&~(DBLWIDTH)) | dw; }
\r
221 inline cTeletextChar ToDblWidth(enumDblWidth dw)
\r
222 { return cTeletextChar((c&~(DBLWIDTH)) | dw); }
\r
224 inline bool GetConceal()
\r
225 { return c&CONCEAL; }
\r
226 inline void SetConceal(bool Conceal)
\r
227 { c=(Conceal)?(c|CONCEAL):(c&~CONCEAL); }
\r
228 inline cTeletextChar ToConceal(bool Conceal)
\r
229 { return cTeletextChar((Conceal)?(c|CONCEAL):(c&~CONCEAL)); }
\r
231 inline bool GetBlink()
\r
232 { return c&BLINK; }
\r
233 inline void SetBlink(bool Blink)
\r
234 { c=(Blink)?(c|BLINK):(c&~BLINK); }
\r
235 inline cTeletextChar ToBlink(bool Blink)
\r
236 { return cTeletextChar((Blink)?(c|BLINK):(c&~BLINK)); }
\r
238 bool operator==(cTeletextChar &chr) { return c==chr.c; }
\r
239 bool operator!=(cTeletextChar &chr) { return c!=chr.c; }
\r
241 /* from osdteletext end*/
\r
243 class VTeletextView;
\r
245 /* Decoder of teletext matrial present in Data stream for VBI reinsertion more or less according to EBU specs*/
\r
246 class TeletextDecoderVBIEBU: public DrainTarget {
\r
248 TeletextDecoderVBIEBU();
\r
249 virtual ~TeletextDecoderVBIEBU();
\r
251 virtual long long SetStartOffset(long long curreftime, bool *rsync);
\r
252 virtual void ResetTimeOffsets();
\r
254 void ResetDecoder();
\r
255 void setKeyinDigits(char digits[3],bool inKeying);
\r
256 void setPage(unsigned int newpage);
\r
257 int getPage() {return selectedpage;};
\r
258 void setRecordigMode(bool isrecord) {isrecording=isrecord;};
\r
259 int *getSubtitlePages() {return record_pages;};
\r
262 virtual void PrepareMediaSample(const MediaPacketList& mplist, UINT samplepos);
\r
263 virtual UINT DeliverMediaSample(const UCHAR* buffer, UINT *samplepos);
\r
265 void registerTeletextView(VTeletextView* view) {txtview=view;};
\r
266 void unRegisterTeletextView(VTeletextView* view) {if (txtview==view) txtview=NULL;};
\r
267 VTeletextView* getTeletxtView() {return txtview;};
\r
269 cTeletextChar getChar(int x, int y) {
\r
270 // Read character content from page
\r
271 if (x<0 || x>=40 || y<0 || y>=25) {
\r
272 Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds read access to teletext page");
\r
273 return cTeletextChar();
\r
275 return Page[x][y].ToDirty(false);
\r
277 bool isDirty(int x, int y) {
\r
278 if (x<0 || x>=40 || y<0 || y>=25) {
\r
279 Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds dirty access to teletext page");
\r
282 return Page[x][y].GetDirty();
\r
284 void setChar(int x, int y, cTeletextChar c) {
\r
285 // Set character at given location
\r
287 if (x<0 || x>=40 || y<0 || y>=25) {
\r
288 Log::getInstance()->log("TeletextDecoderVBIEBU", Log::DEBUG, "Warning: out of bounds write access to teletext page");
\r
291 if (getChar(x,y) != c) {
\r
292 Page[x][y]=c.ToDirty(true);
\r
299 void DecodeTeletext(const UCHAR* buffer, unsigned int field);
\r
300 void RenderTeletextCode(bool renderfirstlineonly);
\r
306 UCHAR curpage[25][40]; //Line DataCache
\r
307 cTeletextChar Page[40][25];
\r
308 char keyindigits[3];
\r
312 int FirstG0CodePage; // 7-bit number, lower 3 bits ignored
\r
313 int SecondG0CodePage; // 7-bit number
\r
320 int record_pages[10];//Only 10 Pages per record;
\r
321 unsigned int firstlineupdate;
\r
322 VTeletextView *txtview;
\r
324 MediaPacket mediapacket;
\r