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