annotate libass/ass_render.c @ 34161:64a0c61c6f18

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