]> git.sesse.net Git - vlc/blob - modules/codec/ogt/subtitle.h
fac2fc09a985986e48b5a931f0f6148e9377540c
[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$
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 #include "pixmap.h"
28
29 #define DECODE_DBG_EXT         1 /* Calls from external routines */
30 #define DECODE_DBG_CALL        2 /* all calls */
31 #define DECODE_DBG_PACKET      4 /* packet assembly info */
32 #define DECODE_DBG_IMAGE       8 /* image bitmaps */
33 #define DECODE_DBG_TRANSFORM  16 /* bitmap transformations */
34 #define DECODE_DBG_RENDER     32 /* rendering information */
35 #define DECODE_DBG_PNG        64 /* Extract subtitles to PNG files. */
36 #define DECODE_DBG_INFO      128
37
38 #define DEBUG_TEXT N_(                                      \
39      "If nonzero, this gives additional debug information." \
40      )
41
42 #define DEBUG_LONGTEXT N_( \
43     "This integer when viewed in binary is a debugging mask\n" \
44     "external call          1\n" \
45     "all calls              2\n" \
46     "packet assembly info   4\n" \
47     "image bitmaps          8\n" \
48     "image transformations 16\n" \
49     "rendering information 32\n" \
50     "extract subtitles     64\n" \
51     "misc info            128\n" )
52
53 #define SUB_ASPECT_RATIO_TEXT N_("Subtitle aspect-ratio correction")
54 #define SUB_ASPECT_RATIO_LONGTEXT N_(                                   \
55     "Use this to force the subtitle aspect ratio. If you give a null string " \
56     "the right value will be determined automatically. Usually this is what " \
57     "you want. For OGT and CVD subtitles this undoes the effect " \
58     "of the underlying video scaling. And using a value of 1 will cause " \
59     "no correction; subtitles will be scaled with the same aspect " \
60     "ratio as as the underlying video (which not correct for OGT or " \
61     "CVD subtitles). You can also force another ratio by giving a pair of " \
62     "integers x:y where y should between x and twice x. For example 4:3, or " \
63     "16:9. Alternatively, you can give a float value expressing pixel " \
64     "squareness. For example 1.25 or 1.3333 which mean the same thing as " \
65     "4:3 and 16:9 respectively." \
66     )
67
68 #define DURATION_SCALE_TEXT N_("Factor to increase subtitle display interval")
69 #define DURATION_SCALE_LONGTEXT N_(                         \
70   "If you find you need extra time for reading subtitles, " \
71   "you can set this higher and it will multiply the display "   \
72   "time by that amount. Use 0 to mean until the next "          \
73   "subtitle.")
74
75 #define HORIZONTAL_CORRECT \
76   N_("Add this to starting horizontal position of subtitle.")
77 #define HORIZONTAL_CORRECT_LONGTEXT N_(                     \
78   "If you need to adjust the subtitle starting position horizontally, " \
79   "set this. Negative values shift left and positive values right. 0 would " \
80   "be no deviation from where the position specified in the subtitle."  \
81   )
82
83 #define VERTICAL_CORRECT \
84   N_("Add this to starting vertical position of subtitle.")
85 #define VERTICAL_CORRECT_LONGTEXT N_(                       \
86   "If you need to adjust the subtitle starting position vertically, " \
87   "set this. Negative values shift up, positive values down. 0 would "  \
88   "be no deviation from where the position specified in the subtitle."  \
89   )
90
91 #define DECODE_DEBUG 1
92 #if DECODE_DEBUG
93 #define dbg_print(mask, s, args...) \
94    if (p_sys && p_sys->i_debug & mask) \
95      msg_Dbg(p_dec, "%s: "s, __func__ , ##args)
96 #else
97 #define dbg_print(mask, s, args...)
98 #endif
99
100 #define LOG_ERR(args...)  msg_Err( p_input, args )
101 #define LOG_WARN(args...) msg_Warn( p_input, args )
102
103 #define GETINT16(p) ( (p[0] <<  8) +   p[1] )  ; p +=2;
104
105 #define GETINT32(p) ( (p[0] << 24) +  (p[1] << 16) +    \
106                       (p[2] <<  8) +  (p[3]) ) ; p += 4;
107
108
109 /* The number of color palette entries allowed in a subtitle. */
110 #define NUM_SUBTITLE_COLORS 4 
111
112 typedef enum  {
113   SUBTITLE_BLOCK_EMPTY,
114   SUBTITLE_BLOCK_PARTIAL,
115   SUBTITLE_BLOCK_COMPLETE
116 } packet_state_t;
117
118 /* The byte storage used by one pixel */
119 #define PIXEL_SIZE 4
120
121 /* Size in bytes of YUV portion above. */ 
122 #define YUV_SIZE 3
123
124
125
126 /* Transparency plane. NOTE: see vlc_video.h for V_PLANE */
127 #define T_PLANE  V_PLANE+1
128
129 struct decoder_sys_t
130 {
131   int            i_debug; /* debugging mask */
132   mtime_t        i_pts;   /* Start PTS of subtitle block */
133   int            i_spu;
134   packet_state_t state;   /* data-gathering state for this subtitle */
135
136   uint16_t       i_image; /* image number in the subtitle stream; 0 is the 
137                              first one. */
138   uint8_t        i_packet;/* packet number for above image number; 0 is the 
139                              first one. */
140   block_t        *p_block;/* Bytes of the packet. */
141   
142   uint8_t buffer[65536 + 20 ]; /* we will never overflow more than 11
143                                   bytes if I'm right */
144   int     b_packetizer;
145   int     i_spu_size;     /* goal for subtitle_data_pos while gathering,
146                              size of used subtitle_data later */
147   vout_thread_t *p_vout;
148
149   /* FIXME: Remove this? */
150   uint8_t *subtitle_data;       /* buffer used to accumulate data from
151                                    successive packets in the same subtitle */
152   int subtitle_data_size;       /* size of the allocated subtitle_data */
153
154   /* Move into subpicture_sys_t? */
155   uint16_t i_image_offset;      /* offset from subtitle_data to compressed
156                                    image data */
157   int i_image_length;           /* size of the compressed image data */
158   int first_field_offset;       /* offset of even raster lines. Used
159                                    only for CVD.
160                                  */
161   int second_field_offset;      /* offset of odd raster lines */
162   int metadata_offset;          /* offset to data describing the image */
163   int metadata_length;          /* length of metadata */
164
165   int subtitle_data_pos;        /* where to write next chunk */
166
167   mtime_t i_duration;           /* how long to display the image, 0 stands
168                                    for "until next subtitle" */
169
170   uint16_t i_x_start, i_y_start; /* position of top leftmost pixel of
171                                      image when displayed */
172   uint16_t i_width, i_height;   /* dimensions in pixels of image */
173
174   ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS];  /* Palette of colors used
175                                                   in subtitle */
176
177
178   ogt_yuvt_t p_palette_highlight[NUM_SUBTITLE_COLORS]; /* Only used
179                                                            for CVD */
180
181   uint8_t i_options;
182   uint8_t i_options2;
183   uint8_t i_cmd;
184   uint32_t i_cmd_arg;
185 };
186
187 struct subpicture_sys_t
188 {
189   int     i_debug;              /* debugging mask */
190   mtime_t i_pts;                /* presentation timestamp */
191
192   uint8_t *p_data;             /* Image data one byte T, Y, U, V */
193
194
195   /* Link to our input */
196   vlc_object_t * p_input;
197   
198   /* Cropping properties */
199   vlc_mutex_t  lock;
200   vlc_bool_t   b_crop;
201   unsigned int i_x_start, i_y_start, i_x_end, i_y_end;
202
203   /* This is only used for color palette Chromas like RGB2. */
204   ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS];  /* Palette of colors used
205                                                   in subtitle */
206
207 };