subtitle.h 7.51 KB
Newer Older
1
2
3
/*****************************************************************************
 * subtitle.h : Common SVCD and CVD subtitles header
 *****************************************************************************
4
 * Copyright (C) 2003,2004 VideoLAN
5
 * $Id: subtitle.h,v 1.13 2004/01/25 19:27:09 rocky Exp $
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * Author: Rocky Bernstein
 *   based on code from:
 *       Julio Sanchez Fernandez (http://subhandler.sourceforge.net)
 *       Sam Hocevar <sam@zoy.org>
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

27
28
#include "pixmap.h"

29
30
31
32
33
34
#define DECODE_DBG_EXT         1 /* Calls from external routines */
#define DECODE_DBG_CALL        2 /* all calls */
#define DECODE_DBG_PACKET      4 /* packet assembly info */
#define DECODE_DBG_IMAGE       8 /* image bitmaps */
#define DECODE_DBG_TRANSFORM  16 /* bitmap transformations */
#define DECODE_DBG_RENDER     32 /* rendering information */
35
36
37
#define DECODE_DBG_PNG        64 /* Extract subtitles to PNG files. */
#define DECODE_DBG_INFO      128

38
39
40
41
#define DEBUG_TEXT N_(					    \
     "If nonzero, this gives additional debug information." \
     )

42
43
44
45
46
47
48
49
50
51
#define DEBUG_LONGTEXT N_( \
    "This integer when viewed in binary is a debugging mask\n" \
    "external call          1\n" \
    "all calls              2\n" \
    "packet assembly info   4\n" \
    "image bitmaps          8\n" \
    "image transformations 16\n" \
    "rendering information 32\n" \
    "extract subtitles     64\n" \
    "misc info            128\n" )
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define SUB_ASPECT_RATIO_TEXT N_("Subtitle aspect-ratio correction")
#define SUB_ASPECT_RATIO_LONGTEXT N_(					\
    "Use this to force the subtitle aspect ratio. If you give a null string " \
    "the right value will be determined automatically. Usually this is what " \
    "you want. For OGT and CVD subtitles this undoes the effect " \
    "of the underlying video scaling. And using a value of 1 will cause " \
    "no correction; subtitles will be scaled with the same aspect " \
    "ratio as as the underlying video (which not correct for OGT or " \
    "CVD subtitles). You can also force another ratio by giving a pair of " \
    "integers x:y where y should between x and twice x. For example 4:3, or " \
    "16:9. Alternatively, you can give a float value expressing pixel " \
    "squareness. For example 1.25 or 1.3333 which mean the same thing as " \
    "4:3 and 16:9 respectively." \
    )

bigben's avatar
bigben committed
68
#define DURATION_SCALE_TEXT N_("Factor to increase subtitle display interval")
69
70
71
72
73
74
#define DURATION_SCALE_LONGTEXT N_(			    \
  "If you find you need extra time for reading subtitles, " \
  "you can set this higher and it will multiply the display "	\
  "time by that amount. Use 0 to mean until the next "		\
  "subtitle.")

75
76
77
78
#define HORIZONTAL_CORRECT \
  N_("Add this to starting horizontal position of subtitle.")
#define HORIZONTAL_CORRECT_LONGTEXT N_(			    \
  "If you need to adjust the subtitle starting position horizontally, " \
79
  "set this. Negative values shift left and postive values right. 0 would " \
80
81
82
83
84
85
  "be no deviation from where the position specified in the subtitle."	\
  )

#define VERTICAL_CORRECT \
  N_("Add this to starting vertical position of subtitle.")
#define VERTICAL_CORRECT_LONGTEXT N_(			    \
86
87
  "If you need to adjust the subtitle starting position vertically, " \
  "set this. Negative values shift up, positive values down. 0 would "	\
88
89
90
  "be no deviation from where the position specified in the subtitle."	\
  )

91
92
93
94
95
96
97
98
99
100
101
102
#define DECODE_DEBUG 1
#if DECODE_DEBUG
#define dbg_print(mask, s, args...) \
   if (p_sys && p_sys->i_debug & mask) \
     msg_Dbg(p_dec, "%s: "s, __func__ , ##args)
#else
#define dbg_print(mask, s, args...)
#endif

#define LOG_ERR(args...)  msg_Err( p_input, args )
#define LOG_WARN(args...) msg_Warn( p_input, args )

103
#define GETINT16(p) ( (p[0] <<  8) +   p[1] )  ; p +=2;
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

#define GETINT32(p) ( (p[0] << 24) +  (p[1] << 16) +    \
                      (p[2] <<  8) +  (p[3]) ) ; p += 4;


/* The number of color palette entries allowed in a subtitle. */
#define NUM_SUBTITLE_COLORS 4 

typedef enum  {
  SUBTITLE_BLOCK_EMPTY,
  SUBTITLE_BLOCK_PARTIAL,
  SUBTITLE_BLOCK_COMPLETE
} packet_state_t;

/* The storage used by one pixel */
#define PIXEL_SIZE 4

/* Size in bytes of YUV portion above. */ 
#define YUV_SIZE 3

/* Transparency plane. NOTE: see vlc_video.h for V_PLANE */
#define T_PLANE  V_PLANE+1

struct decoder_sys_t
{
  int            i_debug; /* debugging mask */
  mtime_t        i_pts;   /* Start PTS of subtitle block */
  int            i_spu;
  packet_state_t state;   /* data-gathering state for this subtitle */

  uint16_t       i_image; /* image number in the subtitle stream; 0 is the 
			     first one. */
  uint8_t        i_packet;/* packet number for above image number; 0 is the 
			     first one. */
  block_t        *p_block;/* Bytes of the packet. */
  
  uint8_t buffer[65536 + 20 ]; /* we will never overflow more than 11
				  bytes if I'm right */
  int     b_packetizer;
  int     i_spu_size;	  /* goal for subtitle_data_pos while gathering,
			     size of used subtitle_data later */
  vout_thread_t *p_vout;

  /* FIXME: Remove this? */
  uint8_t *subtitle_data;	/* buffer used to accumulate data from
				   successive packets in the same subtitle */
  int subtitle_data_size;	/* size of the allocated subtitle_data */

  /* Move into subpicture_sys_t? */
153
  uint16_t i_image_offset;	/* offset from subtitle_data to compressed
154
				   image data */
155
  int i_image_length;	        /* size of the compressed image data */
156
157
158
  int first_field_offset;       /* offset of even raster lines. Used
				   only for CVD.
				 */
159
160
161
162
163
164
  int second_field_offset;      /* offset of odd raster lines */
  int metadata_offset;          /* offset to data describing the image */
  int metadata_length;          /* length of metadata */

  int subtitle_data_pos;	/* where to write next chunk */

165
  mtime_t i_duration;		/* how long to display the image, 0 stands
166
167
168
169
170
171
				   for "until next subtitle" */

  uint16_t i_x_start, i_y_start; /* position of top leftmost pixel of
				     image when displayed */
  uint16_t i_width, i_height;	/* dimensions in pixels of image */

172
  ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS];  /* Palette of colors used
173
174
175
						  in subtitle */


176
  ogt_yuvt_t p_palette_highlight[NUM_SUBTITLE_COLORS]; /* Only used
177
							   for CVD */
178
179
180
181
182
183
184
185
186
187
188
189

  uint8_t i_options;
  uint8_t i_options2;
  uint8_t i_cmd;
  uint32_t i_cmd_arg;
};

struct subpicture_sys_t
{
  int     i_debug;              /* debugging mask */
  mtime_t i_pts;                /* presentation timestamp */

gbazin's avatar
   
gbazin committed
190
  uint8_t *p_data;             /* Image data one byte T, Y, U, V */
191

192

193
194
195
196
197
198
199
  /* Link to our input */
  vlc_object_t * p_input;
  
  /* Cropping properties */
  vlc_mutex_t  lock;
  vlc_bool_t   b_crop;
  unsigned int i_x_start, i_y_start, i_x_end, i_y_end;
200
201
202
203
204

  /* This is only used for color palette Chromas like RGB2. */
  ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS];  /* Palette of colors used
						  in subtitle */

205
};