30200
|
1 /*
|
|
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
|
|
3 * Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
|
|
4 *
|
|
5 * This file is part of libass.
|
|
6 *
|
34011
|
7 * Permission to use, copy, modify, and distribute this software for any
|
|
8 * purpose with or without fee is hereby granted, provided that the above
|
|
9 * copyright notice and this permission notice appear in all copies.
|
30200
|
10 *
|
34011
|
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
30200
|
18 */
|
|
19
|
|
20 #ifndef LIBASS_RENDER_H
|
|
21 #define LIBASS_RENDER_H
|
|
22
|
|
23 #include <inttypes.h>
|
|
24 #include <ft2build.h>
|
|
25 #include FT_FREETYPE_H
|
|
26 #include FT_STROKER_H
|
|
27 #include FT_GLYPH_H
|
|
28 #include FT_SYNTHESIS_H
|
36363
|
29 #ifdef CONFIG_HARFBUZZ
|
|
30 #include "hb.h"
|
|
31 #endif
|
30200
|
32
|
34295
|
33 // XXX: fix the inclusion mess so we can avoid doing this here
|
|
34 typedef struct ass_shaper ASS_Shaper;
|
|
35
|
30200
|
36 #include "ass.h"
|
|
37 #include "ass_font.h"
|
|
38 #include "ass_bitmap.h"
|
|
39 #include "ass_cache.h"
|
|
40 #include "ass_utils.h"
|
|
41 #include "ass_fontconfig.h"
|
|
42 #include "ass_library.h"
|
|
43 #include "ass_drawing.h"
|
|
44
|
31853
|
45 #define GLYPH_CACHE_MAX 1000
|
|
46 #define BITMAP_CACHE_MAX_SIZE 30 * 1048576
|
|
47
|
34011
|
48 #define PARSED_FADE (1<<0)
|
|
49 #define PARSED_A (1<<1)
|
|
50
|
30200
|
51 typedef struct {
|
|
52 double xMin;
|
|
53 double xMax;
|
|
54 double yMin;
|
|
55 double yMax;
|
|
56 } DBBox;
|
|
57
|
|
58 typedef struct {
|
|
59 double x;
|
|
60 double y;
|
|
61 } DVector;
|
|
62
|
|
63 typedef struct free_list {
|
|
64 void *object;
|
|
65 struct free_list *next;
|
|
66 } FreeList;
|
|
67
|
|
68 typedef struct {
|
|
69 int frame_width;
|
|
70 int frame_height;
|
36363
|
71 int storage_width; // width of the source image
|
|
72 int storage_height; // height of the source image
|
30200
|
73 double font_size_coeff; // font size multiplier
|
|
74 double line_spacing; // additional line spacing (in frame pixels)
|
35262
|
75 double line_position; // vertical position for subtitles, 0-100 (0 = no change)
|
30200
|
76 int top_margin; // height of top margin. Everything except toptitles is shifted down by top_margin.
|
|
77 int bottom_margin; // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
|
|
78 int left_margin;
|
|
79 int right_margin;
|
|
80 int use_margins; // 0 - place all subtitles inside original frame
|
|
81 // 1 - use margins for placing toptitles and subtitles
|
36363
|
82 double par; // user defined pixel aspect ratio (0 = unset)
|
30200
|
83 ASS_Hinting hinting;
|
34295
|
84 ASS_ShapingLevel shaper;
|
30200
|
85
|
|
86 char *default_font;
|
|
87 char *default_family;
|
|
88 } ASS_Settings;
|
|
89
|
|
90 // a rendered event
|
|
91 typedef struct {
|
|
92 ASS_Image *imgs;
|
|
93 int top, height, left, width;
|
|
94 int detect_collisions;
|
|
95 int shift_direction;
|
|
96 ASS_Event *event;
|
|
97 } EventImages;
|
|
98
|
|
99 typedef enum {
|
|
100 EF_NONE = 0,
|
|
101 EF_KARAOKE,
|
|
102 EF_KARAOKE_KF,
|
|
103 EF_KARAOKE_KO
|
|
104 } Effect;
|
|
105
|
|
106 // describes a glyph
|
|
107 // GlyphInfo and TextInfo are used for text centering and word-wrapping operations
|
34295
|
108 typedef struct glyph_info {
|
30200
|
109 unsigned symbol;
|
|
110 unsigned skip; // skip glyph when layouting text
|
34295
|
111 ASS_Font *font;
|
|
112 int face_index;
|
|
113 int glyph_index;
|
36363
|
114 #ifdef CONFIG_HARFBUZZ
|
|
115 hb_script_t script;
|
|
116 #else
|
|
117 int script;
|
|
118 #endif
|
34295
|
119 double font_size;
|
|
120 ASS_Drawing *drawing;
|
|
121 FT_Outline *outline;
|
|
122 FT_Outline *border;
|
30200
|
123 Bitmap *bm; // glyph bitmap
|
|
124 Bitmap *bm_o; // outline bitmap
|
|
125 Bitmap *bm_s; // shadow bitmap
|
|
126 FT_BBox bbox;
|
|
127 FT_Vector pos;
|
34295
|
128 FT_Vector offset;
|
30200
|
129 char linebreak; // the first (leading) glyph of some line ?
|
|
130 uint32_t c[4]; // colors
|
|
131 FT_Vector advance; // 26.6
|
34295
|
132 FT_Vector cluster_advance;
|
30200
|
133 Effect effect_type;
|
|
134 int effect_timing; // time duration of current karaoke word
|
|
135 // after process_karaoke_effects: distance in pixels from the glyph origin.
|
|
136 // part of the glyph to the left of it is displayed in a different color.
|
|
137 int effect_skip_timing; // delay after the end of last karaoke word
|
|
138 int asc, desc; // font max ascender and descender
|
|
139 int be; // blur edges
|
|
140 double blur; // gaussian blur
|
|
141 double shadow_x;
|
|
142 double shadow_y;
|
|
143 double frx, fry, frz; // rotation
|
|
144 double fax, fay; // text shearing
|
34295
|
145 double scale_x, scale_y;
|
35262
|
146 int border_style;
|
34295
|
147 double border_x, border_y;
|
35262
|
148 double hspacing;
|
34295
|
149 unsigned italic;
|
|
150 unsigned bold;
|
|
151 int flags;
|
|
152
|
|
153 int bm_run_id;
|
|
154 int shape_run_id;
|
30200
|
155
|
|
156 BitmapHashKey hash_key;
|
34295
|
157
|
|
158 // next glyph in this cluster
|
|
159 struct glyph_info *next;
|
30200
|
160 } GlyphInfo;
|
|
161
|
|
162 typedef struct {
|
|
163 double asc, desc;
|
34295
|
164 int offset, len;
|
30200
|
165 } LineInfo;
|
|
166
|
|
167 typedef struct {
|
|
168 GlyphInfo *glyphs;
|
|
169 int length;
|
|
170 LineInfo *lines;
|
|
171 int n_lines;
|
|
172 double height;
|
|
173 int max_glyphs;
|
|
174 int max_lines;
|
|
175 } TextInfo;
|
|
176
|
|
177 // Renderer state.
|
|
178 // Values like current font face, color, screen position, clipping and so on are stored here.
|
|
179 typedef struct {
|
|
180 ASS_Event *event;
|
|
181 ASS_Style *style;
|
34011
|
182 int parsed_tags;
|
30200
|
183
|
|
184 ASS_Font *font;
|
|
185 double font_size;
|
|
186 int flags; // decoration flags (underline/strike-through)
|
|
187
|
|
188 FT_Stroker stroker;
|
35262
|
189 int stroker_radius; // last stroker radius, for caching stroker objects
|
30200
|
190 int alignment; // alignment overrides go here; if zero, style value will be used
|
|
191 double frx, fry, frz;
|
|
192 double fax, fay; // text shearing
|
|
193 enum {
|
|
194 EVENT_NORMAL, // "normal" top-, sub- or mid- title
|
|
195 EVENT_POSITIONED, // happens after pos(,), margins are ignored
|
|
196 EVENT_HSCROLL, // "Banner" transition effect, text_width is unlimited
|
|
197 EVENT_VSCROLL // "Scroll up", "Scroll down" transition effects
|
|
198 } evt_type;
|
|
199 double pos_x, pos_y; // position
|
|
200 double org_x, org_y; // origin
|
|
201 char have_origin; // origin is explicitly defined; if 0, get_base_point() is used
|
|
202 double scale_x, scale_y;
|
|
203 double hspacing; // distance between letters, in pixels
|
35262
|
204 int border_style;
|
30200
|
205 double border_x; // outline width
|
|
206 double border_y;
|
|
207 uint32_t c[4]; // colors(Primary, Secondary, so on) in RGBA
|
|
208 int clip_x0, clip_y0, clip_x1, clip_y1;
|
|
209 char clip_mode; // 1 = iclip
|
|
210 char detect_collisions;
|
|
211 uint32_t fade; // alpha from \fad
|
|
212 char be; // blur edges
|
|
213 double blur; // gaussian blur
|
|
214 double shadow_x;
|
|
215 double shadow_y;
|
|
216 int drawing_mode; // not implemented; when != 0 text is discarded, except for style override tags
|
|
217 ASS_Drawing *drawing; // current drawing
|
|
218 ASS_Drawing *clip_drawing; // clip vector
|
|
219 int clip_drawing_mode; // 0 = regular clip, 1 = inverse clip
|
|
220
|
|
221 Effect effect_type;
|
|
222 int effect_timing;
|
|
223 int effect_skip_timing;
|
|
224
|
34295
|
225 // bitmap run id (used for final bitmap rendering)
|
|
226 int bm_run_id;
|
|
227
|
30200
|
228 enum {
|
|
229 SCROLL_LR, // left-to-right
|
|
230 SCROLL_RL,
|
|
231 SCROLL_TB, // top-to-bottom
|
|
232 SCROLL_BT
|
|
233 } scroll_direction; // for EVENT_HSCROLL, EVENT_VSCROLL
|
|
234 int scroll_shift;
|
|
235
|
|
236 // face properties
|
|
237 char *family;
|
|
238 unsigned bold;
|
|
239 unsigned italic;
|
|
240 int treat_family_as_pattern;
|
|
241 int wrap_style;
|
34295
|
242 int font_encoding;
|
30200
|
243 } RenderContext;
|
|
244
|
|
245 typedef struct {
|
34295
|
246 Cache *font_cache;
|
|
247 Cache *outline_cache;
|
|
248 Cache *bitmap_cache;
|
|
249 Cache *composite_cache;
|
30200
|
250 size_t glyph_max;
|
|
251 size_t bitmap_max_size;
|
|
252 } CacheStore;
|
|
253
|
|
254 struct ass_renderer {
|
|
255 ASS_Library *library;
|
|
256 FT_Library ftlibrary;
|
|
257 FCInstance *fontconfig_priv;
|
|
258 ASS_Settings settings;
|
|
259 int render_id;
|
|
260 ASS_SynthPriv *synth_priv;
|
34295
|
261 ASS_Shaper *shaper;
|
30200
|
262
|
|
263 ASS_Image *images_root; // rendering result is stored here
|
|
264 ASS_Image *prev_images_root;
|
35262
|
265 int cache_cleared;
|
30200
|
266
|
|
267 EventImages *eimg; // temporary buffer for sorting rendered events
|
|
268 int eimg_size; // allocated buffer size
|
|
269
|
|
270 // frame-global data
|
|
271 int width, height; // screen dimensions
|
|
272 int orig_height; // frame height ( = screen height - margins )
|
|
273 int orig_width; // frame width ( = screen width - margins )
|
|
274 int orig_height_nocrop; // frame height ( = screen height - margins + cropheight)
|
|
275 int orig_width_nocrop; // frame width ( = screen width - margins + cropwidth)
|
36363
|
276 int storage_height; // video height before any rescaling
|
|
277 int storage_width; // video width before any rescaling
|
30200
|
278 ASS_Track *track;
|
|
279 long long time; // frame's timestamp, ms
|
|
280 double font_scale;
|
|
281 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
|
|
282 double border_scale;
|
36363
|
283 double blur_scale;
|
30200
|
284
|
|
285 RenderContext state;
|
|
286 TextInfo text_info;
|
|
287 CacheStore cache;
|
|
288
|
|
289 FreeList *free_head;
|
|
290 FreeList *free_tail;
|
|
291 };
|
|
292
|
|
293 typedef struct render_priv {
|
|
294 int top, height, left, width;
|
|
295 int render_id;
|
|
296 } RenderPriv;
|
|
297
|
|
298 typedef struct {
|
|
299 int x0;
|
|
300 int y0;
|
|
301 int x1;
|
|
302 int y1;
|
|
303 } Rect;
|
|
304
|
|
305 typedef struct {
|
|
306 int a, b; // top and height
|
|
307 int ha, hb; // left and width
|
|
308 } Segment;
|
|
309
|
35262
|
310 void reset_render_context(ASS_Renderer *render_priv, ASS_Style *style);
|
31853
|
311 void ass_free_images(ASS_Image *img);
|
30200
|
312
|
34295
|
313 // XXX: this is actually in ass.c, includes should be fixed later on
|
|
314 void ass_lazy_track_init(ASS_Library *lib, ASS_Track *track);
|
|
315
|
30200
|
316 #endif /* LIBASS_RENDER_H */
|