]> granicus.if.org Git - libass/commitdiff
PAR correction for rendering at non-video resolution
authorGrigori Goronzy <greg@blackbox>
Mon, 29 Jun 2009 15:05:44 +0000 (17:05 +0200)
committerGrigori Goronzy <greg@blackbox>
Mon, 29 Jun 2009 15:34:10 +0000 (17:34 +0200)
The most prominent ASS/SSA renderer (VSFilter) conveniently ignores the
real aspect ratio, and everyone seems to rely on that.  This is fine
when the subtitles are rendered before anamorphic video is stretched
to its native aspect ratio, but results in wrongly stretched text with
native renderers (EOSD).  It can be fixed by making libass aware of
the pixel ratio of the video.  ass_set_aspect_ratio now requires an
extra argument that specifies the pixel ratio, which is just width /
height of the video after decoding.

Glyphs are stretched in x direction before transformation (rotation,
shearing), so there are still issues with transformed glyphs to be
fixed.

libass/ass.h
libass/ass_render.c

index 304b42eeea479ae8d5e36f802450d8accfe102e5..6dd28eccdf38aa1c87d408a01c20479deeb80b6f 100644 (file)
@@ -83,7 +83,7 @@ void ass_renderer_done(ass_renderer_t *priv);
 void ass_set_frame_size(ass_renderer_t *priv, int w, int h);
 void ass_set_margins(ass_renderer_t *priv, int t, int b, int l, int r);
 void ass_set_use_margins(ass_renderer_t *priv, int use);
-void ass_set_aspect_ratio(ass_renderer_t *priv, double ar);
+void ass_set_aspect_ratio(ass_renderer_t *priv, double ar, double par);
 void ass_set_font_scale(ass_renderer_t *priv, double font_scale);
 void ass_set_hinting(ass_renderer_t *priv, ass_hinting_t ht);
 void ass_set_line_spacing(ass_renderer_t *priv, double line_spacing);
index d3d53e40c4cc7980f696f54521e9114f86ded82e..79722e2a49a9eccd60f4431d1a737a071c58f3b6 100644 (file)
@@ -69,6 +69,7 @@ typedef struct ass_settings_s {
     int use_margins;            // 0 - place all subtitles inside original frame
     // 1 - use margins for placing toptitles and subtitles
     double aspect;              // frame aspect ratio, d_width / d_height.
+    double pixel_ratio;         // pixel ratio of the source image
     ass_hinting_t hinting;
 
     char *default_font;
@@ -2742,10 +2743,11 @@ void ass_set_use_margins(ass_renderer_t *priv, int use)
     priv->settings.use_margins = use;
 }
 
-void ass_set_aspect_ratio(ass_renderer_t *priv, double ar)
+void ass_set_aspect_ratio(ass_renderer_t *priv, double ar, double par)
 {
-    if (priv->settings.aspect != ar) {
+    if (priv->settings.aspect != ar || priv->settings.pixel_ratio != par) {
         priv->settings.aspect = ar;
+        priv->settings.pixel_ratio = par;
         ass_reconfigure(priv);
     }
 }
@@ -2840,7 +2842,9 @@ ass_start_frame(ass_renderer_t *render_priv, ass_track_t *track,
     else
         render_priv->border_scale = 1.;
 
-    render_priv->font_scale_x = 1.;
+    // PAR correction
+    render_priv->font_scale_x = render_priv->settings.aspect /
+                                render_priv->settings.pixel_ratio;
 
     render_priv->prev_images_root = render_priv->images_root;
     render_priv->images_root = 0;