]> git.sesse.net Git - vlc/blob - modules/codec/ogt/subtitle.h
* modules/codec/ogt/*: win32 compilation fixes.
[vlc] / modules / codec / ogt / subtitle.h
1 /*****************************************************************************
2  * subtitle.h : Common SVCD and CVD subtitles header
3  *****************************************************************************
4  * Copyright (C) 2003,2004 VideoLAN
5  * $Id: subtitle.h,v 1.5 2004/01/04 22:22:10 gbazin Exp $
6  *
7  * Author: Rocky Bernstein
8  *   based on code from:
9  *       Julio Sanchez Fernandez (http://subhandler.sourceforge.net)
10  *       Sam Hocevar <sam@zoy.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 #define DECODE_DBG_EXT         1 /* Calls from external routines */
28 #define DECODE_DBG_CALL        2 /* all calls */
29 #define DECODE_DBG_PACKET      4 /* packet assembly info */
30 #define DECODE_DBG_IMAGE       8 /* image bitmaps */
31 #define DECODE_DBG_TRANSFORM  16 /* bitmap transformations */
32 #define DECODE_DBG_RENDER     32 /* rendering information */
33 #define DECODE_DBG_PNG        64 /* Extract subtitles to PNG files. */
34 #define DECODE_DBG_INFO      128
35
36 #define DEBUG_LONGTEXT N_( \
37     "This integer when viewed in binary is a debugging mask\n" \
38     "external call          1\n" \
39     "all calls              2\n" \
40     "packet assembly info   4\n" \
41     "image bitmaps          8\n" \
42     "image transformations 16\n" \
43     "rendering information 32\n" \
44     "extract subtitles     64\n" \
45     "misc info            128\n" )
46
47 #define DECODE_DEBUG 1
48 #if DECODE_DEBUG
49 #define dbg_print(mask, s, args...) \
50    if (p_sys && p_sys->i_debug & mask) \
51      msg_Dbg(p_dec, "%s: "s, __func__ , ##args)
52 #else
53 #define dbg_print(mask, s, args...)
54 #endif
55
56 #define LOG_ERR(args...)  msg_Err( p_input, args )
57 #define LOG_WARN(args...) msg_Warn( p_input, args )
58
59 #define GETINT16(p) ( (p[0] <<  8) +   p[1] )  ; p +=2;
60
61 #define GETINT32(p) ( (p[0] << 24) +  (p[1] << 16) +    \
62                       (p[2] <<  8) +  (p[3]) ) ; p += 4;
63
64
65 /* The number of color palette entries allowed in a subtitle. */
66 #define NUM_SUBTITLE_COLORS 4 
67
68 typedef enum  {
69   SUBTITLE_BLOCK_EMPTY,
70   SUBTITLE_BLOCK_PARTIAL,
71   SUBTITLE_BLOCK_COMPLETE
72 } packet_state_t;
73
74 /* Color and transparency of a pixel or a palette (CLUT) entry */
75 typedef union {
76   uint8_t plane[4];
77   struct {
78     uint8_t y;
79     uint8_t v;
80     uint8_t u;
81     uint8_t t;
82   } s;
83 } ogt_yuvt_t;
84
85 /* The storage used by one pixel */
86 #define PIXEL_SIZE 4
87
88 /* Size in bytes of YUV portion above. */ 
89 #define YUV_SIZE 3
90
91 /* Transparency plane. NOTE: see vlc_video.h for V_PLANE */
92 #define T_PLANE  V_PLANE+1
93
94 struct decoder_sys_t
95 {
96   int            i_debug; /* debugging mask */
97   mtime_t        i_pts;   /* Start PTS of subtitle block */
98   int            i_spu;
99   packet_state_t state;   /* data-gathering state for this subtitle */
100
101   uint16_t       i_image; /* image number in the subtitle stream; 0 is the 
102                              first one. */
103   uint8_t        i_packet;/* packet number for above image number; 0 is the 
104                              first one. */
105   block_t        *p_block;/* Bytes of the packet. */
106   
107   uint8_t buffer[65536 + 20 ]; /* we will never overflow more than 11
108                                   bytes if I'm right */
109   int     b_packetizer;
110   int     i_spu_size;     /* goal for subtitle_data_pos while gathering,
111                              size of used subtitle_data later */
112   vout_thread_t *p_vout;
113
114   /* FIXME: Remove this? */
115   uint8_t *subtitle_data;       /* buffer used to accumulate data from
116                                    successive packets in the same subtitle */
117   int subtitle_data_size;       /* size of the allocated subtitle_data */
118
119   /* Move into subpicture_sys_t? */
120   uint16_t comp_image_offset;   /* offset from subtitle_data to compressed
121                                    image data */
122   int comp_image_length;        /* size of the compressed image data */
123   int first_field_offset;       /* offset of even raster lines. Used
124                                    only for CVD.
125                                  */
126   int second_field_offset;      /* offset of odd raster lines */
127   int metadata_offset;          /* offset to data describing the image */
128   int metadata_length;          /* length of metadata */
129
130   int subtitle_data_pos;        /* where to write next chunk */
131
132   uint32_t i_duration;          /* how long to display the image, 0 stands
133                                    for "until next subtitle" */
134
135   uint16_t i_x_start, i_y_start; /* position of top leftmost pixel of
136                                      image when displayed */
137   uint16_t i_width, i_height;   /* dimensions in pixels of image */
138
139   ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS];  /* Palette of colors used
140                                                   in subtitle */
141
142
143   ogt_yuvt_t p_palette_highlight[NUM_SUBTITLE_COLORS]; /* Only used
144                                                            for CVD */
145
146   uint8_t i_options;
147   uint8_t i_options2;
148   uint8_t i_cmd;
149   uint32_t i_cmd_arg;
150 };
151
152 struct subpicture_sys_t
153 {
154   int     i_debug;              /* debugging mask */
155   mtime_t i_pts;                /* presentation timestamp */
156
157   uint8_t *p_data;             /* Image data one byte T, Y, U, V */
158
159   /* Link to our input */
160   vlc_object_t * p_input;
161   
162   /* Cropping properties */
163   vlc_mutex_t  lock;
164   vlc_bool_t   b_crop;
165   unsigned int i_x_start, i_y_start, i_x_end, i_y_end;
166 };