Mercurial > mplayer.hg
changeset 28717:7bbe6626f0e0
Support fractional arguments for some override tags.
Done by parsing all integers as doubles first and then converting them to the
nearest integer. Patch by Grigori G (greg chown ath cx).
author | eugeni |
---|---|
date | Fri, 27 Feb 2009 23:06:47 +0000 |
parents | 0a8b23440a61 |
children | e3b5070f671d |
files | libass/ass_render.c libass/ass_utils.c libass/ass_utils.h |
diffstat | 3 files changed, 40 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/libass/ass_render.c Fri Feb 27 23:06:43 2009 +0000 +++ b/libass/ass_render.c Fri Feb 27 23:06:47 2009 +0000 @@ -781,18 +781,18 @@ double x, y; double k; skip('('); - x1 = strtol(p, &p, 10); + mystrtoi(&p, 10, &x1); skip(','); - y1 = strtol(p, &p, 10); + mystrtoi(&p, 10, &y1); skip(','); - x2 = strtol(p, &p, 10); + mystrtoi(&p, 10, &x2); skip(','); - y2 = strtol(p, &p, 10); + mystrtoi(&p, 10, &y2); if (*p == ',') { skip(','); - t1 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t1); skip(','); - t2 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t2); mp_msg(MSGT_ASS, MSGL_DBG2, "movement6: (%d, %d) -> (%d, %d), (%" PRId64 " .. %" PRId64 ")\n", x1, y1, x2, y2, (int64_t)t1, (int64_t)t2); } else { @@ -886,9 +886,9 @@ } else if (mystrcmp(&p, "pos")) { int v1, v2; skip('('); - v1 = strtol(p, &p, 10); + mystrtoi(&p, 10, &v1); skip(','); - v2 = strtol(p, &p, 10); + mystrtoi(&p, 10, &v2); skip(')'); mp_msg(MSGT_ASS, MSGL_DBG2, "pos(%d, %d)\n", v1, v2); if (render_context.evt_type != EVENT_POSITIONED) { @@ -902,9 +902,9 @@ long long t1, t2, t3, t4; if (*p == 'e') ++p; // either \fad or \fade skip('('); - a1 = strtol(p, &p, 10); + mystrtoi(&p, 10, &a1); skip(','); - a2 = strtol(p, &p, 10); + mystrtoi(&p, 10, &a2); if (*p == ')') { // 2-argument version (\fad, according to specs) // a1 and a2 are fade-in and fade-out durations @@ -919,24 +919,24 @@ // 6-argument version (\fade) // a1 and a2 (and a3) are opacity values skip(','); - a3 = strtol(p, &p, 10); + mystrtoi(&p, 10, &a3); skip(','); - t1 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t1); skip(','); - t2 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t2); skip(','); - t3 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t3); skip(','); - t4 = strtoll(p, &p, 10); + mystrtoll(&p, 10, &t4); } skip(')'); render_context.fade = interpolate_alpha(frame_context.time - render_context.event->Start, t1, t2, t3, t4, a1, a2, a3); } else if (mystrcmp(&p, "org")) { int v1, v2; skip('('); - v1 = strtol(p, &p, 10); + mystrtoi(&p, 10, &v1); skip(','); - v2 = strtol(p, &p, 10); + mystrtoi(&p, 10, &v2); skip(')'); mp_msg(MSGT_ASS, MSGL_DBG2, "org(%d, %d)\n", v1, v2); // render_context.evt_type = EVENT_POSITIONED; @@ -1063,19 +1063,22 @@ render_context.italic = render_context.style->Italic; update_font(); } else if (mystrcmp(&p, "kf") || mystrcmp(&p, "K")) { - int val = strtol(p, &p, 10); + int val = 0; + mystrtoi(&p, 10, &val); render_context.effect_type = EF_KARAOKE_KF; if (render_context.effect_timing) render_context.effect_skip_timing += render_context.effect_timing; render_context.effect_timing = val * 10; } else if (mystrcmp(&p, "ko")) { - int val = strtol(p, &p, 10); + int val = 0; + mystrtoi(&p, 10, &val); render_context.effect_type = EF_KARAOKE_KO; if (render_context.effect_timing) render_context.effect_skip_timing += render_context.effect_timing; render_context.effect_timing = val * 10; } else if (mystrcmp(&p, "k")) { - int val = strtol(p, &p, 10); + int val = 0; + mystrtoi(&p, 10, &val); render_context.effect_type = EF_KARAOKE; if (render_context.effect_timing) render_context.effect_skip_timing += render_context.effect_timing; @@ -1087,7 +1090,8 @@ else render_context.shadow = render_context.style->Shadow; } else if (mystrcmp(&p, "pbo")) { - (void)strtol(p, &p, 10); // ignored + int val = 0; + mystrtoi(&p, 10, &val); // ignored } else if (mystrcmp(&p, "p")) { int val; if (!mystrtoi(&p, 10, &val))
--- a/libass/ass_utils.c Fri Feb 27 23:06:43 2009 +0000 +++ b/libass/ass_utils.c Fri Feb 27 23:06:47 2009 +0000 @@ -32,8 +32,21 @@ int mystrtoi(char** p, int base, int* res) { + // NOTE: base argument is ignored, but not used in libass anyway + double temp_res; char* start = *p; - *res = strtol(*p, p, base); + temp_res = strtod(*p, p); + *res = (int) (temp_res + 0.5); + if (*p != start) return 1; + else return 0; +} + +int mystrtoll(char** p, int base, long long* res) +{ + double temp_res; + char* start = *p; + temp_res = strtod(*p, p); + *res = (long long) (temp_res + 0.5); if (*p != start) return 1; else return 0; }
--- a/libass/ass_utils.h Fri Feb 27 23:06:43 2009 +0000 +++ b/libass/ass_utils.h Fri Feb 27 23:06:47 2009 +0000 @@ -26,6 +26,7 @@ #include <stdint.h> int mystrtoi(char** p, int base, int* res); +int mystrtoll(char** p, int base, long long* res); int mystrtou32(char** p, int base, uint32_t* res); int mystrtod(char** p, double* res); int strtocolor(char** q, uint32_t* res);