annotate libass/ass_parse.c @ 37003:2d8157b3b386

Fix the index passed to PutImage() for item type itVPotmeter. Unlike the position for drawing the button (from bottom to top), the index for the phase image has to be in the usual range, i.e. 0 for 0% and numphases - 1 for 100%, so that the phase image can be designed straightforwardly. Fix the parameter although PutImage() currently doesn't work for item type itVPotmeter at all.
author ib
date Fri, 28 Mar 2014 12:21:07 +0000
parents c3aaaf17c721
children
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
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
50 double ensure_font_size(ASS_Renderer *priv, double size)
30200
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 if (size < 1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
53 size = 1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
54 else if (size > priv->height * 2)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
55 size = priv->height * 2;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
56
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
57 return size;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
58 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
59
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
60 static void change_font_size(ASS_Renderer *render_priv, double sz)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
61 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
62 render_priv->state.font_size = sz;
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 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
66 * \brief Change current font, using setting from render_priv->state.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
67 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
68 void update_font(ASS_Renderer *render_priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
69 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
70 unsigned val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
71 ASS_FontDesc desc;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
72 desc.treat_family_as_pattern = render_priv->state.treat_family_as_pattern;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
73
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
74 if (render_priv->state.family[0] == '@') {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
75 desc.vertical = 1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
76 desc.family = strdup(render_priv->state.family + 1);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
77 } else {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
78 desc.vertical = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
79 desc.family = strdup(render_priv->state.family);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
80 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
81
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
82 val = render_priv->state.bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
83 // 0 = normal, 1 = bold, >1 = exact weight
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 = 200; // bold
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 = 80; // normal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
88 desc.bold = 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 val = render_priv->state.italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
91 if (val == 1 || val == -1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
92 val = 110; // italic
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
93 else if (val <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
94 val = 0; // normal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
95 desc.italic = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
96
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
97 render_priv->state.font =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
98 ass_font_new(render_priv->cache.font_cache, render_priv->library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
99 render_priv->ftlibrary, render_priv->fontconfig_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
100 &desc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
101 free(desc.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
102
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
103 if (render_priv->state.font)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
104 change_font_size(render_priv, render_priv->state.font_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
105 }
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 /**
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
108 * \brief Calculate valid border size. Makes sure the border sizes make sense.
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
109 *
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
110 * \param priv renderer state object
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
111 * \param border_x requested x border size
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
112 * \param border_y requested y border size
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
113 */
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
114 void calc_border(ASS_Renderer *priv, double border_x, double border_y)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
115 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
116 if (border_x < 0 && border_y < 0) {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
117 if (priv->state.border_style == 1 ||
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
118 priv->state.border_style == 3)
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
119 border_x = border_y = priv->state.style->Outline;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
120 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
121 border_x = border_y = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
122 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
123
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
124 priv->state.border_x = border_x;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
125 priv->state.border_y = border_y;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
126 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
127
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
128 /**
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
129 * \brief Change border width
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
130 *
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
131 * \param render_priv renderer state object
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
132 * \param info glyph state object
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
133 */
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
134 void change_border(ASS_Renderer *render_priv, double border_x, double border_y)
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
135 {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
136 int bord = 64 * border_x * render_priv->border_scale;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
137
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
138 if (bord > 0 && border_x == border_y) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
139 if (!render_priv->state.stroker) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
140 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
141 error =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
142 FT_Stroker_New(render_priv->ftlibrary,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
143 &render_priv->state.stroker);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
144 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
145 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
146 "failed to get stroker");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
147 render_priv->state.stroker = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
148 }
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
149 render_priv->state.stroker_radius = -1.0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
150 }
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
151 if (render_priv->state.stroker && render_priv->state.stroker_radius != bord) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
152 FT_Stroker_Set(render_priv->state.stroker, bord,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
153 FT_STROKER_LINECAP_ROUND,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
154 FT_STROKER_LINEJOIN_ROUND, 0);
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
155 render_priv->state.stroker_radius = bord;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
156 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
157 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
158 FT_Stroker_Done(render_priv->state.stroker);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
159 render_priv->state.stroker = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
160 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
161 }
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 * \brief Calculate a weighted average of two colors
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
165 * 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
166 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
167 static void change_color(uint32_t *var, uint32_t new, double pwr)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
168 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
169 (*var) = ((uint32_t) (_r(*var) * (1 - pwr) + _r(new) * pwr) << 24) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
170 ((uint32_t) (_g(*var) * (1 - pwr) + _g(new) * pwr) << 16) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
171 ((uint32_t) (_b(*var) * (1 - pwr) + _b(new) * pwr) << 8) + _a(*var);
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
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
174 // like change_color, but for alpha component only
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
175 inline void change_alpha(uint32_t *var, uint32_t new, double pwr)
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 *var =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
178 (_r(*var) << 24) + (_g(*var) << 16) + (_b(*var) << 8) +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
179 (uint32_t) (_a(*var) * (1 - pwr) + _a(new) * pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
180 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
181
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
182 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
183 * \brief Multiply two alpha values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
184 * \param a first value
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
185 * \param b second value
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
186 * \return result of multiplication
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
187 * Parameters and result are limited by 0xFF.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
188 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
189 inline uint32_t mult_alpha(uint32_t a, uint32_t b)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
190 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
191 return 0xFF - (0xFF - a) * (0xFF - b) / 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
192 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
193
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
194 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
195 * \brief Calculate alpha value by piecewise linear function
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
196 * Used for \fad, \fade implementation.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
197 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
198 static unsigned
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
199 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
200 long long t4, unsigned a1, unsigned a2, unsigned a3)
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 unsigned a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
203 double cf;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
204
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
205 if (now < t1) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
206 a = a1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
207 } else if (now >= t4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
208 a = a3;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
209 } else if (now < t2 && t2 > t1) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
210 cf = ((double) (now - t1)) / (t2 - t1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
211 a = a1 * (1 - cf) + a2 * cf;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
212 } else if (now >= t3 && t4 > t3) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
213 cf = ((double) (now - t3)) / (t4 - t3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
214 a = a2 * (1 - cf) + a3 * cf;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
215 } else { // t2 <= now < t3
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
216 a = a2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
217 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
218
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
219 return a;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
220 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
221
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
222 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
223 * Parse a vector clip into an outline, using the proper scaling
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
224 * parameters. Translate it to correct for screen borders, if needed.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
225 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
226 static char *parse_vector_clip(ASS_Renderer *render_priv, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
227 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
228 int scale = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
229 int res = 0;
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
230 ASS_Drawing *drawing = render_priv->state.clip_drawing;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
231
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
232 ass_drawing_free(drawing);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
233 render_priv->state.clip_drawing =
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
234 ass_drawing_new(render_priv->library, render_priv->ftlibrary);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
235 drawing = render_priv->state.clip_drawing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
236 skipopt('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
237 res = mystrtoi(&p, &scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
238 skipopt(',')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
239 if (!res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
240 scale = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
241 drawing->scale = scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
242 drawing->scale_x = render_priv->font_scale_x * render_priv->font_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
243 drawing->scale_y = render_priv->font_scale;
35701
c7866af24567 Updated libass to 7e45532
SubJunk
parents: 35262
diff changeset
244 while (*p != ')' && *p != '}' && *p != 0)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
245 ass_drawing_add_char(drawing, *p++);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
246 skipopt(')');
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 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
249 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
250
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
251 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
252 * \brief Parse style override tag.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
253 * \param p string to parse
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
254 * \param pwr multiplier for some tag effects (comes from \t tags)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
255 */
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
256 char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
257 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
258 skip_to('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
259 skip('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
260 if ((*p == '}') || (*p == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
261 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
262
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
263 // New tags introduced in vsfilter 2.39
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
264 if (mystrcmp(&p, "xbord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
265 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
266 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
267 val = render_priv->state.border_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
268 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
269 val = -1.;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
270 calc_border(render_priv, val, render_priv->state.border_y);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
271 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
272 } else if (mystrcmp(&p, "ybord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
273 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
274 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
275 val = render_priv->state.border_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
276 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
277 val = -1.;
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
278 calc_border(render_priv, render_priv->state.border_x, val);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
279 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
280 } else if (mystrcmp(&p, "xshad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
281 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
282 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
283 val = render_priv->state.shadow_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
284 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
285 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
286 render_priv->state.shadow_x = val;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
287 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
288 } else if (mystrcmp(&p, "yshad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
289 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
290 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
291 val = render_priv->state.shadow_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
292 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
293 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
294 render_priv->state.shadow_y = val;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
295 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
296 } else if (mystrcmp(&p, "fax")) {
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.fax =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
300 val * pwr + render_priv->state.fax * (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.fax = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
303 } else if (mystrcmp(&p, "fay")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
304 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
305 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
306 render_priv->state.fay =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
307 val * pwr + render_priv->state.fay * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
308 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
309 render_priv->state.fay = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
310 } else if (mystrcmp(&p, "iclip")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
311 int x0, y0, x1, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
312 int res = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
313 char *start = p;
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
314 skip('(');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
315 res &= mystrtoi(&p, &x0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
316 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
317 res &= mystrtoi(&p, &y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
318 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
319 res &= mystrtoi(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
320 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
321 res &= mystrtoi(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
322 skipopt(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
323 if (res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
324 render_priv->state.clip_x0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
325 render_priv->state.clip_x0 * (1 - pwr) + x0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
326 render_priv->state.clip_x1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
327 render_priv->state.clip_x1 * (1 - pwr) + x1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
328 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
329 render_priv->state.clip_y0 * (1 - pwr) + y0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
330 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
331 render_priv->state.clip_y1 * (1 - pwr) + y1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
332 render_priv->state.clip_mode = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
333 } else if (!render_priv->state.clip_drawing) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
334 p = parse_vector_clip(render_priv, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
335 render_priv->state.clip_drawing_mode = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
336 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
337 render_priv->state.clip_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
338 } else if (mystrcmp(&p, "blur")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
339 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
340 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
341 val = render_priv->state.blur * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
342 val = (val < 0) ? 0 : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
343 val = (val > BLUR_MAX_RADIUS) ? BLUR_MAX_RADIUS : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
344 render_priv->state.blur = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
345 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
346 render_priv->state.blur = 0.0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
347 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
348 // ASS standard tags
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
349 } else if (mystrcmp(&p, "fsc")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
350 char tp = *p++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
351 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
352 if (tp == 'x') {
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_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
356 render_priv->state.scale_x * (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_x =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
359 render_priv->state.style->ScaleX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
360 } else if (tp == 'y') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
361 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
362 val /= 100;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
363 render_priv->state.scale_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
364 render_priv->state.scale_y * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
365 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
366 render_priv->state.scale_y =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
367 render_priv->state.style->ScaleY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
368 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
369 } else if (mystrcmp(&p, "fsp")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
370 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
371 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
372 render_priv->state.hspacing =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
373 render_priv->state.hspacing * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
374 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
375 render_priv->state.hspacing = render_priv->state.style->Spacing;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
376 } else if (mystrcmp(&p, "fs+")) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
377 double val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
378 if (mystrtod(&p, &val)) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
379 val = render_priv->state.font_size + pwr * val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
380 } else
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
381 val = render_priv->state.style->FontSize;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
382 if (render_priv->state.font)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
383 change_font_size(render_priv, val);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
384 } else if (mystrcmp(&p, "fs-")) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
385 double val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
386 if (mystrtod(&p, &val))
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
387 val = render_priv->state.font_size - pwr * val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
388 else
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
389 val = render_priv->state.style->FontSize;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
390 if (render_priv->state.font)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
391 change_font_size(render_priv, val);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
392 } else if (mystrcmp(&p, "fs")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
393 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
394 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
395 val = render_priv->state.font_size * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
396 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
397 val = render_priv->state.style->FontSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
398 if (render_priv->state.font)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
399 change_font_size(render_priv, val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
400 } else if (mystrcmp(&p, "bord")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
401 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
402 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
403 val = render_priv->state.border_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
404 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
405 val = -1.; // reset to default
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
406 calc_border(render_priv, val, val);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
407 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
408 } else if (mystrcmp(&p, "move")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
409 double x1, x2, y1, y2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
410 long long t1, t2, delta_t, t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
411 double x, y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
412 double k;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
413 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
414 mystrtod(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
415 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
416 mystrtod(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
417 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
418 mystrtod(&p, &x2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
419 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
420 mystrtod(&p, &y2);
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
421 t1 = t2 = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
422 if (*p == ',') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
423 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
424 mystrtoll(&p, &t1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
425 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
426 mystrtoll(&p, &t2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
427 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
428 "movement6: (%f, %f) -> (%f, %f), (%" PRId64 " .. %"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
429 PRId64 ")\n", x1, y1, x2, y2, (int64_t) t1,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
430 (int64_t) t2);
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
431 // VSFilter
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
432 if (t1 > t2) {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
433 double tmp = t2;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
434 t2 = t1;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
435 t1 = tmp;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
436 }
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
437 }
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
438 if (t1 <= 0 && t2 <= 0) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
439 t1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
440 t2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
441 ass_msg(render_priv->library, MSGL_DBG2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
442 "movement: (%f, %f) -> (%f, %f)", x1, y1, x2, y2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
443 }
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
444 skipopt(')');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
445 delta_t = t2 - t1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
446 t = render_priv->time - render_priv->state.event->Start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
447 if (t < t1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
448 k = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
449 else if (t > t2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
450 k = 1.;
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 k = ((double) (t - t1)) / delta_t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
453 x = k * (x2 - x1) + x1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
454 y = k * (y2 - y1) + y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
455 if (render_priv->state.evt_type != EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
456 render_priv->state.pos_x = x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
457 render_priv->state.pos_y = y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
458 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
459 render_priv->state.evt_type = EVENT_POSITIONED;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
460 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
461 } else if (mystrcmp(&p, "frx")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
462 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
463 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
464 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
465 render_priv->state.frx =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
466 val * pwr + render_priv->state.frx * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
467 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
468 render_priv->state.frx = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
469 } else if (mystrcmp(&p, "fry")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
470 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
471 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
472 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
473 render_priv->state.fry =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
474 val * pwr + render_priv->state.fry * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
475 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
476 render_priv->state.fry = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
477 } else if (mystrcmp(&p, "frz") || mystrcmp(&p, "fr")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
478 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
479 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
480 val *= M_PI / 180;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
481 render_priv->state.frz =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
482 val * pwr + render_priv->state.frz * (1 - pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
483 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
484 render_priv->state.frz =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
485 M_PI * render_priv->state.style->Angle / 180.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
486 } else if (mystrcmp(&p, "fn")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
487 char *start = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
488 char *family;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
489 skip_to('\\');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
490 if (p > start) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
491 family = malloc(p - start + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
492 strncpy(family, start, p - start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
493 family[p - start] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
494 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
495 family = strdup(render_priv->state.style->FontName);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
496 free(render_priv->state.family);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
497 render_priv->state.family = family;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
498 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
499 } else if (mystrcmp(&p, "alpha")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
500 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
501 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
502 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
503 if (strtocolor(render_priv->library, &p, &val, hex)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
504 unsigned char a = val >> 24;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
505 for (i = 0; i < 4; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
506 change_alpha(&render_priv->state.c[i], a, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
507 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
508 change_alpha(&render_priv->state.c[0],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
509 render_priv->state.style->PrimaryColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
510 change_alpha(&render_priv->state.c[1],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
511 render_priv->state.style->SecondaryColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
512 change_alpha(&render_priv->state.c[2],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
513 render_priv->state.style->OutlineColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
514 change_alpha(&render_priv->state.c[3],
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
515 render_priv->state.style->BackColour, pwr);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
516 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
517 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
518 // FIXME: simplify
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
519 } else if (mystrcmp(&p, "an")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
520 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
521 if (mystrtoi(&p, &val) && val) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
522 int v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
523 ass_msg(render_priv->library, MSGL_DBG2, "an %d", val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
524 if (v != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
525 v = 3 - v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
526 val = ((val - 1) % 3) + 1; // horizontal alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
527 val += v * 4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
528 ass_msg(render_priv->library, MSGL_DBG2, "align %d", val);
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
529 if ((render_priv->state.parsed_tags & PARSED_A) == 0) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
530 render_priv->state.alignment = val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
531 render_priv->state.parsed_tags |= PARSED_A;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
532 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
533 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
534 render_priv->state.alignment =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
535 render_priv->state.style->Alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
536 } else if (mystrcmp(&p, "a")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
537 int val;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
538 if (mystrtoi(&p, &val) && val) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
539 if ((render_priv->state.parsed_tags & PARSED_A) == 0) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
540 // take care of a vsfilter quirk: handle illegal \a8 like \a5
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
541 render_priv->state.alignment = (val == 8) ? 5 : val;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
542 render_priv->state.parsed_tags |= PARSED_A;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
543 }
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
544 } else
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
545 render_priv->state.alignment =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
546 render_priv->state.style->Alignment;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
547 } else if (mystrcmp(&p, "pos")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
548 double v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
549 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
550 mystrtod(&p, &v1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
551 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
552 mystrtod(&p, &v2);
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
553 skipopt(')');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
554 ass_msg(render_priv->library, MSGL_DBG2, "pos(%f, %f)", v1, v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
555 if (render_priv->state.evt_type == EVENT_POSITIONED) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
556 ass_msg(render_priv->library, MSGL_V, "Subtitle has a new \\pos "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
557 "after \\move or \\pos, ignoring");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
558 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
559 render_priv->state.evt_type = EVENT_POSITIONED;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
560 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
561 render_priv->state.pos_x = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
562 render_priv->state.pos_y = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
563 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
564 } else if (mystrcmp(&p, "fad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
565 int a1, a2, a3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
566 long long t1, t2, t3, t4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
567 if (*p == 'e')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
568 ++p; // either \fad or \fade
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
569 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
570 mystrtoi(&p, &a1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
571 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
572 mystrtoi(&p, &a2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
573 if (*p == ')') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
574 // 2-argument version (\fad, according to specs)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
575 // a1 and a2 are fade-in and fade-out durations
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
576 t1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
577 t4 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
578 t2 = a1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
579 t3 = t4 - a2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
580 a1 = 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
581 a2 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
582 a3 = 0xFF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
583 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
584 // 6-argument version (\fade)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
585 // a1 and a2 (and a3) are opacity values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
586 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
587 mystrtoi(&p, &a3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
588 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
589 mystrtoll(&p, &t1);
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 mystrtoll(&p, &t2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
592 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
593 mystrtoll(&p, &t3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
594 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
595 mystrtoll(&p, &t4);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
596 }
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
597 skipopt(')');
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
598 if ((render_priv->state.parsed_tags & PARSED_FADE) == 0) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
599 render_priv->state.fade =
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
600 interpolate_alpha(render_priv->time -
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
601 render_priv->state.event->Start, t1, t2,
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
602 t3, t4, a1, a2, a3);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
603 render_priv->state.parsed_tags |= PARSED_FADE;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
604 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
605 } else if (mystrcmp(&p, "org")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
606 int v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
607 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
608 mystrtoi(&p, &v1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
609 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
610 mystrtoi(&p, &v2);
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
611 skipopt(')');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
612 ass_msg(render_priv->library, MSGL_DBG2, "org(%d, %d)", v1, v2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
613 if (!render_priv->state.have_origin) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
614 render_priv->state.org_x = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
615 render_priv->state.org_y = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
616 render_priv->state.have_origin = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
617 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
618 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
619 } else if (mystrcmp(&p, "t")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
620 double v[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
621 int v1, v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
622 double v3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
623 int cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
624 long long t1, t2, t, delta_t;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
625 double k;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
626 skip('(');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
627 for (cnt = 0; cnt < 3; ++cnt) {
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
628 if (!mystrtod(&p, &v[cnt]))
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
629 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
630 skip(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
631 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
632 if (cnt == 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
633 v1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
634 v2 = (v[1] < v1) ? render_priv->state.event->Duration : v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
635 v3 = v[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
636 } else if (cnt == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
637 v1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
638 v2 = (v[1] < v1) ? render_priv->state.event->Duration : v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
639 v3 = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
640 } else if (cnt == 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
641 v1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
642 v2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
643 v3 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
644 } else { // cnt == 0
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
645 v1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
646 v2 = render_priv->state.event->Duration;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
647 v3 = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
648 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
649 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
650 t1 = v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
651 t2 = v2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
652 delta_t = v2 - v1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
653 if (v3 < 0.)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
654 v3 = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
655 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
656 if (t <= t1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
657 k = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
658 else if (t >= t2)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
659 k = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
660 else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
661 assert(delta_t != 0.);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
662 k = pow(((double) (t - t1)) / delta_t, v3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
663 }
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
664 while (*p != ')' && *p != '}' && *p != '\0')
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
665 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
666 skip_to(')'); // in case there is some unknown tag or a comment
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
667 skipopt(')');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
668 } else if (mystrcmp(&p, "clip")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
669 char *start = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
670 int x0, y0, x1, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
671 int res = 1;
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35701
diff changeset
672 skip('(');
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
673 res &= mystrtoi(&p, &x0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
674 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
675 res &= mystrtoi(&p, &y0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
676 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
677 res &= mystrtoi(&p, &x1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
678 skipopt(',');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
679 res &= mystrtoi(&p, &y1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
680 skipopt(')');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
681 if (res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
682 render_priv->state.clip_x0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
683 render_priv->state.clip_x0 * (1 - pwr) + x0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
684 render_priv->state.clip_x1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
685 render_priv->state.clip_x1 * (1 - pwr) + x1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
686 render_priv->state.clip_y0 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
687 render_priv->state.clip_y0 * (1 - pwr) + y0 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
688 render_priv->state.clip_y1 =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
689 render_priv->state.clip_y1 * (1 - pwr) + y1 * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
690 // Might be a vector clip
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
691 } else if (!render_priv->state.clip_drawing) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
692 p = parse_vector_clip(render_priv, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
693 render_priv->state.clip_drawing_mode = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
694 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
695 render_priv->state.clip_x0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
696 render_priv->state.clip_y0 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
697 render_priv->state.clip_x1 = render_priv->track->PlayResX;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
698 render_priv->state.clip_y1 = render_priv->track->PlayResY;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
699 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
700 } else if (mystrcmp(&p, "c")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
701 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
702 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
703 if (!strtocolor(render_priv->library, &p, &val, hex))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
704 val = render_priv->state.style->PrimaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
705 ass_msg(render_priv->library, MSGL_DBG2, "color: %X", val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
706 change_color(&render_priv->state.c[0], val, pwr);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
707 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
708 } else if ((*p >= '1') && (*p <= '4') && (++p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
709 && (mystrcmp(&p, "c") || mystrcmp(&p, "a"))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
710 char n = *(p - 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
711 int cidx = n - '1';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
712 char cmd = *(p - 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
713 uint32_t val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
714 int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
715 assert((n >= '1') && (n <= '4'));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
716 if (!strtocolor(render_priv->library, &p, &val, hex))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
717 switch (n) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
718 case '1':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
719 val = render_priv->state.style->PrimaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
720 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
721 case '2':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
722 val = render_priv->state.style->SecondaryColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
723 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
724 case '3':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
725 val = render_priv->state.style->OutlineColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
726 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
727 case '4':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
728 val = render_priv->state.style->BackColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
729 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
730 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
731 val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
732 break; // impossible due to assert; avoid compilation warning
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
733 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
734 switch (cmd) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
735 case 'c':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
736 change_color(render_priv->state.c + cidx, val, pwr);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
737 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
738 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
739 case 'a':
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
740 change_alpha(render_priv->state.c + cidx, val >> 24, pwr);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
741 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
742 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
743 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
744 ass_msg(render_priv->library, MSGL_WARN, "Bad command: %c%c",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
745 n, cmd);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
746 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
747 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
748 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
749 pwr, n, cmd, render_priv->state.c[cidx]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
750 } else if (mystrcmp(&p, "r")) {
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
751 char *start = p;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
752 char *style;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
753 skip_to('\\');
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
754 if (p > start) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
755 style = malloc(p - start + 1);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
756 strncpy(style, start, p - start);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
757 style[p - start] = '\0';
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
758 reset_render_context(render_priv,
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
759 render_priv->track->styles + lookup_style(render_priv->track, style));
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
760 free(style);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
761 } else
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
762 reset_render_context(render_priv, NULL);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
763 } else if (mystrcmp(&p, "be")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
764 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
765 if (mystrtoi(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
766 // Clamp to a safe upper limit, since high values need excessive CPU
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
767 val = (val < 0) ? 0 : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
768 val = (val > MAX_BE) ? MAX_BE : val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
769 render_priv->state.be = val;
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.be = 0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
772 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
773 } else if (mystrcmp(&p, "b")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
774 int b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
775 if (mystrtoi(&p, &b)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
776 if (pwr >= .5)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
777 render_priv->state.bold = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
778 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
779 render_priv->state.bold = render_priv->state.style->Bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
780 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
781 } else if (mystrcmp(&p, "i")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
782 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
783 if (mystrtoi(&p, &i)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
784 if (pwr >= .5)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
785 render_priv->state.italic = i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
786 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
787 render_priv->state.italic = render_priv->state.style->Italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
788 update_font(render_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
789 } else if (mystrcmp(&p, "kf") || mystrcmp(&p, "K")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
790 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
791 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
792 render_priv->state.effect_type = EF_KARAOKE_KF;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
793 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
794 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
795 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
796 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
797 } else if (mystrcmp(&p, "ko")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
798 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
799 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
800 render_priv->state.effect_type = EF_KARAOKE_KO;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
801 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
802 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
803 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
804 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
805 } else if (mystrcmp(&p, "k")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
806 int val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
807 mystrtoi(&p, &val);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
808 render_priv->state.effect_type = EF_KARAOKE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
809 if (render_priv->state.effect_timing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
810 render_priv->state.effect_skip_timing +=
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
811 render_priv->state.effect_timing;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
812 render_priv->state.effect_timing = val * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
813 } else if (mystrcmp(&p, "shad")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
814 double val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
815 if (mystrtod(&p, &val)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
816 if (render_priv->state.shadow_x == render_priv->state.shadow_y)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
817 val = render_priv->state.shadow_x * (1 - pwr) + val * pwr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
818 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
819 val = 0.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
820 render_priv->state.shadow_x = render_priv->state.shadow_y = val;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
821 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
822 } else if (mystrcmp(&p, "s")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
823 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
824 if (mystrtoi(&p, &val) && val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
825 render_priv->state.flags |= DECO_STRIKETHROUGH;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
826 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
827 render_priv->state.flags &= ~DECO_STRIKETHROUGH;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
828 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
829 } else if (mystrcmp(&p, "u")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
830 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
831 if (mystrtoi(&p, &val) && val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
832 render_priv->state.flags |= DECO_UNDERLINE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
833 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
834 render_priv->state.flags &= ~DECO_UNDERLINE;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
835 render_priv->state.bm_run_id++;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
836 } else if (mystrcmp(&p, "pbo")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
837 double val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
838 if (mystrtod(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
839 render_priv->state.drawing->pbo = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
840 } else if (mystrcmp(&p, "p")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
841 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
842 if (!mystrtoi(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
843 val = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
844 if (val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
845 render_priv->state.drawing->scale = val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
846 render_priv->state.drawing_mode = !!val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
847 } else if (mystrcmp(&p, "q")) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
848 int val;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
849 if (!mystrtoi(&p, &val))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
850 val = render_priv->track->WrapStyle;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
851 render_priv->state.wrap_style = val;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
852 } else if (mystrcmp(&p, "fe")) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
853 int val;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
854 if (!mystrtoi(&p, &val))
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
855 val = render_priv->state.style->Encoding;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
856 render_priv->state.font_encoding = val;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
857 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
858
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
859 return p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
860 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
861
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
862 void apply_transition_effects(ASS_Renderer *render_priv, ASS_Event *event)
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 int v[4];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
865 int cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
866 char *p = event->Effect;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
867
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
868 if (!p || !*p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
869 return;
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 cnt = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
872 while (cnt < 4 && (p = strchr(p, ';'))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
873 v[cnt++] = atoi(++p);
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
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
876 if (strncmp(event->Effect, "Banner;", 7) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
877 int delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
878 if (cnt < 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
879 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
880 "Error parsing effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
881 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
882 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
883 if (cnt >= 2 && v[1] == 0) // right-to-left
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
884 render_priv->state.scroll_direction = SCROLL_RL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
885 else // left-to-right
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
886 render_priv->state.scroll_direction = SCROLL_LR;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
887
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
888 delay = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
889 if (delay == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
890 delay = 1; // ?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
891 render_priv->state.scroll_shift =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
892 (render_priv->time - render_priv->state.event->Start) / delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
893 render_priv->state.evt_type = EVENT_HSCROLL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
894 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
895 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
896
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
897 if (strncmp(event->Effect, "Scroll up;", 10) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
898 render_priv->state.scroll_direction = SCROLL_BT;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
899 } else if (strncmp(event->Effect, "Scroll down;", 12) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
900 render_priv->state.scroll_direction = SCROLL_TB;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
901 } else {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
902 ass_msg(render_priv->library, MSGL_DBG2,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
903 "Unknown transition effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
904 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
905 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
906 // parse scroll up/down parameters
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
907 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
908 int delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
909 int y0, y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
910 if (cnt < 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
911 ass_msg(render_priv->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
912 "Error parsing effect: '%s'", event->Effect);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
913 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
914 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
915 delay = v[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
916 if (delay == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
917 delay = 1; // ?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
918 render_priv->state.scroll_shift =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
919 (render_priv->time - render_priv->state.event->Start) / delay;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
920 if (v[0] < v[1]) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
921 y0 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
922 y1 = v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
923 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
924 y0 = v[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
925 y1 = v[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
926 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
927 if (y1 == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
928 y1 = render_priv->track->PlayResY; // y0=y1=0 means fullscreen scrolling
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
929 render_priv->state.clip_y0 = y0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
930 render_priv->state.clip_y1 = y1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
931 render_priv->state.evt_type = EVENT_VSCROLL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
932 render_priv->state.detect_collisions = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
933 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
934
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
935 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
936
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
937 /**
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
938 * \brief determine karaoke effects
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
939 * Karaoke effects cannot be calculated during parse stage (get_next_char()),
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
940 * so they are done in a separate step.
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
941 * Parse stage: when karaoke style override is found, its parameters are stored in the next glyph's
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
942 * (the first glyph of the karaoke word)'s effect_type and effect_timing.
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
943 * This function:
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
944 * 1. sets effect_type for all glyphs in the word (_karaoke_ word)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
945 * 2. sets effect_timing for all glyphs to x coordinate of the border line between the left and right karaoke parts
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
946 * (left part is filled with PrimaryColour, right one - with SecondaryColour).
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
947 */
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
948 void process_karaoke_effects(ASS_Renderer *render_priv)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
949 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
950 GlyphInfo *cur, *cur2;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
951 GlyphInfo *s1, *e1; // start and end of the current word
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
952 GlyphInfo *s2; // start of the next word
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
953 int i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
954 int timing; // current timing
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
955 int tm_start, tm_end; // timings at start and end of the current word
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
956 int tm_current;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
957 double dt;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
958 int x;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
959 int x_start, x_end;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
960
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
961 tm_current = render_priv->time - render_priv->state.event->Start;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
962 timing = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
963 s1 = s2 = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
964 for (i = 0; i <= render_priv->text_info.length; ++i) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
965 cur = render_priv->text_info.glyphs + i;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
966 if ((i == render_priv->text_info.length)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
967 || (cur->effect_type != EF_NONE)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
968 s1 = s2;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
969 s2 = cur;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
970 if (s1) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
971 e1 = s2 - 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
972 tm_start = timing + s1->effect_skip_timing;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
973 tm_end = tm_start + s1->effect_timing;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
974 timing = tm_end;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
975 x_start = 1000000;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
976 x_end = -1000000;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
977 for (cur2 = s1; cur2 <= e1; ++cur2) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
978 x_start = FFMIN(x_start, d6_to_int(cur2->bbox.xMin + cur2->pos.x));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
979 x_end = FFMAX(x_end, d6_to_int(cur2->bbox.xMax + cur2->pos.x));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
980 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
981
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
982 dt = (tm_current - tm_start);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
983 if ((s1->effect_type == EF_KARAOKE)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
984 || (s1->effect_type == EF_KARAOKE_KO)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
985 if (dt > 0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
986 x = x_end + 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
987 else
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
988 x = x_start;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
989 } else if (s1->effect_type == EF_KARAOKE_KF) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
990 dt /= (tm_end - tm_start);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
991 x = x_start + (x_end - x_start) * dt;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
992 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
993 ass_msg(render_priv->library, MSGL_ERR,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
994 "Unknown effect type");
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
995 continue;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
996 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
997
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
998 for (cur2 = s1; cur2 <= e1; ++cur2) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
999 cur2->effect_type = s1->effect_type;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1000 cur2->effect_timing = x - d6_to_int(cur2->pos.x);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1001 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1002 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1003 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1004 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1005 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1006
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1007
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1008 /**
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
1009 * \brief Get next ucs4 char from string, parsing UTF-8 and escapes
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1010 * \param str string pointer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1011 * \return ucs4 code of the next char
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1012 * On return str points to the unparsed part of the string
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1013 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1014 unsigned get_next_char(ASS_Renderer *render_priv, char **str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1015 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1016 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1017 unsigned chr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1018 if (*p == '\t') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1019 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1020 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1021 return ' ';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1022 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1023 if (*p == '\\') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1024 if ((p[1] == 'N') || ((p[1] == 'n') &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1025 (render_priv->state.wrap_style == 2))) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1026 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1027 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1028 return '\n';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1029 } else if (p[1] == 'n') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1030 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1031 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1032 return ' ';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1033 } else if (p[1] == 'h') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1034 p += 2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1035 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1036 return NBSP;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1037 } else if (p[1] == '{') {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1038 p += 2;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1039 *str = p;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1040 return '{';
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1041 } else if (p[1] == '}') {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1042 p += 2;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1043 *str = p;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
1044 return '}';
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1045 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1046 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1047 chr = ass_utf8_get_char((char **) &p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1048 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1049 return chr;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1050 }