Mercurial > mplayer.hg
annotate libass/ass_render.c @ 19931:399bb1fcdc94
Move variable declaration to a more deeply nested block. It is not used outside of it.
author | eugeni |
---|---|
date | Fri, 22 Sep 2006 18:47:29 +0000 |
parents | 3db9da42f0b8 |
children | 0b5b9cbbc74e |
rev | line source |
---|---|
18937 | 1 #include "config.h" |
2 | |
3 #include <assert.h> | |
4 #include <math.h> | |
19378 | 5 #include <inttypes.h> |
18937 | 6 #include <ft2build.h> |
7 #include FT_FREETYPE_H | |
8 #include FT_STROKER_H | |
9 #include FT_GLYPH_H | |
10 #include FT_SYNTHESIS_H | |
11 | |
12 #include "mp_msg.h" | |
13 | |
14 #include "ass.h" | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
15 #include "ass_bitmap.h" |
18937 | 16 #include "ass_cache.h" |
17 #include "ass_utils.h" | |
18 #include "ass_fontconfig.h" | |
19 | |
20 #include "libvo/sub.h" // for utf8_get_char | |
21 | |
22 #define MAX_GLYPHS 1000 | |
23 #define MAX_LINES 100 | |
24 | |
25 char *get_path(char *); | |
26 | |
27 extern char *font_name; | |
28 #ifdef HAVE_FONTCONFIG | |
29 extern int font_fontconfig; | |
30 #else | |
31 static int font_fontconfig = 0; | |
32 #endif | |
33 | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
34 static int last_render_id = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
35 |
18937 | 36 struct ass_instance_s { |
37 FT_Library library; | |
38 fc_instance_t* fontconfig_priv; | |
39 ass_settings_t settings; | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
40 int render_id; |
19848 | 41 ass_synth_priv_t* synth_priv; |
18937 | 42 |
43 ass_image_t* images_root; // rendering result is stored here | |
44 }; | |
45 | |
46 int no_more_font_messages = 0; // don't print font warnings | |
47 | |
48 typedef enum {EF_NONE = 0, EF_KARAOKE, EF_KARAOKE_KF, EF_KARAOKE_KO} effect_t; | |
49 | |
50 // describes a glyph | |
51 // glyph_info_t and text_info_t are used for text centering and word-wrapping operations | |
52 typedef struct glyph_info_s { | |
53 unsigned symbol; | |
54 FT_Glyph glyph; | |
55 FT_Glyph outline_glyph; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
56 bitmap_t* bm; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
57 bitmap_t* bm_o; |
18937 | 58 FT_BBox bbox; |
59 FT_Vector pos; | |
60 char linebreak; // the first (leading) glyph of some line ? | |
19691 | 61 uint32_t c[4]; // colors |
18937 | 62 FT_Vector advance; // 26.6 |
63 effect_t effect_type; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
64 int effect_timing; // time duration of current karaoke word |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
65 // after process_karaoke_effects: distance in pixels from the glyph origin. |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
66 // part of the glyph to the left of it is displayed in a different color. |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
67 int effect_skip_timing; // delay after the end of last karaoke word |
18937 | 68 int asc, desc; // font max ascender and descender |
69 // int height; | |
19848 | 70 int be; // blur edges |
18937 | 71 |
72 glyph_hash_key_t hash_key; | |
73 } glyph_info_t; | |
74 | |
75 typedef struct line_info_s { | |
76 int asc, desc; | |
77 } line_info_t; | |
78 | |
79 typedef struct text_info_s { | |
80 glyph_info_t* glyphs; | |
81 int length; | |
82 line_info_t lines[MAX_LINES]; | |
83 int n_lines; | |
84 int height; | |
85 } text_info_t; | |
86 | |
87 | |
88 // Renderer state. | |
89 // Values like current font face, color, screen position, clipping and so on are stored here. | |
90 typedef struct render_context_s { | |
91 ass_event_t* event; | |
92 ass_style_t* style; | |
93 | |
94 FT_Face face; | |
95 char* font_path; | |
96 int font_size; | |
97 | |
98 FT_Stroker stroker; | |
99 int alignment; // alignment overrides go here; if zero, style value will be used | |
100 double rotation; | |
101 enum { EVENT_NORMAL, // "normal" top-, sub- or mid- title | |
19556 | 102 EVENT_POSITIONED, // happens after pos(,), margins are ignored |
103 EVENT_HSCROLL, // "Banner" transition effect, text_width is unlimited | |
104 EVENT_VSCROLL // "Scroll up", "Scroll down" transition effects | |
18937 | 105 } evt_type; |
106 int pos_x, pos_y; // position | |
107 int org_x, org_y; // origin | |
108 double scale_x, scale_y; | |
109 int hspacing; // distance between letters, in pixels | |
110 double border; // outline width | |
19691 | 111 uint32_t c[4]; // colors(Primary, Secondary, so on) in RGBA |
18937 | 112 int clip_x0, clip_y0, clip_x1, clip_y1; |
113 char detect_collisions; | |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
114 uint32_t fade; // alpha from \fad |
19848 | 115 char be; // blur edges |
18937 | 116 |
117 effect_t effect_type; | |
118 int effect_timing; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
119 int effect_skip_timing; |
18937 | 120 |
19556 | 121 enum { SCROLL_LR, // left-to-right |
122 SCROLL_RL, | |
123 SCROLL_TB, // top-to-bottom | |
124 SCROLL_BT | |
125 } scroll_direction; // for EVENT_HSCROLL, EVENT_VSCROLL | |
126 int scroll_shift; | |
127 | |
18937 | 128 // face properties |
129 char* family; | |
130 unsigned bold; | |
131 unsigned italic; | |
132 | |
133 } render_context_t; | |
134 | |
135 // frame-global data | |
136 typedef struct frame_context_s { | |
137 ass_instance_t* ass_priv; | |
138 int width, height; // screen dimensions | |
139 int orig_height; // frame height ( = screen height - margins ) | |
19538 | 140 int orig_width; // frame width ( = screen width - margins ) |
18937 | 141 ass_track_t* track; |
142 long long time; // frame's timestamp, ms | |
19825
f351a3fc3e42
Make font outline width proportional to movie resolution.
eugeni
parents:
19716
diff
changeset
|
143 double font_scale; |
18937 | 144 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio |
19917
6a31849e2b80
In r19831, font size multiplier was mistakenly applied to border width.
eugeni
parents:
19906
diff
changeset
|
145 double border_scale; |
18937 | 146 } frame_context_t; |
147 | |
148 static ass_instance_t* ass_instance; | |
149 static ass_settings_t* global_settings; | |
150 static text_info_t text_info; | |
151 static render_context_t render_context; | |
152 static frame_context_t frame_context; | |
153 | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
154 // a rendered event |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
155 typedef struct event_images_s { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
156 ass_image_t* imgs; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
157 int top, height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
158 int detect_collisions; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
159 int shift_direction; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
160 ass_event_t* event; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
161 } event_images_t; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
162 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
163 struct render_priv_s { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
164 int top, height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
165 int render_id; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
166 }; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
167 |
18937 | 168 static void ass_lazy_track_init(void) |
169 { | |
170 ass_track_t* track = frame_context.track; | |
171 if (track->PlayResX && track->PlayResY) | |
172 return; | |
173 if (!track->PlayResX && !track->PlayResY) { | |
174 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Neither PlayResX nor PlayResY defined. Assuming 384x288. \n"); | |
175 track->PlayResX = 384; | |
176 track->PlayResY = 288; | |
177 } else { | |
19538 | 178 double orig_aspect = (global_settings->aspect * frame_context.height * frame_context.orig_width) / |
179 frame_context.orig_height / frame_context.width; | |
18937 | 180 if (!track->PlayResY) { |
181 track->PlayResY = track->PlayResX / orig_aspect + .5; | |
182 mp_msg(MSGT_GLOBAL, MSGL_WARN, "PlayResY undefined, setting %d \n", track->PlayResY); | |
183 } else if (!track->PlayResX) { | |
184 track->PlayResX = track->PlayResY * orig_aspect + .5; | |
185 mp_msg(MSGT_GLOBAL, MSGL_WARN, "PlayResX undefined, setting %d \n", track->PlayResX); | |
186 } | |
187 } | |
188 } | |
189 | |
190 ass_instance_t* ass_init(void) | |
191 { | |
192 char* family = 0; | |
193 char* path = 0; | |
194 char* fonts_path = 0; | |
195 int error; | |
196 fc_instance_t* fc_priv; | |
197 FT_Library ft; | |
19518 | 198 ass_instance_t* priv = 0; |
18937 | 199 |
200 if (font_fontconfig && font_name) | |
201 family = strdup(font_name); | |
202 | |
203 if (!font_fontconfig && font_name) | |
204 path = strdup(font_name); | |
205 else | |
206 path = get_path("subfont.ttf"); | |
207 | |
208 fonts_path = get_path("fonts"); | |
209 | |
210 fc_priv = fontconfig_init(fonts_path, family, path); | |
211 | |
212 free(fonts_path); | |
213 if (path) free(path); | |
214 if (family) free(family); | |
215 | |
216 if (!fc_priv) | |
19517 | 217 goto ass_init_exit; |
18937 | 218 |
219 error = FT_Init_FreeType( &ft ); | |
220 if ( error ) { | |
221 mp_msg(MSGT_GLOBAL, MSGL_FATAL, "FT_Init_FreeType failed\n"); | |
222 fontconfig_done(fc_priv); | |
19517 | 223 goto ass_init_exit; |
18937 | 224 } |
225 | |
226 priv = calloc(1, sizeof(ass_instance_t)); | |
227 if (!priv) { | |
228 FT_Done_FreeType(ft); | |
229 fontconfig_done(fc_priv); | |
19517 | 230 goto ass_init_exit; |
18937 | 231 } |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
232 |
19848 | 233 priv->synth_priv = ass_synth_init(); |
234 | |
18937 | 235 priv->library = ft; |
236 priv->fontconfig_priv = fc_priv; | |
237 // images_root and related stuff is zero-filled in calloc | |
238 | |
239 ass_face_cache_init(); | |
240 ass_glyph_cache_init(); | |
241 | |
242 text_info.glyphs = calloc(MAX_GLYPHS, sizeof(glyph_info_t)); | |
243 | |
19517 | 244 ass_init_exit: |
245 if (priv) mp_msg(MSGT_GLOBAL, MSGL_INFO, "[ass] Init\n"); | |
246 else mp_msg(MSGT_GLOBAL, MSGL_ERR, "[ass] Init failed\n"); | |
247 | |
18937 | 248 return priv; |
249 } | |
250 | |
251 void ass_done(ass_instance_t* priv) | |
252 { | |
253 ass_face_cache_done(); | |
254 ass_glyph_cache_done(); | |
255 if (priv && priv->library) FT_Done_FreeType(priv->library); | |
256 if (priv && priv->fontconfig_priv) fontconfig_done(priv->fontconfig_priv); | |
19848 | 257 if (priv && priv->synth_priv) ass_synth_done(priv->synth_priv); |
18937 | 258 if (priv) free(priv); |
259 if (text_info.glyphs) free(text_info.glyphs); | |
260 } | |
261 | |
262 /** | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
263 * \brief Create a new ass_image_t |
18937 | 264 * Parameters are the same as ass_image_t fields. |
265 */ | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
266 static ass_image_t* my_draw_bitmap(unsigned char* bitmap, int bitmap_w, int bitmap_h, int stride, int dst_x, int dst_y, uint32_t color) |
18937 | 267 { |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
268 ass_image_t* img = calloc(1, sizeof(ass_image_t)); |
18937 | 269 |
270 img->w = bitmap_w; | |
271 img->h = bitmap_h; | |
272 img->stride = stride; | |
273 img->bitmap = bitmap; | |
274 img->color = color; | |
275 img->dst_x = dst_x; | |
276 img->dst_y = dst_y; | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
277 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
278 return img; |
18937 | 279 } |
280 | |
281 /** | |
282 * \brief convert bitmap glyph into ass_image_t struct(s) | |
283 * \param bit freetype bitmap glyph, FT_PIXEL_MODE_GRAY | |
284 * \param dst_x bitmap x coordinate in video frame | |
285 * \param dst_y bitmap y coordinate in video frame | |
286 * \param color first color, RGBA | |
287 * \param color2 second color, RGBA | |
288 * \param brk x coordinate relative to glyph origin, color is used to the left of brk, color2 - to the right | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
289 * \param tail pointer to the last image's next field, head of the generated list should be stored here |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
290 * \return pointer to the new list tail |
18937 | 291 * Performs clipping. Uses my_draw_bitmap for actual bitmap convertion. |
292 */ | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
293 static ass_image_t** render_glyph(bitmap_t* bm, int dst_x, int dst_y, uint32_t color, uint32_t color2, int brk, ass_image_t** tail) |
18937 | 294 { |
295 // brk is relative to dst_x | |
296 // color = color left of brk | |
297 // color2 = color right of brk | |
298 int b_x0, b_y0, b_x1, b_y1; // visible part of the bitmap | |
299 int clip_x0, clip_y0, clip_x1, clip_y1; | |
300 int tmp; | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
301 ass_image_t* img; |
18937 | 302 |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
303 dst_x += bm->left; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
304 dst_y += bm->top; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
305 brk -= bm->left; |
18937 | 306 |
307 // clipping | |
308 clip_x0 = render_context.clip_x0; | |
309 clip_y0 = render_context.clip_y0; | |
310 clip_x1 = render_context.clip_x1; | |
311 clip_y1 = render_context.clip_y1; | |
312 b_x0 = 0; | |
313 b_y0 = 0; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
314 b_x1 = bm->w; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
315 b_y1 = bm->h; |
18937 | 316 |
317 tmp = dst_x - clip_x0; | |
318 if (tmp < 0) { | |
319 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "clip left\n"); | |
320 b_x0 = - tmp; | |
321 } | |
322 tmp = dst_y - clip_y0; | |
323 if (tmp < 0) { | |
324 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "clip top\n"); | |
325 b_y0 = - tmp; | |
326 } | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
327 tmp = clip_x1 - dst_x - bm->w; |
18937 | 328 if (tmp < 0) { |
329 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "clip right\n"); | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
330 b_x1 = bm->w + tmp; |
18937 | 331 } |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
332 tmp = clip_y1 - dst_y - bm->h; |
18937 | 333 if (tmp < 0) { |
334 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "clip bottom\n"); | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
335 b_y1 = bm->h + tmp; |
18937 | 336 } |
337 | |
338 if ((b_y0 >= b_y1) || (b_x0 >= b_x1)) | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
339 return tail; |
18937 | 340 |
341 if (brk > b_x0) { // draw left part | |
342 if (brk > b_x1) brk = b_x1; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
343 img = my_draw_bitmap(bm->buffer + bm->w * b_y0 + b_x0, |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
344 brk - b_x0, b_y1 - b_y0, bm->w, |
18937 | 345 dst_x + b_x0, dst_y + b_y0, color); |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
346 *tail = img; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
347 tail = &img->next; |
18937 | 348 } |
349 if (brk < b_x1) { // draw right part | |
350 if (brk < b_x0) brk = b_x0; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
351 img = my_draw_bitmap(bm->buffer + bm->w * b_y0 + brk, |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
352 b_x1 - brk, b_y1 - b_y0, bm->w, |
18937 | 353 dst_x + brk, dst_y + b_y0, color2); |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
354 *tail = img; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
355 tail = &img->next; |
18937 | 356 } |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
357 return tail; |
18937 | 358 } |
359 | |
360 /** | |
361 * \brief Render text_info_t struct into ass_images_t list | |
362 * Rasterize glyphs and put them in glyph cache. | |
363 */ | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
364 static ass_image_t* render_text(text_info_t* text_info, int dst_x, int dst_y) |
18937 | 365 { |
366 int pen_x, pen_y; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
367 int i, error; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
368 bitmap_t* bm; |
18937 | 369 glyph_hash_val_t hash_val; |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
370 ass_image_t* head; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
371 ass_image_t** tail = &head; |
18937 | 372 |
373 for (i = 0; i < text_info->length; ++i) { | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
374 if (text_info->glyphs[i].glyph) { |
18937 | 375 if ((text_info->glyphs[i].symbol == '\n') || (text_info->glyphs[i].symbol == 0)) |
376 continue; | |
19848 | 377 error = glyph_to_bitmap(ass_instance->synth_priv, |
378 text_info->glyphs[i].glyph, text_info->glyphs[i].outline_glyph, | |
379 &text_info->glyphs[i].bm, &text_info->glyphs[i].bm_o, text_info->glyphs[i].be); | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
380 if (error) |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
381 text_info->glyphs[i].symbol = 0; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
382 FT_Done_Glyph(text_info->glyphs[i].glyph); |
19873 | 383 if (text_info->glyphs[i].outline_glyph) |
384 FT_Done_Glyph(text_info->glyphs[i].outline_glyph); | |
18937 | 385 |
386 // cache | |
387 hash_val.bbox_scaled = text_info->glyphs[i].bbox; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
388 hash_val.bm_o = text_info->glyphs[i].bm_o; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
389 hash_val.bm = text_info->glyphs[i].bm; |
18937 | 390 hash_val.advance.x = text_info->glyphs[i].advance.x; |
391 hash_val.advance.y = text_info->glyphs[i].advance.y; | |
392 cache_add_glyph(&(text_info->glyphs[i].hash_key), &hash_val); | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
393 |
18937 | 394 } |
395 } | |
396 | |
397 for (i = 0; i < text_info->length; ++i) { | |
398 glyph_info_t* info = text_info->glyphs + i; | |
19873 | 399 if ((info->symbol == 0) || (info->symbol == '\n') || !info->bm_o) |
18937 | 400 continue; |
401 | |
402 pen_x = dst_x + info->pos.x; | |
403 pen_y = dst_y + info->pos.y; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
404 bm = info->bm_o; |
18937 | 405 |
406 if ((info->effect_type == EF_KARAOKE_KO) && (info->effect_timing <= info->bbox.xMax)) { | |
407 // do nothing | |
408 } else | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
409 tail = render_glyph(bm, pen_x, pen_y, info->c[2], 0, 1000000, tail); |
18937 | 410 } |
411 for (i = 0; i < text_info->length; ++i) { | |
412 glyph_info_t* info = text_info->glyphs + i; | |
19873 | 413 if ((info->symbol == 0) || (info->symbol == '\n') || !info->bm) |
18937 | 414 continue; |
415 | |
416 pen_x = dst_x + info->pos.x; | |
417 pen_y = dst_y + info->pos.y; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
418 bm = info->bm; |
18937 | 419 |
420 if ((info->effect_type == EF_KARAOKE) || (info->effect_type == EF_KARAOKE_KO)) { | |
421 if (info->effect_timing > info->bbox.xMax) | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
422 tail = render_glyph(bm, pen_x, pen_y, info->c[0], 0, 1000000, tail); |
18937 | 423 else |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
424 tail = render_glyph(bm, pen_x, pen_y, info->c[1], 0, 1000000, tail); |
18937 | 425 } else if (info->effect_type == EF_KARAOKE_KF) { |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
426 tail = render_glyph(bm, pen_x, pen_y, info->c[0], info->c[1], info->effect_timing, tail); |
18937 | 427 } else |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
428 tail = render_glyph(bm, pen_x, pen_y, info->c[0], 0, 1000000, tail); |
18937 | 429 } |
430 | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
431 *tail = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
432 return head; |
18937 | 433 } |
434 | |
435 /** | |
436 * \brief Mapping between script and screen coordinates | |
437 */ | |
438 static int x2scr(int x) { | |
19538 | 439 return x*frame_context.width / frame_context.track->PlayResX + global_settings->left_margin; |
18937 | 440 } |
441 /** | |
442 * \brief Mapping between script and screen coordinates | |
443 */ | |
444 static int y2scr(int y) { | |
445 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin; | |
446 } | |
447 // the same for toptitles | |
448 static int y2scr_top(int y) { | |
19538 | 449 if (global_settings->use_margins) |
450 return y * frame_context.orig_height / frame_context.track->PlayResY; | |
451 else | |
452 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin; | |
18937 | 453 } |
454 // the same for subtitles | |
455 static int y2scr_sub(int y) { | |
19538 | 456 if (global_settings->use_margins) |
457 return y * frame_context.orig_height / frame_context.track->PlayResY + | |
458 global_settings->top_margin + global_settings->bottom_margin; | |
459 else | |
460 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin; | |
18937 | 461 } |
462 | |
463 static void vmirror_bbox(FT_BBox* orig, FT_BBox* pbbox) { | |
464 pbbox->xMin = orig->xMin; | |
465 pbbox->xMax = orig->xMax; | |
466 pbbox->yMin = - orig->yMax; | |
467 pbbox->yMax = - orig->yMin; | |
468 } | |
469 | |
470 static void compute_string_bbox( text_info_t* info, FT_BBox *abbox ) { | |
471 FT_BBox bbox; | |
472 int n; | |
473 | |
474 /* initialize string bbox to "empty" values */ | |
475 bbox.xMin = bbox.yMin = 32000; | |
476 bbox.xMax = bbox.yMax = -32000; | |
477 | |
478 /* for each glyph image, compute its bounding box, */ | |
479 /* translate it, and grow the string bbox */ | |
480 for ( n = 0; n < info->length; n++ ) { | |
481 FT_BBox glyph_bbox; | |
482 vmirror_bbox( &(info->glyphs[n].bbox), &glyph_bbox ); | |
483 glyph_bbox.xMin += info->glyphs[n].pos.x; | |
484 glyph_bbox.xMax += info->glyphs[n].pos.x; | |
485 glyph_bbox.yMin += info->glyphs[n].pos.y; | |
486 glyph_bbox.yMax += info->glyphs[n].pos.y; | |
487 if ( glyph_bbox.xMin < bbox.xMin ) bbox.xMin = glyph_bbox.xMin; | |
488 if ( glyph_bbox.yMin < bbox.yMin ) bbox.yMin = glyph_bbox.yMin; | |
489 if ( glyph_bbox.xMax > bbox.xMax ) bbox.xMax = glyph_bbox.xMax; | |
490 if ( glyph_bbox.yMax > bbox.yMax ) bbox.yMax = glyph_bbox.yMax; | |
491 } | |
492 | |
493 /* check that we really grew the string bbox */ | |
494 if ( bbox.xMin > bbox.xMax ) { | |
495 bbox.xMin = 0; | |
496 bbox.yMin = 0; | |
497 bbox.xMax = 0; | |
498 bbox.yMax = 0; | |
499 } | |
500 | |
501 /* return string bbox */ | |
502 *abbox = bbox; | |
503 } | |
504 | |
505 | |
506 /** | |
507 * \brief Check if starting part of (*p) matches sample. If true, shift p to the first symbol after the matching part. | |
508 */ | |
19104
2ec2301183cd
marks several read-only string parameters which aren't modified inside the called function as const. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
19066
diff
changeset
|
509 static inline int mystrcmp(char** p, const char* sample) { |
18937 | 510 int len = strlen(sample); |
511 if (strncmp(*p, sample, len) == 0) { | |
512 (*p) += len; | |
513 return 1; | |
514 } else | |
515 return 0; | |
516 } | |
517 | |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
19399
diff
changeset
|
518 double ass_internal_font_size_coeff = 0.8; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
19399
diff
changeset
|
519 |
18937 | 520 static void change_font_size(int sz) |
521 { | |
19825
f351a3fc3e42
Make font outline width proportional to movie resolution.
eugeni
parents:
19716
diff
changeset
|
522 double size = sz * frame_context.font_scale; |
18937 | 523 |
524 if (size < 1) | |
525 size = 1; | |
526 else if (size > frame_context.height * 2) | |
527 size = frame_context.height * 2; | |
528 | |
529 FT_Set_Pixel_Sizes(render_context.face, 0, size); | |
530 | |
531 render_context.font_size = sz; | |
532 } | |
533 | |
534 /** | |
535 * \brief Change current font, using setting from render_context. | |
536 */ | |
537 static void update_font(void) | |
538 { | |
539 int error; | |
540 unsigned val; | |
541 ass_instance_t* priv = frame_context.ass_priv; | |
542 face_desc_t desc; | |
543 desc.family = strdup(render_context.family); | |
544 | |
545 val = render_context.bold; | |
546 // 0 = normal, 1 = bold, >1 = exact weight | |
547 if (val == 0) val = 80; // normal | |
548 else if (val == 1) val = 200; // bold | |
549 desc.bold = val; | |
550 | |
551 val = render_context.italic; | |
552 if (val == 0) val = 0; // normal | |
553 else if (val == 1) val = 110; //italic | |
554 desc.italic = val; | |
555 | |
556 error = ass_new_face(priv->library, priv->fontconfig_priv, &desc, &(render_context.face)); | |
557 if (error) { | |
558 render_context.face = 0; | |
559 } | |
560 | |
561 if (render_context.face) | |
562 change_font_size(render_context.font_size); | |
563 } | |
564 | |
565 /** | |
566 * \brief Change border width | |
19873 | 567 * negative value resets border to style value |
18937 | 568 */ |
569 static void change_border(double border) | |
570 { | |
19918
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
571 int b; |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
572 if (!render_context.face) return; |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
573 |
19919 | 574 if (border < 0) { |
575 if (render_context.style->BorderStyle == 1) { | |
576 if (render_context.style->Outline == 0 && render_context.style->Shadow > 0) | |
19873 | 577 border = 1.; |
19919 | 578 else |
579 border = render_context.style->Outline; | |
580 } else | |
581 border = 1.; | |
582 } | |
583 render_context.border = border; | |
19873 | 584 |
19919 | 585 b = 64 * border * frame_context.border_scale; |
586 if (b > 0) { | |
19918
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
587 if (!render_context.stroker) { |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
588 int error; |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
589 #if (FREETYPE_MAJOR > 2) || ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR > 1)) |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
590 error = FT_Stroker_New( ass_instance->library, &render_context.stroker ); |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
591 #else // < 2.2 |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
592 error = FT_Stroker_New( render_context.face->memory, &render_context.stroker ); |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
593 #endif |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
594 if (error) { |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
595 mp_msg(MSGT_GLOBAL, MSGL_V, "failed to get stroker\n"); |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
596 render_context.stroker = 0; |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
597 } |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
598 } |
1de67089c19a
Fix FT_Stroker use in libass. The previous variant ended up with 0-width
eugeni
parents:
19917
diff
changeset
|
599 if (render_context.stroker) |
19873 | 600 FT_Stroker_Set( render_context.stroker, b, |
19919 | 601 FT_STROKER_LINECAP_ROUND, |
602 FT_STROKER_LINEJOIN_ROUND, | |
603 0 ); | |
604 } else { | |
605 FT_Stroker_Done(render_context.stroker); | |
606 render_context.stroker = 0; | |
607 } | |
18937 | 608 } |
609 | |
610 #define _r(c) ((c)>>24) | |
611 #define _g(c) (((c)>>16)&0xFF) | |
612 #define _b(c) (((c)>>8)&0xFF) | |
613 #define _a(c) ((c)&0xFF) | |
614 | |
615 /** | |
616 * \brief Calculate a weighted average of two colors | |
617 * calculates c1*(1-a) + c2*a, but separately for each component except alpha | |
618 */ | |
619 static void change_color(uint32_t* var, uint32_t new, double pwr) | |
620 { | |
621 (*var)= ((uint32_t)(_r(*var) * (1 - pwr) + _r(new) * pwr) << 24) + | |
622 ((uint32_t)(_g(*var) * (1 - pwr) + _g(new) * pwr) << 16) + | |
623 ((uint32_t)(_b(*var) * (1 - pwr) + _b(new) * pwr) << 8) + | |
624 _a(*var); | |
625 } | |
626 | |
627 // like change_color, but for alpha component only | |
628 static void change_alpha(uint32_t* var, uint32_t new, double pwr) | |
629 { | |
630 *var = (_r(*var) << 24) + (_g(*var) << 16) + (_b(*var) << 8) + (_a(*var) * (1 - pwr) + _a(new) * pwr); | |
631 } | |
632 | |
19406
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
633 /** |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
634 * \brief Multiply two alpha values |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
635 * \param a first value |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
636 * \param b second value |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
637 * \return result of multiplication |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
638 * Parameters and result are limited by 0xFF. |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
639 */ |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
640 static uint32_t mult_alpha(uint32_t a, uint32_t b) |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
641 { |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
642 return 0xFF - (0xFF - a) * (0xFF - b) / 0xFF; |
747a5c394a69
Fix wrong handling of transparency in \fad(\fade).
eugeni
parents:
19405
diff
changeset
|
643 } |
18937 | 644 |
645 /** | |
646 * \brief Calculate alpha value by piecewise linear function | |
647 * Used for \fad, \fade implementation. | |
648 */ | |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
649 static unsigned interpolate_alpha(long long now, |
18937 | 650 long long t1, long long t2, long long t3, long long t4, |
651 unsigned a1, unsigned a2, unsigned a3) | |
652 { | |
653 unsigned a; | |
654 double cf; | |
655 if (now <= t1) { | |
656 a = a1; | |
657 } else if (now >= t4) { | |
658 a = a3; | |
659 } else if (now < t2) { // and > t1 | |
660 cf = ((double)(now - t1)) / (t2 - t1); | |
661 a = a1 * (1 - cf) + a2 * cf; | |
662 } else if (now > t3) { | |
663 cf = ((double)(now - t3)) / (t4 - t3); | |
664 a = a2 * (1 - cf) + a3 * cf; | |
665 } else { // t2 <= now <= t3 | |
666 a = a2; | |
667 } | |
668 | |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
669 return a; |
18937 | 670 } |
671 | |
19873 | 672 static void reset_render_context(); |
673 | |
18937 | 674 /** |
675 * \brief Parse style override tag. | |
676 * \param p string to parse | |
677 * \param pwr multiplier for some tag effects (comes from \t tags) | |
678 */ | |
679 static char* parse_tag(char* p, double pwr) { | |
680 #define skip_all(x) if (*p == (x)) ++p; else { \ | |
681 while ((*p != (x)) && (*p != '}') && (*p != 0)) {++p;} } | |
682 #define skip(x) if (*p == (x)) ++p; else { return p; } | |
683 | |
684 skip_all('\\'); | |
685 if ((*p == '}') || (*p == 0)) | |
686 return p; | |
687 | |
688 if (mystrcmp(&p, "fsc")) { | |
689 char tp = *p++; | |
690 double val; | |
691 if (tp == 'x') { | |
692 if (mystrtod(&p, &val)) { | |
693 val /= 100; | |
694 render_context.scale_x = (val - 1.) * pwr + 1.; | |
695 } else | |
696 render_context.scale_x = render_context.style->ScaleX; | |
697 } else if (tp == 'y') { | |
698 if (mystrtod(&p, &val)) { | |
699 val /= 100; | |
700 render_context.scale_y = (val - 1.) * pwr + 1.; | |
701 } else | |
702 render_context.scale_y = render_context.style->ScaleY; | |
703 } | |
704 } else if (mystrcmp(&p, "fsp")) { | |
705 int val; | |
706 if (mystrtoi(&p, 10, &val)) | |
707 render_context.hspacing = val * pwr; | |
708 else | |
709 render_context.hspacing = 0; | |
710 } else if (mystrcmp(&p, "fs")) { | |
711 int val; | |
712 if (mystrtoi(&p, 10, &val)) | |
713 val = render_context.font_size * ( 1 - pwr ) + val * pwr; | |
714 else | |
715 val = render_context.style->FontSize; | |
716 if (render_context.face) | |
717 change_font_size(val); | |
718 } else if (mystrcmp(&p, "bord")) { | |
719 double val; | |
720 if (mystrtod(&p, &val)) | |
721 val = render_context.border * ( 1 - pwr ) + val * pwr; | |
722 else | |
19873 | 723 val = -1.; // reset to default |
18937 | 724 change_border(val); |
725 } else if (mystrcmp(&p, "move")) { | |
726 int x1, x2, y1, y2; | |
19044 | 727 long long t1, t2, delta_t, t; |
18937 | 728 int x, y; |
729 double k; | |
730 skip('('); | |
731 x1 = strtol(p, &p, 10); | |
732 skip(','); | |
733 y1 = strtol(p, &p, 10); | |
734 skip(','); | |
735 x2 = strtol(p, &p, 10); | |
736 skip(','); | |
737 y2 = strtol(p, &p, 10); | |
19044 | 738 if (*p == ',') { |
739 skip(','); | |
740 t1 = strtoll(p, &p, 10); | |
741 skip(','); | |
742 t2 = strtoll(p, &p, 10); | |
19378 | 743 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "movement6: (%d, %d) -> (%d, %d), (%" PRId64 " .. %" PRId64 ")\n", |
744 x1, y1, x2, y2, (int64_t)t1, (int64_t)t2); | |
19044 | 745 } else { |
746 t1 = 0; | |
747 t2 = render_context.event->Duration; | |
748 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "movement: (%d, %d) -> (%d, %d)\n", x1, y1, x2, y2); | |
749 } | |
750 skip(')'); | |
751 delta_t = t2 - t1; | |
752 t = frame_context.time - render_context.event->Start; | |
753 if (t < t1) | |
754 k = 0.; | |
755 else if (t > t2) | |
756 k = 1.; | |
757 else k = ((double)(t - t1)) / delta_t; | |
18937 | 758 x = k * (x2 - x1) + x1; |
759 y = k * (y2 - y1) + y1; | |
760 render_context.pos_x = x; | |
761 render_context.pos_y = y; | |
762 render_context.detect_collisions = 0; | |
763 render_context.evt_type = EVENT_POSITIONED; | |
764 } else if (mystrcmp(&p, "frx") || mystrcmp(&p, "fry")) { | |
19622 | 765 double val; |
766 mystrtod(&p, &val); | |
18937 | 767 mp_msg(MSGT_GLOBAL, MSGL_V, "frx/fry unimplemented \n"); |
768 } else if (mystrcmp(&p, "frz") || mystrcmp(&p, "fr")) { | |
769 double angle; | |
19622 | 770 double val; |
771 mystrtod(&p, &val); | |
18937 | 772 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "setting rotation to %.2f\n", val * pwr); |
773 angle = M_PI * val / 180; | |
774 render_context.rotation = angle * pwr; | |
775 } else if (mystrcmp(&p, "fn")) { | |
776 char* start = p; | |
777 char* family; | |
778 skip_all('\\'); | |
779 family = malloc(p - start + 1); | |
780 strncpy(family, start, p - start); | |
781 family[p - start] = '\0'; | |
782 if (render_context.family) | |
783 free(render_context.family); | |
784 render_context.family = family; | |
785 update_font(); | |
786 } else if (mystrcmp(&p, "alpha")) { | |
787 uint32_t val; | |
19691 | 788 int i; |
18937 | 789 if (strtocolor(&p, &val)) { |
790 unsigned char a = val >> 24; | |
19691 | 791 for (i = 0; i < 4; ++i) |
792 change_alpha(&render_context.c[i], a, pwr); | |
18937 | 793 } else { |
19691 | 794 change_alpha(&render_context.c[0], render_context.style->PrimaryColour, pwr); |
795 change_alpha(&render_context.c[1], render_context.style->SecondaryColour, pwr); | |
796 change_alpha(&render_context.c[2], render_context.style->OutlineColour, pwr); | |
797 change_alpha(&render_context.c[3], render_context.style->BackColour, pwr); | |
18937 | 798 } |
799 // FIXME: simplify | |
800 } else if (mystrcmp(&p, "an")) { | |
801 int val = strtol(p, &p, 10); | |
802 int v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment | |
803 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "an %d\n", val); | |
804 if (v != 0) v = 3 - v; | |
805 val = ((val - 1) % 3) + 1; // horizontal alignment | |
806 val += v*4; | |
807 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "align %d\n", val); | |
808 render_context.alignment = val; | |
809 } else if (mystrcmp(&p, "a")) { | |
810 int val = strtol(p, &p, 10); | |
811 render_context.alignment = val; | |
812 } else if (mystrcmp(&p, "pos")) { | |
813 int v1, v2; | |
814 skip('('); | |
815 v1 = strtol(p, &p, 10); | |
816 skip(','); | |
817 v2 = strtol(p, &p, 10); | |
818 skip(')'); | |
819 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "pos(%d, %d)\n", v1, v2); | |
820 render_context.evt_type = EVENT_POSITIONED; | |
821 render_context.detect_collisions = 0; | |
822 render_context.pos_x = v1; | |
823 render_context.pos_y = v2; | |
19398
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
824 } else if (mystrcmp(&p, "fad")) { |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
825 int a1, a2, a3; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
826 long long t1, t2, t3, t4; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
827 if (*p == 'e') ++p; // either \fad or \fade |
18937 | 828 skip('('); |
829 a1 = strtol(p, &p, 10); | |
830 skip(','); | |
831 a2 = strtol(p, &p, 10); | |
19398
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
832 if (*p == ')') { |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
833 // 2-argument version (\fad, according to specs) |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
834 // a1 and a2 are fade-in and fade-out durations |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
835 t1 = 0; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
836 t4 = render_context.event->Duration; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
837 t2 = a1; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
838 t3 = t4 - a2; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
839 a1 = 0xFF; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
840 a2 = 0; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
841 a3 = 0xFF; |
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
842 } else { |
19399 | 843 // 6-argument version (\fade) |
844 // a1 and a2 (and a3) are opacity values | |
845 skip(','); | |
846 a3 = strtol(p, &p, 10); | |
847 skip(','); | |
848 t1 = strtoll(p, &p, 10); | |
849 skip(','); | |
850 t2 = strtoll(p, &p, 10); | |
851 skip(','); | |
852 t3 = strtoll(p, &p, 10); | |
853 skip(','); | |
854 t4 = strtoll(p, &p, 10); | |
19398
bb5164e0f70f
Allow \fade to be used in place of \fad and vice versa.
eugeni
parents:
19378
diff
changeset
|
855 } |
18937 | 856 skip(')'); |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
857 render_context.fade = interpolate_alpha(frame_context.time - render_context.event->Start, t1, t2, t3, t4, a1, a2, a3); |
18937 | 858 } else if (mystrcmp(&p, "org")) { |
859 int v1, v2; | |
860 skip('('); | |
861 v1 = strtol(p, &p, 10); | |
862 skip(','); | |
863 v2 = strtol(p, &p, 10); | |
864 skip(')'); | |
865 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "org(%d, %d)\n", v1, v2); | |
866 // render_context.evt_type = EVENT_POSITIONED; | |
867 render_context.org_x = v1; | |
868 render_context.org_y = v2; | |
869 } else if (mystrcmp(&p, "t")) { | |
870 double v[3]; | |
871 int v1, v2; | |
872 double v3; | |
873 int cnt; | |
874 long long t1, t2, t, delta_t; | |
875 double k; | |
876 skip('('); | |
877 for (cnt = 0; cnt < 3; ++cnt) { | |
878 if (*p == '\\') | |
879 break; | |
880 v[cnt] = strtod(p, &p); | |
881 skip(','); | |
882 } | |
883 if (cnt == 3) { | |
884 v1 = v[0]; v2 = v[1]; v3 = v[2]; | |
885 } else if (cnt == 2) { | |
886 v1 = v[0]; v2 = v[1]; v3 = 1.; | |
887 } else if (cnt == 1) { | |
888 v1 = 0; v2 = render_context.event->Duration; v3 = v[0]; | |
889 } else { // cnt == 0 | |
890 v1 = 0; v2 = render_context.event->Duration; v3 = 1.; | |
891 } | |
892 render_context.detect_collisions = 0; | |
893 t1 = v1; | |
894 t2 = v2; | |
895 delta_t = v2 - v1; | |
896 t = frame_context.time - render_context.event->Start; // FIXME: move to render_context | |
897 if (t < t1) | |
898 k = 0.; | |
899 else if (t > t2) | |
900 k = 1.; | |
901 else k = ((double)(t - t1)) / delta_t; | |
902 while (*p == '\\') | |
903 p = parse_tag(p, k); // maybe k*pwr ? no, specs forbid nested \t's | |
904 skip_all(')'); // FIXME: better skip(')'), but much more tags support required | |
905 } else if (mystrcmp(&p, "clip")) { | |
906 int x0, y0, x1, y1; | |
907 int res = 1; | |
908 skip('('); | |
909 res &= mystrtoi(&p, 10, &x0); | |
910 skip(','); | |
911 res &= mystrtoi(&p, 10, &y0); | |
912 skip(','); | |
913 res &= mystrtoi(&p, 10, &x1); | |
914 skip(','); | |
915 res &= mystrtoi(&p, 10, &y1); | |
916 skip(')'); | |
917 if (res) { | |
918 render_context.clip_x0 = render_context.clip_x0 * (1-pwr) + x0 * pwr; | |
919 render_context.clip_x1 = render_context.clip_x1 * (1-pwr) + x1 * pwr; | |
920 render_context.clip_y0 = render_context.clip_y0 * (1-pwr) + y0 * pwr; | |
921 render_context.clip_y1 = render_context.clip_y1 * (1-pwr) + y1 * pwr; | |
922 } else { | |
923 render_context.clip_x0 = 0; | |
924 render_context.clip_y0 = 0; | |
925 render_context.clip_x1 = frame_context.track->PlayResX; | |
926 render_context.clip_y1 = frame_context.track->PlayResY; | |
927 } | |
928 } else if (mystrcmp(&p, "c")) { | |
929 uint32_t val; | |
930 if (!strtocolor(&p, &val)) | |
931 val = render_context.style->PrimaryColour; | |
932 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "color: %X\n", val); | |
19691 | 933 change_color(&render_context.c[0], val, pwr); |
18937 | 934 } else if ((*p >= '1') && (*p <= '4') && (++p) && (mystrcmp(&p, "c") || mystrcmp(&p, "a"))) { |
935 char n = *(p-2); | |
19691 | 936 int cidx = n - '1'; |
18937 | 937 char cmd = *(p-1); |
938 uint32_t val; | |
939 assert((n >= '1') && (n <= '4')); | |
940 if (!strtocolor(&p, &val)) | |
941 switch(n) { | |
942 case '1': val = render_context.style->PrimaryColour; break; | |
943 case '2': val = render_context.style->SecondaryColour; break; | |
944 case '3': val = render_context.style->OutlineColour; break; | |
945 case '4': val = render_context.style->BackColour; break; | |
946 default : val = 0; break; // impossible due to assert; avoid compilation warning | |
947 } | |
948 switch (cmd) { | |
19691 | 949 case 'c': change_color(render_context.c + cidx, val, pwr); break; |
950 case 'a': change_alpha(render_context.c + cidx, val >> 24, pwr); break; | |
18937 | 951 default: mp_msg(MSGT_GLOBAL, MSGL_WARN, "Bad command: %c%c\n", n, cmd); break; |
952 } | |
19691 | 953 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "single c/a at %f: %c%c = %X \n", pwr, n, cmd, render_context.c[cidx]); |
18937 | 954 } else if (mystrcmp(&p, "r")) { |
19873 | 955 reset_render_context(); |
18937 | 956 } else if (mystrcmp(&p, "be")) { |
957 int val; | |
19848 | 958 if (mystrtoi(&p, 10, &val)) |
959 render_context.be = val ? 1 : 0; | |
960 else | |
961 render_context.be = 0; | |
18937 | 962 mp_msg(MSGT_GLOBAL, MSGL_V, "be unimplemented \n"); |
963 } else if (mystrcmp(&p, "b")) { | |
964 int b; | |
965 if (mystrtoi(&p, 10, &b)) | |
966 render_context.bold = b; | |
967 else | |
968 render_context.bold = - render_context.style->Bold; | |
969 update_font(); | |
970 } else if (mystrcmp(&p, "i")) { | |
971 int i; | |
972 if (mystrtoi(&p, 10, &i)) | |
973 render_context.italic = i; | |
974 else | |
975 render_context.italic = - render_context.style->Italic; | |
976 update_font(); | |
977 } else if (mystrcmp(&p, "kf") || mystrcmp(&p, "K")) { | |
978 int val = strtol(p, &p, 10); | |
979 render_context.effect_type = EF_KARAOKE_KF; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
980 if (render_context.effect_timing) |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
981 render_context.effect_skip_timing += render_context.effect_timing; |
18937 | 982 render_context.effect_timing = val * 10; |
983 } else if (mystrcmp(&p, "ko")) { | |
984 int val = strtol(p, &p, 10); | |
985 render_context.effect_type = EF_KARAOKE_KO; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
986 if (render_context.effect_timing) |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
987 render_context.effect_skip_timing += render_context.effect_timing; |
18937 | 988 render_context.effect_timing = val * 10; |
989 } else if (mystrcmp(&p, "k")) { | |
990 int val = strtol(p, &p, 10); | |
991 render_context.effect_type = EF_KARAOKE; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
992 if (render_context.effect_timing) |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
993 render_context.effect_skip_timing += render_context.effect_timing; |
18937 | 994 render_context.effect_timing = val * 10; |
995 } | |
996 | |
997 return p; | |
998 | |
999 #undef skip | |
1000 #undef skip_all | |
1001 } | |
1002 | |
1003 /** | |
1004 * \brief Get next ucs4 char from string, parsing and executing style overrides | |
1005 * \param str string pointer | |
1006 * \return ucs4 code of the next char | |
1007 * On return str points to the unparsed part of the string | |
1008 */ | |
1009 static unsigned get_next_char(char** str) | |
1010 { | |
1011 char* p = *str; | |
1012 unsigned chr; | |
1013 if (*p == '{') { // '\0' goes here | |
1014 p++; | |
1015 while (1) { | |
1016 p = parse_tag(p, 1.); | |
1017 if (*p == '}') { // end of tag | |
1018 p++; | |
1019 if (*p == '{') { | |
1020 p++; | |
1021 continue; | |
1022 } else | |
1023 break; | |
1024 } else if (*p != '\\') | |
1025 mp_msg(MSGT_GLOBAL, MSGL_V, "Unable to parse: \"%s\" \n", p); | |
1026 if (*p == 0) | |
1027 break; | |
1028 } | |
1029 } | |
1030 if (*p == '\t') { | |
1031 ++p; | |
1032 *str = p; | |
1033 return ' '; | |
1034 } | |
1035 if (*p == '\\') { | |
1036 if ((*(p+1) == 'N') || ((*(p+1) == 'n') && (frame_context.track->WrapStyle == 2))) { | |
1037 p += 2; | |
1038 *str = p; | |
1039 return '\n'; | |
1040 } else if (*(p+1) == 'n') { | |
1041 p += 2; | |
1042 *str = p; | |
1043 return ' '; | |
1044 } | |
1045 } | |
1046 chr = utf8_get_char(&p); | |
1047 *str = p; | |
1048 return chr; | |
1049 } | |
1050 | |
19556 | 1051 static void apply_transition_effects(ass_event_t* event) |
1052 { | |
1053 int v[4]; | |
1054 int cnt; | |
1055 char* p = event->Effect; | |
1056 | |
1057 if (!p || !*p) return; | |
1058 | |
1059 cnt = 0; | |
1060 while (cnt < 4 && (p = strchr(p, ';'))) { | |
1061 v[cnt++] = atoi(++p); | |
1062 } | |
1063 | |
1064 if (strncmp(event->Effect, "Banner;", 7) == 0) { | |
1065 int delay; | |
1066 if (cnt < 1) { | |
1067 mp_msg(MSGT_GLOBAL, MSGL_V, "Error parsing effect: %s \n", event->Effect); | |
1068 return; | |
1069 } | |
1070 if (cnt >= 2 && v[1] == 0) // right-to-left | |
1071 render_context.scroll_direction = SCROLL_RL; | |
1072 else // left-to-right | |
1073 render_context.scroll_direction = SCROLL_LR; | |
1074 | |
1075 delay = v[0]; | |
1076 if (delay == 0) delay = 1; // ? | |
1077 render_context.scroll_shift = (frame_context.time - render_context.event->Start) / delay; | |
1078 render_context.evt_type = EVENT_HSCROLL; | |
1079 return; | |
1080 } | |
1081 | |
1082 if (strncmp(event->Effect, "Scroll up;", 10) == 0) { | |
1083 render_context.scroll_direction = SCROLL_BT; | |
1084 } else if (strncmp(event->Effect, "Scroll down;", 12) == 0) { | |
1085 render_context.scroll_direction = SCROLL_TB; | |
1086 } else { | |
1087 mp_msg(MSGT_GLOBAL, MSGL_V, "Unknown transition effect: %s \n", event->Effect); | |
1088 return; | |
1089 } | |
1090 // parse scroll up/down parameters | |
1091 { | |
1092 int delay; | |
1093 int y0, y1; | |
1094 if (cnt < 3) { | |
1095 mp_msg(MSGT_GLOBAL, MSGL_V, "Error parsing effect: %s \n", event->Effect); | |
1096 return; | |
1097 } | |
1098 delay = v[2]; | |
1099 if (delay == 0) delay = 1; // ? | |
1100 render_context.scroll_shift = (frame_context.time - render_context.event->Start) / delay; | |
1101 if (v[0] < v[1]) { | |
1102 y0 = v[0]; y1 = v[1]; | |
1103 } else { | |
1104 y0 = v[1]; y1 = v[0]; | |
1105 } | |
1106 if (y1 == 0) | |
1107 y1 = frame_context.track->PlayResY; // y0=y1=0 means fullscreen scrolling | |
1108 render_context.clip_y0 = y0; | |
1109 render_context.clip_y1 = y1; | |
1110 render_context.evt_type = EVENT_VSCROLL; | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1111 render_context.detect_collisions = 0; |
19556 | 1112 } |
1113 | |
1114 } | |
1115 | |
18937 | 1116 /** |
19873 | 1117 * \brief partially reset render_context to style values |
1118 * Works like {\r}: resets some style overrides | |
1119 */ | |
1120 static void reset_render_context(void) | |
1121 { | |
1122 render_context.c[0] = render_context.style->PrimaryColour; | |
1123 render_context.c[1] = render_context.style->SecondaryColour; | |
1124 render_context.c[2] = render_context.style->OutlineColour; | |
1125 render_context.c[3] = render_context.style->BackColour; | |
1126 render_context.font_size = render_context.style->FontSize; | |
1127 | |
1128 if (render_context.family) | |
1129 free(render_context.family); | |
1130 render_context.family = strdup(render_context.style->FontName); | |
1131 render_context.bold = - render_context.style->Bold; | |
1132 render_context.italic = - render_context.style->Italic; | |
1133 update_font(); | |
1134 | |
1135 change_border(-1.); | |
1136 render_context.scale_x = render_context.style->ScaleX; | |
1137 render_context.scale_y = render_context.style->ScaleY; | |
1138 render_context.hspacing = 0; // FIXME | |
1139 render_context.be = 0; | |
1140 | |
1141 // FIXME: does not reset unsupported attributes. | |
1142 } | |
1143 | |
1144 /** | |
18937 | 1145 * \brief Start new event. Reset render_context. |
1146 */ | |
19873 | 1147 static void init_render_context(ass_event_t* event) |
18937 | 1148 { |
1149 render_context.event = event; | |
1150 render_context.style = frame_context.track->styles + event->Style; | |
19873 | 1151 |
1152 reset_render_context(); | |
1153 | |
18937 | 1154 render_context.evt_type = EVENT_NORMAL; |
1155 render_context.alignment = 0; | |
19404 | 1156 render_context.rotation = M_PI * render_context.style->Angle / 180.; |
18937 | 1157 render_context.pos_x = 0; |
1158 render_context.pos_y = 0; | |
1159 render_context.org_x = 0; | |
1160 render_context.org_y = 0; | |
1161 render_context.clip_x0 = 0; | |
1162 render_context.clip_y0 = 0; | |
1163 render_context.clip_x1 = frame_context.track->PlayResX; | |
1164 render_context.clip_y1 = frame_context.track->PlayResY; | |
1165 render_context.detect_collisions = 1; | |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1166 render_context.fade = 0; |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1167 render_context.effect_type = EF_NONE; |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1168 render_context.effect_timing = 0; |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1169 render_context.effect_skip_timing = 0; |
18937 | 1170 |
19556 | 1171 apply_transition_effects(event); |
18937 | 1172 } |
1173 | |
19873 | 1174 static void free_render_context(void) |
18937 | 1175 { |
1176 } | |
1177 | |
1178 /** | |
1179 * \brief Get normal and outline glyphs from cache (if possible) or font face | |
1180 * \param index face glyph index | |
1181 * \param symbol ucs4 char | |
1182 * \param info out: struct filled with extracted data | |
1183 * \param advance advance vector of the extracted glyph | |
1184 * \return 0 on success | |
1185 */ | |
1186 static int get_glyph(int index, int symbol, glyph_info_t* info, FT_Vector* advance) | |
1187 { | |
1188 int error; | |
1189 glyph_hash_val_t* val; | |
1190 glyph_hash_key_t* key = &(info->hash_key); | |
1191 | |
1192 key->face = render_context.face; | |
1193 key->size = render_context.font_size; | |
1194 key->index = index; | |
1195 key->outline = (render_context.border * 0xFFFF); // convert to 16.16 | |
1196 key->scale_x = (render_context.scale_x * 0xFFFF); | |
1197 key->scale_y = (render_context.scale_y * 0xFFFF); | |
1198 key->angle = (render_context.rotation * 0xFFFF); | |
1199 key->advance = *advance; | |
1200 key->bold = render_context.bold; | |
1201 key->italic = render_context.italic; | |
19848 | 1202 key->be = render_context.be; |
18937 | 1203 |
1204 val = cache_find_glyph(key); | |
1205 // val = 0; | |
1206 | |
1207 if (val) { | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
1208 info->glyph = info->outline_glyph = 0; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
1209 info->bm = val->bm; |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
1210 info->bm_o = val->bm_o; |
18937 | 1211 info->bbox = val->bbox_scaled; |
1212 info->advance.x = val->advance.x; | |
1213 info->advance.y = val->advance.y; | |
1214 | |
1215 return 0; | |
1216 } | |
1217 | |
1218 // not found, get a new outline glyph from face | |
1219 // mp_msg(MSGT_GLOBAL, MSGL_INFO, "miss, index = %d, symbol = %c, adv = (%d, %d)\n", index, symbol, advance->x, advance->y); | |
1220 | |
1221 error = FT_Load_Glyph(render_context.face, index, FT_LOAD_NO_BITMAP ); | |
1222 if (error) { | |
1223 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Error loading glyph\n"); | |
1224 return error; | |
1225 } | |
1226 | |
1227 #if (FREETYPE_MAJOR > 2) || \ | |
1228 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \ | |
1229 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10)) | |
1230 // FreeType >= 2.1.10 required | |
1231 if (!(render_context.face->style_flags & FT_STYLE_FLAG_ITALIC) && | |
1232 ((render_context.italic == 1) || (render_context.italic > 55))) { | |
1233 FT_GlyphSlot_Oblique(render_context.face->glyph); | |
1234 } | |
1235 #endif | |
1236 error = FT_Get_Glyph(render_context.face->glyph, &(info->glyph)); | |
1237 if (error) { | |
1238 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Error getting glyph\n"); | |
1239 return error; | |
1240 } | |
1241 | |
1242 info->advance.x = info->glyph->advance.x >> 10; | |
1243 info->advance.y = info->glyph->advance.y >> 10; | |
1244 | |
19873 | 1245 if (render_context.stroker) { |
1246 info->outline_glyph = info->glyph; | |
1247 error = FT_Glyph_Stroke( &(info->outline_glyph), render_context.stroker, 0 ); // don't destroy original | |
1248 if (error) { | |
1249 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FT_Glyph_Stroke error %d \n", error); | |
1250 } | |
1251 } else { | |
1252 info->outline_glyph = 0; | |
19002
da05237044c2
Ignoring FT_Glyph_Stroke() errors can potentially lead to double free().
eugeni
parents:
18937
diff
changeset
|
1253 } |
18937 | 1254 |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
1255 info->bm = info->bm_o = 0; |
18937 | 1256 |
1257 return 0; | |
1258 } | |
1259 | |
1260 /** | |
1261 * \brief rearrange text between lines | |
1262 * \param max_text_width maximal text line width in pixels | |
1263 * The algo is similar to the one in libvo/sub.c: | |
1264 * 1. Place text, wrapping it when current line is full | |
1265 * 2. Try moving words from the end of a line to the beginning of the next one while it reduces | |
1266 * the difference in lengths between this two lines. | |
1267 * The result may not be optimal, but usually is good enough. | |
1268 */ | |
1269 static void wrap_lines_smart(int max_text_width) | |
1270 { | |
1271 int i, j; | |
1272 glyph_info_t *cur, *s1, *e1, *s2, *s3, *w; | |
1273 int last_space; | |
1274 int break_type; | |
1275 int exit; | |
1276 int pen_shift_x; | |
1277 int pen_shift_y; | |
1278 int max_asc, max_desc; | |
1279 int cur_line; | |
1280 | |
1281 last_space = -1; | |
1282 text_info.n_lines = 1; | |
1283 break_type = 0; | |
1284 s1 = text_info.glyphs; // current line start | |
1285 for (i = 0; i < text_info.length; ++i) { | |
19370 | 1286 int break_at, s_offset, len; |
18937 | 1287 cur = text_info.glyphs + i; |
19370 | 1288 break_at = -1; |
1289 s_offset = s1->bbox.xMin + s1->pos.x; | |
1290 len = (cur->bbox.xMax + cur->pos.x) - s_offset; | |
18937 | 1291 |
1292 if (cur->symbol == '\n') { | |
1293 break_type = 2; | |
1294 break_at = i; | |
1295 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "forced line break at %d\n", break_at); | |
1296 } | |
1297 | |
1298 if (len >= max_text_width) { | |
1299 break_type = 1; | |
1300 break_at = last_space; | |
1301 if (break_at == -1) | |
1302 break_at = i - 1; | |
1303 if (break_at == -1) | |
1304 break_at = 0; | |
1305 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "overfill at %d\n", i); | |
1306 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "line break at %d\n", break_at); | |
1307 } | |
1308 | |
1309 if (break_at != -1) { | |
1310 // need to use one more line | |
1311 // marking break_at+1 as start of a new line | |
1312 int lead = break_at + 1; // the first symbol of the new line | |
1313 if (text_info.n_lines >= MAX_LINES) { | |
1314 // to many lines ! | |
1315 // no more linebreaks | |
1316 for (j = lead; j < text_info.length; ++j) | |
1317 text_info.glyphs[j].linebreak = 0; | |
1318 break; | |
1319 } | |
1320 if (lead < text_info.length) | |
1321 text_info.glyphs[lead].linebreak = break_type; | |
1322 last_space = -1; | |
1323 s1 = text_info.glyphs + lead; | |
1324 s_offset = s1->bbox.xMin + s1->pos.x; | |
1325 text_info.n_lines ++; | |
1326 } | |
1327 | |
1328 if (cur->symbol == ' ') | |
1329 last_space = i; | |
1330 } | |
1331 #define DIFF(x,y) (((x) < (y)) ? (y - x) : (x - y)) | |
1332 exit = 0; | |
1333 while (!exit) { | |
1334 exit = 1; | |
1335 w = s3 = text_info.glyphs; | |
1336 s1 = s2 = 0; | |
1337 for (i = 0; i <= text_info.length; ++i) { | |
1338 cur = text_info.glyphs + i; | |
1339 if ((i == text_info.length) || cur->linebreak) { | |
1340 s1 = s2; | |
1341 s2 = s3; | |
1342 s3 = cur; | |
1343 if (s1 && (s2->linebreak == 1)) { // have at least 2 lines, and linebreak is 'soft' | |
1344 int l1, l2, l1_new, l2_new; | |
1345 | |
1346 w = s2; | |
1347 do { --w; } while ((w > s1) && (w->symbol == ' ')); | |
19663
042680f89e7d
Fix possible unallocated memory read in libass line wrapping code.
eugeni
parents:
19651
diff
changeset
|
1348 while ((w > s1) && (w->symbol != ' ')) { --w; } |
18937 | 1349 e1 = w; |
19663
042680f89e7d
Fix possible unallocated memory read in libass line wrapping code.
eugeni
parents:
19651
diff
changeset
|
1350 while ((e1 > s1) && (e1->symbol == ' ')) { --e1; } |
18937 | 1351 if (w->symbol == ' ') ++w; |
1352 | |
1353 l1 = ((s2-1)->bbox.xMax + (s2-1)->pos.x) - (s1->bbox.xMin + s1->pos.x); | |
1354 l2 = ((s3-1)->bbox.xMax + (s3-1)->pos.x) - (s2->bbox.xMin + s2->pos.x); | |
1355 l1_new = (e1->bbox.xMax + e1->pos.x) - (s1->bbox.xMin + s1->pos.x); | |
1356 l2_new = ((s3-1)->bbox.xMax + (s3-1)->pos.x) - (w->bbox.xMin + w->pos.x); | |
1357 | |
1358 if (DIFF(l1_new, l2_new) < DIFF(l1, l2)) { | |
1359 w->linebreak = 1; | |
1360 s2->linebreak = 0; | |
1361 exit = 0; | |
1362 } | |
1363 } | |
1364 } | |
1365 if (i == text_info.length) | |
1366 break; | |
1367 } | |
1368 | |
1369 } | |
1370 assert(text_info.n_lines >= 1); | |
1371 #undef DIFF | |
1372 | |
1373 text_info.height = 0; | |
1374 max_asc = max_desc = 0; | |
1375 cur_line = 0; | |
1376 for (i = 0; i < text_info.length + 1; ++i) { | |
1377 if ((i == text_info.length) || text_info.glyphs[i].linebreak) { | |
1378 text_info.lines[cur_line].asc = max_asc; | |
1379 text_info.lines[cur_line].desc = max_desc; | |
1380 text_info.height += max_asc + max_desc; | |
1381 cur_line ++; | |
1382 max_asc = max_desc = 0; | |
1383 } | |
1384 if (i < text_info.length) { | |
1385 cur = text_info.glyphs + i; | |
1386 if (cur->asc > max_asc) | |
1387 max_asc = cur->asc * render_context.scale_y; | |
1388 if (cur->desc > max_desc) | |
1389 max_desc = cur->desc * render_context.scale_y; | |
1390 } | |
1391 } | |
1392 | |
1393 pen_shift_x = 0; | |
1394 pen_shift_y = 0; | |
1395 cur_line = 1; | |
1396 for (i = 0; i < text_info.length; ++i) { | |
1397 cur = text_info.glyphs + i; | |
1398 if (cur->linebreak) { | |
1399 int height = text_info.lines[cur_line - 1].desc + text_info.lines[cur_line].asc; | |
1400 cur_line ++; | |
1401 pen_shift_x = - cur->pos.x; | |
1402 pen_shift_y += (height >> 6) + global_settings->line_spacing; | |
1403 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "shifting from %d to %d by (%d, %d)\n", i, text_info.length - 1, pen_shift_x, pen_shift_y); | |
1404 } | |
1405 cur->pos.x += pen_shift_x; | |
1406 cur->pos.y += pen_shift_y; | |
1407 } | |
1408 } | |
1409 | |
1410 /** | |
1411 * \brief determine karaoke effects | |
1412 * Karaoke effects cannot be calculated during parse stage (get_next_char()), | |
1413 * so they are done in a separate step. | |
1414 * Parse stage: when karaoke style override is found, its parameters are stored in the next glyph's | |
1415 * (the first glyph of the karaoke word)'s effect_type and effect_timing. | |
1416 * This function: | |
1417 * 1. sets effect_type for all glyphs in the word (_karaoke_ word) | |
1418 * 2. sets effect_timing for all glyphs to x coordinate of the border line between the left and right karaoke parts | |
1419 * (left part is filled with PrimaryColour, right one - with SecondaryColour). | |
1420 */ | |
1421 static void process_karaoke_effects(void) | |
1422 { | |
1423 glyph_info_t *cur, *cur2; | |
1424 glyph_info_t *s1, *e1; // start and end of the current word | |
1425 glyph_info_t *s2; // start of the next word | |
1426 int i; | |
1427 int timing; // current timing | |
1428 int tm_start, tm_end; // timings at start and end of the current word | |
1429 int tm_current; | |
1430 double dt; | |
1431 int x; | |
1432 int x_start, x_end; | |
1433 | |
1434 tm_current = frame_context.time - render_context.event->Start; | |
1435 timing = 0; | |
1436 s1 = s2 = 0; | |
1437 for (i = 0; i <= text_info.length; ++i) { | |
1438 cur = text_info.glyphs + i; | |
1439 if ((i == text_info.length) || (cur->effect_type != EF_NONE)) { | |
1440 s1 = s2; | |
1441 s2 = cur; | |
1442 if (s1) { | |
1443 e1 = s2 - 1; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1444 tm_start = timing + s1->effect_skip_timing; |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1445 tm_end = tm_start + s1->effect_timing; |
18937 | 1446 timing = tm_end; |
1447 x_start = s1->bbox.xMin + s1->pos.x; | |
1448 x_end = e1->bbox.xMax + e1->pos.x; | |
1449 | |
1450 dt = (tm_current - tm_start); | |
1451 if ((s1->effect_type == EF_KARAOKE) || (s1->effect_type == EF_KARAOKE_KO)) { | |
1452 if (dt > 0) | |
1453 x = x_end + 1; | |
1454 else | |
1455 x = x_start; | |
1456 } else if (s1->effect_type == EF_KARAOKE_KF) { | |
1457 dt /= (tm_end - tm_start); | |
1458 x = x_start + (x_end - x_start) * dt; | |
1459 } else { | |
1460 mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unknown effect type (internal error) \n"); | |
1461 continue; | |
1462 } | |
1463 | |
1464 for (cur2 = s1; cur2 <= e1; ++cur2) { | |
1465 cur2->effect_type = s1->effect_type; | |
1466 cur2->effect_timing = x - cur2->pos.x; | |
1467 } | |
1468 } | |
1469 } | |
1470 } | |
1471 } | |
1472 | |
19066
26a30496ec96
marks several function without a prototype which arent used outside its sourcefile as static, Patch by Stefan Huehner - stefan AT huehner-org
reynaldo
parents:
19044
diff
changeset
|
1473 static int get_face_ascender(FT_Face face) |
18937 | 1474 { |
1475 int v = face->size->metrics.ascender; | |
19693
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1476 int v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale); |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1477 if (v > v2 * 0.9) |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1478 return v; |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1479 else |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1480 return v2; |
18937 | 1481 } |
1482 | |
19066
26a30496ec96
marks several function without a prototype which arent used outside its sourcefile as static, Patch by Stefan Huehner - stefan AT huehner-org
reynaldo
parents:
19044
diff
changeset
|
1483 static int get_face_descender(FT_Face face) |
18937 | 1484 { |
19693
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1485 int v = - face->size->metrics.descender; |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1486 int v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale); |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1487 if (v > v2 * 0.9) |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1488 return v; |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1489 else |
3fc2235ff062
Workaround for broken fonts with bad ascender/descender.
eugeni
parents:
19692
diff
changeset
|
1490 return v2; |
18937 | 1491 } |
1492 | |
1493 /** | |
1494 * \brief Main ass rendering function, glues everything together | |
1495 * \param event event to render | |
1496 * Process event, appending resulting ass_image_t's to images_root. | |
1497 */ | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1498 static int ass_render_event(ass_event_t* event, event_images_t* event_images) |
18937 | 1499 { |
1500 char* p; | |
1501 FT_UInt glyph_index; | |
1502 FT_Bool use_kerning; | |
1503 FT_UInt previous; | |
1504 FT_UInt num_glyphs; | |
1505 FT_Vector pen; | |
1506 int error; | |
1507 unsigned code; | |
1508 FT_BBox bbox; | |
1509 int i, j; | |
1510 FT_Vector shift; | |
1511 int MarginL, MarginR, MarginV; | |
1512 int last_break; | |
1513 int alignment, halign, valign; | |
19556 | 1514 int device_x = 0, device_y = 0; |
18937 | 1515 |
19651 | 1516 if (event->Style >= frame_context.track->n_styles) { |
19650 | 1517 mp_msg(MSGT_GLOBAL, MSGL_WARN, "No style found!\n"); |
1518 return 1; | |
1519 } | |
1520 if (!event->Text) { | |
1521 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Empty event!\n"); | |
1522 return 1; | |
1523 } | |
1524 | |
18937 | 1525 init_render_context(event); |
1526 | |
1527 text_info.length = 0; | |
1528 pen.x = 0; | |
1529 pen.y = 0; | |
1530 previous = 0; | |
1531 num_glyphs = 0; | |
1532 p = event->Text; | |
1533 // Event parsing. | |
1534 while (1) { | |
1535 // get next char, executing style override | |
1536 // this affects render_context | |
1537 code = get_next_char(&p); | |
1538 | |
1539 // face could have been changed in get_next_char | |
1540 if (!render_context.face) { | |
1541 free_render_context(); | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1542 return 1; |
18937 | 1543 } |
1544 | |
1545 if (code == 0) | |
1546 break; | |
1547 | |
1548 use_kerning = FT_HAS_KERNING(render_context.face); | |
1549 | |
1550 if (text_info.length >= MAX_GLYPHS) { | |
1551 mp_msg(MSGT_GLOBAL, MSGL_WARN, "\nMAX_GLYPHS reached: event %d, start = %llu, duration = %llu\n Text = %s\n", | |
1552 (int)(event - frame_context.track->events), event->Start, event->Duration, event->Text); | |
1553 break; | |
1554 } | |
1555 | |
1556 glyph_index = FT_Get_Char_Index( render_context.face, code); | |
1557 | |
1558 if ( use_kerning && previous && glyph_index ) { | |
1559 FT_Vector delta; | |
1560 FT_Get_Kerning( render_context.face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); | |
1561 pen.x += delta.x; | |
1562 pen.y += delta.y; | |
1563 } | |
1564 | |
1565 shift.x = pen.x & 63; | |
1566 shift.y = pen.y & 63; | |
1567 | |
1568 if ((render_context.scale_x != 1.) || (render_context.scale_y != 1.) || | |
1569 (frame_context.font_scale_x != 1.)) { | |
1570 FT_Matrix matrix; | |
1571 matrix.xx = (FT_Fixed)( render_context.scale_x * frame_context.font_scale_x * 0x10000L ); | |
1572 matrix.xy = (FT_Fixed)( 0 * 0x10000L ); | |
1573 matrix.yx = (FT_Fixed)( 0 * 0x10000L ); | |
1574 matrix.yy = (FT_Fixed)( render_context.scale_y * 0x10000L ); | |
1575 | |
1576 FT_Set_Transform( render_context.face, &matrix, &shift ); | |
1577 } else { | |
1578 FT_Set_Transform(render_context.face, 0, &shift); | |
1579 } | |
1580 | |
1581 error = get_glyph(glyph_index, code, text_info.glyphs + text_info.length, &shift); | |
1582 | |
1583 if (error) { | |
1584 continue; | |
1585 } | |
1586 | |
1587 text_info.glyphs[text_info.length].pos.x = pen.x >> 6; | |
1588 text_info.glyphs[text_info.length].pos.y = pen.y >> 6; | |
1589 | |
1590 pen.x += text_info.glyphs[text_info.length].advance.x; | |
1591 pen.x += render_context.hspacing; | |
1592 pen.y += text_info.glyphs[text_info.length].advance.y; | |
1593 | |
1594 // if it's an outline glyph, we still need to fill the bbox | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
19825
diff
changeset
|
1595 if (text_info.glyphs[text_info.length].glyph) { |
18937 | 1596 FT_Glyph_Get_CBox( text_info.glyphs[text_info.length].glyph, FT_GLYPH_BBOX_PIXELS, &(text_info.glyphs[text_info.length].bbox) ); |
1597 } | |
1598 | |
1599 | |
1600 previous = glyph_index; | |
1601 | |
1602 text_info.glyphs[text_info.length].symbol = code; | |
1603 text_info.glyphs[text_info.length].linebreak = 0; | |
19692
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1604 for (i = 0; i < 4; ++i) { |
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1605 uint32_t clr = render_context.c[i]; |
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1606 change_alpha(&clr, mult_alpha(_a(clr), render_context.fade), 1.); |
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1607 text_info.glyphs[text_info.length].c[i] = clr; |
5b40e87b9619
Change \fad behaviour so that it does not get cancelled by \r.
eugeni
parents:
19691
diff
changeset
|
1608 } |
18937 | 1609 text_info.glyphs[text_info.length].effect_type = render_context.effect_type; |
1610 text_info.glyphs[text_info.length].effect_timing = render_context.effect_timing; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1611 text_info.glyphs[text_info.length].effect_skip_timing = render_context.effect_skip_timing; |
18937 | 1612 text_info.glyphs[text_info.length].asc = get_face_ascender(render_context.face); |
1613 text_info.glyphs[text_info.length].desc = get_face_descender(render_context.face); | |
19848 | 1614 text_info.glyphs[text_info.length].be = render_context.be; |
18937 | 1615 |
1616 text_info.length++; | |
19716
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1617 |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1618 render_context.effect_type = EF_NONE; |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1619 render_context.effect_timing = 0; |
e4e492fcc2f7
Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents:
19693
diff
changeset
|
1620 render_context.effect_skip_timing = 0; |
18937 | 1621 } |
1622 | |
1623 if (text_info.length == 0) { | |
1624 // no valid symbols in the event; this can be smth like {comment} | |
1625 free_render_context(); | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1626 return 1; |
18937 | 1627 } |
1628 | |
1629 // depends on glyph x coordinates being monotonous, so it should be done before line wrap | |
1630 process_karaoke_effects(); | |
1631 | |
1632 // alignments | |
1633 alignment = render_context.alignment; | |
1634 if (!alignment) | |
1635 alignment = render_context.style->Alignment; | |
1636 halign = alignment & 3; | |
1637 valign = alignment & 12; | |
1638 | |
19649 | 1639 MarginL = (event->MarginL) ? event->MarginL : render_context.style->MarginL; |
1640 MarginR = (event->MarginR) ? event->MarginR : render_context.style->MarginR; | |
1641 MarginV = (event->MarginV) ? event->MarginV : render_context.style->MarginV; | |
19556 | 1642 |
1643 if (render_context.evt_type != EVENT_HSCROLL) { | |
19931
399bb1fcdc94
Move variable declaration to a more deeply nested block. It is not used outside of it.
eugeni
parents:
19919
diff
changeset
|
1644 int max_text_width; |
399bb1fcdc94
Move variable declaration to a more deeply nested block. It is not used outside of it.
eugeni
parents:
19919
diff
changeset
|
1645 |
19557 | 1646 // calculate max length of a line |
1647 max_text_width = x2scr(frame_context.track->PlayResX - MarginR) - x2scr(MarginL); | |
19556 | 1648 |
19557 | 1649 // rearrange text in several lines |
1650 wrap_lines_smart(max_text_width); | |
19556 | 1651 |
19557 | 1652 // align text |
1653 last_break = -1; | |
1654 for (i = 1; i < text_info.length + 1; ++i) { // (text_info.length + 1) is the end of the last line | |
1655 if ((i == text_info.length) || text_info.glyphs[i].linebreak) { | |
1656 int width, shift; | |
1657 glyph_info_t* first_glyph = text_info.glyphs + last_break + 1; | |
1658 glyph_info_t* last_glyph = text_info.glyphs + i - 1; | |
18937 | 1659 |
19557 | 1660 while ((last_glyph >= first_glyph) && ((last_glyph->symbol == '\n') || (last_glyph->symbol == 0))) |
1661 last_glyph --; | |
18937 | 1662 |
19557 | 1663 width = last_glyph->pos.x + last_glyph->bbox.xMax - first_glyph->pos.x - first_glyph->bbox.xMin; |
1664 shift = - first_glyph->bbox.xMin; // now text line starts exactly at 0 (left margin) | |
1665 if (halign == HALIGN_LEFT) { // left aligned, no action | |
1666 } else if (halign == HALIGN_RIGHT) { // right aligned | |
1667 shift = max_text_width - width; | |
1668 } else if (halign == HALIGN_CENTER) { // centered | |
1669 shift = (max_text_width - width) / 2; | |
1670 } | |
1671 for (j = last_break + 1; j < i; ++j) { | |
1672 text_info.glyphs[j].pos.x += shift; | |
1673 } | |
1674 last_break = i - 1; | |
18937 | 1675 } |
1676 } | |
1677 } | |
1678 | |
1679 // determing text bounding box | |
1680 compute_string_bbox(&text_info, &bbox); | |
19904
640093581779
Calculate text bounding box in such way that it does not depend on the height
eugeni
parents:
19891
diff
changeset
|
1681 bbox.yMin = - (text_info.lines[0].asc >> 6); |
640093581779
Calculate text bounding box in such way that it does not depend on the height
eugeni
parents:
19891
diff
changeset
|
1682 bbox.yMax = (text_info.height - text_info.lines[0].asc) >> 6; |
18937 | 1683 |
1684 // determine device coordinates for text | |
19556 | 1685 |
1686 // x coordinate for everything except positioned events | |
1687 if (render_context.evt_type == EVENT_NORMAL || | |
1688 render_context.evt_type == EVENT_VSCROLL) { | |
1689 device_x = x2scr(MarginL); | |
1690 } else if (render_context.evt_type == EVENT_HSCROLL) { | |
1691 if (render_context.scroll_direction == SCROLL_RL) | |
1692 device_x = x2scr(frame_context.track->PlayResX - render_context.scroll_shift); | |
1693 else if (render_context.scroll_direction == SCROLL_LR) | |
1694 device_x = x2scr(render_context.scroll_shift) - (bbox.xMax - bbox.xMin); | |
1695 } | |
18937 | 1696 |
19556 | 1697 // y coordinate for everything except positioned events |
1698 if (render_context.evt_type == EVENT_NORMAL || | |
1699 render_context.evt_type == EVENT_HSCROLL) { | |
18937 | 1700 if (valign == VALIGN_TOP) { // toptitle |
1701 device_y = y2scr_top(MarginV) + (text_info.lines[0].asc >> 6); | |
1702 } else if (valign == VALIGN_CENTER) { // midtitle | |
1703 int scr_y = y2scr(frame_context.track->PlayResY / 2); | |
1704 device_y = scr_y - (bbox.yMax - bbox.yMin) / 2; | |
1705 } else { // subtitle | |
1706 int scr_y; | |
1707 if (valign != VALIGN_SUB) | |
1708 mp_msg(MSGT_GLOBAL, MSGL_V, "Invalid valign, supposing 0 (subtitle)\n"); | |
1709 scr_y = y2scr_sub(frame_context.track->PlayResY - MarginV); | |
1710 device_y = scr_y; | |
1711 device_y -= (text_info.height >> 6); | |
1712 device_y += (text_info.lines[0].asc >> 6); | |
1713 } | |
19556 | 1714 } else if (render_context.evt_type == EVENT_VSCROLL) { |
1715 if (render_context.scroll_direction == SCROLL_TB) | |
1716 device_y = y2scr(render_context.clip_y0 + render_context.scroll_shift) - (bbox.yMax - bbox.yMin); | |
1717 else if (render_context.scroll_direction == SCROLL_BT) | |
1718 device_y = y2scr(render_context.clip_y1 - render_context.scroll_shift); | |
1719 } | |
1720 | |
1721 // positioned events are totally different | |
1722 if (render_context.evt_type == EVENT_POSITIONED) { | |
18937 | 1723 int align_shift_x = 0; |
1724 int align_shift_y = 0; | |
1725 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "positioned event at %d, %d\n", render_context.pos_x, render_context.pos_y); | |
1726 switch(halign) { | |
1727 case HALIGN_LEFT: | |
1728 align_shift_x = - bbox.xMin; | |
1729 break; | |
1730 case HALIGN_CENTER: | |
1731 align_shift_x = - (bbox.xMax + bbox.xMin) /2; | |
1732 break; | |
1733 case HALIGN_RIGHT: | |
1734 align_shift_x = - bbox.xMax; | |
1735 break; | |
1736 } | |
1737 switch(valign) { | |
1738 case VALIGN_TOP: | |
1739 align_shift_y = - bbox.yMin; | |
1740 break; | |
1741 case VALIGN_CENTER: | |
1742 align_shift_y = - (bbox.yMax + bbox.yMin) /2; | |
1743 break; | |
1744 case VALIGN_SUB: | |
1745 align_shift_y = - bbox.yMax; | |
1746 break; | |
1747 } | |
1748 device_x = x2scr(render_context.pos_x) + align_shift_x; | |
1749 device_y = y2scr(render_context.pos_y) + align_shift_y; | |
1750 } | |
1751 | |
1752 // fix clip coordinates (they depend on alignment) | |
1753 render_context.clip_x0 = x2scr(render_context.clip_x0); | |
1754 render_context.clip_x1 = x2scr(render_context.clip_x1); | |
19556 | 1755 if (render_context.evt_type == EVENT_NORMAL || |
1756 render_context.evt_type == EVENT_HSCROLL || | |
1757 render_context.evt_type == EVENT_VSCROLL) { | |
18937 | 1758 if (valign == VALIGN_TOP) { |
1759 render_context.clip_y0 = y2scr_top(render_context.clip_y0); | |
1760 render_context.clip_y1 = y2scr_top(render_context.clip_y1); | |
1761 } else if (valign == VALIGN_CENTER) { | |
1762 render_context.clip_y0 = y2scr(render_context.clip_y0); | |
1763 render_context.clip_y1 = y2scr(render_context.clip_y1); | |
1764 } else if (valign == VALIGN_SUB) { | |
1765 render_context.clip_y0 = y2scr_sub(render_context.clip_y0); | |
1766 render_context.clip_y1 = y2scr_sub(render_context.clip_y1); | |
1767 } | |
1768 } else if (render_context.evt_type == EVENT_POSITIONED) { | |
1769 render_context.clip_y0 = y2scr(render_context.clip_y0); | |
1770 render_context.clip_y1 = y2scr(render_context.clip_y1); | |
1771 } | |
1772 | |
1773 // rotate glyphs if needed | |
1774 if (render_context.rotation != 0.) { | |
1775 double angle = render_context.rotation; | |
1776 FT_Vector center; | |
1777 FT_Matrix matrix_rotate; | |
1778 | |
1779 matrix_rotate.xx = (FT_Fixed)( cos( angle ) * 0x10000L ); | |
1780 matrix_rotate.xy = (FT_Fixed)( -sin( angle ) * 0x10000L ); | |
1781 matrix_rotate.yx = (FT_Fixed)( sin( angle ) * 0x10000L ); | |
1782 matrix_rotate.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); | |
1783 | |
1784 if (((render_context.org_x != 0) || (render_context.org_y != 0)) && (render_context.evt_type == EVENT_POSITIONED)) { | |
1785 center.x = render_context.org_x; | |
1786 center.y = render_context.org_y; | |
1787 } else { | |
1788 FT_BBox str_bbox; | |
1789 | |
1790 center.x = text_info.glyphs[0].pos.x + device_x; | |
1791 center.y = text_info.glyphs[0].pos.y + device_y; | |
1792 | |
1793 compute_string_bbox(&text_info, &str_bbox); | |
1794 center.x += (str_bbox.xMax - str_bbox.xMin) / 2; | |
1795 center.y += (str_bbox.yMax - str_bbox.yMin) / 2; | |
1796 } | |
1797 // mp_msg(MSGT_GLOBAL, MSGL_DBG2, "\ncenter: %d, %d\n", center.x, center.y); | |
1798 | |
1799 for (i = 0; i < text_info.length; ++i) { | |
1800 glyph_info_t* info = text_info.glyphs + i; | |
1801 | |
1802 // calculating shift vector | |
1803 // shift = (position - center)*M - (position - center) | |
1804 FT_Vector start; | |
1805 FT_Vector start_old; | |
1806 // mp_msg(MSGT_GLOBAL, MSGL_INFO, "start: (%d, %d) + (%d, %d) - (%d, %d) = (%d, %d)\n", info->pos.x, info->pos.y, device_x, device_y, center.x, center.y, | |
1807 // info->pos.x + device_x - center.x, info->pos.y + device_y - center.y); | |
1808 start.x = (info->pos.x + device_x - center.x) << 6; | |
1809 start.y = - (info->pos.y + device_y - center.y) << 6; | |
1810 start_old.x = start.x; | |
1811 start_old.y = start.y; | |
1812 // mp_msg(MSGT_GLOBAL, MSGL_INFO, "start: %d, %d\n", start.x / 64, start.y / 64); | |
1813 | |
1814 FT_Vector_Transform(&start, &matrix_rotate); | |
1815 | |
1816 start.x -= start_old.x; | |
1817 start.y -= start_old.y; | |
1818 | |
1819 info->pos.x += start.x >> 6; | |
1820 info->pos.y -= start.y >> 6; | |
1821 | |
1822 // mp_msg(MSGT_GLOBAL, MSGL_DBG2, "shift: %d, %d\n", start.x / 64, start.y / 64); | |
19873 | 1823 if (info->glyph) |
18937 | 1824 FT_Glyph_Transform( info->glyph, &matrix_rotate, 0 ); |
19873 | 1825 if (info->outline_glyph) |
18937 | 1826 FT_Glyph_Transform( info->outline_glyph, &matrix_rotate, 0 ); |
1827 } | |
1828 } | |
1829 | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1830 event_images->top = device_y - (text_info.lines[0].asc >> 6); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1831 event_images->height = text_info.height >> 6; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1832 event_images->detect_collisions = render_context.detect_collisions; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1833 event_images->shift_direction = (valign == VALIGN_TOP) ? 1 : -1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1834 event_images->event = event; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1835 event_images->imgs = render_text(&text_info, device_x, device_y); |
18937 | 1836 |
1837 free_render_context(); | |
1838 | |
1839 return 0; | |
1840 } | |
1841 | |
1842 void ass_configure(ass_instance_t* priv, const ass_settings_t* config) | |
1843 { | |
19539 | 1844 if (memcmp(&priv->settings, config, sizeof(ass_settings_t)) != 0) { |
1845 mp_msg(MSGT_GLOBAL, MSGL_V, "ass_configure: %d x %d; margins: l: %d, r: %d, t: %d, b: %d \n", | |
1846 config->frame_width, config->frame_height, | |
1847 config->left_margin, config->right_margin, config->top_margin, config->bottom_margin); | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1848 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1849 priv->render_id = ++last_render_id; |
19539 | 1850 memcpy(&priv->settings, config, sizeof(ass_settings_t)); |
1851 ass_glyph_cache_reset(); | |
1852 } | |
18937 | 1853 } |
1854 | |
1855 /** | |
1856 * \brief Start a new frame | |
1857 */ | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1858 static int ass_start_frame(ass_instance_t *priv, ass_track_t* track, long long now) |
18937 | 1859 { |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1860 ass_image_t* img; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1861 |
18937 | 1862 ass_instance = priv; |
1863 global_settings = &priv->settings; | |
1864 | |
1865 if (!priv->settings.frame_width && !priv->settings.frame_height) | |
1866 return 1; // library not initialized | |
1867 | |
1868 frame_context.ass_priv = priv; | |
1869 frame_context.width = global_settings->frame_width; | |
1870 frame_context.height = global_settings->frame_height; | |
19538 | 1871 frame_context.orig_width = global_settings->frame_width - global_settings->left_margin - global_settings->right_margin; |
18937 | 1872 frame_context.orig_height = global_settings->frame_height - global_settings->top_margin - global_settings->bottom_margin; |
1873 frame_context.track = track; | |
1874 frame_context.time = now; | |
1875 | |
1876 ass_lazy_track_init(); | |
1877 | |
19825
f351a3fc3e42
Make font outline width proportional to movie resolution.
eugeni
parents:
19716
diff
changeset
|
1878 frame_context.font_scale = global_settings->font_size_coeff * ass_internal_font_size_coeff * |
f351a3fc3e42
Make font outline width proportional to movie resolution.
eugeni
parents:
19716
diff
changeset
|
1879 frame_context.orig_height / frame_context.track->PlayResY; |
19917
6a31849e2b80
In r19831, font size multiplier was mistakenly applied to border width.
eugeni
parents:
19906
diff
changeset
|
1880 frame_context.border_scale = ((double)frame_context.orig_height) / frame_context.track->PlayResY; |
19825
f351a3fc3e42
Make font outline width proportional to movie resolution.
eugeni
parents:
19716
diff
changeset
|
1881 |
18937 | 1882 if (frame_context.width * track->PlayResY == frame_context.height * track->PlayResX) |
1883 frame_context.font_scale_x = 1.; | |
1884 else | |
19566 | 1885 frame_context.font_scale_x = ((double)(frame_context.orig_width * track->PlayResY)) / (frame_context.orig_height * track->PlayResX); |
18937 | 1886 |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1887 img = priv->images_root; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1888 while (img) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1889 ass_image_t* next = img->next; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1890 free(img); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1891 img = next; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1892 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1893 priv->images_root = 0; |
18937 | 1894 |
1895 return 0; | |
1896 } | |
1897 | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1898 static int cmp_event_layer(const void* p1, const void* p2) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1899 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1900 ass_event_t* e1 = ((event_images_t*)p1)->event; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1901 ass_event_t* e2 = ((event_images_t*)p2)->event; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1902 if (e1->Layer < e2->Layer) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1903 return -1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1904 if (e1->Layer > e2->Layer) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1905 return 1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1906 if (e1->Start < e2->Start) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1907 return -1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1908 if (e1->Start > e2->Start) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1909 return 1; |
19906
f72c694ee566
Sort events by ReadOrder (if both layer and start time are equal).
eugeni
parents:
19904
diff
changeset
|
1910 if (e1->ReadOrder < e2->ReadOrder) |
f72c694ee566
Sort events by ReadOrder (if both layer and start time are equal).
eugeni
parents:
19904
diff
changeset
|
1911 return -1; |
f72c694ee566
Sort events by ReadOrder (if both layer and start time are equal).
eugeni
parents:
19904
diff
changeset
|
1912 if (e1->ReadOrder > e2->ReadOrder) |
f72c694ee566
Sort events by ReadOrder (if both layer and start time are equal).
eugeni
parents:
19904
diff
changeset
|
1913 return 1; |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1914 return 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1915 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1916 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1917 #define MAX_EVENTS 100 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1918 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1919 static render_priv_t* get_render_priv(ass_event_t* event) |
18937 | 1920 { |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1921 if (!event->render_priv) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1922 event->render_priv = calloc(1, sizeof(render_priv_t)); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1923 // FIXME: check render_id |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1924 if (ass_instance->render_id != event->render_priv->render_id) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1925 memset(event->render_priv, 0, sizeof(render_priv_t)); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1926 event->render_priv->render_id = ass_instance->render_id; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1927 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1928 return event->render_priv; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1929 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1930 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1931 typedef struct segment_s { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1932 int a, b; // top and height |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1933 } segment_t; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1934 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1935 static int overlap(segment_t* s1, segment_t* s2) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1936 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1937 if (s1->a >= s2->b || s2->a >= s1->b) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1938 return 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1939 return 1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1940 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1941 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1942 static int cmp_segment(const void* p1, const void* p2) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1943 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1944 return ((segment_t*)p1)->a - ((segment_t*)p1)->b; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1945 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1946 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1947 static void shift_event(event_images_t* ei, int shift) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1948 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1949 ass_image_t* cur = ei->imgs; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1950 while (cur) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1951 cur->dst_y += shift; |
19664
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1952 // clip top and bottom |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1953 if (cur->dst_y < 0) { |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1954 int clip = - cur->dst_y; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1955 cur->h -= clip; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1956 cur->bitmap += clip * cur->stride; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1957 cur->dst_y = 0; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1958 } |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1959 if (cur->dst_y + cur->h >= frame_context.height) { |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1960 int clip = cur->dst_y + cur->h - frame_context.height; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1961 cur->h -= clip; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1962 } |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1963 if (cur->h <= 0) { |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1964 cur->h = 0; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1965 cur->dst_y = 0; |
f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
eugeni
parents:
19663
diff
changeset
|
1966 } |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1967 cur = cur->next; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1968 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1969 ei->top += shift; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1970 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1971 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1972 // dir: 1 - move down |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1973 // -1 - move up |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1974 static int fit_segment(segment_t* s, segment_t* fixed, int* cnt, int dir) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1975 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1976 int i; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1977 int shift; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1978 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1979 if (*cnt == 0) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1980 *cnt = 1; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1981 fixed[0].a = s->a; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1982 fixed[0].b = s->b; |
18937 | 1983 return 0; |
1984 } | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1985 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1986 if (dir == 1) { // move down |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1987 if (s->b <= fixed[0].a) // all ok |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1988 return 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1989 for (i = 0; i < *cnt; ++i) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1990 shift = fixed[i].b - s->a; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1991 if (i == *cnt - 1 || fixed[i+1].a >= shift + s->b) { // here is a good place |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1992 fixed[i].b += s->b - s->a; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1993 return shift; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1994 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1995 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1996 } else { // dir == -1, move up |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1997 if (s->a >= fixed[*cnt-1].b) // all ok |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1998 return 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
1999 for (i = *cnt-1; i >= 0; --i) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2000 shift = fixed[i].a - s->b; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2001 if (i == 0 || fixed[i-1].b <= shift + s->a) { // here is a good place |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2002 fixed[i].a -= s->b - s->a; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2003 return shift; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2004 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2005 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2006 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2007 assert(0); // unreachable |
18937 | 2008 } |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2009 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2010 static void fix_collisions(event_images_t* imgs, int cnt) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2011 { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2012 segment_t used[MAX_EVENTS]; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2013 int cnt_used = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2014 int i, j; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2015 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2016 // fill used[] with fixed events |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2017 for (i = 0; i < cnt; ++i) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2018 render_priv_t* priv; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2019 if (!imgs[i].detect_collisions) break; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2020 priv = get_render_priv(imgs[i].event); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2021 if (priv->height > 0) { // it's a fixed event |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2022 segment_t s; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2023 s.a = priv->top; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2024 s.b = priv->top + priv->height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2025 if (priv->height != imgs[i].height) { // no, it's not |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2026 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Achtung! Event height has changed! \n"); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2027 priv->top = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2028 priv->height = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2029 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2030 for (j = 0; j < cnt_used; ++j) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2031 if (overlap(&s, used + j)) { // no, it's not |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2032 priv->top = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2033 priv->height = 0; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2034 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2035 if (priv->height > 0) { // still a fixed event |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2036 used[cnt_used].a = priv->top; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2037 used[cnt_used].b = priv->top + priv->height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2038 cnt_used ++; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2039 shift_event(imgs + i, priv->top - imgs[i].top); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2040 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2041 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2042 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2043 qsort(used, cnt_used, sizeof(segment_t), cmp_segment); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2044 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2045 // try to fit other events in free spaces |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2046 for (i = 0; i < cnt; ++i) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2047 render_priv_t* priv; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2048 if (!imgs[i].detect_collisions) break; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2049 priv = get_render_priv(imgs[i].event); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2050 if (priv->height == 0) { // not a fixed event |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2051 int shift; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2052 segment_t s; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2053 s.a = imgs[i].top; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2054 s.b = imgs[i].top + imgs[i].height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2055 shift = fit_segment(&s, used, &cnt_used, imgs[i].shift_direction); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2056 if (shift) shift_event(imgs + i, shift); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2057 // make it fixed |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2058 priv->top = imgs[i].top; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2059 priv->height = imgs[i].height; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2060 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2061 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2062 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2063 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2064 |
18937 | 2065 /** |
2066 * \brief render a frame | |
2067 * \param priv library handle | |
2068 * \param track track | |
2069 * \param now current video timestamp (ms) | |
2070 */ | |
2071 ass_image_t* ass_render_frame(ass_instance_t *priv, ass_track_t* track, long long now) | |
2072 { | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2073 int i, cnt, rc; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2074 event_images_t eimg[MAX_EVENTS]; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2075 event_images_t* last; |
19891 | 2076 ass_image_t** tail; |
18937 | 2077 |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2078 // init frame |
18937 | 2079 rc = ass_start_frame(priv, track, now); |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2080 if (rc != 0) |
18937 | 2081 return 0; |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2082 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2083 // render events separately |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2084 cnt = 0; |
18937 | 2085 for (i = 0; i < track->n_events; ++i) { |
2086 ass_event_t* event = track->events + i; | |
2087 if ( (event->Start <= now) && (now < (event->Start + event->Duration)) ) { | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2088 if (cnt < MAX_EVENTS) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2089 rc = ass_render_event(event, eimg + cnt); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2090 if (!rc) ++cnt; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2091 } else { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2092 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Too many simultaneous events \n"); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2093 break; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2094 } |
18937 | 2095 } |
2096 } | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2097 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2098 // sort by layer |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2099 qsort(eimg, cnt, sizeof(event_images_t), cmp_event_layer); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2100 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2101 // call fix_collisions for each group of events with the same layer |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2102 last = eimg; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2103 for (i = 1; i < cnt; ++i) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2104 if (last->event->Layer != eimg[i].event->Layer) { |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2105 fix_collisions(last, eimg + i - last); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2106 last = eimg + i; |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2107 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2108 if (cnt > 0) |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2109 fix_collisions(last, eimg + cnt - last); |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2110 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2111 // concat lists |
19891 | 2112 tail = &ass_instance->images_root; |
2113 for (i = 0; i < cnt; ++i) { | |
2114 ass_image_t* cur = eimg[i].imgs; | |
2115 while (cur) { | |
2116 *tail = cur; | |
2117 tail = &cur->next; | |
2118 cur = cur->next; | |
2119 } | |
19638
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2120 } |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2121 |
a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents:
19636
diff
changeset
|
2122 return ass_instance->images_root; |
18937 | 2123 } |
2124 |