annotate libass/ass_parse.c @ 31438:3afcf20a13e4

Move faac/lame/toolame/twolame option array declarations to appropriate headers.
author diego
date Mon, 21 Jun 2010 09:51:26 +0000
parents 48d020c5ceca
children e64df5862cea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
2 * Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
3 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
4 * This file is part of libass.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
5 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
6 * Permission to use, copy, modify, and distribute this software for any
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
9 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
17 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
18
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
19 #include "config.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
20
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
21 #include <stdio.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
22 #include <stdlib.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
23 #include <string.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
24 #include <math.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
25
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
26 #include "ass_render.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
27 #include "ass_parse.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
28
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
29 #define MAX_BE 127
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
30 #define NBSP 0xa0 // unicode non-breaking space character
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
31
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
32 #define skip_to(x) while ((*p != (x)) && (*p != '}') && (*p != 0)) { ++p;}
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
33 #define skip(x) if (*p == (x)) ++p; else { return p; }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
34 #define skipopt(x) if (*p == (x)) { ++p; }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
35
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
36 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
37 * \brief Check if starting part of (*p) matches sample.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
38 * If true, shift p to the first symbol after the matching part.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
39 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
40 static inline int mystrcmp(char **p, const char *sample)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
41 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
42 int len = strlen(sample);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
43 if (strncmp(*p, sample, len) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
44 (*p) += len;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
45 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
46 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
47 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
48 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
49
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
50 static void change_font_size(ASS_Renderer *render_priv, double sz)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
51 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
52 double size = sz * render_priv->font_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
53
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
54 if (size < 1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
55 size = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
56 else if (size > render_priv->height * 2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
57 size = render_priv->height * 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
58
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
59 ass_font_set_size(render_priv->state.font, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
60
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
61 render_priv->state.font_size = sz;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
62 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
63
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
64 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
65 * \brief Change current font, using setting from render_priv->state.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
66 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
67 void update_font(ASS_Renderer *render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
68 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
69 unsigned val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
70 ASS_FontDesc desc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
71 desc.family = strdup(render_priv->state.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
72 desc.treat_family_as_pattern =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
73 render_priv->state.treat_family_as_pattern;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
74
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
75 val = render_priv->state.bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
76 // 0 = normal, 1 = bold, >1 = exact weight
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
77 if (val == 1 || val == -1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
78 val = 200; // bold
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
79 else if (val <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
80 val = 80; // normal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
81 desc.bold = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
82
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
83 val = render_priv->state.italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
84 if (val == 1 || val == -1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
85 val = 110; // italic
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
86 else if (val <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
87 val = 0; // normal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
88 desc.italic = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
89
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
90 render_priv->state.font =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
91 ass_font_new(render_priv->cache.font_cache, render_priv->library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
92 render_priv->ftlibrary, render_priv->fontconfig_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
93 &desc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
94 free(desc.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
95
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
96 if (render_priv->state.font)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
97 change_font_size(render_priv, render_priv->state.font_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
98 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
99
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
100 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
101 * \brief Change border width
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
102 * negative value resets border to style value
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
103 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
104 void change_border(ASS_Renderer *render_priv, double border_x,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
105 double border_y)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
106 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
107 int bord;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
108 if (!render_priv->state.font)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
109 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
110
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
111 if (border_x < 0 && border_y < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
112 if (render_priv->state.style->BorderStyle == 1 ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
113 render_priv->state.style->BorderStyle == 3)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
114 border_x = border_y = render_priv->state.style->Outline;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
115 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
116 border_x = border_y = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
117 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
118
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
119 render_priv->state.border_x = border_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
120 render_priv->state.border_y = border_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
121
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
122 bord = 64 * border_x * render_priv->border_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
123 if (bord > 0 && border_x == border_y) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
124 if (!render_priv->state.stroker) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
125 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
126 error =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
127 FT_Stroker_New(render_priv->ftlibrary,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
128 &render_priv->state.stroker);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
129 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
130 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
131 "failed to get stroker");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
132 render_priv->state.stroker = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
133 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
134 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
135 if (render_priv->state.stroker)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
136 FT_Stroker_Set(render_priv->state.stroker, bord,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
137 FT_STROKER_LINECAP_ROUND,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
138 FT_STROKER_LINEJOIN_ROUND, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
139 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
140 FT_Stroker_Done(render_priv->state.stroker);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
141 render_priv->state.stroker = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
142 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
143 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
144
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
145 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
146 * \brief Calculate a weighted average of two colors
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
147 * calculates c1*(1-a) + c2*a, but separately for each component except alpha
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
148 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
149 static void change_color(uint32_t *var, uint32_t new, double pwr)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
150 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
151 (*var) = ((uint32_t) (_r(*var) * (1 - pwr) + _r(new) * pwr) << 24) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
152 ((uint32_t) (_g(*var) * (1 - pwr) + _g(new) * pwr) << 16) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
153 ((uint32_t) (_b(*var) * (1 - pwr) + _b(new) * pwr) << 8) + _a(*var);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
154 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
155
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
156 // like change_color, but for alpha component only
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
157 inline void change_alpha(uint32_t *var, uint32_t new, double pwr)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
158 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
159 *var =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
160 (_r(*var) << 24) + (_g(*var) << 16) + (_b(*var) << 8) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
161 (uint32_t) (_a(*var) * (1 - pwr) + _a(new) * pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
162 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
163
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
164 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
165 * \brief Multiply two alpha values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
166 * \param a first value
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
167 * \param b second value
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
168 * \return result of multiplication
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
169 * Parameters and result are limited by 0xFF.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
170 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
171 inline uint32_t mult_alpha(uint32_t a, uint32_t b)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
172 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
173 return 0xFF - (0xFF - a) * (0xFF - b) / 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
174 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
175
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
176 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
177 * \brief Calculate alpha value by piecewise linear function
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
178 * Used for \fad, \fade implementation.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
179 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
180 static unsigned
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
181 interpolate_alpha(long long now, long long t1, long long t2, long long t3,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
182 long long t4, unsigned a1, unsigned a2, unsigned a3)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
183 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
184 unsigned a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
185 double cf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
186 if (now <= t1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
187 a = a1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
188 } else if (now >= t4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
189 a = a3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
190 } else if (now < t2) { // and > t1
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
191 cf = ((double) (now - t1)) / (t2 - t1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
192 a = a1 * (1 - cf) + a2 * cf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
193 } else if (now > t3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
194 cf = ((double) (now - t3)) / (t4 - t3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
195 a = a2 * (1 - cf) + a3 * cf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
196 } else { // t2 <= now <= t3
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
197 a = a2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
198 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
199
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
200 return a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
201 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
202
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
203 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
204 * Parse a vector clip into an outline, using the proper scaling
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
205 * parameters. Translate it to correct for screen borders, if needed.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
206 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
207 static char *parse_vector_clip(ASS_Renderer *render_priv, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
208 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
209 int scale = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
210 int res = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
211 ASS_Drawing *drawing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
212
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
213 render_priv->state.clip_drawing = ass_drawing_new(
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
214 render_priv->fontconfig_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
215 render_priv->state.font,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
216 render_priv->settings.hinting,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
217 render_priv->ftlibrary);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
218 drawing = render_priv->state.clip_drawing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
219 skipopt('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
220 res = mystrtoi(&p, &scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
221 skipopt(',')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
222 if (!res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
223 scale = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
224 drawing->scale = scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
225 drawing->scale_x = render_priv->font_scale_x * render_priv->font_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
226 drawing->scale_y = render_priv->font_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
227 while (*p != ')' && *p != '}' && p != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
228 ass_drawing_add_char(drawing, *p++);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
229 skipopt(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
230 if (ass_drawing_parse(drawing, 1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
231 // We need to translate the clip according to screen borders
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
232 if (render_priv->settings.left_margin != 0 ||
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
233 render_priv->settings.top_margin != 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
234 FT_Vector trans = {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
235 .x = int_to_d6(render_priv->settings.left_margin),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
236 .y = -int_to_d6(render_priv->settings.top_margin),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
237 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
238 FT_Outline_Translate(&drawing->glyph->outline, trans.x, trans.y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
239 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
240 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
241 "Parsed vector clip: scale %d, scales (%f, %f) string [%s]\n",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
242 scale, drawing->scale_x, drawing->scale_y, drawing->text);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
243 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
244
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
245 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
246 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
247
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
248 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
249 * \brief Parse style override tag.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
250 * \param p string to parse
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
251 * \param pwr multiplier for some tag effects (comes from \t tags)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
252 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
253 static char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
254 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
255 skip_to('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
256 skip('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
257 if ((*p == '}') || (*p == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
258 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
259
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
260 // New tags introduced in vsfilter 2.39
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
261 if (mystrcmp(&p, "xbord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
262 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
263 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
264 val = render_priv->state.border_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
265 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
266 val = -1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
267 change_border(render_priv, val, render_priv->state.border_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
268 } else if (mystrcmp(&p, "ybord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
269 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
270 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
271 val = render_priv->state.border_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
272 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
273 val = -1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
274 change_border(render_priv, render_priv->state.border_x, val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
275 } else if (mystrcmp(&p, "xshad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
276 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
277 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
278 val = render_priv->state.shadow_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
279 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
280 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
281 render_priv->state.shadow_x = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
282 } else if (mystrcmp(&p, "yshad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
283 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
284 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
285 val = render_priv->state.shadow_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
286 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
287 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
288 render_priv->state.shadow_y = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
289 } else if (mystrcmp(&p, "fax")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
290 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
291 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
292 render_priv->state.fax =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
293 val * pwr + render_priv->state.fax * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
294 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
295 render_priv->state.fax = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
296 } else if (mystrcmp(&p, "fay")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
297 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
298 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
299 render_priv->state.fay =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
300 val * pwr + render_priv->state.fay * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
301 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
302 render_priv->state.fay = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
303 } else if (mystrcmp(&p, "iclip")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
304 int x0, y0, x1, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
305 int res = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
306 char *start = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
307 skipopt('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
308 res &= mystrtoi(&p, &x0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
309 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
310 res &= mystrtoi(&p, &y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
311 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
312 res &= mystrtoi(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
313 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
314 res &= mystrtoi(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
315 skipopt(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
316 if (res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
317 render_priv->state.clip_x0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
318 render_priv->state.clip_x0 * (1 - pwr) + x0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
319 render_priv->state.clip_x1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
320 render_priv->state.clip_x1 * (1 - pwr) + x1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
321 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
322 render_priv->state.clip_y0 * (1 - pwr) + y0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
323 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
324 render_priv->state.clip_y1 * (1 - pwr) + y1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
325 render_priv->state.clip_mode = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
326 } else if (!render_priv->state.clip_drawing) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
327 p = parse_vector_clip(render_priv, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
328 render_priv->state.clip_drawing_mode = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
329 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
330 render_priv->state.clip_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
331 } else if (mystrcmp(&p, "blur")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
332 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
333 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
334 val = render_priv->state.blur * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
335 val = (val < 0) ? 0 : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
336 val = (val > BLUR_MAX_RADIUS) ? BLUR_MAX_RADIUS : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
337 render_priv->state.blur = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
338 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
339 render_priv->state.blur = 0.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
340 // ASS standard tags
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
341 } else if (mystrcmp(&p, "fsc")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
342 char tp = *p++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
343 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
344 if (tp == 'x') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
345 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
346 val /= 100;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
347 render_priv->state.scale_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
348 render_priv->state.scale_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
349 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
350 render_priv->state.scale_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
351 render_priv->state.style->ScaleX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
352 } else if (tp == 'y') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
353 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
354 val /= 100;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
355 render_priv->state.scale_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
356 render_priv->state.scale_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
357 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
358 render_priv->state.scale_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
359 render_priv->state.style->ScaleY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
360 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
361 } else if (mystrcmp(&p, "fsp")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
362 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
363 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
364 render_priv->state.hspacing =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
365 render_priv->state.hspacing * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
366 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
367 render_priv->state.hspacing = render_priv->state.style->Spacing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
368 } else if (mystrcmp(&p, "fs")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
369 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
370 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
371 val = render_priv->state.font_size * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
372 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
373 val = render_priv->state.style->FontSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
374 if (render_priv->state.font)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
375 change_font_size(render_priv, val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
376 } else if (mystrcmp(&p, "bord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
377 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
378 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
379 if (render_priv->state.border_x == render_priv->state.border_y)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
380 val = render_priv->state.border_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
381 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
382 val = -1.; // reset to default
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
383 change_border(render_priv, val, val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
384 } else if (mystrcmp(&p, "move")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
385 double x1, x2, y1, y2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
386 long long t1, t2, delta_t, t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
387 double x, y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
388 double k;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
389 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
390 mystrtod(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
391 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
392 mystrtod(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
393 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
394 mystrtod(&p, &x2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
395 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
396 mystrtod(&p, &y2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
397 if (*p == ',') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
398 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
399 mystrtoll(&p, &t1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
400 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
401 mystrtoll(&p, &t2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
402 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
403 "movement6: (%f, %f) -> (%f, %f), (%" PRId64 " .. %"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
404 PRId64 ")\n", x1, y1, x2, y2, (int64_t) t1,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
405 (int64_t) t2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
406 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
407 t1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
408 t2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
409 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
410 "movement: (%f, %f) -> (%f, %f)", x1, y1, x2, y2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
411 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
412 skip(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
413 delta_t = t2 - t1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
414 t = render_priv->time - render_priv->state.event->Start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
415 if (t < t1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
416 k = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
417 else if (t > t2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
418 k = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
419 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
420 k = ((double) (t - t1)) / delta_t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
421 x = k * (x2 - x1) + x1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
422 y = k * (y2 - y1) + y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
423 if (render_priv->state.evt_type != EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
424 render_priv->state.pos_x = x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
425 render_priv->state.pos_y = y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
426 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
427 render_priv->state.evt_type = EVENT_POSITIONED;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
428 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
429 } else if (mystrcmp(&p, "frx")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
430 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
431 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
432 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
433 render_priv->state.frx =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
434 val * pwr + render_priv->state.frx * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
435 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
436 render_priv->state.frx = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
437 } else if (mystrcmp(&p, "fry")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
438 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
439 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
440 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
441 render_priv->state.fry =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
442 val * pwr + render_priv->state.fry * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
443 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
444 render_priv->state.fry = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
445 } else if (mystrcmp(&p, "frz") || mystrcmp(&p, "fr")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
446 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
447 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
448 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
449 render_priv->state.frz =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
450 val * pwr + render_priv->state.frz * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
451 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
452 render_priv->state.frz =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
453 M_PI * render_priv->state.style->Angle / 180.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
454 } else if (mystrcmp(&p, "fn")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
455 char *start = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
456 char *family;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
457 skip_to('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
458 if (p > start) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
459 family = malloc(p - start + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
460 strncpy(family, start, p - start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
461 family[p - start] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
462 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
463 family = strdup(render_priv->state.style->FontName);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
464 if (render_priv->state.family)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
465 free(render_priv->state.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
466 render_priv->state.family = family;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
467 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
468 } else if (mystrcmp(&p, "alpha")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
469 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
470 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
471 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
472 if (strtocolor(render_priv->library, &p, &val, hex)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
473 unsigned char a = val >> 24;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
474 for (i = 0; i < 4; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
475 change_alpha(&render_priv->state.c[i], a, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
476 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
477 change_alpha(&render_priv->state.c[0],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
478 render_priv->state.style->PrimaryColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
479 change_alpha(&render_priv->state.c[1],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
480 render_priv->state.style->SecondaryColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
481 change_alpha(&render_priv->state.c[2],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
482 render_priv->state.style->OutlineColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
483 change_alpha(&render_priv->state.c[3],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
484 render_priv->state.style->BackColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
485 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
486 // FIXME: simplify
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
487 } else if (mystrcmp(&p, "an")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
488 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
489 if (mystrtoi(&p, &val) && val) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
490 int v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
491 ass_msg(render_priv->library, MSGL_DBG2, "an %d", val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
492 if (v != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
493 v = 3 - v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
494 val = ((val - 1) % 3) + 1; // horizontal alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
495 val += v * 4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
496 ass_msg(render_priv->library, MSGL_DBG2, "align %d", val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
497 render_priv->state.alignment = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
498 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
499 render_priv->state.alignment =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
500 render_priv->state.style->Alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
501 } else if (mystrcmp(&p, "a")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
502 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
503 if (mystrtoi(&p, &val) && val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
504 // take care of a vsfilter quirk: handle illegal \a8 like \a5
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
505 render_priv->state.alignment = (val == 8) ? 5 : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
506 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
507 render_priv->state.alignment =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
508 render_priv->state.style->Alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
509 } else if (mystrcmp(&p, "pos")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
510 double v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
511 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
512 mystrtod(&p, &v1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
513 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
514 mystrtod(&p, &v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
515 skip(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
516 ass_msg(render_priv->library, MSGL_DBG2, "pos(%f, %f)", v1, v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
517 if (render_priv->state.evt_type == EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
518 ass_msg(render_priv->library, MSGL_V, "Subtitle has a new \\pos "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
519 "after \\move or \\pos, ignoring");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
520 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
521 render_priv->state.evt_type = EVENT_POSITIONED;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
522 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
523 render_priv->state.pos_x = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
524 render_priv->state.pos_y = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
525 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
526 } else if (mystrcmp(&p, "fad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
527 int a1, a2, a3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
528 long long t1, t2, t3, t4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
529 if (*p == 'e')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
530 ++p; // either \fad or \fade
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
531 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
532 mystrtoi(&p, &a1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
533 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
534 mystrtoi(&p, &a2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
535 if (*p == ')') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
536 // 2-argument version (\fad, according to specs)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
537 // a1 and a2 are fade-in and fade-out durations
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
538 t1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
539 t4 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
540 t2 = a1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
541 t3 = t4 - a2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
542 a1 = 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
543 a2 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
544 a3 = 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
545 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
546 // 6-argument version (\fade)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
547 // a1 and a2 (and a3) are opacity values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
548 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
549 mystrtoi(&p, &a3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
550 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
551 mystrtoll(&p, &t1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
552 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
553 mystrtoll(&p, &t2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
554 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
555 mystrtoll(&p, &t3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
556 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
557 mystrtoll(&p, &t4);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
558 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
559 skip(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
560 render_priv->state.fade =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
561 interpolate_alpha(render_priv->time -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
562 render_priv->state.event->Start, t1, t2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
563 t3, t4, a1, a2, a3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
564 } else if (mystrcmp(&p, "org")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
565 int v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
566 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
567 mystrtoi(&p, &v1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
568 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
569 mystrtoi(&p, &v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
570 skip(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
571 ass_msg(render_priv->library, MSGL_DBG2, "org(%d, %d)", v1, v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
572 if (!render_priv->state.have_origin) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
573 render_priv->state.org_x = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
574 render_priv->state.org_y = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
575 render_priv->state.have_origin = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
576 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
577 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
578 } else if (mystrcmp(&p, "t")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
579 double v[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
580 int v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
581 double v3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
582 int cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
583 long long t1, t2, t, delta_t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
584 double k;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
585 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
586 for (cnt = 0; cnt < 3; ++cnt) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
587 if (*p == '\\')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
588 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
589 v[cnt] = strtod(p, &p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
590 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
591 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
592 if (cnt == 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
593 v1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
594 v2 = (v[1] < v1) ? render_priv->state.event->Duration : v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
595 v3 = v[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
596 } else if (cnt == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
597 v1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
598 v2 = (v[1] < v1) ? render_priv->state.event->Duration : v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
599 v3 = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
600 } else if (cnt == 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
601 v1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
602 v2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
603 v3 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
604 } else { // cnt == 0
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
605 v1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
606 v2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
607 v3 = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
608 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
609 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
610 t1 = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
611 t2 = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
612 delta_t = v2 - v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
613 if (v3 < 0.)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
614 v3 = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
615 t = render_priv->time - render_priv->state.event->Start; // FIXME: move to render_context
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
616 if (t <= t1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
617 k = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
618 else if (t >= t2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
619 k = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
620 else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
621 assert(delta_t != 0.);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
622 k = pow(((double) (t - t1)) / delta_t, v3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
623 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
624 while (*p == '\\')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
625 p = parse_tag(render_priv, p, k); // maybe k*pwr ? no, specs forbid nested \t's
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
626 skip_to(')'); // in case there is some unknown tag or a comment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
627 skip(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
628 } else if (mystrcmp(&p, "clip")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
629 char *start = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
630 int x0, y0, x1, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
631 int res = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
632 skipopt('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
633 res &= mystrtoi(&p, &x0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
634 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
635 res &= mystrtoi(&p, &y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
636 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
637 res &= mystrtoi(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
638 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
639 res &= mystrtoi(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
640 skipopt(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
641 if (res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
642 render_priv->state.clip_x0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
643 render_priv->state.clip_x0 * (1 - pwr) + x0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
644 render_priv->state.clip_x1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
645 render_priv->state.clip_x1 * (1 - pwr) + x1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
646 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
647 render_priv->state.clip_y0 * (1 - pwr) + y0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
648 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
649 render_priv->state.clip_y1 * (1 - pwr) + y1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
650 // Might be a vector clip
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
651 } else if (!render_priv->state.clip_drawing) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
652 p = parse_vector_clip(render_priv, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
653 render_priv->state.clip_drawing_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
654 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
655 render_priv->state.clip_x0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
656 render_priv->state.clip_y0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
657 render_priv->state.clip_x1 = render_priv->track->PlayResX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
658 render_priv->state.clip_y1 = render_priv->track->PlayResY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
659 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
660 } else if (mystrcmp(&p, "c")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
661 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
662 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
663 if (!strtocolor(render_priv->library, &p, &val, hex))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
664 val = render_priv->state.style->PrimaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
665 ass_msg(render_priv->library, MSGL_DBG2, "color: %X", val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
666 change_color(&render_priv->state.c[0], val, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
667 } else if ((*p >= '1') && (*p <= '4') && (++p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
668 && (mystrcmp(&p, "c") || mystrcmp(&p, "a"))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
669 char n = *(p - 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
670 int cidx = n - '1';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
671 char cmd = *(p - 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
672 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
673 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
674 assert((n >= '1') && (n <= '4'));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
675 if (!strtocolor(render_priv->library, &p, &val, hex))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
676 switch (n) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
677 case '1':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
678 val = render_priv->state.style->PrimaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
679 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
680 case '2':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
681 val = render_priv->state.style->SecondaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
682 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
683 case '3':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
684 val = render_priv->state.style->OutlineColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
685 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
686 case '4':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
687 val = render_priv->state.style->BackColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
688 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
689 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
690 val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
691 break; // impossible due to assert; avoid compilation warning
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
692 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
693 switch (cmd) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
694 case 'c':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
695 change_color(render_priv->state.c + cidx, val, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
696 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
697 case 'a':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
698 change_alpha(render_priv->state.c + cidx, val >> 24, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
699 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
700 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
701 ass_msg(render_priv->library, MSGL_WARN, "Bad command: %c%c",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
702 n, cmd);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
703 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
704 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
705 ass_msg(render_priv->library, MSGL_DBG2, "single c/a at %f: %c%c = %X",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
706 pwr, n, cmd, render_priv->state.c[cidx]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
707 } else if (mystrcmp(&p, "r")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
708 reset_render_context(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
709 } else if (mystrcmp(&p, "be")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
710 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
711 if (mystrtoi(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
712 // Clamp to a safe upper limit, since high values need excessive CPU
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
713 val = (val < 0) ? 0 : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
714 val = (val > MAX_BE) ? MAX_BE : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
715 render_priv->state.be = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
716 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
717 render_priv->state.be = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
718 } else if (mystrcmp(&p, "b")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
719 int b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
720 if (mystrtoi(&p, &b)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
721 if (pwr >= .5)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
722 render_priv->state.bold = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
723 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
724 render_priv->state.bold = render_priv->state.style->Bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
725 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
726 } else if (mystrcmp(&p, "i")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
727 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
728 if (mystrtoi(&p, &i)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
729 if (pwr >= .5)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
730 render_priv->state.italic = i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
731 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
732 render_priv->state.italic = render_priv->state.style->Italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
733 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
734 } else if (mystrcmp(&p, "kf") || mystrcmp(&p, "K")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
735 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
736 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
737 render_priv->state.effect_type = EF_KARAOKE_KF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
738 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
739 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
740 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
741 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
742 } else if (mystrcmp(&p, "ko")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
743 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
744 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
745 render_priv->state.effect_type = EF_KARAOKE_KO;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
746 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
747 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
748 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
749 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
750 } else if (mystrcmp(&p, "k")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
751 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
752 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
753 render_priv->state.effect_type = EF_KARAOKE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
754 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
755 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
756 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
757 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
758 } else if (mystrcmp(&p, "shad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
759 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
760 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
761 if (render_priv->state.shadow_x == render_priv->state.shadow_y)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
762 val = render_priv->state.shadow_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
763 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
764 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
765 render_priv->state.shadow_x = render_priv->state.shadow_y = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
766 } else if (mystrcmp(&p, "s")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
767 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
768 if (mystrtoi(&p, &val) && val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
769 render_priv->state.flags |= DECO_STRIKETHROUGH;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
770 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
771 render_priv->state.flags &= ~DECO_STRIKETHROUGH;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
772 } else if (mystrcmp(&p, "u")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
773 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
774 if (mystrtoi(&p, &val) && val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
775 render_priv->state.flags |= DECO_UNDERLINE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
776 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
777 render_priv->state.flags &= ~DECO_UNDERLINE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
778 } else if (mystrcmp(&p, "pbo")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
779 double val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
780 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
781 render_priv->state.drawing->pbo = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
782 } else if (mystrcmp(&p, "p")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
783 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
784 if (!mystrtoi(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
785 val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
786 if (val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
787 render_priv->state.drawing->scale = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
788 render_priv->state.drawing_mode = !!val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
789 } else if (mystrcmp(&p, "q")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
790 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
791 if (!mystrtoi(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
792 val = render_priv->track->WrapStyle;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
793 render_priv->state.wrap_style = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
794 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
795
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
796 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
797 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
798
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
799 void apply_transition_effects(ASS_Renderer *render_priv, ASS_Event *event)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
800 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
801 int v[4];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
802 int cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
803 char *p = event->Effect;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
804
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
805 if (!p || !*p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
806 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
807
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
808 cnt = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
809 while (cnt < 4 && (p = strchr(p, ';'))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
810 v[cnt++] = atoi(++p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
811 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
812
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
813 if (strncmp(event->Effect, "Banner;", 7) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
814 int delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
815 if (cnt < 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
816 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
817 "Error parsing effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
818 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
819 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
820 if (cnt >= 2 && v[1] == 0) // right-to-left
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
821 render_priv->state.scroll_direction = SCROLL_RL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
822 else // left-to-right
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
823 render_priv->state.scroll_direction = SCROLL_LR;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
824
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
825 delay = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
826 if (delay == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
827 delay = 1; // ?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
828 render_priv->state.scroll_shift =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
829 (render_priv->time - render_priv->state.event->Start) / delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
830 render_priv->state.evt_type = EVENT_HSCROLL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
831 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
832 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
833
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
834 if (strncmp(event->Effect, "Scroll up;", 10) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
835 render_priv->state.scroll_direction = SCROLL_BT;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
836 } else if (strncmp(event->Effect, "Scroll down;", 12) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
837 render_priv->state.scroll_direction = SCROLL_TB;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
838 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
839 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
840 "Unknown transition effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
841 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
842 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
843 // parse scroll up/down parameters
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
844 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
845 int delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
846 int y0, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
847 if (cnt < 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
848 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
849 "Error parsing effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
850 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
851 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
852 delay = v[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
853 if (delay == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
854 delay = 1; // ?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
855 render_priv->state.scroll_shift =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
856 (render_priv->time - render_priv->state.event->Start) / delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
857 if (v[0] < v[1]) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
858 y0 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
859 y1 = v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
860 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
861 y0 = v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
862 y1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
863 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
864 if (y1 == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
865 y1 = render_priv->track->PlayResY; // y0=y1=0 means fullscreen scrolling
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
866 render_priv->state.clip_y0 = y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
867 render_priv->state.clip_y1 = y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
868 render_priv->state.evt_type = EVENT_VSCROLL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
869 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
870 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
871
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
872 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
873
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
874 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
875 * \brief Get next ucs4 char from string, parsing and executing style overrides
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
876 * \param str string pointer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
877 * \return ucs4 code of the next char
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
878 * On return str points to the unparsed part of the string
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
879 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
880 unsigned get_next_char(ASS_Renderer *render_priv, char **str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
881 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
882 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
883 unsigned chr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
884 if (*p == '{') { // '\0' goes here
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
885 p++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
886 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
887 p = parse_tag(render_priv, p, 1.);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
888 if (*p == '}') { // end of tag
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
889 p++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
890 if (*p == '{') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
891 p++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
892 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
893 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
894 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
895 } else if (*p != '\\')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
896 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
897 "Unable to parse: '%s'", p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
898 if (*p == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
899 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
900 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
901 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
902 if (*p == '\t') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
903 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
904 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
905 return ' ';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
906 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
907 if (*p == '\\') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
908 if ((p[1] == 'N') || ((p[1] == 'n') &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
909 (render_priv->state.wrap_style == 2))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
910 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
911 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
912 return '\n';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
913 } else if (p[1] == 'n') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
914 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
915 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
916 return ' ';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
917 } else if (p[1] == 'h') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
918 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
919 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
920 return NBSP;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
921 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
922 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
923 chr = ass_utf8_get_char((char **) &p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
924 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
925 return chr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
926 }