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