summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2022-09-09 01:01:52 +0200
committerOneric <oneric@oneric.stub>2022-09-24 20:24:40 +0200
commitb6db99a3930b609ca1ba5a0b9930b5c6dc5701dc (patch)
treebee37249cde435269b341be7957da3dd9fab2d05
parent717cb93daa15c3684c502eab092f1341cd0a21e0 (diff)
downloadlibass-b6db99a3930b609ca1ba5a0b9930b5c6dc5701dc.tar.bz2
libass-b6db99a3930b609ca1ba5a0b9930b5c6dc5701dc.tar.xz
render: improve storage res fallback when PAR is set
When storage size is not set, we currently use PlayRes as a fallback hoping it matches the original storage res. We know this is flawed, but even if PlayRes relates to a dimension of the source video, in case of anamorphic video either the native display width or storage width may have been used. We always want the latter, so if PAR information was supplied, try to ensure we get something in the storage aspect ratio. Note, that this could actually also worsen the rendering for unknown storage res cases eg if PlayRes already was the original storage size but the subs got repurposed for a non-anamorphic (re)encode. Though, such reused subs won't render correctly in VSFilter too anyway, so we probably don't need to worry to much about this.
-rw-r--r--libass/ass_render.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c
index 15ce092..682c588 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -978,7 +978,21 @@ ASS_Vector ass_layout_res(ASS_Renderer *render_priv)
return (ASS_Vector) { settings->storage_width, settings->storage_height };
ASS_Track *track = render_priv->track;
- return (ASS_Vector) { track->PlayResX, track->PlayResY };
+ if (settings->par <= 0 || settings->par == 1 ||
+ !render_priv->orig_width || !render_priv->orig_height)
+ return (ASS_Vector) { track->PlayResX, track->PlayResY };
+ if (settings->par > 1)
+ return (ASS_Vector) {
+ lround(track->PlayResY * render_priv->orig_width / render_priv->orig_height
+ / settings->par),
+ track->PlayResY
+ };
+ else
+ return (ASS_Vector) {
+ track->PlayResX,
+ lround(track->PlayResX * render_priv->orig_height / render_priv->orig_width
+ * settings->par)
+ };
}
static void init_font_scale(ASS_Renderer *render_priv)