Imported Debian version 2.5.3~trusty1
[deb_ffmpeg.git] / ffmpeg / libavcodec / ass_split.h
1 /*
2 * SSA/ASS spliting functions
3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef AVCODEC_ASS_SPLIT_H
23 #define AVCODEC_ASS_SPLIT_H
24
25 /**
26 * fields extracted from the [Script Info] section
27 */
28 typedef struct {
29 char *script_type; /**< SSA script format version (eg. v4.00) */
30 char *collisions; /**< how subtitles are moved to prevent collisions */
31 int play_res_x; /**< video width that ASS coords are referring to */
32 int play_res_y; /**< video height that ASS coords are referring to */
33 float timer; /**< time multiplier to apply to SSA clock (in %) */
34 } ASSScriptInfo;
35
36 /**
37 * fields extracted from the [V4(+) Styles] section
38 */
39 typedef struct {
40 char *name; /**< name of the tyle (case sensitive) */
41 char *font_name; /**< font face (case sensitive) */
42 int font_size; /**< font height */
43 int primary_color; /**< color that a subtitle will normally appear in */
44 int secondary_color;
45 int outline_color; /**< color for outline in ASS, called tertiary in SSA */
46 int back_color; /**< color of the subtitle outline or shadow */
47 int bold; /**< whether text is bold (1) or not (0) */
48 int italic; /**< whether text is italic (1) or not (0) */
49 int underline; /**< whether text is underlined (1) or not (0) */
50 int strikeout;
51 float scalex;
52 float scaley;
53 float spacing;
54 float angle;
55 int border_style;
56 float outline;
57 float shadow;
58 int alignment; /**< position of the text (left, center, top...),
59 defined after the layout of the numpad
60 (1-3 sub, 4-6 mid, 7-9 top) */
61 int margin_l;
62 int margin_r;
63 int margin_v;
64 int alpha_level;
65 int encoding;
66 } ASSStyle;
67
68 /**
69 * fields extracted from the [Events] section
70 */
71 typedef struct {
72 int layer; /**< higher numbered layers are drawn over lower numbered */
73 int start; /**< start time of the dialog in centiseconds */
74 int end; /**< end time of the dialog in centiseconds */
75 char *style; /**< name of the ASSStyle to use with this dialog */
76 char *name;
77 int margin_l;
78 int margin_r;
79 int margin_v;
80 char *effect;
81 char *text; /**< actual text which will be displayed as a subtitle,
82 can include style override control codes (see
83 ff_ass_split_override_codes()) */
84 } ASSDialog;
85
86 /**
87 * structure containing the whole split ASS data
88 */
89 typedef struct {
90 ASSScriptInfo script_info; /**< general information about the SSA script*/
91 ASSStyle *styles; /**< array of split out styles */
92 int styles_count; /**< number of ASSStyle in the styles array */
93 ASSDialog *dialogs; /**< array of split out dialogs */
94 int dialogs_count; /**< number of ASSDialog in the dialogs array*/
95 } ASS;
96
97 /**
98 * This struct can be casted to ASS to access to the split data.
99 */
100 typedef struct ASSSplitContext ASSSplitContext;
101
102 /**
103 * Split a full ASS file or a ASS header from a string buffer and store
104 * the split structure in a newly allocated context.
105 *
106 * @param buf String containing the ASS formated data.
107 * @return Newly allocated struct containing split data.
108 */
109 ASSSplitContext *ff_ass_split(const char *buf);
110
111 /**
112 * Split one or several ASS "Dialogue" lines from a string buffer and store
113 * them in a already initialized context.
114 *
115 * @param ctx Context previously initialized by ff_ass_split().
116 * @param buf String containing the ASS "Dialogue" lines.
117 * @param cache Set to 1 to keep all the previously split ASSDialog in
118 * the context, or set to 0 to free all the previously split
119 * ASSDialog.
120 * @param number If not NULL, the pointed integer will be set to the number
121 * of split ASSDialog.
122 * @return Pointer to the first split ASSDialog.
123 */
124 ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
125 int cache, int *number);
126
127 /**
128 * Free all the memory allocated for an ASSSplitContext.
129 *
130 * @param ctx Context previously initialized by ff_ass_split().
131 */
132 void ff_ass_split_free(ASSSplitContext *ctx);
133
134
135 /**
136 * Set of callback functions corresponding to each override codes that can
137 * be encountered in a "Dialogue" Text field.
138 */
139 typedef struct {
140 /**
141 * @defgroup ass_styles ASS styles
142 * @{
143 */
144 void (*text)(void *priv, const char *text, int len);
145 void (*new_line)(void *priv, int forced);
146 void (*style)(void *priv, char style, int close);
147 void (*color)(void *priv, unsigned int /* color */, unsigned int color_id);
148 void (*alpha)(void *priv, int alpha, int alpha_id);
149 void (*font_name)(void *priv, const char *name);
150 void (*font_size)(void *priv, int size);
151 void (*alignment)(void *priv, int alignment);
152 void (*cancel_overrides)(void *priv, const char *style);
153 /** @} */
154
155 /**
156 * @defgroup ass_functions ASS functions
157 * @{
158 */
159 void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
160 void (*origin)(void *priv, int x, int y);
161 /** @} */
162
163 /**
164 * @defgroup ass_end end of Dialogue Event
165 * @{
166 */
167 void (*end)(void *priv);
168 /** @} */
169 } ASSCodesCallbacks;
170
171 /**
172 * Split override codes out of a ASS "Dialogue" Text field.
173 *
174 * @param callbacks Set of callback functions called for each override code
175 * encountered.
176 * @param priv Opaque pointer passed to the callback functions.
177 * @param buf The ASS "Dialogue" Text field to split.
178 * @return >= 0 on success otherwise an error code <0
179 */
180 int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
181 const char *buf);
182
183 /**
184 * Find an ASSStyle structure by its name.
185 *
186 * @param ctx Context previously initialized by ff_ass_split().
187 * @param style name of the style to search for.
188 * @return the ASSStyle corresponding to style, or NULL if style can't be found
189 */
190 ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style);
191
192 #endif /* AVCODEC_ASS_SPLIT_H */