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 *
|
|
7 * libass is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * libass 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
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License along
|
|
18 * with libass; if not, write to the Free Software Foundation, Inc.,
|
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 */
|
|
21
|
|
22 #ifndef LIBASS_RENDER_H
|
|
23 #define LIBASS_RENDER_H
|
|
24
|
|
25 #include <inttypes.h>
|
|
26 #include <ft2build.h>
|
|
27 #include FT_FREETYPE_H
|
|
28 #include FT_STROKER_H
|
|
29 #include FT_GLYPH_H
|
|
30 #include FT_SYNTHESIS_H
|
|
31
|
|
32 #include "ass.h"
|
|
33 #include "ass_font.h"
|
|
34 #include "ass_bitmap.h"
|
|
35 #include "ass_cache.h"
|
|
36 #include "ass_utils.h"
|
|
37 #include "ass_fontconfig.h"
|
|
38 #include "ass_library.h"
|
|
39 #include "ass_drawing.h"
|
|
40
|
|
41 typedef struct {
|
|
42 double xMin;
|
|
43 double xMax;
|
|
44 double yMin;
|
|
45 double yMax;
|
|
46 } DBBox;
|
|
47
|
|
48 typedef struct {
|
|
49 double x;
|
|
50 double y;
|
|
51 } DVector;
|
|
52
|
|
53 typedef struct free_list {
|
|
54 void *object;
|
|
55 struct free_list *next;
|
|
56 } FreeList;
|
|
57
|
|
58 typedef struct {
|
|
59 int frame_width;
|
|
60 int frame_height;
|
|
61 double font_size_coeff; // font size multiplier
|
|
62 double line_spacing; // additional line spacing (in frame pixels)
|
|
63 int top_margin; // height of top margin. Everything except toptitles is shifted down by top_margin.
|
|
64 int bottom_margin; // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
|
|
65 int left_margin;
|
|
66 int right_margin;
|
|
67 int use_margins; // 0 - place all subtitles inside original frame
|
|
68 // 1 - use margins for placing toptitles and subtitles
|
|
69 double aspect; // frame aspect ratio, d_width / d_height.
|
|
70 double storage_aspect; // pixel ratio of the source image
|
|
71 ASS_Hinting hinting;
|
|
72
|
|
73 char *default_font;
|
|
74 char *default_family;
|
|
75 } ASS_Settings;
|
|
76
|
|
77 // a rendered event
|
|
78 typedef struct {
|
|
79 ASS_Image *imgs;
|
|
80 int top, height, left, width;
|
|
81 int detect_collisions;
|
|
82 int shift_direction;
|
|
83 ASS_Event *event;
|
|
84 } EventImages;
|
|
85
|
|
86 typedef enum {
|
|
87 EF_NONE = 0,
|
|
88 EF_KARAOKE,
|
|
89 EF_KARAOKE_KF,
|
|
90 EF_KARAOKE_KO
|
|
91 } Effect;
|
|
92
|
|
93 // describes a glyph
|
|
94 // GlyphInfo and TextInfo are used for text centering and word-wrapping operations
|
|
95 typedef struct {
|
|
96 unsigned symbol;
|
|
97 unsigned skip; // skip glyph when layouting text
|
|
98 FT_Glyph glyph;
|
|
99 FT_Glyph outline_glyph;
|
|
100 Bitmap *bm; // glyph bitmap
|
|
101 Bitmap *bm_o; // outline bitmap
|
|
102 Bitmap *bm_s; // shadow bitmap
|
|
103 FT_BBox bbox;
|
|
104 FT_Vector pos;
|
|
105 char linebreak; // the first (leading) glyph of some line ?
|
|
106 uint32_t c[4]; // colors
|
|
107 FT_Vector advance; // 26.6
|
|
108 Effect effect_type;
|
|
109 int effect_timing; // time duration of current karaoke word
|
|
110 // after process_karaoke_effects: distance in pixels from the glyph origin.
|
|
111 // part of the glyph to the left of it is displayed in a different color.
|
|
112 int effect_skip_timing; // delay after the end of last karaoke word
|
|
113 int asc, desc; // font max ascender and descender
|
|
114 int be; // blur edges
|
|
115 double blur; // gaussian blur
|
|
116 double shadow_x;
|
|
117 double shadow_y;
|
|
118 double frx, fry, frz; // rotation
|
|
119 double fax, fay; // text shearing
|
|
120
|
|
121 BitmapHashKey hash_key;
|
|
122 } GlyphInfo;
|
|
123
|
|
124 typedef struct {
|
|
125 double asc, desc;
|
|
126 } LineInfo;
|
|
127
|
|
128 typedef struct {
|
|
129 GlyphInfo *glyphs;
|
|
130 int length;
|
|
131 LineInfo *lines;
|
|
132 int n_lines;
|
|
133 double height;
|
|
134 int max_glyphs;
|
|
135 int max_lines;
|
|
136 } TextInfo;
|
|
137
|
|
138 // Renderer state.
|
|
139 // Values like current font face, color, screen position, clipping and so on are stored here.
|
|
140 typedef struct {
|
|
141 ASS_Event *event;
|
|
142 ASS_Style *style;
|
|
143
|
|
144 ASS_Font *font;
|
|
145 char *font_path;
|
|
146 double font_size;
|
|
147 int flags; // decoration flags (underline/strike-through)
|
|
148
|
|
149 FT_Stroker stroker;
|
|
150 int alignment; // alignment overrides go here; if zero, style value will be used
|
|
151 double frx, fry, frz;
|
|
152 double fax, fay; // text shearing
|
|
153 enum {
|
|
154 EVENT_NORMAL, // "normal" top-, sub- or mid- title
|
|
155 EVENT_POSITIONED, // happens after pos(,), margins are ignored
|
|
156 EVENT_HSCROLL, // "Banner" transition effect, text_width is unlimited
|
|
157 EVENT_VSCROLL // "Scroll up", "Scroll down" transition effects
|
|
158 } evt_type;
|
|
159 double pos_x, pos_y; // position
|
|
160 double org_x, org_y; // origin
|
|
161 char have_origin; // origin is explicitly defined; if 0, get_base_point() is used
|
|
162 double scale_x, scale_y;
|
|
163 double hspacing; // distance between letters, in pixels
|
|
164 double border_x; // outline width
|
|
165 double border_y;
|
|
166 uint32_t c[4]; // colors(Primary, Secondary, so on) in RGBA
|
|
167 int clip_x0, clip_y0, clip_x1, clip_y1;
|
|
168 char clip_mode; // 1 = iclip
|
|
169 char detect_collisions;
|
|
170 uint32_t fade; // alpha from \fad
|
|
171 char be; // blur edges
|
|
172 double blur; // gaussian blur
|
|
173 double shadow_x;
|
|
174 double shadow_y;
|
|
175 int drawing_mode; // not implemented; when != 0 text is discarded, except for style override tags
|
|
176 ASS_Drawing *drawing; // current drawing
|
|
177 ASS_Drawing *clip_drawing; // clip vector
|
|
178 int clip_drawing_mode; // 0 = regular clip, 1 = inverse clip
|
|
179
|
|
180 Effect effect_type;
|
|
181 int effect_timing;
|
|
182 int effect_skip_timing;
|
|
183
|
|
184 enum {
|
|
185 SCROLL_LR, // left-to-right
|
|
186 SCROLL_RL,
|
|
187 SCROLL_TB, // top-to-bottom
|
|
188 SCROLL_BT
|
|
189 } scroll_direction; // for EVENT_HSCROLL, EVENT_VSCROLL
|
|
190 int scroll_shift;
|
|
191
|
|
192 // face properties
|
|
193 char *family;
|
|
194 unsigned bold;
|
|
195 unsigned italic;
|
|
196 int treat_family_as_pattern;
|
|
197 int wrap_style;
|
|
198 } RenderContext;
|
|
199
|
|
200 typedef struct {
|
|
201 Hashmap *font_cache;
|
|
202 Hashmap *glyph_cache;
|
|
203 Hashmap *bitmap_cache;
|
|
204 Hashmap *composite_cache;
|
|
205 size_t glyph_max;
|
|
206 size_t bitmap_max_size;
|
|
207 } CacheStore;
|
|
208
|
|
209 struct ass_renderer {
|
|
210 ASS_Library *library;
|
|
211 FT_Library ftlibrary;
|
|
212 FCInstance *fontconfig_priv;
|
|
213 ASS_Settings settings;
|
|
214 int render_id;
|
|
215 ASS_SynthPriv *synth_priv;
|
|
216
|
|
217 ASS_Image *images_root; // rendering result is stored here
|
|
218 ASS_Image *prev_images_root;
|
|
219
|
|
220 EventImages *eimg; // temporary buffer for sorting rendered events
|
|
221 int eimg_size; // allocated buffer size
|
|
222
|
|
223 // frame-global data
|
|
224 int width, height; // screen dimensions
|
|
225 int orig_height; // frame height ( = screen height - margins )
|
|
226 int orig_width; // frame width ( = screen width - margins )
|
|
227 int orig_height_nocrop; // frame height ( = screen height - margins + cropheight)
|
|
228 int orig_width_nocrop; // frame width ( = screen width - margins + cropwidth)
|
|
229 ASS_Track *track;
|
|
230 long long time; // frame's timestamp, ms
|
|
231 double font_scale;
|
|
232 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
|
|
233 double border_scale;
|
|
234
|
|
235 RenderContext state;
|
|
236 TextInfo text_info;
|
|
237 CacheStore cache;
|
|
238
|
|
239 FreeList *free_head;
|
|
240 FreeList *free_tail;
|
|
241 };
|
|
242
|
|
243 typedef struct render_priv {
|
|
244 int top, height, left, width;
|
|
245 int render_id;
|
|
246 } RenderPriv;
|
|
247
|
|
248 typedef struct {
|
|
249 int x0;
|
|
250 int y0;
|
|
251 int x1;
|
|
252 int y1;
|
|
253 } Rect;
|
|
254
|
|
255 typedef struct {
|
|
256 int a, b; // top and height
|
|
257 int ha, hb; // left and width
|
|
258 } Segment;
|
|
259
|
|
260 void reset_render_context(ASS_Renderer *render_priv);
|
|
261
|
|
262 #endif /* LIBASS_RENDER_H */
|