File: vt.h

package info (click to toggle)
zapping 0.10~cvs6-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,856 kB
  • ctags: 11,841
  • sloc: ansic: 111,154; asm: 11,770; sh: 9,812; xml: 2,742; makefile: 1,283; perl: 488
file content (408 lines) | stat: -rw-r--r-- 9,314 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 *  libzvbi - Teletext decoder
 *
 *  Copyright (C) 2000, 2001, 2003, 2004 Michael H. Schimek
 *
 *  Based on code from AleVT 1.5.1
 *  Copyright (C) 1998, 1999 Edgar Toernig <froese@gmx.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: vt.h,v 1.39 2005/09/01 01:40:52 mschimek Exp $ */

#ifndef VT_H
#define VT_H

#include "bcd.h"		/* vbi3_pgno, vbi3_subno */
#include "lang.h"		/* vbi3_charset_code */
#include "page.h"		/* vbi3_color */

/**
 * @internal
 * EN 300 706, Section 9.4.2, Table 3 Page function.
 */
typedef enum {
	PAGE_FUNCTION_ACI		= -4,	/* libzvbi private */
	PAGE_FUNCTION_EPG		= -3,	/* libzvbi private */
	PAGE_FUNCTION_DISCARD		= -2,	/* libzvbi private */
	PAGE_FUNCTION_UNKNOWN		= -1,	/* libzvbi private */
	PAGE_FUNCTION_LOP		= 0,
	PAGE_FUNCTION_DATA,
	PAGE_FUNCTION_GPOP,
	PAGE_FUNCTION_POP,
	PAGE_FUNCTION_GDRCS,
	PAGE_FUNCTION_DRCS,
	PAGE_FUNCTION_MOT,
	PAGE_FUNCTION_MIP,
	PAGE_FUNCTION_BTT,
	PAGE_FUNCTION_AIT,
	PAGE_FUNCTION_MPT,
	PAGE_FUNCTION_MPT_EX,
	PAGE_FUNCTION_TRIGGER
} page_function;

extern const char *
page_function_name		(page_function		function);

/**
 * @internal
 * TOP BTT links to other TOP pages.
 * top_page_number() translates this to enum page_function.
 */
typedef enum {
	TOP_PAGE_FUNCTION_MPT = 1,
	TOP_PAGE_FUNCTION_AIT,
	TOP_PAGE_FUNCTION_MPT_EX,
} top_page_function;

/**
 * @internal
 * 9.4.2 Table 3 Page coding.
 */
typedef enum {
	PAGE_CODING_UNKNOWN = -1,	/**< libzvbi private */
	PAGE_CODING_ODD_PARITY,
	PAGE_CODING_UBYTES,
	PAGE_CODING_TRIPLETS,
	PAGE_CODING_HAMMING84,
	PAGE_CODING_AIT,
	/**
	 * First byte is a hamming 8/4 coded page_coding,
	 * describing remaining 39 bytes.
	 */
	PAGE_CODING_META84
} page_coding;

extern const char *
page_coding_name		(page_coding		coding);

/**
 * @internal
 * TOP BTT page type.
 * decode_btt_page() translates this to MIP page type
 * which is defined as enum vbi3_page_type in vbi.h.
 */
typedef enum {
	BTT_NO_PAGE = 0,
	BTT_SUBTITLE,
	/** S = single page */
	BTT_PROGR_INDEX_S,
	/** M = multi-page (number of subpages in MPT or MPT-EX) */
	BTT_PROGR_INDEX_M,
	BTT_BLOCK_S,
	BTT_BLOCK_M,
	BTT_GROUP_S,
	BTT_GROUP_M,
	BTT_NORMAL_S,
	BTT_NORMAL_9,		/**< ? */
	BTT_NORMAL_M,
	BTT_NORMAL_11,		/**< ? */
	BTT_12,			/**< ? */
	BTT_13,			/**< ? */
	BTT_14,			/**< ? */
	BTT_15			/**< ? */
} btt_page_type;

/**
 * @internal
 * 12.3.1 Table 28 Enhancement object type.
 */
typedef enum {
	LOCAL_ENHANCEMENT_DATA = 0,	/**< depends on context */
	OBJECT_TYPE_NONE = 0,
	OBJECT_TYPE_ACTIVE,
	OBJECT_TYPE_ADAPTIVE,
	OBJECT_TYPE_PASSIVE
} object_type;

extern const char *
object_type_name		(object_type		type);

/**
 * @internal
 * 14.2 Table 31, 9.4.6 Table 9 DRCS character coding.
 */
typedef enum {
	DRCS_MODE_12_10_1,
	DRCS_MODE_12_10_2,
	DRCS_MODE_12_10_4,
	DRCS_MODE_6_5_4,
	DRCS_MODE_SUBSEQUENT_PTU = 14,
	DRCS_MODE_NO_DATA
} drcs_mode;

extern const char *
drcs_mode_name			(drcs_mode		mode);

/** @internal */
#define DRCS_PTUS_PER_PAGE 48

/** @internal */
typedef struct {
	page_function		function;

	/** NO_PAGE (pgno) when unused or broken. */
	vbi3_pgno		pgno;

	/**
	 * X/27/4 ... 5 format 1 (struct lop.link[]):
	 * Set of subpages required: 1 << (0 ... 15).
	 * Otherwise subpage number or VBI3_NO_SUBNO.
	 */
	vbi3_subno		subno;
} pagenum;

/** @internal */
#define NO_PAGE(pgno) (((pgno) & 0xFF) == 0xFF)

extern void
pagenum_dump			(const pagenum *	pn,
				 FILE *			fp);

/* Level one page enhancement */

/**
 * @internal
 * 12.3.1 Packet X/26 code triplet.
 * Broken triplets are set to -1, -1, -1.
 */
typedef struct {
	unsigned	address		: 8;
	unsigned	mode		: 8;
	unsigned	data		: 8;
} /* __attribute__ ((packed)) */ triplet;

/** @internal */
typedef triplet enhancement[16 * 13 + 1];

/* Level one page extension */

/**
 * @internal
 * 9.4.2.2 X/28/0, X/28/4 and
 * 10.6.4 MOT POP link fallback flags.
 */
typedef struct {
	vbi3_bool	black_bg_substitution;

	int		left_panel_columns;
	int		right_panel_columns;
} ext_fallback;

/** @internal */
#define VBI3_TRANSPARENT_BLACK 8

/**
 * @internal
 * 9.4.2 Packet X/28
 * 9.5 Packet M/29
 */
typedef struct {
	/**
	 * We have data from packets X/28 (in lop) or M/29 (in magazine)
	 * with this set of designations. Magazine is always valid,
	 * LOP should fall back to magazine unless these bits are set:
	 *
	 * - 1 << 4 color_map[0 ... 15] is valid
	 * - 1 << 1 drcs_clut[] is valid
	 * - 1 << 0 or
	 *   1 << 4 everything else is valid.
	 */
	unsigned int		designations;

	/** Primary and secondary character set. */
	vbi3_charset_code	charset_code[2];

	/** Blah. */
	unsigned int		def_screen_color;
	unsigned int		def_row_color;

	/**
	 * Adding these values (0, 8, 16, 24) to character color
	 * 0 ... 7 gives index into color_map[] below.
	 */ 
	unsigned int		foreground_clut;
	unsigned int		background_clut;

	ext_fallback		fallback;

	/**
	 * - 2 dummy entries, 12x10x1 (G)DRCS use the color_map[]
	 *     like built-in chars.
	 * - 4 entries for 12x10x2 GDRCS pixel 0 ... 3 to color_map[].
	 * - 4 more for local DRCS
	 * - 16 entries for 12x10x4 and 6x5x4 GDRCS pixel 0 ... 15
	 *      to color_map[].
	 * - 16 more for local DRCS.
	 */
	vbi3_color		drcs_clut[2 + 2 * 4 + 2 * 16];

	/**
	 * CLUTs 0 ... 4 of 8 colors each. CLUT 2 & 3 are redefinable
	 * at Level 2.5, CLUT 0 to 3 at Level 3.5, except color_map[8]
	 * which is "transparent" color (VBI3_TRANSPARENT_BLACK).
	 * CLUT 4 contains libzvbi private colors which never change.
	 */
	vbi3_rgba		color_map[40];
} extension;

extern void
extension_dump			(const extension *	ext,
				 FILE *			fp);

/**
 * @internal
 *
 * 12.3.1 Table 28 Mode 10001, 10101 - Object invocation,
 * object definition. See also triplet_object_address().
 *
 * MOT default, POP and GPOP object address.
 *
 * n8  n7  n6  n5  n4  n3  n2  n1  n0
 * packet  triplet lsb ----- s1 -----
 */
typedef int object_address;

/** @internal */
typedef struct {
	pagenum			page;
	uint8_t			text[12];
} ait_title;

/* Level one page */

/**
 * @internal
 * 9.3.1.3 Control bits (0xE03F7F),
 * 15.2 National subset C12-C14,
 * B.6 Transmission rules for enhancement data.
 */
#define C4_ERASE_PAGE		0x000080
#define C5_NEWSFLASH		0x004000
#define C6_SUBTITLE		0x008000
#define C7_SUPPRESS_HEADER	0x010000
#define C8_UPDATE		0x020000
#define C9_INTERRUPTED		0x040000
#define C10_INHIBIT_DISPLAY	0x080000
#define C11_MAGAZINE_SERIAL	0x100000
#define C12_FRAGMENT		0x200000
#define C13_PARTIAL_PAGE	0x400000
#define C14_RESERVED		0x800000

/**
 * @internal
 * @brief Level one page.
 */
struct lop {
	/** Raw text as received. */
	uint8_t			raw[26][40];

	/** Packet X/27/0-5 links. */
	pagenum			link[6 * 6];

	/**
	 * Packet X/27 flag (ETR 287 section 10.4):
	 * Have FLOF navigation, display row 24.
	 */
	vbi3_bool		have_flof;
};

/* Magazine */

/**
 * @internal
 * 10.6.4 MOT object links
 */
typedef struct {
	vbi3_pgno		pgno;
	ext_fallback		fallback;
	struct {
		object_type		type;
		object_address		address;
	}			default_obj[2];
} pop_link;

/**
 * @internal
 * @brief Magazine defaults.
 */
typedef struct {
	/** Default extension. */
	extension		extension;

	/**
	 * Page number to pop_link[] and drcs_link[] for default
	 * object invocation. Valid range is 0 ... 7, broken -1.
	 */
	uint8_t			pop_lut[0x100];
	uint8_t			drcs_lut[0x100];

	/**
	 * Level 2.5 (0) or 3.5 (1), 1 global and 7 local links to
	 * POP/DRCS page. Unused or broken: NO_PAGE (pgno).
	 */
    	pop_link		pop_link[2][8];
	vbi3_pgno		drcs_link[2][8];
} magazine;

/* Network */

/** @inline */
#define SUBCODE_SINGLE_PAGE	0x0000
/** @inline */
#define SUBCODE_MULTI_PAGE	0xFFFE
/** @inline */
#define SUBCODE_UNKNOWN		0xFFFF

/** @inline */
typedef struct {
	/* Information gathered from MOT, MIP, BTT, G/POP pages. */

	/** Actually a vbi3_page_type. */
	uint8_t			page_type;

	/** Actually a vbi3_charset_code, 0xFF unknown. */
  	uint8_t			charset_code;

	/**
	 * Highest subpage number transmitted according to MOT, MIP, BTT.
	 * - 0x0000		single page (SUBCODE_SINGLE_PAGE)
	 * - 0x0002 - 0x0079	multi-page
	 * - 0x0080 - 0x3F7F	clock page, other pages with non-standard
	 *			subpages not to be cached
	 * - 0xFFFE		has 2+ subpages (libzvbi) (SUBCODE_MULTI_PAGE)
	 * - 0xFFFF		unknown (libzvbi) (SUBCODE_UNKNOWN)
	 */
	uint16_t 		subcode;

	/** Last received page flags (cache_page.flags) */
	uint32_t	       flags;

	/* Cache statistics. */

	/** Subpages cached now and ever. */
	uint8_t			n_subpages;
	uint8_t			max_subpages;

	/** Subpage numbers actually encountered (0x00 ... 0x79). */
	uint8_t			subno_min;
	uint8_t			subno_max;
} page_stat;

extern const magazine *
_vbi3_teletext_decoder_default_magazine (void);

#endif /* VT_H */