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

eugeni subversion at mplayerhq.hu
Fri Feb 16 18:49:35 CET 2007


Author: eugeni
Date: Fri Feb 16 18:49:35 2007
New Revision: 22231

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

Log:
Move conversions between 16.16, 26.6 fixed point and int, double to separate
functions. Some rounding errors are fixed along the way.


Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c	(original)
+++ trunk/libass/ass_render.c	Fri Feb 16 18:49:35 2007
@@ -497,12 +497,12 @@
 	if (text_info.length > 0) {
 		bbox.xMin = 32000;
 		bbox.xMax = -32000;
-		bbox.yMin = - (text_info.lines[0].asc >> 6) + text_info.glyphs[0].pos.y;
-		bbox.yMax = ((text_info.height - text_info.lines[0].asc) >> 6) + text_info.glyphs[0].pos.y;
+		bbox.yMin = - d6_to_int(text_info.lines[0].asc) + text_info.glyphs[0].pos.y;
+		bbox.yMax = d6_to_int(text_info.height - text_info.lines[0].asc) + text_info.glyphs[0].pos.y;
 
 		for (i = 0; i < text_info.length; ++i) {
 			int s = text_info.glyphs[i].pos.x;
-			int e = s + (text_info.glyphs[i].advance.x >> 6);
+			int e = s + d6_to_int(text_info.glyphs[i].advance.x);
 			bbox.xMin = FFMIN(bbox.xMin, s);
 			bbox.xMax = FFMAX(bbox.xMax, e);
 		}
@@ -1241,8 +1241,8 @@
 	if (!info->glyph)
 		return 0;
 
-	info->advance.x = info->glyph->advance.x >> 10;
-	info->advance.y = info->glyph->advance.y >> 10;
+	info->advance.x = d16_to_d6(info->glyph->advance.x);
+	info->advance.y = d16_to_d6(info->glyph->advance.y);
 
 	if (render_context.stroker) {
 		info->outline_glyph = info->glyph;
@@ -1410,7 +1410,7 @@
 			int height = text_info.lines[cur_line - 1].desc + text_info.lines[cur_line].asc;
 			cur_line ++;
 			pen_shift_x = - cur->pos.x;
-			pen_shift_y += (height >> 6) + global_settings->line_spacing;
+			pen_shift_y += d6_to_int(height) + global_settings->line_spacing;
 			mp_msg(MSGT_ASS, MSGL_DBG2, "shifting from %d to %d by (%d, %d)\n", i, text_info.length - 1, pen_shift_x, pen_shift_y);
 		}
 		cur->pos.x += pen_shift_x;
@@ -1606,8 +1606,8 @@
 			continue;
 		}
 		
-		text_info.glyphs[text_info.length].pos.x = pen.x >> 6;
-		text_info.glyphs[text_info.length].pos.y = pen.y >> 6;
+		text_info.glyphs[text_info.length].pos.x = d6_to_int(pen.x);
+		text_info.glyphs[text_info.length].pos.y = d6_to_int(pen.y);
 		
 		pen.x += text_info.glyphs[text_info.length].advance.x;
 		pen.x += render_context.hspacing;
@@ -1722,7 +1722,7 @@
 	if (render_context.evt_type == EVENT_NORMAL ||
 	    render_context.evt_type == EVENT_HSCROLL) {
 		if (valign == VALIGN_TOP) { // toptitle
-			device_y = y2scr_top(MarginV) + (text_info.lines[0].asc >> 6);
+			device_y = y2scr_top(MarginV) + d6_to_int(text_info.lines[0].asc);
 		} else if (valign == VALIGN_CENTER) { // midtitle
 			int scr_y = y2scr(frame_context.track->PlayResY / 2);
 			device_y = scr_y - (bbox.yMax - bbox.yMin) / 2;
@@ -1732,8 +1732,8 @@
 				mp_msg(MSGT_ASS, MSGL_V, "Invalid valign, supposing 0 (subtitle)\n");
 			scr_y = y2scr_sub(frame_context.track->PlayResY - MarginV);
 			device_y = scr_y;
-			device_y -= (text_info.height >> 6);
-			device_y += (text_info.lines[0].asc >> 6);
+			device_y -= d6_to_int(text_info.height);
+			device_y += d6_to_int(text_info.lines[0].asc);
 		}
 	} else if (render_context.evt_type == EVENT_VSCROLL) {
 		if (render_context.scroll_direction == SCROLL_TB)
@@ -1807,8 +1807,8 @@
 
 			// calculating shift vector
 			// shift = (position - center)*M - (position - center)
-			start.x = (info->pos.x + device_x - center.x) << 6;
-			start.y = - (info->pos.y + device_y - center.y) << 6;
+			start.x = int_to_d6(info->pos.x + device_x - center.x);
+			start.y = int_to_d6(info->pos.y + device_y - center.y);
 			start_old.x = start.x;
 			start_old.y = start.y;
 
@@ -1817,8 +1817,8 @@
 			start.x -= start_old.x;
 			start.y -= start_old.y;
 
-			info->pos.x += start.x >> 6;
-			info->pos.y -= start.y >> 6;
+			info->pos.x += d6_to_int(start.x);
+			info->pos.y -= d6_to_int(start.y);
 
 			if (info->glyph)
 				FT_Glyph_Transform( info->glyph, &matrix_rotate, 0 );
@@ -1827,8 +1827,8 @@
 		}
 	}
 
-	event_images->top = device_y - (text_info.lines[0].asc >> 6);
-	event_images->height = text_info.height >> 6;
+	event_images->top = device_y - d6_to_int(text_info.lines[0].asc);
+	event_images->height = d6_to_int(text_info.height);
 	event_images->detect_collisions = render_context.detect_collisions;
 	event_images->shift_direction = (valign == VALIGN_TOP) ? 1 : -1;
 	event_images->event = event;

Modified: trunk/libass/ass_utils.h
==============================================================================
--- trunk/libass/ass_utils.h	(original)
+++ trunk/libass/ass_utils.h	Fri Feb 16 18:49:35 2007
@@ -25,5 +25,31 @@
 int mystrtou32(char** p, int base, uint32_t* res);
 int mystrtod(char** p, double* res);
 int strtocolor(char** q, uint32_t* res);
+
+static inline int d6_to_int(int x) {
+	return (x + 32) >> 6;
+}
+static inline int d16_to_int(int x) {
+	return (x + 32768) >> 16;
+}
+static inline int int_to_d6(int x) {
+	return x << 6;
+}
+static inline int int_to_d16(int x) {
+	return x << 16;
+}
+static inline int d16_to_d6(int x) {
+	return (x + 512) >> 10;
+}
+static inline int d6_to_d16(int x) {
+	return x << 10;
+}
+static inline double d6_to_double(int x) {
+	return x / 64.;
+}
+static inline int double_to_d6(double x) {
+	return (int)(x * 64);
+}
+
 #endif
 



More information about the MPlayer-cvslog mailing list