Avoid text deformation and subtitles moving outside the screen in pan-and-scan
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Fri, 19 Oct 2007 18:16:23 +0000 (18:16 +0000)
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Fri, 19 Oct 2007 18:16:23 +0000 (18:16 +0000)
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].

git-svn-id: svn://git.mplayerhq.hu/mplayer/trunk@24815 b3059339-0415-0410-9bf9-f77b7e298cf2

libass/ass_render.c
libvo/vo_gl.c

index d0facd7..5b97b8a 100644 (file)
@@ -184,6 +184,8 @@ typedef struct frame_context_s {
        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 @@ static ass_image_t* render_text(text_info_t* text_info, int dst_x, int dst_y)
  * \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 @@ static int ass_start_frame(ass_renderer_t *priv, ass_track_t* track, long long n
        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;
 
index a81c783..9b8e55f 100644 (file)
@@ -907,8 +907,8 @@ static int control(uint32_t request, void *data, ...)
       if (scaled_osd) {r->w = image_width; r->h = image_height;}
       else if (vo_fs) {
         r->w = vo_screenwidth; r->h = vo_screenheight;
-        r->ml = r->mr = ass_border_x > 0 ? ass_border_x : 0;
-        r->mt = r->mb = ass_border_y > 0 ? ass_border_y : 0;
+        r->ml = r->mr = ass_border_x;
+        r->mt = r->mb = ass_border_y;
       } else {
         r->w = vo_dwidth; r->h = vo_dheight;
       }