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