[MPlayer-cvslog] r28752 - in trunk/libass: ass_render.c ass_utils.c ass_utils.h

eugeni subversion at mplayerhq.hu
Sat Feb 28 00:06:47 CET 2009


Author: eugeni
Date: Sat Feb 28 00:06:47 2009
New Revision: 28752

Log:
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).

Modified:
   trunk/libass/ass_render.c
   trunk/libass/ass_utils.c
   trunk/libass/ass_utils.h

Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c	Sat Feb 28 00:06:43 2009	(r28751)
+++ trunk/libass/ass_render.c	Sat Feb 28 00:06:47 2009	(r28752)
@@ -781,18 +781,18 @@ static char* parse_tag(char* p, double p
 		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 @@ static char* parse_tag(char* p, double p
 	} 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 @@ static char* parse_tag(char* p, double p
 		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 @@ static char* parse_tag(char* p, double p
 			// 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 @@ static char* parse_tag(char* p, double p
 			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 @@ static char* parse_tag(char* p, double p
 		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))

Modified: trunk/libass/ass_utils.c
==============================================================================
--- trunk/libass/ass_utils.c	Sat Feb 28 00:06:43 2009	(r28751)
+++ trunk/libass/ass_utils.c	Sat Feb 28 00:06:47 2009	(r28752)
@@ -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;
 }

Modified: trunk/libass/ass_utils.h
==============================================================================
--- trunk/libass/ass_utils.h	Sat Feb 28 00:06:43 2009	(r28751)
+++ trunk/libass/ass_utils.h	Sat Feb 28 00:06:47 2009	(r28752)
@@ -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);



More information about the MPlayer-cvslog mailing list