diff libass/ass_render.c @ 24787:02535b3216c5

Avoid text deformation and subtitles moving outside the screen in pan-and-scan mode. For this, crop amounts are passed from vo_gl as negative margins sizes. They are used to calculate aspect ratio. They are ignored when calculating subtitle positions, so subtitles will stay on screen most of the time. Based on a patch by Jindrich Makovicka [makovick gmail com].
author eugeni
date Fri, 19 Oct 2007 18:16:23 +0000
parents 32865ce92732
children d7ab7fda755a
line wrap: on
line diff
--- a/libass/ass_render.c	Fri Oct 19 17:30:47 2007 +0000
+++ b/libass/ass_render.c	Fri Oct 19 18:16:23 2007 +0000
@@ -184,6 +184,8 @@
 	int width, height; // screen dimensions
 	int orig_height; // frame height ( = screen height - margins )
 	int orig_width; // frame width ( = screen width - margins )
+	int orig_height_nocrop; // frame height ( = screen height - margins + cropheight)
+	int orig_width_nocrop; // frame width ( = screen width - margins + cropwidth)
 	ass_track_t* track;
 	long long time; // frame's timestamp, ms
 	double font_scale;
@@ -446,28 +448,33 @@
  * \brief Mapping between script and screen coordinates
  */
 static int x2scr(int x) {
-	return x*frame_context.orig_width / frame_context.track->PlayResX + global_settings->left_margin;
+	return x*frame_context.orig_width_nocrop / frame_context.track->PlayResX +
+		FFMAX(global_settings->left_margin, 0);
 }
 /**
  * \brief Mapping between script and screen coordinates
  */
 static int y2scr(int y) {
-	return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
+	return y * frame_context.orig_height_nocrop / frame_context.track->PlayResY +
+		FFMAX(global_settings->top_margin, 0);
 }
 // the same for toptitles
 static int y2scr_top(int y) {
 	if (global_settings->use_margins)
-		return y * frame_context.orig_height / frame_context.track->PlayResY;
+		return y * frame_context.orig_height_nocrop / frame_context.track->PlayResY;
 	else
-		return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
+		return y * frame_context.orig_height_nocrop / frame_context.track->PlayResY +
+			FFMAX(global_settings->top_margin, 0);
 }
 // the same for subtitles
 static int y2scr_sub(int y) {
 	if (global_settings->use_margins)
-		return y * frame_context.orig_height / frame_context.track->PlayResY +
-		       global_settings->top_margin + global_settings->bottom_margin;
+		return y * frame_context.orig_height_nocrop / frame_context.track->PlayResY +
+			FFMAX(global_settings->top_margin, 0) +
+			FFMAX(global_settings->bottom_margin, 0);
 	else
-		return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
+		return y * frame_context.orig_height_nocrop / frame_context.track->PlayResY +
+			FFMAX(global_settings->top_margin, 0);
 }
 
 static void compute_string_bbox( text_info_t* info, FT_BBox *abbox ) {
@@ -2101,6 +2108,12 @@
 	frame_context.height = global_settings->frame_height;
 	frame_context.orig_width = global_settings->frame_width - global_settings->left_margin - global_settings->right_margin;
 	frame_context.orig_height = global_settings->frame_height - global_settings->top_margin - global_settings->bottom_margin;
+	frame_context.orig_width_nocrop = global_settings->frame_width -
+		FFMAX(global_settings->left_margin, 0) -
+		FFMAX(global_settings->right_margin, 0);
+	frame_context.orig_height_nocrop = global_settings->frame_height -
+		FFMAX(global_settings->top_margin, 0) -
+		FFMAX(global_settings->bottom_margin, 0);
 	frame_context.track = track;
 	frame_context.time = now;