annotate libass/ass_render.c @ 35767:23e241430e9c

Cosmetic: Replace uiMenuInit().
author ib
date Thu, 24 Jan 2013 17:37:49 +0000
parents c7866af24567
children c3aaaf17c721
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26582
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26582
diff changeset
3 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
4 * This file is part of libass.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26582
diff changeset
5 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
6 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
8 * copyright notice and this permission notice appear in all copies.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26582
diff changeset
9 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26582
diff changeset
17 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
18
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
19 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
20
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include <math.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
24 #include "ass_render.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
25 #include "ass_parse.h"
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
26 #include "ass_shaper.h"
22258
9c1160622400 Reallocate event_images_t, removing limit on simultanious events count.
eugeni
parents: 22221
diff changeset
27
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
28 #define MAX_GLYPHS_INITIAL 1024
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
29 #define MAX_LINES_INITIAL 64
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
30 #define SUBPIXEL_MASK 63
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
31 #define SUBPIXEL_ACCURACY 7
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
33 ASS_Renderer *ass_renderer_init(ASS_Library *library)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
35 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
36 FT_Library ft;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
37 ASS_Renderer *priv = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
38 int vmajor, vminor, vpatch;
20202
9b67ed06f721 Zerofill libass static variables during initialization.
eugeni
parents: 20201
diff changeset
39
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
40 error = FT_Init_FreeType(&ft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
41 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
42 ass_msg(library, MSGL_FATAL, "%s failed", "FT_Init_FreeType");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
43 goto ass_init_exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
44 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
46 FT_Library_Version(ft, &vmajor, &vminor, &vpatch);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
47 ass_msg(library, MSGL_V, "Raster: FreeType %d.%d.%d",
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
48 vmajor, vminor, vpatch);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
49
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
50 priv = calloc(1, sizeof(ASS_Renderer));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
51 if (!priv) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
52 FT_Done_FreeType(ft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
53 goto ass_init_exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
54 }
26032
93dcb01491cf Print FreeType version in libass init. Makes error logs slightly more helpful.
eugeni
parents: 25513
diff changeset
55
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
56 priv->synth_priv = ass_synth_init(BLUR_MAX_RADIUS);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
57
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
58 priv->library = library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
59 priv->ftlibrary = ft;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
60 // images_root and related stuff is zero-filled in calloc
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19825
diff changeset
61
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
62 priv->cache.font_cache = ass_font_cache_create();
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
63 priv->cache.bitmap_cache = ass_bitmap_cache_create();
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
64 priv->cache.composite_cache = ass_composite_cache_create();
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
65 priv->cache.outline_cache = ass_outline_cache_create();
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
66 priv->cache.glyph_max = GLYPH_CACHE_MAX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
67 priv->cache.bitmap_max_size = BITMAP_CACHE_MAX_SIZE;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
68
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
69 priv->text_info.max_glyphs = MAX_GLYPHS_INITIAL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
70 priv->text_info.max_lines = MAX_LINES_INITIAL;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
71 priv->text_info.glyphs = calloc(MAX_GLYPHS_INITIAL, sizeof(GlyphInfo));
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
72 priv->text_info.lines = calloc(MAX_LINES_INITIAL, sizeof(LineInfo));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
73
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
74 priv->settings.font_size_coeff = 1.;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
75
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
76 priv->shaper = ass_shaper_new(0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
77 ass_shaper_info(library);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
78 #ifdef CONFIG_HARFBUZZ
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
79 priv->settings.shaper = ASS_SHAPING_COMPLEX;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
80 #else
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
81 priv->settings.shaper = ASS_SHAPING_SIMPLE;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
82 #endif
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
83
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
84 ass_init_exit:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
85 if (priv)
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
86 ass_msg(library, MSGL_V, "Initialized");
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
87 else
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
88 ass_msg(library, MSGL_ERR, "Initialization failed");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
89
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
90 return priv;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
91 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
92
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
93 static void free_list_clear(ASS_Renderer *render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
94 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
95 if (render_priv->free_head) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
96 FreeList *item = render_priv->free_head;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
97 while(item) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
98 FreeList *oi = item;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
99 free(item->object);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
100 item = item->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
101 free(oi);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
102 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
103 render_priv->free_head = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
104 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
105 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
106
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
107 void ass_renderer_done(ASS_Renderer *render_priv)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
109 ass_cache_done(render_priv->cache.font_cache);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
110 ass_cache_done(render_priv->cache.bitmap_cache);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
111 ass_cache_done(render_priv->cache.composite_cache);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
112 ass_cache_done(render_priv->cache.outline_cache);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
113
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
114 ass_free_images(render_priv->images_root);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
115 ass_free_images(render_priv->prev_images_root);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
116
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
117 if (render_priv->state.stroker) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
118 FT_Stroker_Done(render_priv->state.stroker);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
119 render_priv->state.stroker = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
120 }
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
121 if (render_priv->ftlibrary)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
122 FT_Done_FreeType(render_priv->ftlibrary);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
123 if (render_priv->fontconfig_priv)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
124 fontconfig_done(render_priv->fontconfig_priv);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
125 if (render_priv->synth_priv)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
126 ass_synth_done(render_priv->synth_priv);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
127 ass_shaper_free(render_priv->shaper);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
128 free(render_priv->eimg);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
129 free(render_priv->text_info.glyphs);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
130 free(render_priv->text_info.lines);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
131
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
132 free(render_priv->settings.default_font);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
133 free(render_priv->settings.default_family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
134
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
135 free_list_clear(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
136 free(render_priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
140 * \brief Create a new ASS_Image
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
141 * Parameters are the same as ASS_Image fields.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
142 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
143 static ASS_Image *my_draw_bitmap(unsigned char *bitmap, int bitmap_w,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
144 int bitmap_h, int stride, int dst_x,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
145 int dst_y, uint32_t color)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
147 ASS_Image *img = malloc(sizeof(ASS_Image));
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
148
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
149 if (img) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
150 img->w = bitmap_w;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
151 img->h = bitmap_h;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
152 img->stride = stride;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
153 img->bitmap = bitmap;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
154 img->color = color;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
155 img->dst_x = dst_x;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
156 img->dst_y = dst_y;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
157 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
158
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
159 return img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
160 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
161
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
162 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
163 * \brief Mapping between script and screen coordinates
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
164 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
165 static double x2scr(ASS_Renderer *render_priv, double x)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
166 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
167 return x * render_priv->orig_width_nocrop / render_priv->font_scale_x /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
168 render_priv->track->PlayResX +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
169 FFMAX(render_priv->settings.left_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
170 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
171 static double x2scr_pos(ASS_Renderer *render_priv, double x)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
172 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
173 return x * render_priv->orig_width / render_priv->font_scale_x / render_priv->track->PlayResX +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
174 render_priv->settings.left_margin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
175 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
176 static double x2scr_scaled(ASS_Renderer *render_priv, double x)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
177 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
178 return x * render_priv->orig_width_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
179 render_priv->track->PlayResX +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
180 FFMAX(render_priv->settings.left_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
181 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
182 static double x2scr_pos_scaled(ASS_Renderer *render_priv, double x)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
183 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
184 return x * render_priv->orig_width / render_priv->track->PlayResX +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
185 render_priv->settings.left_margin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
186 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
187 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
188 * \brief Mapping between script and screen coordinates
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
189 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
190 static double y2scr(ASS_Renderer *render_priv, double y)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
191 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
192 return y * render_priv->orig_height_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
193 render_priv->track->PlayResY +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
194 FFMAX(render_priv->settings.top_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
195 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
196 static double y2scr_pos(ASS_Renderer *render_priv, double y)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
197 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
198 return y * render_priv->orig_height / render_priv->track->PlayResY +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
199 render_priv->settings.top_margin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
200 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
201
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
202 // the same for toptitles
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
203 static double y2scr_top(ASS_Renderer *render_priv, double y)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
204 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
205 if (render_priv->settings.use_margins)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
206 return y * render_priv->orig_height_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
207 render_priv->track->PlayResY;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
208 else
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
209 return y * render_priv->orig_height_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
210 render_priv->track->PlayResY +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
211 FFMAX(render_priv->settings.top_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
212 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
213 // the same for subtitles
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
214 static double y2scr_sub(ASS_Renderer *render_priv, double y)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
215 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
216 if (render_priv->settings.use_margins)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
217 return y * render_priv->orig_height_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
218 render_priv->track->PlayResY +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
219 FFMAX(render_priv->settings.top_margin, 0)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
220 + FFMAX(render_priv->settings.bottom_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
221 else
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
222 return y * render_priv->orig_height_nocrop /
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
223 render_priv->track->PlayResY +
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
224 FFMAX(render_priv->settings.top_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
225 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
226
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
227 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
228 * \brief Convert bitmap glyphs into ASS_Image list with inverse clipping
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
229 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
230 * Inverse clipping with the following strategy:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
231 * - find rectangle from (x0, y0) to (cx0, y1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
232 * - find rectangle from (cx0, y0) to (cx1, cy0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
233 * - find rectangle from (cx0, cy1) to (cx1, y1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
234 * - find rectangle from (cx1, y0) to (x1, y1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
235 * These rectangles can be invalid and in this case are discarded.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
236 * Afterwards, they are clipped against the screen coordinates.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
237 * In an additional pass, the rectangles need to be split up left/right for
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
238 * karaoke effects. This can result in a lot of bitmaps (6 to be exact).
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
239 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
240 static ASS_Image **render_glyph_i(ASS_Renderer *render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
241 Bitmap *bm, int dst_x, int dst_y,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
242 uint32_t color, uint32_t color2, int brk,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
243 ASS_Image **tail)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
244 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
245 int i, j, x0, y0, x1, y1, cx0, cy0, cx1, cy1, sx, sy, zx, zy;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
246 Rect r[4];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
247 ASS_Image *img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
248
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
249 dst_x += bm->left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
250 dst_y += bm->top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
251
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
252 // we still need to clip against screen boundaries
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
253 zx = x2scr_pos_scaled(render_priv, 0);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
254 zy = y2scr_pos(render_priv, 0);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
255 sx = x2scr_pos_scaled(render_priv, render_priv->track->PlayResX);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
256 sy = y2scr_pos(render_priv, render_priv->track->PlayResY);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
257
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
258 x0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
259 y0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
260 x1 = bm->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
261 y1 = bm->h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
262 cx0 = render_priv->state.clip_x0 - dst_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
263 cy0 = render_priv->state.clip_y0 - dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
264 cx1 = render_priv->state.clip_x1 - dst_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
265 cy1 = render_priv->state.clip_y1 - dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
266
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
267 // calculate rectangles and discard invalid ones while we're at it.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
268 i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
269 r[i].x0 = x0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
270 r[i].y0 = y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
271 r[i].x1 = (cx0 > x1) ? x1 : cx0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
272 r[i].y1 = y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
273 if (r[i].x1 > r[i].x0 && r[i].y1 > r[i].y0) i++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
274 r[i].x0 = (cx0 < 0) ? x0 : cx0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
275 r[i].y0 = y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
276 r[i].x1 = (cx1 > x1) ? x1 : cx1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
277 r[i].y1 = (cy0 > y1) ? y1 : cy0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
278 if (r[i].x1 > r[i].x0 && r[i].y1 > r[i].y0) i++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
279 r[i].x0 = (cx0 < 0) ? x0 : cx0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
280 r[i].y0 = (cy1 < 0) ? y0 : cy1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
281 r[i].x1 = (cx1 > x1) ? x1 : cx1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
282 r[i].y1 = y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
283 if (r[i].x1 > r[i].x0 && r[i].y1 > r[i].y0) i++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
284 r[i].x0 = (cx1 < 0) ? x0 : cx1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
285 r[i].y0 = y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
286 r[i].x1 = x1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
287 r[i].y1 = y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
288 if (r[i].x1 > r[i].x0 && r[i].y1 > r[i].y0) i++;
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29382
diff changeset
289
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
290 // clip each rectangle to screen coordinates
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
291 for (j = 0; j < i; j++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
292 r[j].x0 = (r[j].x0 + dst_x < zx) ? zx - dst_x : r[j].x0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
293 r[j].y0 = (r[j].y0 + dst_y < zy) ? zy - dst_y : r[j].y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
294 r[j].x1 = (r[j].x1 + dst_x > sx) ? sx - dst_x : r[j].x1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
295 r[j].y1 = (r[j].y1 + dst_y > sy) ? sy - dst_y : r[j].y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
296 }
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
297
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
298 // draw the rectangles
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
299 for (j = 0; j < i; j++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
300 int lbrk = brk;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
301 // kick out rectangles that are invalid now
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
302 if (r[j].x1 <= r[j].x0 || r[j].y1 <= r[j].y0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
303 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
304 // split up into left and right for karaoke, if needed
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
305 if (lbrk > r[j].x0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
306 if (lbrk > r[j].x1) lbrk = r[j].x1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
307 img = my_draw_bitmap(bm->buffer + r[j].y0 * bm->stride + r[j].x0,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
308 lbrk - r[j].x0, r[j].y1 - r[j].y0,
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
309 bm->stride, dst_x + r[j].x0, dst_y + r[j].y0, color);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
310 if (!img) break;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
311 *tail = img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
312 tail = &img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
313 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
314 if (lbrk < r[j].x1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
315 if (lbrk < r[j].x0) lbrk = r[j].x0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
316 img = my_draw_bitmap(bm->buffer + r[j].y0 * bm->stride + lbrk,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
317 r[j].x1 - lbrk, r[j].y1 - r[j].y0,
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
318 bm->stride, dst_x + lbrk, dst_y + r[j].y0, color2);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
319 if (!img) break;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
320 *tail = img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
321 tail = &img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
322 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
323 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
324
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
325 return tail;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
326 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
327
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
328 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
329 * \brief convert bitmap glyph into ASS_Image struct(s)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
330 * \param bit freetype bitmap glyph, FT_PIXEL_MODE_GRAY
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
331 * \param dst_x bitmap x coordinate in video frame
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
332 * \param dst_y bitmap y coordinate in video frame
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
333 * \param color first color, RGBA
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
334 * \param color2 second color, RGBA
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
335 * \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
336 * \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
337 * \return pointer to the new list tail
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
338 * Performs clipping. Uses my_draw_bitmap for actual bitmap convertion.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
339 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
340 static ASS_Image **
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
341 render_glyph(ASS_Renderer *render_priv, Bitmap *bm, int dst_x, int dst_y,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
342 uint32_t color, uint32_t color2, int brk, ASS_Image **tail)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
343 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
344 // Inverse clipping in use?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
345 if (render_priv->state.clip_mode)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
346 return render_glyph_i(render_priv, bm, dst_x, dst_y, color, color2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
347 brk, tail);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
348
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
349 // brk is relative to dst_x
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
350 // color = color left of brk
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
351 // color2 = color right of brk
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
352 int b_x0, b_y0, b_x1, b_y1; // visible part of the bitmap
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
353 int clip_x0, clip_y0, clip_x1, clip_y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
354 int tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
355 ASS_Image *img;
29382
363310571aae Cosmetics: make some variables constant to signify their intended use and,
eugeni
parents: 29381
diff changeset
356
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
357 dst_x += bm->left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
358 dst_y += bm->top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
359 brk -= bm->left;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
360
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
361 // clipping
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
362 clip_x0 = FFMINMAX(render_priv->state.clip_x0, 0, render_priv->width);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
363 clip_y0 = FFMINMAX(render_priv->state.clip_y0, 0, render_priv->height);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
364 clip_x1 = FFMINMAX(render_priv->state.clip_x1, 0, render_priv->width);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
365 clip_y1 = FFMINMAX(render_priv->state.clip_y1, 0, render_priv->height);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
366 b_x0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
367 b_y0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
368 b_x1 = bm->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
369 b_y1 = bm->h;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
370
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
371 tmp = dst_x - clip_x0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
372 if (tmp < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
373 ass_msg(render_priv->library, MSGL_DBG2, "clip left");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
374 b_x0 = -tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
375 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
376 tmp = dst_y - clip_y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
377 if (tmp < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
378 ass_msg(render_priv->library, MSGL_DBG2, "clip top");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
379 b_y0 = -tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
380 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
381 tmp = clip_x1 - dst_x - bm->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
382 if (tmp < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
383 ass_msg(render_priv->library, MSGL_DBG2, "clip right");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
384 b_x1 = bm->w + tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
385 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
386 tmp = clip_y1 - dst_y - bm->h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
387 if (tmp < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
388 ass_msg(render_priv->library, MSGL_DBG2, "clip bottom");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
389 b_y1 = bm->h + tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
390 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
391
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
392 if ((b_y0 >= b_y1) || (b_x0 >= b_x1))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
393 return tail;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
394
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
395 if (brk > b_x0) { // draw left part
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
396 if (brk > b_x1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
397 brk = b_x1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
398 img = my_draw_bitmap(bm->buffer + bm->stride * b_y0 + b_x0,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
399 brk - b_x0, b_y1 - b_y0, bm->stride,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
400 dst_x + b_x0, dst_y + b_y0, color);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
401 if (!img) return tail;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
402 *tail = img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
403 tail = &img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
404 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
405 if (brk < b_x1) { // draw right part
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
406 if (brk < b_x0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
407 brk = b_x0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
408 img = my_draw_bitmap(bm->buffer + bm->stride * b_y0 + brk,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
409 b_x1 - brk, b_y1 - b_y0, bm->stride,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
410 dst_x + brk, dst_y + b_y0, color2);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
411 if (!img) return tail;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
412 *tail = img;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
413 tail = &img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
414 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
415 return tail;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
416 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
417
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
418 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
419 * \brief Replace the bitmap buffer in ASS_Image with a copy
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
420 * \param img ASS_Image to operate on
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
421 * \return pointer to old bitmap buffer
29381
fd2047f3adf6 Fix read after the end of allocated buffer.
eugeni
parents: 29263
diff changeset
422 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
423 static unsigned char *clone_bitmap_buffer(ASS_Image *img)
29381
fd2047f3adf6 Fix read after the end of allocated buffer.
eugeni
parents: 29263
diff changeset
424 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
425 unsigned char *old_bitmap = img->bitmap;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
426 int size = img->stride * (img->h - 1) + img->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
427 img->bitmap = malloc(size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
428 memcpy(img->bitmap, old_bitmap, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
429 return old_bitmap;
29381
fd2047f3adf6 Fix read after the end of allocated buffer.
eugeni
parents: 29263
diff changeset
430 }
fd2047f3adf6 Fix read after the end of allocated buffer.
eugeni
parents: 29263
diff changeset
431
fd2047f3adf6 Fix read after the end of allocated buffer.
eugeni
parents: 29263
diff changeset
432 /**
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
433 * \brief Calculate overlapping area of two consecutive bitmaps and in case they
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
434 * overlap, blend them together
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
435 * Mainly useful for translucent glyphs and especially borders, to avoid the
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
436 * luminance adding up where they overlap (which looks ugly)
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
437 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
438 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
439 render_overlap(ASS_Renderer *render_priv, ASS_Image **last_tail,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
440 ASS_Image **tail)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
441 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
442 int left, top, bottom, right;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
443 int old_left, old_top, w, h, cur_left, cur_top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
444 int x, y, opos, cpos;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
445 char m;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
446 CompositeHashKey hk;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
447 CompositeHashValue *hv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
448 CompositeHashValue chv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
449 int ax = (*last_tail)->dst_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
450 int ay = (*last_tail)->dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
451 int aw = (*last_tail)->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
452 int as = (*last_tail)->stride;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
453 int ah = (*last_tail)->h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
454 int bx = (*tail)->dst_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
455 int by = (*tail)->dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
456 int bw = (*tail)->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
457 int bs = (*tail)->stride;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
458 int bh = (*tail)->h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
459 unsigned char *a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
460 unsigned char *b;
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
461
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
462 if ((*last_tail)->bitmap == (*tail)->bitmap)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
463 return;
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
464
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
465 if ((*last_tail)->color != (*tail)->color)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
466 return;
28840
7d0ea9013974 Add a proper color check to the overlap compositing.
greg
parents: 28839
diff changeset
467
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
468 // Calculate overlap coordinates
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
469 left = (ax > bx) ? ax : bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
470 top = (ay > by) ? ay : by;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
471 right = ((ax + aw) < (bx + bw)) ? (ax + aw) : (bx + bw);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
472 bottom = ((ay + ah) < (by + bh)) ? (ay + ah) : (by + bh);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
473 if ((right <= left) || (bottom <= top))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
474 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
475 old_left = left - ax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
476 old_top = top - ay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
477 w = right - left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
478 h = bottom - top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
479 cur_left = left - bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
480 cur_top = top - by;
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
481
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
482 // Query cache
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
483 hk.a = (*last_tail)->bitmap;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
484 hk.b = (*tail)->bitmap;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
485 hk.aw = aw;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
486 hk.ah = ah;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
487 hk.bw = bw;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
488 hk.bh = bh;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
489 hk.ax = ax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
490 hk.ay = ay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
491 hk.bx = bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
492 hk.by = by;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
493 hk.as = as;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
494 hk.bs = bs;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
495 hv = ass_cache_get(render_priv->cache.composite_cache, &hk);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
496 if (hv) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
497 (*last_tail)->bitmap = hv->a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
498 (*tail)->bitmap = hv->b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
499 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
500 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
501 // Allocate new bitmaps and copy over data
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
502 a = clone_bitmap_buffer(*last_tail);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
503 b = clone_bitmap_buffer(*tail);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
504
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
505 // Blend overlapping area
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
506 for (y = 0; y < h; y++)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
507 for (x = 0; x < w; x++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
508 opos = (old_top + y) * (as) + (old_left + x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
509 cpos = (cur_top + y) * (bs) + (cur_left + x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
510 m = FFMIN(a[opos] + b[cpos], 0xff);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
511 (*last_tail)->bitmap[opos] = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
512 (*tail)->bitmap[cpos] = m;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
513 }
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
514
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
515 // Insert bitmaps into the cache
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
516 chv.a = (*last_tail)->bitmap;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
517 chv.b = (*tail)->bitmap;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
518 ass_cache_put(render_priv->cache.composite_cache, &hk, &chv);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
519 }
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
520
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
521 static void free_list_add(ASS_Renderer *render_priv, void *object)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
522 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
523 if (!render_priv->free_head) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
524 render_priv->free_head = calloc(1, sizeof(FreeList));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
525 render_priv->free_head->object = object;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
526 render_priv->free_tail = render_priv->free_head;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
527 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
528 FreeList *l = calloc(1, sizeof(FreeList));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
529 l->object = object;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
530 render_priv->free_tail->next = l;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
531 render_priv->free_tail = render_priv->free_tail->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
532 }
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
533 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
534
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 28788
diff changeset
535 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
536 * Iterate through a list of bitmaps and blend with clip vector, if
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
537 * applicable. The blended bitmaps are added to a free list which is freed
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
538 * at the start of a new frame.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
539 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
540 static void blend_vector_clip(ASS_Renderer *render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
541 ASS_Image *head)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
542 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
543 FT_Outline *outline;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
544 Bitmap *clip_bm = NULL;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
545 ASS_Image *cur;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
546 ASS_Drawing *drawing = render_priv->state.clip_drawing;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
547 BitmapHashKey key;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
548 BitmapHashValue *val;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
549
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
550 if (!drawing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
551 return;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
552
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
553 // Try to get mask from cache
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
554 memset(&key, 0, sizeof(key));
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
555 key.type = BITMAP_CLIP;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
556 key.u.clip.text = drawing->text;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
557 val = ass_cache_get(render_priv->cache.bitmap_cache, &key);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
558
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
559 if (val) {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
560 clip_bm = val->bm;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
561 } else {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
562 BitmapHashValue v;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
563
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
564 // Not found in cache, parse and rasterize it
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
565 outline = ass_drawing_parse(drawing, 1);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
566 if (!outline) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
567 ass_msg(render_priv->library, MSGL_WARN,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
568 "Clip vector parsing failed. Skipping.");
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
569 goto blend_vector_error;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
570 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
571
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
572 // We need to translate the clip according to screen borders
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
573 if (render_priv->settings.left_margin != 0 ||
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
574 render_priv->settings.top_margin != 0) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
575 FT_Vector trans = {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
576 .x = int_to_d6(render_priv->settings.left_margin),
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
577 .y = -int_to_d6(render_priv->settings.top_margin),
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
578 };
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
579 FT_Outline_Translate(outline, trans.x, trans.y);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
580 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
581
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
582 ass_msg(render_priv->library, MSGL_DBG2,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
583 "Parsed vector clip: scales (%f, %f) string [%s]\n",
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
584 drawing->scale_x, drawing->scale_y, drawing->text);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
585
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
586 clip_bm = outline_to_bitmap(render_priv->library,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
587 render_priv->ftlibrary, outline, 0);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
588
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
589 // Add to cache
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
590 memset(&v, 0, sizeof(v));
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
591 key.u.clip.text = strdup(drawing->text);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
592 v.bm = clip_bm;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
593 ass_cache_put(render_priv->cache.bitmap_cache, &key, &v);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
594 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
595 blend_vector_error:
19965
70352570e9ae Shadow support in libass.
eugeni
parents: 19940
diff changeset
596
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
597 if (!clip_bm) goto blend_vector_exit;
19965
70352570e9ae Shadow support in libass.
eugeni
parents: 19940
diff changeset
598
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
599 // Iterate through bitmaps and blend/clip them
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
600 for (cur = head; cur; cur = cur->next) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
601 int left, top, right, bottom, apos, bpos, y, x, w, h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
602 int ax, ay, aw, ah, as;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
603 int bx, by, bw, bh, bs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
604 int aleft, atop, bleft, btop;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
605 unsigned char *abuffer, *bbuffer, *nbuffer;
19965
70352570e9ae Shadow support in libass.
eugeni
parents: 19940
diff changeset
606
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
607 abuffer = cur->bitmap;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
608 bbuffer = clip_bm->buffer;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
609 ax = cur->dst_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
610 ay = cur->dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
611 aw = cur->w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
612 ah = cur->h;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
613 as = cur->stride;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
614 bx = clip_bm->left;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
615 by = clip_bm->top;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
616 bw = clip_bm->w;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
617 bh = clip_bm->h;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
618 bs = clip_bm->stride;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
619
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
620 // Calculate overlap coordinates
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
621 left = (ax > bx) ? ax : bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
622 top = (ay > by) ? ay : by;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
623 right = ((ax + aw) < (bx + bw)) ? (ax + aw) : (bx + bw);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
624 bottom = ((ay + ah) < (by + bh)) ? (ay + ah) : (by + bh);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
625 aleft = left - ax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
626 atop = top - ay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
627 w = right - left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
628 h = bottom - top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
629 bleft = left - bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
630 btop = top - by;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
631
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
632 if (render_priv->state.clip_drawing_mode) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
633 // Inverse clip
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
634 if (ax + aw < bx || ay + ah < by || ax > bx + bw ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
635 ay > by + bh) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
636 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
637 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
638
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
639 // Allocate new buffer and add to free list
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
640 nbuffer = malloc(as * ah);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
641 if (!nbuffer) goto blend_vector_exit;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
642 free_list_add(render_priv, nbuffer);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
643
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
644 // Blend together
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
645 memcpy(nbuffer, abuffer, as * (ah - 1) + aw);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
646 for (y = 0; y < h; y++)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
647 for (x = 0; x < w; x++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
648 apos = (atop + y) * as + aleft + x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
649 bpos = (btop + y) * bs + bleft + x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
650 nbuffer[apos] = FFMAX(0, abuffer[apos] - bbuffer[bpos]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
651 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
652 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
653 // Regular clip
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
654 if (ax + aw < bx || ay + ah < by || ax > bx + bw ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
655 ay > by + bh) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
656 cur->w = cur->h = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
657 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
658 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
659
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
660 // Allocate new buffer and add to free list
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
661 nbuffer = calloc(as, ah);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
662 if (!nbuffer) goto blend_vector_exit;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
663 free_list_add(render_priv, nbuffer);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
664
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
665 // Blend together
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
666 for (y = 0; y < h; y++)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
667 for (x = 0; x < w; x++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
668 apos = (atop + y) * as + aleft + x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
669 bpos = (btop + y) * bs + bleft + x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
670 nbuffer[apos] = (abuffer[apos] * bbuffer[bpos] + 255) >> 8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
671 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
672 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
673 cur->bitmap = nbuffer;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
674 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
675
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
676 blend_vector_exit:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
677 ass_drawing_free(render_priv->state.clip_drawing);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
678 render_priv->state.clip_drawing = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
679 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
680
34549
da8125c9ecad Do not try to render \r.
reimar
parents: 34295
diff changeset
681 #define SKIP_SYMBOL(x) ((x) == 0 || (x) == '\n' || (x) == '\r')
da8125c9ecad Do not try to render \r.
reimar
parents: 34295
diff changeset
682
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
683 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
684 * \brief Convert TextInfo struct to ASS_Image list
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
685 * Splits glyphs in halves when needed (for \kf karaoke).
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
686 */
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
687 static ASS_Image *render_text(ASS_Renderer *render_priv, int dst_x, int dst_y)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
688 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
689 int pen_x, pen_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
690 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
691 Bitmap *bm;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
692 ASS_Image *head;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
693 ASS_Image **tail = &head;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
694 ASS_Image **last_tail = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
695 ASS_Image **here_tail = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
696 TextInfo *text_info = &render_priv->text_info;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
697
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
698 for (i = 0; i < text_info->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
699 GlyphInfo *info = text_info->glyphs + i;
34549
da8125c9ecad Do not try to render \r.
reimar
parents: 34295
diff changeset
700 if (SKIP_SYMBOL(info->symbol) || !info->bm_s
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
701 || (info->shadow_x == 0 && info->shadow_y == 0) || info->skip)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
702 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
703
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
704 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
705 if (!info->bm_s) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
706 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
707 continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
708 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
709
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
710 pen_x =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
711 dst_x + (info->pos.x >> 6) +
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
712 (int) (info->shadow_x * render_priv->border_scale);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
713 pen_y =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
714 dst_y + (info->pos.y >> 6) +
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
715 (int) (info->shadow_y * render_priv->border_scale);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
716 bm = info->bm_s;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
717
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
718 here_tail = tail;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
719 tail =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
720 render_glyph(render_priv, bm, pen_x, pen_y, info->c[3], 0,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
721 1000000, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
722
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
723 if (last_tail && tail != here_tail && ((info->c[3] & 0xff) > 0))
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
724 render_overlap(render_priv, last_tail, here_tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
725 last_tail = here_tail;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
726
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
727 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
728 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
729 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
730
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
731 last_tail = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
732 for (i = 0; i < text_info->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
733 GlyphInfo *info = text_info->glyphs + i;
34549
da8125c9ecad Do not try to render \r.
reimar
parents: 34295
diff changeset
734 if (SKIP_SYMBOL(info->symbol) || !info->bm_o
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
735 || info->skip)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
736 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
737
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
738 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
739 if (!info->bm_o) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
740 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
741 continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
742 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
743
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
744 pen_x = dst_x + (info->pos.x >> 6);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
745 pen_y = dst_y + (info->pos.y >> 6);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
746 bm = info->bm_o;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
747
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
748 if ((info->effect_type == EF_KARAOKE_KO)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
749 && (info->effect_timing <= (info->bbox.xMax >> 6))) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
750 // do nothing
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
751 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
752 here_tail = tail;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
753 tail =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
754 render_glyph(render_priv, bm, pen_x, pen_y, info->c[2],
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
755 0, 1000000, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
756 if (last_tail && tail != here_tail && ((info->c[2] & 0xff) > 0))
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
757 render_overlap(render_priv, last_tail, here_tail);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
758
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
759 last_tail = here_tail;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
760 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
761 info = info->next;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
762 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
763 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
764
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
765 for (i = 0; i < text_info->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
766 GlyphInfo *info = text_info->glyphs + i;
34549
da8125c9ecad Do not try to render \r.
reimar
parents: 34295
diff changeset
767 if (SKIP_SYMBOL(info->symbol) || !info->bm
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
768 || info->skip)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
769 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
770
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
771 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
772 if (!info->bm) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
773 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
774 continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
775 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
776
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
777 pen_x = dst_x + (info->pos.x >> 6);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
778 pen_y = dst_y + (info->pos.y >> 6);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
779 bm = info->bm;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
780
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
781 if ((info->effect_type == EF_KARAOKE)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
782 || (info->effect_type == EF_KARAOKE_KO)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
783 if (info->effect_timing > (info->bbox.xMax >> 6))
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
784 tail =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
785 render_glyph(render_priv, bm, pen_x, pen_y,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
786 info->c[0], 0, 1000000, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
787 else
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
788 tail =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
789 render_glyph(render_priv, bm, pen_x, pen_y,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
790 info->c[1], 0, 1000000, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
791 } else if (info->effect_type == EF_KARAOKE_KF) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
792 tail =
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
793 render_glyph(render_priv, bm, pen_x, pen_y, info->c[0],
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
794 info->c[1], info->effect_timing, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
795 } else
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
796 tail =
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
797 render_glyph(render_priv, bm, pen_x, pen_y, info->c[0],
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
798 0, 1000000, tail);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
799 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
800 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
801 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
802
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
803 *tail = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
804 blend_vector_clip(render_priv, head);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
805
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
806 return head;
28748
06983ef189b9 With pan-and-scan, keep positioned events in their original positions
eugeni
parents: 28719
diff changeset
807 }
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29382
diff changeset
808
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
809 static void compute_string_bbox(TextInfo *text, DBBox *bbox)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
810 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
811 int i;
19556
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
812
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
813 if (text->length > 0) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
814 bbox->xMin = 32000;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
815 bbox->xMax = -32000;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
816 bbox->yMin = -1 * text->lines[0].asc + d6_to_double(text->glyphs[0].pos.y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
817 bbox->yMax = text->height - text->lines[0].asc +
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
818 d6_to_double(text->glyphs[0].pos.y);
19556
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
819
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
820 for (i = 0; i < text->length; ++i) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
821 GlyphInfo *info = text->glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
822 if (info->skip) continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
823 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
824 double s = d6_to_double(info->pos.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
825 double e = s + d6_to_double(info->advance.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
826 bbox->xMin = FFMIN(bbox->xMin, s);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
827 bbox->xMax = FFMAX(bbox->xMax, e);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
828 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
829 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
830 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
831 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
832 bbox->xMin = bbox->xMax = bbox->yMin = bbox->yMax = 0.;
19556
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
833 }
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
834
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
835 /**
19873
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
836 * \brief partially reset render_context to style values
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
837 * Works like {\r}: resets some style overrides
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
838 */
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
839 void reset_render_context(ASS_Renderer *render_priv, ASS_Style *style)
19873
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
840 {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
841 if (!style)
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
842 style = render_priv->state.style;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
843
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
844 render_priv->state.c[0] = style->PrimaryColour;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
845 render_priv->state.c[1] = style->SecondaryColour;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
846 render_priv->state.c[2] = style->OutlineColour;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
847 render_priv->state.c[3] = style->BackColour;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
848 render_priv->state.flags =
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
849 (style->Underline ? DECO_UNDERLINE : 0) |
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
850 (style->StrikeOut ? DECO_STRIKETHROUGH : 0);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
851 render_priv->state.font_size = style->FontSize;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
852
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
853 free(render_priv->state.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
854 render_priv->state.family = NULL;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
855 render_priv->state.family = strdup(style->FontName);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
856 render_priv->state.treat_family_as_pattern =
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
857 style->treat_fontname_as_pattern;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
858 render_priv->state.bold = style->Bold;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
859 render_priv->state.italic = style->Italic;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
860 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
861
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
862 render_priv->state.border_style = style->BorderStyle;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
863 calc_border(render_priv, style->Outline, style->Outline);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
864 change_border(render_priv, render_priv->state.border_x, render_priv->state.border_y);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
865 render_priv->state.scale_x = style->ScaleX;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
866 render_priv->state.scale_y = style->ScaleY;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
867 render_priv->state.hspacing = style->Spacing;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
868 render_priv->state.be = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
869 render_priv->state.blur = 0.0;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
870 render_priv->state.shadow_x = style->Shadow;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
871 render_priv->state.shadow_y = style->Shadow;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
872 render_priv->state.frx = render_priv->state.fry = 0.;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
873 render_priv->state.frz = M_PI * style->Angle / 180.;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
874 render_priv->state.fax = render_priv->state.fay = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
875 render_priv->state.wrap_style = render_priv->track->WrapStyle;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
876 render_priv->state.font_encoding = style->Encoding;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
877 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
878
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
879 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
880 * \brief Start new event. Reset render_priv->state.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
881 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
882 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
883 init_render_context(ASS_Renderer *render_priv, ASS_Event *event)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
884 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
885 render_priv->state.event = event;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
886 render_priv->state.style = render_priv->track->styles + event->Style;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
887 render_priv->state.parsed_tags = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
888
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
889 reset_render_context(render_priv, render_priv->state.style);
19873
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
890
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
891 render_priv->state.evt_type = EVENT_NORMAL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
892 render_priv->state.alignment = render_priv->state.style->Alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
893 render_priv->state.pos_x = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
894 render_priv->state.pos_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
895 render_priv->state.org_x = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
896 render_priv->state.org_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
897 render_priv->state.have_origin = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
898 render_priv->state.clip_x0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
899 render_priv->state.clip_y0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
900 render_priv->state.clip_x1 = render_priv->track->PlayResX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
901 render_priv->state.clip_y1 = render_priv->track->PlayResY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
902 render_priv->state.clip_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
903 render_priv->state.detect_collisions = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
904 render_priv->state.fade = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
905 render_priv->state.drawing_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
906 render_priv->state.effect_type = EF_NONE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
907 render_priv->state.effect_timing = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
908 render_priv->state.effect_skip_timing = 0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
909 render_priv->state.bm_run_id = 0;
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
910 ass_drawing_free(render_priv->state.drawing);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
911 render_priv->state.drawing = ass_drawing_new(render_priv->library,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
912 render_priv->ftlibrary);
19873
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
913
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
914 apply_transition_effects(render_priv, event);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
915 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
916
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
917 static void free_render_context(ASS_Renderer *render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
918 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
919 free(render_priv->state.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
920 ass_drawing_free(render_priv->state.drawing);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
921
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
922 render_priv->state.family = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
923 render_priv->state.drawing = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
924 }
19873
98d32b832c3a Reduce code duplication in init_render_context().
eugeni
parents: 19848
diff changeset
925
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
926 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
927 * Replace the outline of a glyph by a contour which makes up a simple
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
928 * opaque rectangle.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
929 */
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
930 static void draw_opaque_box(ASS_Renderer *render_priv, int asc, int desc,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
931 FT_Outline *ol, FT_Vector advance, int sx, int sy)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
932 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
933 int i;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
934 int adv = advance.x;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
935 double scale_y = render_priv->state.scale_y;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
936 double scale_x = render_priv->state.scale_x;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
937
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
938 // to avoid gaps
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
939 sx = FFMAX(64, sx);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
940 sy = FFMAX(64, sy);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
941
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
942 // Emulate the WTFish behavior of VSFilter, i.e. double-scale
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
943 // the sizes of the opaque box.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
944 adv += double_to_d6(render_priv->state.hspacing * render_priv->font_scale
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
945 * scale_x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
946 adv *= scale_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
947 sx *= scale_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
948 sy *= scale_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
949 desc *= scale_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
950 desc += asc * (scale_y - 1.0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
951
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
952 FT_Vector points[4] = {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
953 { .x = -sx, .y = asc + sy },
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
954 { .x = adv + sx, .y = asc + sy },
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
955 { .x = adv + sx, .y = -desc - sy },
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
956 { .x = -sx, .y = -desc - sy },
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
957 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
958
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
959 FT_Outline_New(render_priv->ftlibrary, 4, 1, ol);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
960
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
961 ol->n_points = ol->n_contours = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
962 for (i = 0; i < 4; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
963 ol->points[ol->n_points] = points[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
964 ol->tags[ol->n_points++] = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
965 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
966 ol->contours[ol->n_contours++] = ol->n_points - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
967 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
968
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
969 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
970 * Stroke an outline glyph in x/y direction. Applies various fixups to get
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
971 * around limitations of the FreeType stroker.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
972 */
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
973 static void stroke_outline(ASS_Renderer *render_priv, FT_Outline *outline,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
974 int sx, int sy)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
975 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
976 if (sx <= 0 && sy <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
977 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
978
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
979 fix_freetype_stroker(outline, sx, sy);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
980
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
981 // Borders are equal; use the regular stroker
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
982 if (sx == sy && render_priv->state.stroker) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
983 int error;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
984 unsigned n_points, n_contours;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
985
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
986 FT_StrokerBorder border = FT_Outline_GetOutsideBorder(outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
987 error = FT_Stroker_ParseOutline(render_priv->state.stroker, outline, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
988 if (error) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
989 ass_msg(render_priv->library, MSGL_WARN,
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
990 "FT_Stroker_ParseOutline failed, error: %d", error);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
991 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
992 error = FT_Stroker_GetBorderCounts(render_priv->state.stroker, border,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
993 &n_points, &n_contours);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
994 if (error) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
995 ass_msg(render_priv->library, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
996 "FT_Stroker_GetBorderCounts failed, error: %d", error);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
997 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
998 FT_Outline_Done(render_priv->ftlibrary, outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
999 FT_Outline_New(render_priv->ftlibrary, n_points, n_contours, outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1000 outline->n_points = outline->n_contours = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1001 FT_Stroker_ExportBorder(render_priv->state.stroker, border, outline);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1002
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1003 // "Stroke" with the outline emboldener in two passes.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1004 // The outlines look uglier, but the emboldening never adds any points
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1005 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1006 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1007 FT_Outline nol;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1008
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1009 FT_Outline_New(render_priv->ftlibrary, outline->n_points,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1010 outline->n_contours, &nol);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1011 FT_Outline_Copy(outline, &nol);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1012
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1013 FT_Outline_Embolden(outline, sx * 2);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1014 FT_Outline_Translate(outline, -sx, -sx);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1015 FT_Outline_Embolden(&nol, sy * 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1016 FT_Outline_Translate(&nol, -sy, -sy);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1017
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1018 for (i = 0; i < outline->n_points; i++)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1019 outline->points[i].y = nol.points[i].y;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1020
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1021 FT_Outline_Done(render_priv->ftlibrary, &nol);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1022 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1023 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1024
23179
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1025 /**
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1026 * \brief Prepare glyph hash
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1027 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1028 static void
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1029 fill_glyph_hash(ASS_Renderer *priv, OutlineHashKey *outline_key,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1030 GlyphInfo *info)
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1031 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1032 if (info->drawing) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1033 DrawingHashKey *key = &outline_key->u.drawing;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1034 outline_key->type = OUTLINE_DRAWING;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1035 key->scale_x = double_to_d16(info->scale_x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1036 key->scale_y = double_to_d16(info->scale_y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1037 key->outline.x = double_to_d16(info->border_x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1038 key->outline.y = double_to_d16(info->border_y);
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1039 key->border_style = info->border_style;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1040 key->hash = info->drawing->hash;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1041 key->text = info->drawing->text;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1042 key->pbo = info->drawing->pbo;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1043 key->scale = info->drawing->scale;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1044 } else {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1045 GlyphHashKey *key = &outline_key->u.glyph;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1046 outline_key->type = OUTLINE_GLYPH;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1047 key->font = info->font;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1048 key->size = info->font_size;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1049 key->face_index = info->face_index;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1050 key->glyph_index = info->glyph_index;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1051 key->bold = info->bold;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1052 key->italic = info->italic;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1053 key->scale_x = double_to_d16(info->scale_x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1054 key->scale_y = double_to_d16(info->scale_y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1055 key->outline.x = double_to_d16(info->border_x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1056 key->outline.y = double_to_d16(info->border_y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1057 key->flags = info->flags;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1058 key->border_style = info->border_style;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1059 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1060 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1061
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1062 /**
23179
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1063 * \brief Get normal and outline (border) glyphs
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1064 * \param info out: struct filled with extracted data
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1065 * Tries to get both glyphs from cache.
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1066 * If they can't be found, gets a glyph from font face, generates outline with FT_Stroker,
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1067 * and add them to cache.
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1068 * The glyphs are returned in info->glyph and info->outline_glyph
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1069 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1070 static void
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1071 get_outline_glyph(ASS_Renderer *priv, GlyphInfo *info)
23021
a81c390d4a22 Move outline glyph generation to a separate function, using outline glyph
eugeni
parents: 23017
diff changeset
1072 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1073 OutlineHashValue *val;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1074 OutlineHashKey key;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1075
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1076 memset(&info->hash_key, 0, sizeof(key));
23021
a81c390d4a22 Move outline glyph generation to a separate function, using outline glyph
eugeni
parents: 23017
diff changeset
1077
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1078 fill_glyph_hash(priv, &key, info);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1079 val = ass_cache_get(priv->cache.outline_cache, &key);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1080
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1081 if (!val) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1082 OutlineHashValue v;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1083 memset(&v, 0, sizeof(v));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1084
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1085 if (info->drawing) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1086 ASS_Drawing *drawing = info->drawing;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1087 ass_drawing_hash(drawing);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1088 if(!ass_drawing_parse(drawing, 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1089 return;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1090 outline_copy(priv->ftlibrary, &drawing->outline,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1091 &v.outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1092 v.advance.x = drawing->advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1093 v.advance.y = drawing->advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1094 v.asc = drawing->asc;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1095 v.desc = drawing->desc;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1096 key.u.drawing.text = strdup(drawing->text);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1097 } else {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1098 // arbitrary, not too small to prevent grid fitting rounding effects
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1099 // XXX: this is a rather crude hack
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1100 const double ft_size = 256.0;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1101 ass_face_set_size(info->font->faces[info->face_index], ft_size);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1102 ass_font_set_transform(info->font,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1103 info->scale_x * info->font_size / ft_size,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1104 info->scale_y * info->font_size / ft_size,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1105 NULL);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1106 FT_Glyph glyph =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1107 ass_font_get_glyph(priv->fontconfig_priv, info->font,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1108 info->symbol, info->face_index, info->glyph_index,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1109 priv->settings.hinting, info->flags);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1110 if (glyph != NULL) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1111 outline_copy(priv->ftlibrary,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1112 &((FT_OutlineGlyph)glyph)->outline, &v.outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1113 if (priv->settings.shaper == ASS_SHAPING_SIMPLE) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1114 v.advance.x = d16_to_d6(glyph->advance.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1115 v.advance.y = d16_to_d6(glyph->advance.y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1116 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1117 FT_Done_Glyph(glyph);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1118 ass_font_get_asc_desc(info->font, info->symbol,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1119 &v.asc, &v.desc);
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1120 v.asc *= info->scale_y * info->font_size / ft_size;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1121 v.desc *= info->scale_y * info->font_size / ft_size;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1122 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1123 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1124
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1125 if (!v.outline)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1126 return;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1127
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1128 FT_Outline_Get_CBox(v.outline, &v.bbox_scaled);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1129
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1130 if (info->border_style == 3 &&
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1131 (info->border_x > 0 || info->border_y > 0)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1132 FT_Vector advance;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1133
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1134 v.border = calloc(1, sizeof(FT_Outline));
23021
a81c390d4a22 Move outline glyph generation to a separate function, using outline glyph
eugeni
parents: 23017
diff changeset
1135
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1136 if (priv->settings.shaper == ASS_SHAPING_SIMPLE || info->drawing)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1137 advance = v.advance;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1138 else
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1139 advance = info->advance;
23025
ab0943242d1a Store outline_glyph (glyph border) in glyph cache.
eugeni
parents: 23024
diff changeset
1140
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1141 draw_opaque_box(priv, v.asc, v.desc, v.border, advance,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1142 double_to_d6(info->border_x * priv->border_scale),
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1143 double_to_d6(info->border_y * priv->border_scale));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1144
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1145 } else if ((info->border_x > 0 || info->border_y > 0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1146 && double_to_d6(info->scale_x) && double_to_d6(info->scale_y)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1147
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1148 change_border(priv, info->border_x, info->border_y);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1149 outline_copy(priv->ftlibrary, v.outline, &v.border);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1150 stroke_outline(priv, v.border,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1151 double_to_d6(info->border_x * priv->border_scale),
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1152 double_to_d6(info->border_y * priv->border_scale));
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1153 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1154
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1155 v.lib = priv->ftlibrary;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1156 val = ass_cache_put(priv->cache.outline_cache, &key, &v);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1157 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1158
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1159 info->hash_key.u.outline.outline = val;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1160 info->outline = val->outline;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1161 info->border = val->border;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1162 info->bbox = val->bbox_scaled;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1163 if (info->drawing || priv->settings.shaper == ASS_SHAPING_SIMPLE) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1164 info->cluster_advance.x = info->advance.x = val->advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1165 info->cluster_advance.y = info->advance.y = val->advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1166 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1167 info->asc = val->asc;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1168 info->desc = val->desc;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1169
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1170 ass_drawing_free(info->drawing);
23021
a81c390d4a22 Move outline glyph generation to a separate function, using outline glyph
eugeni
parents: 23017
diff changeset
1171 }
a81c390d4a22 Move outline glyph generation to a separate function, using outline glyph
eugeni
parents: 23017
diff changeset
1172
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1173 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1174 * \brief Apply transformation to outline points of a glyph
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1175 * Applies rotations given by frx, fry and frz and projects the points back
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1176 * onto the screen plane.
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1177 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1178 static void
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1179 transform_3d_points(FT_Vector shift, FT_Outline *outline, double frx, double fry,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1180 double frz, double fax, double fay, double scale,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1181 int yshift)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1182 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1183 double sx = sin(frx);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1184 double sy = sin(fry);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1185 double sz = sin(frz);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1186 double cx = cos(frx);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1187 double cy = cos(fry);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1188 double cz = cos(frz);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1189 FT_Vector *p = outline->points;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1190 double x, y, z, xx, yy, zz;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1191 int i, dist;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1192
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1193 dist = 20000 * scale;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1194 for (i = 0; i < outline->n_points; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1195 x = (double) p[i].x + shift.x + (fax * (yshift - p[i].y));
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1196 y = (double) p[i].y + shift.y + (-fay * p[i].x);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1197 z = 0.;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1198
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1199 xx = x * cz + y * sz;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1200 yy = -(x * sz - y * cz);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1201 zz = z;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1202
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1203 x = xx;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1204 y = yy * cx + zz * sx;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1205 z = yy * sx - zz * cx;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1206
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1207 xx = x * cy + z * sy;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1208 yy = y;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1209 zz = x * sy - z * cy;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1210
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1211 zz = FFMAX(zz, 1000 - dist);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1212
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1213 x = (xx * dist) / (zz + dist);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1214 y = (yy * dist) / (zz + dist);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1215 p[i].x = x - shift.x + 0.5;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1216 p[i].y = y - shift.y + 0.5;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1217 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1218 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1219
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1220 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1221 * \brief Apply 3d transformation to several objects
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1222 * \param shift FreeType vector
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1223 * \param glyph FreeType glyph
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1224 * \param glyph2 FreeType glyph
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1225 * \param frx x-axis rotation angle
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1226 * \param fry y-axis rotation angle
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1227 * \param frz z-axis rotation angle
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1228 * Rotates both glyphs by frx, fry and frz. Shift vector is added before rotation and subtracted after it.
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1229 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1230 static void
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1231 transform_3d(FT_Vector shift, FT_Outline *outline, FT_Outline *border,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1232 double frx, double fry, double frz, double fax, double fay,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1233 double scale, int yshift)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1234 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1235 frx = -frx;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1236 frz = -frz;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1237 if (frx != 0. || fry != 0. || frz != 0. || fax != 0. || fay != 0.) {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1238 if (outline)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1239 transform_3d_points(shift, outline, frx, fry, frz,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1240 fax, fay, scale, yshift);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1241
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1242 if (border)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1243 transform_3d_points(shift, border, frx, fry, frz,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1244 fax, fay, scale, yshift);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1245 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1246 }
23173
1170ac4d7f5b Move transform_3d() call to get_bitmap_glyph().
eugeni
parents: 23172
diff changeset
1247
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1248 /**
23179
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1249 * \brief Get bitmaps for a glyph
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1250 * \param info glyph info
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1251 * Tries to get glyph bitmaps from bitmap cache.
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1252 * If they can't be found, they are generated by rotating and rendering the glyph.
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1253 * After that, bitmaps are added to the cache.
eaed63bb5078 Update comments.
eugeni
parents: 23178
diff changeset
1254 * They are returned in info->bm (glyph), info->bm_o (outline) and info->bm_s (shadow).
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1255 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1256 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1257 get_bitmap_glyph(ASS_Renderer *render_priv, GlyphInfo *info)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1258 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1259 BitmapHashValue *val;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1260 OutlineBitmapHashKey *key = &info->hash_key.u.outline;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1261
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1262 if (!info->outline || info->symbol == '\n' || info->symbol == 0 || info->skip)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1263 return;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1264
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1265 val = ass_cache_get(render_priv->cache.bitmap_cache, &info->hash_key);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1266
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1267 if (!val) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1268 FT_Vector shift;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1269 BitmapHashValue hash_val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1270 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1271 double fax_scaled, fay_scaled;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1272 FT_Outline *outline, *border;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1273 double scale_x = render_priv->font_scale_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1274
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1275 hash_val.bm = hash_val.bm_o = hash_val.bm_s = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1276
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1277 outline_copy(render_priv->ftlibrary, info->outline, &outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1278 outline_copy(render_priv->ftlibrary, info->border, &border);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1279
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1280 // calculating rotation shift vector (from rotation origin to the glyph basepoint)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1281 shift.x = key->shift_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1282 shift.y = key->shift_y;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1283 fax_scaled = info->fax / info->scale_y * info->scale_x;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1284 fay_scaled = info->fay / info->scale_x * info->scale_y;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1285
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1286 // apply rotation
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1287 transform_3d(shift, outline, border,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1288 info->frx, info->fry, info->frz, fax_scaled,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1289 fay_scaled, render_priv->font_scale, info->asc);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1290
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1291 // PAR correction scaling
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1292 FT_Matrix m = { double_to_d16(scale_x), 0,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1293 0, double_to_d16(1.0) };
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1294
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1295 // subpixel shift
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1296 if (outline) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1297 if (scale_x != 1.0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1298 FT_Outline_Transform(outline, &m);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1299 FT_Outline_Translate(outline, key->advance.x, -key->advance.y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1300 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1301 if (border) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1302 if (scale_x != 1.0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1303 FT_Outline_Transform(border, &m);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1304 FT_Outline_Translate(border, key->advance.x, -key->advance.y);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1305 }
23177
134a2baca452 Move glyph_to_bitmap() call and outline glyph deallocation to
eugeni
parents: 23175
diff changeset
1306
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1307 // render glyph
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1308 error = outline_to_bitmap3(render_priv->library,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1309 render_priv->synth_priv,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1310 render_priv->ftlibrary,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1311 outline, border,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1312 &hash_val.bm, &hash_val.bm_o,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1313 &hash_val.bm_s, info->be,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1314 info->blur * render_priv->border_scale,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1315 key->shadow_offset,
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1316 info->border_style);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1317 if (error)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1318 info->symbol = 0;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1319
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1320 val = ass_cache_put(render_priv->cache.bitmap_cache, &info->hash_key,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1321 &hash_val);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1322
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1323 outline_free(render_priv->ftlibrary, outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1324 outline_free(render_priv->ftlibrary, border);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1325 }
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1326
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1327 info->bm = val->bm;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1328 info->bm_o = val->bm_o;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1329 info->bm_s = val->bm_s;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1330
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1331 // VSFilter compatibility: invisible fill and no border?
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1332 // In this case no shadow is supposed to be rendered.
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1333 if (!info->border && (info->c[0] & 0xFF) == 0xFF)
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1334 info->bm_s = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1335 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1336
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1337 /**
19932
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1338 * This function goes through text_info and calculates text parameters.
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1339 * The following text_info fields are filled:
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1340 * height
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1341 * lines[].height
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1342 * lines[].asc
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1343 * lines[].desc
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1344 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1345 static void measure_text(ASS_Renderer *render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1346 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1347 TextInfo *text_info = &render_priv->text_info;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1348 int cur_line = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1349 double max_asc = 0., max_desc = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1350 GlyphInfo *last = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1351 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1352 int empty_line = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1353 text_info->height = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1354 for (i = 0; i < text_info->length + 1; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1355 if ((i == text_info->length) || text_info->glyphs[i].linebreak) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1356 if (empty_line && cur_line > 0 && last && i < text_info->length) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1357 max_asc = d6_to_double(last->asc) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1358 max_desc = d6_to_double(last->desc) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1359 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1360 text_info->lines[cur_line].asc = max_asc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1361 text_info->lines[cur_line].desc = max_desc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1362 text_info->height += max_asc + max_desc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1363 cur_line++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1364 max_asc = max_desc = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1365 empty_line = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1366 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1367 empty_line = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1368 if (i < text_info->length) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1369 GlyphInfo *cur = text_info->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1370 if (d6_to_double(cur->asc) > max_asc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1371 max_asc = d6_to_double(cur->asc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1372 if (d6_to_double(cur->desc) > max_desc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1373 max_desc = d6_to_double(cur->desc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1374 if (cur->symbol != '\n' && cur->symbol != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1375 last = cur;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1376 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1377 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1378 text_info->height +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1379 (text_info->n_lines -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1380 1) * render_priv->settings.line_spacing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1381 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1382
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1383 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1384 * Mark extra whitespace for later removal.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1385 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1386 #define IS_WHITESPACE(x) ((x->symbol == ' ' || x->symbol == '\n') \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1387 && !x->linebreak)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1388 static void trim_whitespace(ASS_Renderer *render_priv)
19932
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1389 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1390 int i, j;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1391 GlyphInfo *cur;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1392 TextInfo *ti = &render_priv->text_info;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1393
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1394 // Mark trailing spaces
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1395 i = ti->length - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1396 cur = ti->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1397 while (i && IS_WHITESPACE(cur)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1398 cur->skip++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1399 cur = ti->glyphs + --i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1400 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1401
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1402 // Mark leading whitespace
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1403 i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1404 cur = ti->glyphs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1405 while (i < ti->length && IS_WHITESPACE(cur)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1406 cur->skip++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1407 cur = ti->glyphs + ++i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1408 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1409
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1410 // Mark all extraneous whitespace inbetween
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1411 for (i = 0; i < ti->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1412 cur = ti->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1413 if (cur->linebreak) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1414 // Mark whitespace before
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1415 j = i - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1416 cur = ti->glyphs + j;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1417 while (j && IS_WHITESPACE(cur)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1418 cur->skip++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1419 cur = ti->glyphs + --j;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1420 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1421 // A break itself can contain a whitespace, too
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1422 cur = ti->glyphs + i;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1423 if (cur->symbol == ' ') {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1424 cur->skip++;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1425 // Mark whitespace after
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1426 j = i + 1;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1427 cur = ti->glyphs + j;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1428 while (j < ti->length && IS_WHITESPACE(cur)) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1429 cur->skip++;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1430 cur = ti->glyphs + ++j;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1431 }
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1432 i = j - 1;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1433 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1434 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1435 }
19932
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1436 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1437 #undef IS_WHITESPACE
19932
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1438
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1439 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1440 * \brief rearrange text between lines
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1441 * \param max_text_width maximal text line width in pixels
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1442 * The algo is similar to the one in libvo/sub.c:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1443 * 1. Place text, wrapping it when current line is full
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1444 * 2. Try moving words from the end of a line to the beginning of the next one while it reduces
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1445 * the difference in lengths between this two lines.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1446 * The result may not be optimal, but usually is good enough.
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1447 *
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1448 * FIXME: implement style 0 and 3 correctly
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1449 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1450 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1451 wrap_lines_smart(ASS_Renderer *render_priv, double max_text_width)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1452 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1453 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1454 GlyphInfo *cur, *s1, *e1, *s2, *s3, *w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1455 int last_space;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1456 int break_type;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1457 int exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1458 double pen_shift_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1459 double pen_shift_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1460 int cur_line;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1461 int run_offset;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1462 TextInfo *text_info = &render_priv->text_info;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1463
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1464 last_space = -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1465 text_info->n_lines = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1466 break_type = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1467 s1 = text_info->glyphs; // current line start
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1468 for (i = 0; i < text_info->length; ++i) {
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1469 int break_at = -1;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1470 double s_offset, len;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1471 cur = text_info->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1472 s_offset = d6_to_double(s1->bbox.xMin + s1->pos.x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1473 len = d6_to_double(cur->bbox.xMax + cur->pos.x) - s_offset;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1474
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1475 if (cur->symbol == '\n') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1476 break_type = 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1477 break_at = i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1478 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1479 "forced line break at %d", break_at);
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1480 } else if (cur->symbol == ' ') {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1481 last_space = i;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1482 } else if (len >= max_text_width
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1483 && (render_priv->state.wrap_style != 2)) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1484 break_type = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1485 break_at = last_space;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1486 if (break_at >= 0)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1487 ass_msg(render_priv->library, MSGL_DBG2, "line break at %d",
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
1488 break_at);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1489 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1490
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1491 if (break_at != -1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1492 // need to use one more line
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1493 // marking break_at+1 as start of a new line
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1494 int lead = break_at + 1; // the first symbol of the new line
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1495 if (text_info->n_lines >= text_info->max_lines) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1496 // Raise maximum number of lines
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1497 text_info->max_lines *= 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1498 text_info->lines = realloc(text_info->lines,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1499 sizeof(LineInfo) *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1500 text_info->max_lines);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1501 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1502 if (lead < text_info->length) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1503 text_info->glyphs[lead].linebreak = break_type;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1504 last_space = -1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1505 s1 = text_info->glyphs + lead;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1506 s_offset = d6_to_double(s1->bbox.xMin + s1->pos.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1507 text_info->n_lines++;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1508 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1509 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1510 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1511 #define DIFF(x,y) (((x) < (y)) ? (y - x) : (x - y))
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1512 exit = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1513 while (!exit && render_priv->state.wrap_style != 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1514 exit = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1515 w = s3 = text_info->glyphs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1516 s1 = s2 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1517 for (i = 0; i <= text_info->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1518 cur = text_info->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1519 if ((i == text_info->length) || cur->linebreak) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1520 s1 = s2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1521 s2 = s3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1522 s3 = cur;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1523 if (s1 && (s2->linebreak == 1)) { // have at least 2 lines, and linebreak is 'soft'
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1524 double l1, l2, l1_new, l2_new;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1525
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1526 w = s2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1527 do {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1528 --w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1529 } while ((w > s1) && (w->symbol == ' '));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1530 while ((w > s1) && (w->symbol != ' ')) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1531 --w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1532 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1533 e1 = w;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1534 while ((e1 > s1) && (e1->symbol == ' ')) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1535 --e1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1536 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1537 if (w->symbol == ' ')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1538 ++w;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1539
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1540 l1 = d6_to_double(((s2 - 1)->bbox.xMax + (s2 - 1)->pos.x) -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1541 (s1->bbox.xMin + s1->pos.x));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1542 l2 = d6_to_double(((s3 - 1)->bbox.xMax + (s3 - 1)->pos.x) -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1543 (s2->bbox.xMin + s2->pos.x));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1544 l1_new = d6_to_double(
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1545 (e1->bbox.xMax + e1->pos.x) -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1546 (s1->bbox.xMin + s1->pos.x));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1547 l2_new = d6_to_double(
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1548 ((s3 - 1)->bbox.xMax + (s3 - 1)->pos.x) -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1549 (w->bbox.xMin + w->pos.x));
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1550
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1551 if (DIFF(l1_new, l2_new) < DIFF(l1, l2)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1552 w->linebreak = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1553 s2->linebreak = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1554 exit = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1555 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1556 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1557 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1558 if (i == text_info->length)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1559 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1560 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1561
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1562 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1563 assert(text_info->n_lines >= 1);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1564 #undef DIFF
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1565
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1566 measure_text(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1567 trim_whitespace(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1568
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1569 pen_shift_x = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1570 pen_shift_y = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1571 cur_line = 1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1572 run_offset = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1573
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1574 i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1575 cur = text_info->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1576 while (i < text_info->length && cur->skip)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1577 cur = text_info->glyphs + ++i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1578 pen_shift_x = d6_to_double(-cur->pos.x);
19932
0b5b9cbbc74e Move calculation of text parameters (number of lines, height, etc.) from
eugeni
parents: 19931
diff changeset
1579
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1580 for (i = 0; i < text_info->length; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1581 cur = text_info->glyphs + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1582 if (cur->linebreak) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1583 while (i < text_info->length && cur->skip && cur->symbol != '\n')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1584 cur = text_info->glyphs + ++i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1585 double height =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1586 text_info->lines[cur_line - 1].desc +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1587 text_info->lines[cur_line].asc;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1588 text_info->lines[cur_line - 1].len = i -
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1589 text_info->lines[cur_line - 1].offset;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1590 text_info->lines[cur_line].offset = i;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1591 cur_line++;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1592 run_offset++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1593 pen_shift_x = d6_to_double(-cur->pos.x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1594 pen_shift_y += height + render_priv->settings.line_spacing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1595 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1596 "shifting from %d to %d by (%f, %f)", i,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1597 text_info->length - 1, pen_shift_x, pen_shift_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1598 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1599 cur->bm_run_id += run_offset;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1600 cur->pos.x += double_to_d6(pen_shift_x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1601 cur->pos.y += double_to_d6(pen_shift_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1602 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1603 text_info->lines[cur_line - 1].len =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1604 text_info->length - text_info->lines[cur_line - 1].offset;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1605
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1606 #if 0
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1607 // print line info
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1608 for (i = 0; i < text_info->n_lines; i++) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1609 printf("line %d offset %d length %d\n", i, text_info->lines[i].offset,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1610 text_info->lines[i].len);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1611 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1612 #endif
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1613 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1614
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1615 /**
20294
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1616 * \brief Calculate base point for positioning and rotation
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1617 * \param bbox text bbox
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1618 * \param alignment alignment
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1619 * \param bx, by out: base point coordinates
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1620 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1621 static void get_base_point(DBBox *bbox, int alignment, double *bx, double *by)
20294
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1622 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1623 const int halign = alignment & 3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1624 const int valign = alignment & 12;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1625 if (bx)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1626 switch (halign) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1627 case HALIGN_LEFT:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1628 *bx = bbox->xMin;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1629 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1630 case HALIGN_CENTER:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1631 *bx = (bbox->xMax + bbox->xMin) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1632 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1633 case HALIGN_RIGHT:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1634 *bx = bbox->xMax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1635 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1636 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1637 if (by)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1638 switch (valign) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1639 case VALIGN_TOP:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1640 *by = bbox->yMin;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1641 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1642 case VALIGN_CENTER:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1643 *by = (bbox->yMax + bbox->yMin) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1644 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1645 case VALIGN_SUB:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1646 *by = bbox->yMax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1647 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1648 }
20294
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1649 }
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1650
4d7c8478e523 Move base point calculation to a separate function. Will be reused soon.
eugeni
parents: 20293
diff changeset
1651 /**
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1652 * Prepare bitmap hash key of a glyph
22215
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 22214
diff changeset
1653 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1654 static void
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1655 fill_bitmap_hash(ASS_Renderer *priv, GlyphInfo *info,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1656 OutlineBitmapHashKey *hash_key)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1657 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1658 hash_key->frx = rot_key(info->frx);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1659 hash_key->fry = rot_key(info->fry);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1660 hash_key->frz = rot_key(info->frz);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1661 hash_key->fax = double_to_d16(info->fax);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1662 hash_key->fay = double_to_d16(info->fay);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1663 hash_key->be = info->be;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1664 hash_key->blur = info->blur;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1665 hash_key->shadow_offset.x = double_to_d6(
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1666 info->shadow_x * priv->border_scale -
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1667 (int) (info->shadow_x * priv->border_scale));
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1668 hash_key->shadow_offset.y = double_to_d6(
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1669 info->shadow_y * priv->border_scale -
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1670 (int) (info->shadow_y * priv->border_scale));
22215
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 22214
diff changeset
1671 }
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 22214
diff changeset
1672
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 22214
diff changeset
1673 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1674 * \brief Main ass rendering function, glues everything together
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1675 * \param event event to render
29048
584ff003cce9 Document the ass_render_event event_images parameter.
reimar
parents: 29047
diff changeset
1676 * \param event_images struct containing resulting images, will also be initialized
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1677 * Process event, appending resulting ASS_Image's to images_root.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1678 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1679 static int
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1680 ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1681 EventImages *event_images)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1682 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1683 char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1684 FT_UInt previous;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1685 FT_UInt num_glyphs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1686 FT_Vector pen;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1687 unsigned code;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1688 DBBox bbox;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1689 int i, j;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1690 int MarginL, MarginR, MarginV;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1691 int last_break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1692 int alignment, halign, valign;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1693 double device_x = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1694 double device_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1695 TextInfo *text_info = &render_priv->text_info;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1696 GlyphInfo *glyphs = render_priv->text_info.glyphs;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1697 ASS_Drawing *drawing;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1698
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1699 if (event->Style >= render_priv->track->n_styles) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1700 ass_msg(render_priv->library, MSGL_WARN, "No style found");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1701 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1702 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1703 if (!event->Text) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1704 ass_msg(render_priv->library, MSGL_WARN, "Empty event");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1705 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1706 }
19650
d89179256560 More checks in ass_render_event.
eugeni
parents: 19649
diff changeset
1707
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1708 init_render_context(render_priv, event);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1709
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1710 drawing = render_priv->state.drawing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1711 text_info->length = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1712 num_glyphs = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1713 p = event->Text;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1714
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1715 int in_tag = 0;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1716
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1717 // Event parsing.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1718 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1719 // get next char, executing style override
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1720 // this affects render_context
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1721 do {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1722 code = 0;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1723 if (!in_tag && *p == '{') { // '\0' goes here
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1724 p++;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1725 in_tag = 1;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1726 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1727 if (in_tag) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1728 int prev_drawing_mode = render_priv->state.drawing_mode;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1729 p = parse_tag(render_priv, p, 1.);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1730 if (*p == '}') { // end of tag
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1731 p++;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1732 in_tag = 0;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1733 } else if (*p != '\\') {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1734 ass_msg(render_priv->library, MSGL_V,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1735 "Unable to parse: '%.30s'", p);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1736 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1737 if (prev_drawing_mode && !render_priv->state.drawing_mode) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1738 // Drawing mode was just disabled. We must exit and draw it
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1739 // immediately, instead of letting further tags affect it.
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1740 // See bug #47.
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1741 break;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1742 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1743 } else {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1744 code = get_next_char(render_priv, &p);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1745 if (code && render_priv->state.drawing_mode) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1746 ass_drawing_add_char(drawing, (char) code);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1747 continue; // skip everything in drawing mode
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1748 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1749 break;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1750 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1751 } while (*p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1752
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1753 if (text_info->length >= text_info->max_glyphs) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1754 // Raise maximum number of glyphs
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1755 text_info->max_glyphs *= 2;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1756 text_info->glyphs = glyphs =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1757 realloc(text_info->glyphs,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1758 sizeof(GlyphInfo) * text_info->max_glyphs);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1759 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1760
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1761 // Clear current GlyphInfo
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1762 memset(&glyphs[text_info->length], 0, sizeof(GlyphInfo));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1763
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1764 // Parse drawing
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1765 if (drawing->i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1766 drawing->scale_x = render_priv->state.scale_x *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1767 render_priv->font_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1768 drawing->scale_y = render_priv->state.scale_y *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1769 render_priv->font_scale;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1770 code = 0xfffc; // object replacement character
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1771 glyphs[text_info->length].drawing = drawing;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1772 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1773
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1774 // face could have been changed in get_next_char
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1775 if (!render_priv->state.font) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1776 free_render_context(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1777 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1778 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1779
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1780 if (code == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1781 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1782
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1783 // Fill glyph information
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1784 glyphs[text_info->length].symbol = code;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1785 glyphs[text_info->length].font = render_priv->state.font;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1786 for (i = 0; i < 4; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1787 uint32_t clr = render_priv->state.c[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1788 change_alpha(&clr,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1789 mult_alpha(_a(clr), render_priv->state.fade), 1.);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1790 glyphs[text_info->length].c[i] = clr;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1791 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1792 glyphs[text_info->length].effect_type = render_priv->state.effect_type;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1793 glyphs[text_info->length].effect_timing =
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1794 render_priv->state.effect_timing;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1795 glyphs[text_info->length].effect_skip_timing =
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1796 render_priv->state.effect_skip_timing;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1797 glyphs[text_info->length].font_size =
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1798 render_priv->state.font_size * render_priv->font_scale;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1799 glyphs[text_info->length].be = render_priv->state.be;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1800 glyphs[text_info->length].blur = render_priv->state.blur;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1801 glyphs[text_info->length].shadow_x = render_priv->state.shadow_x;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1802 glyphs[text_info->length].shadow_y = render_priv->state.shadow_y;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1803 glyphs[text_info->length].scale_x= render_priv->state.scale_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1804 glyphs[text_info->length].scale_y = render_priv->state.scale_y;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1805 glyphs[text_info->length].border_style = render_priv->state.border_style;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1806 glyphs[text_info->length].border_x= render_priv->state.border_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1807 glyphs[text_info->length].border_y = render_priv->state.border_y;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1808 glyphs[text_info->length].hspacing = render_priv->state.hspacing;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1809 glyphs[text_info->length].bold = render_priv->state.bold;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1810 glyphs[text_info->length].italic = render_priv->state.italic;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1811 glyphs[text_info->length].flags = render_priv->state.flags;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1812 glyphs[text_info->length].frx = render_priv->state.frx;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1813 glyphs[text_info->length].fry = render_priv->state.fry;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1814 glyphs[text_info->length].frz = render_priv->state.frz;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1815 glyphs[text_info->length].fax = render_priv->state.fax;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1816 glyphs[text_info->length].fay = render_priv->state.fay;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1817 glyphs[text_info->length].bm_run_id = render_priv->state.bm_run_id;
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21506
diff changeset
1818
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1819 if (glyphs[text_info->length].drawing) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1820 drawing = render_priv->state.drawing =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1821 ass_drawing_new(render_priv->library, render_priv->ftlibrary);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1822 }
19716
e4e492fcc2f7 Bugfix: timing for empty karaoke words was lost, resulting
eugeni
parents: 19693
diff changeset
1823
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1824 text_info->length++;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1825
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1826 render_priv->state.effect_type = EF_NONE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1827 render_priv->state.effect_timing = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1828 render_priv->state.effect_skip_timing = 0;
19931
399bb1fcdc94 Move variable declaration to a more deeply nested block. It is not used outside of it.
eugeni
parents: 19919
diff changeset
1829
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1830 }
19556
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
1831
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1832 if (text_info->length == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1833 // no valid symbols in the event; this can be smth like {comment}
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1834 free_render_context(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1835 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1836 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1837
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1838 // Find shape runs and shape text
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1839 ass_shaper_set_base_direction(render_priv->shaper,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1840 resolve_base_direction(render_priv->state.font_encoding));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1841 ass_shaper_find_runs(render_priv->shaper, render_priv, glyphs,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1842 text_info->length);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1843 ass_shaper_shape(render_priv->shaper, text_info);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1844
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1845 // Retrieve glyphs
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1846 for (i = 0; i < text_info->length; i++) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1847 GlyphInfo *info = glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1848 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1849 get_outline_glyph(render_priv, info);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1850 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1851 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1852 info = glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1853
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1854 // Add additional space after italic to non-italic style changes
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1855 if (i && glyphs[i - 1].italic && !info->italic) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1856 int back = i - 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1857 GlyphInfo *og = &glyphs[back];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1858 while (back && og->bbox.xMax - og->bbox.xMin == 0
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1859 && og->italic)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1860 og = &glyphs[--back];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1861 if (og->bbox.xMax > og->cluster_advance.x)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1862 og->cluster_advance.x = og->bbox.xMax;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1863 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1864
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1865 // add horizontal letter spacing
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1866 info->cluster_advance.x += double_to_d6(info->hspacing *
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1867 render_priv->font_scale * info->scale_x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1868
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1869 // add displacement for vertical shearing
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1870 info->cluster_advance.y += (info->fay / info->scale_x * info->scale_y) * info->cluster_advance.x;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1871
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1872 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1873
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1874 // Preliminary layout (for line wrapping)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1875 previous = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1876 pen.x = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1877 pen.y = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1878 for (i = 0; i < text_info->length; i++) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1879 GlyphInfo *info = glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1880 FT_Vector cluster_pen = pen;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1881 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1882 info->pos.x = cluster_pen.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1883 info->pos.y = cluster_pen.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1884
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1885 cluster_pen.x += info->advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1886 cluster_pen.y += info->advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1887
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1888 // fill bitmap hash
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1889 info->hash_key.type = BITMAP_OUTLINE;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1890 fill_bitmap_hash(render_priv, info, &info->hash_key.u.outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1891
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1892 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1893 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1894 info = glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1895 pen.x += info->cluster_advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1896 pen.y += info->cluster_advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1897 previous = info->symbol;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1898 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1899
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1900
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1901 // depends on glyph x coordinates being monotonous, so it should be done before line wrap
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1902 process_karaoke_effects(render_priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1903
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1904 // alignments
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1905 alignment = render_priv->state.alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1906 halign = alignment & 3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1907 valign = alignment & 12;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1908
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1909 MarginL =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1910 (event->MarginL) ? event->MarginL : render_priv->state.style->MarginL;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1911 MarginR =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1912 (event->MarginR) ? event->MarginR : render_priv->state.style->MarginR;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1913 MarginV =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1914 (event->MarginV) ? event->MarginV : render_priv->state.style->MarginV;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1915
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1916 // calculate max length of a line
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1917 double max_text_width =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1918 x2scr(render_priv, render_priv->track->PlayResX - MarginR) -
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1919 x2scr(render_priv, MarginL);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1920
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1921 // wrap lines
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1922 if (render_priv->state.evt_type != EVENT_HSCROLL) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1923 // rearrange text in several lines
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1924 wrap_lines_smart(render_priv, max_text_width);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1925 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1926 // no breaking or wrapping, everything in a single line
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1927 text_info->lines[0].offset = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1928 text_info->lines[0].len = text_info->length;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1929 text_info->n_lines = 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1930 measure_text(render_priv);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1931 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
1932
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1933 // Reorder text into visual order
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1934 FriBidiStrIndex *cmap = ass_shaper_reorder(render_priv->shaper, text_info);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1935
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1936 // Reposition according to the map
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1937 pen.x = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1938 pen.y = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1939 int lineno = 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1940 for (i = 0; i < text_info->length; i++) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1941 GlyphInfo *info = glyphs + cmap[i];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1942 if (glyphs[i].linebreak) {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
1943 pen.y -= (info->fay / info->scale_x * info->scale_y) * pen.x;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1944 pen.x = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1945 pen.y += double_to_d6(text_info->lines[lineno-1].desc);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1946 pen.y += double_to_d6(text_info->lines[lineno].asc);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1947 pen.y += double_to_d6(render_priv->settings.line_spacing);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1948 lineno++;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1949 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1950 if (info->skip) continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1951 FT_Vector cluster_pen = pen;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1952 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1953 info->pos.x = info->offset.x + cluster_pen.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1954 info->pos.y = info->offset.y + cluster_pen.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1955 cluster_pen.x += info->advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1956 cluster_pen.y += info->advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1957 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1958 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1959 info = glyphs + cmap[i];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1960 pen.x += info->cluster_advance.x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1961 pen.y += info->cluster_advance.y;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1962 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1963
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1964 // align lines
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1965 if (render_priv->state.evt_type != EVENT_HSCROLL) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1966 last_break = -1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1967 double width = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1968 for (i = 0; i <= text_info->length; ++i) { // (text_info->length + 1) is the end of the last line
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1969 if ((i == text_info->length) || glyphs[i].linebreak) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1970 // remove letter spacing (which is included in cluster_advance)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1971 if (i > 0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1972 width -= render_priv->state.hspacing * render_priv->font_scale *
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1973 glyphs[i-1].scale_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1974 double shift = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1975 if (halign == HALIGN_LEFT) { // left aligned, no action
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1976 shift = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1977 } else if (halign == HALIGN_RIGHT) { // right aligned
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1978 shift = max_text_width - width;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1979 } else if (halign == HALIGN_CENTER) { // centered
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1980 shift = (max_text_width - width) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1981 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1982 for (j = last_break + 1; j < i; ++j) {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1983 GlyphInfo *info = glyphs + j;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1984 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1985 info->pos.x += double_to_d6(shift);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1986 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1987 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1988 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1989 last_break = i - 1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1990 width = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1991 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1992 if (i < text_info->length && !glyphs[i].skip &&
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1993 glyphs[i].symbol != '\n' && glyphs[i].symbol != 0) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1994 width += d6_to_double(glyphs[i].cluster_advance.x);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1995 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1996 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1997 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1998
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
1999 // determing text bounding box
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2000 compute_string_bbox(text_info, &bbox);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2001
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2002 // determine device coordinates for text
19556
c7057724ba8c Transition effects support.
eugeni
parents: 19539
diff changeset
2003
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2004 // x coordinate for everything except positioned events
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2005 if (render_priv->state.evt_type == EVENT_NORMAL ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2006 render_priv->state.evt_type == EVENT_VSCROLL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2007 device_x = x2scr(render_priv, MarginL);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2008 } else if (render_priv->state.evt_type == EVENT_HSCROLL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2009 if (render_priv->state.scroll_direction == SCROLL_RL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2010 device_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2011 x2scr(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2012 render_priv->track->PlayResX -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2013 render_priv->state.scroll_shift);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2014 else if (render_priv->state.scroll_direction == SCROLL_LR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2015 device_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2016 x2scr(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2017 render_priv->state.scroll_shift) - (bbox.xMax -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2018 bbox.xMin);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2019 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2020
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2021 // y coordinate for everything except positioned events
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2022 if (render_priv->state.evt_type == EVENT_NORMAL ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2023 render_priv->state.evt_type == EVENT_HSCROLL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2024 if (valign == VALIGN_TOP) { // toptitle
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2025 device_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2026 y2scr_top(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2027 MarginV) + text_info->lines[0].asc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2028 } else if (valign == VALIGN_CENTER) { // midtitle
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2029 double scr_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2030 y2scr(render_priv, render_priv->track->PlayResY / 2.0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2031 device_y = scr_y - (bbox.yMax + bbox.yMin) / 2.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2032 } else { // subtitle
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2033 double scr_top, scr_bottom, scr_y0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2034 if (valign != VALIGN_SUB)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2035 ass_msg(render_priv->library, MSGL_V,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2036 "Invalid valign, assuming 0 (subtitle)");
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2037 scr_bottom =
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2038 y2scr_sub(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2039 render_priv->track->PlayResY - MarginV);
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2040 scr_top = y2scr_top(render_priv, 0); //xxx not always 0?
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2041 device_y = scr_bottom + (scr_top - scr_bottom) *
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2042 render_priv->settings.line_position / 100.0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2043 device_y -= text_info->height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2044 device_y += text_info->lines[0].asc;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2045 // clip to top to avoid confusion if line_position is very high,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2046 // turning the subtitle into a toptitle
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2047 // also, don't change behavior if line_position is not used
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2048 scr_y0 = scr_top + text_info->lines[0].asc;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2049 if (device_y < scr_y0 && render_priv->settings.line_position > 0) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2050 device_y = scr_y0;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2051 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2052 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2053 } else if (render_priv->state.evt_type == EVENT_VSCROLL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2054 if (render_priv->state.scroll_direction == SCROLL_TB)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2055 device_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2056 y2scr(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2057 render_priv->state.clip_y0 +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2058 render_priv->state.scroll_shift) - (bbox.yMax -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2059 bbox.yMin);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2060 else if (render_priv->state.scroll_direction == SCROLL_BT)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2061 device_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2062 y2scr(render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2063 render_priv->state.clip_y1 -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2064 render_priv->state.scroll_shift);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2065 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2066
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2067 // positioned events are totally different
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2068 if (render_priv->state.evt_type == EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2069 double base_x = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2070 double base_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2071 ass_msg(render_priv->library, MSGL_DBG2, "positioned event at %f, %f",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2072 render_priv->state.pos_x, render_priv->state.pos_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2073 get_base_point(&bbox, alignment, &base_x, &base_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2074 device_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2075 x2scr_pos(render_priv, render_priv->state.pos_x) - base_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2076 device_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2077 y2scr_pos(render_priv, render_priv->state.pos_y) - base_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2078 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2079
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2080 // fix clip coordinates (they depend on alignment)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2081 if (render_priv->state.evt_type == EVENT_NORMAL ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2082 render_priv->state.evt_type == EVENT_HSCROLL ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2083 render_priv->state.evt_type == EVENT_VSCROLL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2084 render_priv->state.clip_x0 =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2085 x2scr_scaled(render_priv, render_priv->state.clip_x0);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2086 render_priv->state.clip_x1 =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2087 x2scr_scaled(render_priv, render_priv->state.clip_x1);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2088 if (valign == VALIGN_TOP) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2089 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2090 y2scr_top(render_priv, render_priv->state.clip_y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2091 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2092 y2scr_top(render_priv, render_priv->state.clip_y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2093 } else if (valign == VALIGN_CENTER) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2094 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2095 y2scr(render_priv, render_priv->state.clip_y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2096 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2097 y2scr(render_priv, render_priv->state.clip_y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2098 } else if (valign == VALIGN_SUB) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2099 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2100 y2scr_sub(render_priv, render_priv->state.clip_y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2101 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2102 y2scr_sub(render_priv, render_priv->state.clip_y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2103 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2104 } else if (render_priv->state.evt_type == EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2105 render_priv->state.clip_x0 =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2106 x2scr_pos_scaled(render_priv, render_priv->state.clip_x0);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2107 render_priv->state.clip_x1 =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2108 x2scr_pos_scaled(render_priv, render_priv->state.clip_x1);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2109 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2110 y2scr_pos(render_priv, render_priv->state.clip_y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2111 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2112 y2scr_pos(render_priv, render_priv->state.clip_y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2113 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2114
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2115 // calculate rotation parameters
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2116 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2117 DVector center;
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29382
diff changeset
2118
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2119 if (render_priv->state.have_origin) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2120 center.x = x2scr(render_priv, render_priv->state.org_x);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2121 center.y = y2scr(render_priv, render_priv->state.org_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2122 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2123 double bx = 0., by = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2124 get_base_point(&bbox, alignment, &bx, &by);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2125 center.x = device_x + bx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2126 center.y = device_y + by;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2127 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2128
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2129 for (i = 0; i < text_info->length; ++i) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2130 GlyphInfo *info = glyphs + i;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2131 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2132 OutlineBitmapHashKey *key = &info->hash_key.u.outline;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2133
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2134 if (key->frx || key->fry || key->frz || key->fax || key->fay) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2135 key->shift_x = info->pos.x + double_to_d6(device_x - center.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2136 key->shift_y = -(info->pos.y + double_to_d6(device_y - center.y));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2137 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2138 key->shift_x = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2139 key->shift_y = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2140 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2141 info = info->next;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2142 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2143 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2144 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2145
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2146 // convert glyphs to bitmaps
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2147 int left = render_priv->settings.left_margin;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2148 device_x = (device_x - left) * render_priv->font_scale_x + left;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2149 for (i = 0; i < text_info->length; ++i) {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2150 GlyphInfo *info = glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2151 while (info) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2152 OutlineBitmapHashKey *key = &info->hash_key.u.outline;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2153 info->pos.x *= render_priv->font_scale_x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2154 key->advance.x =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2155 double_to_d6(device_x - (int) device_x +
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2156 d6_to_double(info->pos.x & SUBPIXEL_MASK)) & ~SUBPIXEL_ACCURACY;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2157 key->advance.y =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2158 double_to_d6(device_y - (int) device_y +
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2159 d6_to_double(info->pos.y & SUBPIXEL_MASK)) & ~SUBPIXEL_ACCURACY;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2160 get_bitmap_glyph(render_priv, info);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2161 info = info->next;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2162 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2163 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2164
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2165 memset(event_images, 0, sizeof(*event_images));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2166 event_images->top = device_y - text_info->lines[0].asc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2167 event_images->height = text_info->height;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2168 event_images->left =
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2169 (device_x + bbox.xMin * render_priv->font_scale_x) + 0.5;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2170 event_images->width =
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2171 (bbox.xMax - bbox.xMin) * render_priv->font_scale_x + 0.5;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2172 event_images->detect_collisions = render_priv->state.detect_collisions;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2173 event_images->shift_direction = (valign == VALIGN_TOP) ? 1 : -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2174 event_images->event = event;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2175 event_images->imgs = render_text(render_priv, (int) device_x, (int) device_y);
23174
29b5596adecd Move get_bitmap_glyph() call to a separate loop.
eugeni
parents: 23173
diff changeset
2176
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2177 ass_shaper_cleanup(render_priv->shaper, text_info);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2178 free_render_context(render_priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2179
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2180 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2181 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2182
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2183 /**
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2184 * \brief deallocate image list
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2185 * \param img list pointer
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2186 */
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2187 void ass_free_images(ASS_Image *img)
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2188 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2189 while (img) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2190 ASS_Image *next = img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2191 free(img);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2192 img = next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2193 }
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2194 }
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2195
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2196 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2197 * \brief Check cache limits and reset cache if they are exceeded
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2198 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2199 static void check_cache_limits(ASS_Renderer *priv, CacheStore *cache)
20446
e8adc3778348 Split ass_configure() into several smaller functions.
eugeni
parents: 20320
diff changeset
2200 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2201 if (ass_cache_empty(cache->bitmap_cache, cache->bitmap_max_size)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2202 ass_cache_empty(cache->composite_cache, 0);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2203 ass_free_images(priv->prev_images_root);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2204 priv->prev_images_root = 0;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2205 priv->cache_cleared = 1;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2206 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2207 if (ass_cache_empty(cache->outline_cache, cache->glyph_max)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2208 ass_cache_empty(cache->bitmap_cache, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2209 ass_cache_empty(cache->composite_cache, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2210 ass_free_images(priv->prev_images_root);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2211 priv->prev_images_root = 0;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2212 priv->cache_cleared = 1;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2213 }
26582
62ac4f8062ee Remove libass dependency on global font_fontconfig variable.
eugeni
parents: 26033
diff changeset
2214 }
62ac4f8062ee Remove libass dependency on global font_fontconfig variable.
eugeni
parents: 26033
diff changeset
2215
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2216 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2217 * \brief Start a new frame
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2218 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2219 static int
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2220 ass_start_frame(ASS_Renderer *render_priv, ASS_Track *track,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2221 long long now)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2222 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2223 ASS_Settings *settings_priv = &render_priv->settings;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2224
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2225 if (!render_priv->settings.frame_width
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2226 && !render_priv->settings.frame_height)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2227 return 1; // library not initialized
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2228
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2229 if (render_priv->library != track->library)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2230 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2231
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2232 if (!render_priv->fontconfig_priv)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2233 return 1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2234
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2235 free_list_clear(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2236
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2237 if (track->n_events == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2238 return 1; // nothing to do
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2239
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2240 render_priv->track = track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2241 render_priv->time = now;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2242
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2243 ass_lazy_track_init(render_priv->library, render_priv->track);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2244
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2245 render_priv->font_scale = settings_priv->font_size_coeff *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2246 render_priv->orig_height / render_priv->track->PlayResY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2247 if (render_priv->track->ScaledBorderAndShadow)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2248 render_priv->border_scale =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2249 ((double) render_priv->orig_height) /
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2250 render_priv->track->PlayResY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2251 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2252 render_priv->border_scale = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2253
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2254 ass_shaper_set_kerning(render_priv->shaper, track->Kerning);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2255 if (track->Language)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2256 ass_shaper_set_language(render_priv->shaper, track->Language);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2257 ass_shaper_set_level(render_priv->shaper, render_priv->settings.shaper);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
2258
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2259 // PAR correction
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2260 render_priv->font_scale_x = render_priv->settings.aspect /
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2261 render_priv->settings.storage_aspect;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2262
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2263 render_priv->prev_images_root = render_priv->images_root;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2264 render_priv->images_root = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2265
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2266 check_cache_limits(render_priv, &render_priv->cache);
19825
f351a3fc3e42 Make font outline width proportional to movie resolution.
eugeni
parents: 19716
diff changeset
2267
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2268 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2269 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2270
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2271 static int cmp_event_layer(const void *p1, const void *p2)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2272 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2273 ASS_Event *e1 = ((EventImages *) p1)->event;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2274 ASS_Event *e2 = ((EventImages *) p2)->event;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2275 if (e1->Layer < e2->Layer)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2276 return -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2277 if (e1->Layer > e2->Layer)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2278 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2279 if (e1->ReadOrder < e2->ReadOrder)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2280 return -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2281 if (e1->ReadOrder > e2->ReadOrder)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2282 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2283 return 0;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2284 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2285
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2286 static ASS_RenderPriv *get_render_priv(ASS_Renderer *render_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2287 ASS_Event *event)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2288 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2289 if (!event->render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2290 event->render_priv = calloc(1, sizeof(ASS_RenderPriv));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2291 if (render_priv->render_id != event->render_priv->render_id) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2292 memset(event->render_priv, 0, sizeof(ASS_RenderPriv));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2293 event->render_priv->render_id = render_priv->render_id;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2294 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2295
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2296 return event->render_priv;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2297 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2298
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2299 static int overlap(Segment *s1, Segment *s2)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2300 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2301 if (s1->a >= s2->b || s2->a >= s1->b ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2302 s1->ha >= s2->hb || s2->ha >= s1->hb)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2303 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2304 return 1;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2305 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2306
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2307 static int cmp_segment(const void *p1, const void *p2)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2308 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2309 return ((Segment *) p1)->a - ((Segment *) p2)->a;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2310 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2311
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2312 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2313 shift_event(ASS_Renderer *render_priv, EventImages *ei, int shift)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2314 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2315 ASS_Image *cur = ei->imgs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2316 while (cur) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2317 cur->dst_y += shift;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2318 // clip top and bottom
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2319 if (cur->dst_y < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2320 int clip = -cur->dst_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2321 cur->h -= clip;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2322 cur->bitmap += clip * cur->stride;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2323 cur->dst_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2324 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2325 if (cur->dst_y + cur->h >= render_priv->height) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2326 int clip = cur->dst_y + cur->h - render_priv->height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2327 cur->h -= clip;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2328 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2329 if (cur->h <= 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2330 cur->h = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2331 cur->dst_y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2332 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2333 cur = cur->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2334 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2335 ei->top += shift;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2336 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2337
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2338 // dir: 1 - move down
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2339 // -1 - move up
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2340 static int fit_segment(Segment *s, Segment *fixed, int *cnt, int dir)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2341 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2342 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2343 int shift = 0;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2344
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2345 if (dir == 1) // move down
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2346 for (i = 0; i < *cnt; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2347 if (s->b + shift <= fixed[i].a || s->a + shift >= fixed[i].b ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2348 s->hb <= fixed[i].ha || s->ha >= fixed[i].hb)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2349 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2350 shift = fixed[i].b - s->a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2351 } else // dir == -1, move up
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2352 for (i = *cnt - 1; i >= 0; --i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2353 if (s->b + shift <= fixed[i].a || s->a + shift >= fixed[i].b ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2354 s->hb <= fixed[i].ha || s->ha >= fixed[i].hb)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2355 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2356 shift = fixed[i].a - s->b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2357 }
21097
77316737de63 Fix collision detection. The old method tried to avoid gaps between subtitles
eugeni
parents: 21066
diff changeset
2358
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2359 fixed[*cnt].a = s->a + shift;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2360 fixed[*cnt].b = s->b + shift;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2361 fixed[*cnt].ha = s->ha;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2362 fixed[*cnt].hb = s->hb;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2363 (*cnt)++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2364 qsort(fixed, *cnt, sizeof(Segment), cmp_segment);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2365
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2366 return shift;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2367 }
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2368
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2369 static void
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2370 fix_collisions(ASS_Renderer *render_priv, EventImages *imgs, int cnt)
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2371 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2372 Segment *used = malloc(cnt * sizeof(*used));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2373 int cnt_used = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2374 int i, j;
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2375
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2376 // fill used[] with fixed events
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2377 for (i = 0; i < cnt; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2378 ASS_RenderPriv *priv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2379 if (!imgs[i].detect_collisions)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2380 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2381 priv = get_render_priv(render_priv, imgs[i].event);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2382 if (priv->height > 0) { // it's a fixed event
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2383 Segment s;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2384 s.a = priv->top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2385 s.b = priv->top + priv->height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2386 s.ha = priv->left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2387 s.hb = priv->left + priv->width;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2388 if (priv->height != imgs[i].height) { // no, it's not
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2389 ass_msg(render_priv->library, MSGL_WARN,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
2390 "Event height has changed");
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2391 priv->top = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2392 priv->height = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2393 priv->left = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2394 priv->width = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2395 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2396 for (j = 0; j < cnt_used; ++j)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2397 if (overlap(&s, used + j)) { // no, it's not
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2398 priv->top = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2399 priv->height = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2400 priv->left = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2401 priv->width = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2402 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2403 if (priv->height > 0) { // still a fixed event
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2404 used[cnt_used].a = priv->top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2405 used[cnt_used].b = priv->top + priv->height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2406 used[cnt_used].ha = priv->left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2407 used[cnt_used].hb = priv->left + priv->width;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2408 cnt_used++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2409 shift_event(render_priv, imgs + i, priv->top - imgs[i].top);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2410 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2411 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2412 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2413 qsort(used, cnt_used, sizeof(Segment), cmp_segment);
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2414
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2415 // try to fit other events in free spaces
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2416 for (i = 0; i < cnt; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2417 ASS_RenderPriv *priv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2418 if (!imgs[i].detect_collisions)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2419 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2420 priv = get_render_priv(render_priv, imgs[i].event);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2421 if (priv->height == 0) { // not a fixed event
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2422 int shift;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2423 Segment s;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2424 s.a = imgs[i].top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2425 s.b = imgs[i].top + imgs[i].height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2426 s.ha = imgs[i].left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2427 s.hb = imgs[i].left + imgs[i].width;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2428 shift = fit_segment(&s, used, &cnt_used, imgs[i].shift_direction);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2429 if (shift)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2430 shift_event(render_priv, imgs + i, shift);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2431 // make it fixed
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2432 priv->top = imgs[i].top;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2433 priv->height = imgs[i].height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2434 priv->left = imgs[i].left;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2435 priv->width = imgs[i].width;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2436 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2437
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2438 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2439
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2440 free(used);
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2441 }
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2442
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2443 /**
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2444 * \brief compare two images
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2445 * \param i1 first image
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2446 * \param i2 second image
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2447 * \return 0 if identical, 1 if different positions, 2 if different content
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2448 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2449 static int ass_image_compare(ASS_Image *i1, ASS_Image *i2)
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2450 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2451 if (i1->w != i2->w)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2452 return 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2453 if (i1->h != i2->h)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2454 return 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2455 if (i1->stride != i2->stride)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2456 return 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2457 if (i1->color != i2->color)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2458 return 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2459 if (i1->bitmap != i2->bitmap)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2460 return 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2461 if (i1->dst_x != i2->dst_x)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2462 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2463 if (i1->dst_y != i2->dst_y)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2464 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2465 return 0;
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2466 }
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2467
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2468 /**
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2469 * \brief compare current and previous image list
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2470 * \param priv library handle
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2471 * \return 0 if identical, 1 if different positions, 2 if different content
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2472 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2473 static int ass_detect_change(ASS_Renderer *priv)
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2474 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2475 ASS_Image *img, *img2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2476 int diff;
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2477
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2478 if (priv->cache_cleared)
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2479 return 2;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2480
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2481 img = priv->prev_images_root;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2482 img2 = priv->images_root;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2483 diff = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2484 while (img && diff < 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2485 ASS_Image *next, *next2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2486 next = img->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2487 if (img2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2488 int d = ass_image_compare(img, img2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2489 if (d > diff)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2490 diff = d;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2491 next2 = img2->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2492 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2493 // previous list is shorter
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2494 diff = 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2495 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2496 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2497 img = next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2498 img2 = next2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2499 }
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2500
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2501 // is the previous list longer?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2502 if (img2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2503 diff = 2;
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2504
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2505 return diff;
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2506 }
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2507
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2508 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2509 * \brief render a frame
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2510 * \param priv library handle
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2511 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2512 * \param now current video timestamp (ms)
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2513 * \param detect_change a value describing how the new images differ from the previous ones will be written here:
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2514 * 0 if identical, 1 if different positions, 2 if different content.
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2515 * Can be NULL, in that case no detection is performed.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2516 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2517 ASS_Image *ass_render_frame(ASS_Renderer *priv, ASS_Track *track,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2518 long long now, int *detect_change)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2519 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2520 int i, cnt, rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2521 EventImages *last;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2522 ASS_Image **tail;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2523
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2524 // init frame
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2525 rc = ass_start_frame(priv, track, now);
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2526 if (rc != 0) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2527 if (detect_change) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2528 *detect_change = 2;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2529 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2530 return 0;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2531 }
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2532
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2533 // render events separately
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2534 cnt = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2535 for (i = 0; i < track->n_events; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2536 ASS_Event *event = track->events + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2537 if ((event->Start <= now)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2538 && (now < (event->Start + event->Duration))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2539 if (cnt >= priv->eimg_size) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2540 priv->eimg_size += 100;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2541 priv->eimg =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2542 realloc(priv->eimg,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2543 priv->eimg_size * sizeof(EventImages));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2544 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2545 rc = ass_render_event(priv, event, priv->eimg + cnt);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2546 if (!rc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2547 ++cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2548 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2549 }
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2550
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2551 // sort by layer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2552 qsort(priv->eimg, cnt, sizeof(EventImages), cmp_event_layer);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2553
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2554 // call fix_collisions for each group of events with the same layer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2555 last = priv->eimg;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2556 for (i = 1; i < cnt; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2557 if (last->event->Layer != priv->eimg[i].event->Layer) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2558 fix_collisions(priv, last, priv->eimg + i - last);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2559 last = priv->eimg + i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2560 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2561 if (cnt > 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2562 fix_collisions(priv, last, priv->eimg + cnt - last);
19638
a3473d990fed Better collision detection algorithm. The idea is to keep a subtitle in place
eugeni
parents: 19636
diff changeset
2563
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2564 // concat lists
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2565 tail = &priv->images_root;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2566 for (i = 0; i < cnt; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2567 ASS_Image *cur = priv->eimg[i].imgs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2568 while (cur) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2569 *tail = cur;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2570 tail = &cur->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2571 cur = cur->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2572 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2573 }
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2574
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2575 if (detect_change)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2576 *detect_change = ass_detect_change(priv);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29178
diff changeset
2577
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2578 // free the previous image list
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2579 ass_free_images(priv->prev_images_root);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2580 priv->prev_images_root = 0;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34549
diff changeset
2581 priv->cache_cleared = 0;
21506
8174acbf0633 Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents: 21460
diff changeset
2582
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29406
diff changeset
2583 return priv->images_root;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2584 }