~ubuntu-branches/ubuntu/maverick/zapping/maverick

« back to all changes in this revision

Viewing changes to libvbi/exp-vtx.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-03-08 23:19:08 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050308231908-oip7rfv6lcmo8c0e
Tags: 0.9.2-2ubuntu1
Rebuilt for Python transition (2.3 -> 2.4)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  libzvbi - VTX export function
 
3
 *
 
4
 *  Copyright (C) 2001, 2002, 2003, 2004 Michael H. Schimek
 
5
 *
 
6
 *  Based on code from AleVT 1.5.1
 
7
 *  Copyright (C) 1998, 1999 Edgar Toernig <froese@gmx.de>
 
8
 *  Copyright (C) 1999 Paul Ortyl <ortylp@from.pl>
 
9
 *
 
10
 *  Based on code from VideoteXt 0.6
 
11
 *  Copyright (C) 1995, 1996, 1997 Martin Buck
 
12
 *    <martin-2.buck@student.uni-ulm.de>
 
13
 *
 
14
 *  This program is free software; you can redistribute it and/or modify
 
15
 *  it under the terms of the GNU General Public License as published by
 
16
 *  the Free Software Foundation; either version 2 of the License, or
 
17
 *  (at your option) any later version.
 
18
 *
 
19
 *  This program is distributed in the hope that it will be useful,
 
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 *  GNU General Public License for more details.
 
23
 *
 
24
 *  You should have received a copy of the GNU General Public License
 
25
 *  along with this program; if not, write to the Free Software
 
26
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
27
 */
 
28
 
 
29
/* $Id: exp-vtx.c,v 1.12 2005/01/19 04:17:54 mschimek Exp $ */
 
30
 
 
31
/* VTX is the file format used by the VideoteXt application. It stores
 
32
   Teletext pages in raw level 1.0 format. Level 1.5 additional characters
 
33
   (e.g. accents), the FLOF and TOP navigation bars and the level 2.5
 
34
   chrome will be lost.
 
35
 
 
36
   Since restoring the raw page from a fmt_page is complicated we violate
 
37
   encapsulation by fetching a raw copy from the cache. :-( */
 
38
 
 
39
#ifdef HAVE_CONFIG_H
 
40
#  include "config.h"
 
41
#endif
 
42
 
 
43
#include <assert.h>
 
44
#include <inttypes.h>
 
45
 
 
46
#include "hamm.h"               /* vbi3_rev8() */
 
47
#include "cache-priv.h"         /* cache_page */
 
48
#include "page-priv.h"          /* vbi3_page_priv */
 
49
#include "common/intl-priv.h"
 
50
#include "export-priv.h"
 
51
 
 
52
struct header {
 
53
        uint8_t                 signature[5];
 
54
        uint8_t                 pagenum_l;
 
55
        uint8_t                 pagenum_h;
 
56
        uint8_t                 hour;
 
57
        uint8_t                 minute;
 
58
        uint8_t                 charset;
 
59
        uint8_t                 wst_flags;
 
60
        uint8_t                 vtx_flags;
 
61
};
 
62
 
 
63
/*
 
64
 *  VTX - VideoteXt File (VTXV4)
 
65
 */
 
66
 
 
67
static vbi3_bool
 
68
export                          (vbi3_export *          e,
 
69
                                 const vbi3_page *      pg)
 
70
{
 
71
        const vbi3_page_priv *pgp;
 
72
        const cache_page *cp;
 
73
        struct header h;
 
74
 
 
75
        if (pg->pgno < 0x100 || pg->pgno > 0x8FF) {
 
76
                _vbi3_export_error_printf
 
77
                        (e, _("Can only export Teletext pages."));
 
78
                return FALSE;
 
79
        }
 
80
 
 
81
        pgp = CONST_PARENT (pg, vbi3_page_priv, pg);
 
82
 
 
83
        if (pg->priv != pgp || !pgp->cp) {
 
84
                _vbi3_export_error_printf (e, _("Page is not cached."));
 
85
                return FALSE;
 
86
        }
 
87
 
 
88
        cp = pgp->cp;
 
89
 
 
90
        if (cp->function != PAGE_FUNCTION_UNKNOWN
 
91
            && cp->function != PAGE_FUNCTION_LOP) {
 
92
                _vbi3_export_error_printf
 
93
                        (e, _("Cannot export this page, is not displayable."));
 
94
                goto error;
 
95
        }
 
96
 
 
97
        memcpy (h.signature, "VTXV4", 5);
 
98
 
 
99
        h.pagenum_l = cp->pgno & 0xFF;
 
100
        h.pagenum_h = (cp->pgno >> 8) & 15;
 
101
 
 
102
        h.hour = 0;
 
103
        h.minute = 0;
 
104
 
 
105
        h.charset = cp->national & 7;
 
106
 
 
107
        h.wst_flags = cp->flags & C4_ERASE_PAGE;
 
108
        h.wst_flags |= vbi3_rev8 (cp->flags >> 12);
 
109
        h.vtx_flags = (0 << 7) | (0 << 6) | (0 << 5) | (0 << 4) | (0 << 3);
 
110
        /* notfound, pblf (?), hamming error, virtual, seven bits */
 
111
 
 
112
        if (fwrite (&h, sizeof (h), 1, e->fp) != 1)
 
113
                goto write_error;
 
114
 
 
115
        if (fwrite (cp->data.lop.raw, 40 * 24, 1, e->fp) != 1)
 
116
                goto write_error;
 
117
 
 
118
        return TRUE;
 
119
 
 
120
 write_error:
 
121
        _vbi3_export_write_error (e);
 
122
 
 
123
 error:
 
124
        return FALSE;
 
125
}
 
126
 
 
127
static const vbi3_export_info
 
128
export_info = {
 
129
        .keyword                = "vtx",
 
130
        .label                  = N_("VTX"),
 
131
        .tooltip                = N_("Export this page as VTX file, the "
 
132
                                     "format used by VideoteXt and vbidecode"),
 
133
 
 
134
        /* From VideoteXt examples/mime.types */
 
135
        .mime_type              = "application/videotext",
 
136
        .extension              = "vtx",
 
137
};
 
138
 
 
139
const _vbi3_export_module
 
140
_vbi3_export_module_vtx = {
 
141
        .export_info            = &export_info,
 
142
 
 
143
        /* no private data, no options */
 
144
 
 
145
        .export                 = export
 
146
};