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