annotate libass/ass_render.c @ 32359:3f8dcfb95845

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