From 0e1702ad7a6a827d400c87b7a98aea11e54d2127 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Thu, 23 Aug 2012 00:59:46 +0300 Subject: [PATCH] Add ass_set_storage_size and fix related scaling issues \blur radius is not scaled from script to storage resolution but is scaled from storage to display resolution. The same applies to borders and shadows if ScaledBorderAndShadow is "no". (If it is "yes", borders and shadows are scaled from script to display resolution just like before.) --- libass/ass.h | 9 +++++++++ libass/ass_render.c | 9 +++++++-- libass/ass_render.h | 5 +++++ libass/ass_render_api.c | 27 +++++++++++++++++++++++++-- libass/libass.sym | 1 + 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/libass/ass.h b/libass/ass.h index 2d767f7..022668b 100644 --- a/libass/ass.h +++ b/libass/ass.h @@ -159,6 +159,15 @@ void ass_renderer_done(ASS_Renderer *priv); */ void ass_set_frame_size(ASS_Renderer *priv, int w, int h); +/** + * \brief Set the source image size in pixels. The source aspect ratio + * is automatically reset to the value corresponding to this image size. + * \param priv renderer handle + * \param w width + * \param h height + */ +void ass_set_storage_size(ASS_Renderer *priv, int w, int h); + /** * \brief Set shaping level. This is merely a hint, the renderer will use * whatever is available if the request cannot be fulfilled. diff --git a/libass/ass_render.c b/libass/ass_render.c index 2f0732e..6681612 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1308,7 +1308,7 @@ get_bitmap_glyph(ASS_Renderer *render_priv, GlyphInfo *info) outline, border, &hash_val.bm, &hash_val.bm_o, &hash_val.bm_s, info->be, - info->blur * render_priv->border_scale, + info->blur * render_priv->blur_scale, key->shadow_offset, info->border_style, info->border_x || info->border_y); @@ -2242,12 +2242,17 @@ ass_start_frame(ASS_Renderer *render_priv, ASS_Track *track, render_priv->font_scale = settings_priv->font_size_coeff * render_priv->orig_height / render_priv->track->PlayResY; + if (render_priv->storage_height) + render_priv->blur_scale = ((double) render_priv->orig_height) / + render_priv->storage_height; + else + render_priv->blur_scale = 1.; if (render_priv->track->ScaledBorderAndShadow) render_priv->border_scale = ((double) render_priv->orig_height) / render_priv->track->PlayResY; else - render_priv->border_scale = 1.; + render_priv->border_scale = render_priv->blur_scale; render_priv->border_scale *= settings_priv->font_size_coeff; ass_shaper_set_kerning(render_priv->shaper, track->Kerning); diff --git a/libass/ass_render.h b/libass/ass_render.h index 45d19bb..8feeadc 100644 --- a/libass/ass_render.h +++ b/libass/ass_render.h @@ -65,6 +65,8 @@ typedef struct free_list { typedef struct { int frame_width; int frame_height; + int storage_width; // width of the source image + int storage_height; // height of the source image double font_size_coeff; // font size multiplier double line_spacing; // additional line spacing (in frame pixels) double line_position; // vertical position for subtitles, 0-100 (0 = no change) @@ -264,11 +266,14 @@ struct ass_renderer { 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) + int storage_height; // video height before any rescaling + int storage_width; // video width before any rescaling ASS_Track *track; long long time; // frame's timestamp, ms double font_scale; double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio double border_scale; + double blur_scale; RenderContext state; TextInfo text_info; diff --git a/libass/ass_render_api.c b/libass/ass_render_api.c index e70e5ed..babc442 100644 --- a/libass/ass_render_api.c +++ b/libass/ass_render_api.c @@ -43,6 +43,13 @@ static void ass_reconfigure(ASS_Renderer *priv) priv->orig_height_nocrop = settings->frame_height - FFMAX(settings->top_margin, 0) - FFMAX(settings->bottom_margin, 0); + if (settings->storage_height) { + priv->storage_width = settings->storage_width; + priv->storage_height = settings->storage_height; + } else { + priv->storage_width = priv->orig_width; + priv->storage_height = priv->orig_height; + } } void ass_set_frame_size(ASS_Renderer *priv, int w, int h) @@ -50,10 +57,26 @@ void ass_set_frame_size(ASS_Renderer *priv, int w, int h) if (priv->settings.frame_width != w || priv->settings.frame_height != h) { priv->settings.frame_width = w; priv->settings.frame_height = h; - if (priv->settings.aspect == 0.) { + if (priv->settings.aspect == 0.) priv->settings.aspect = ((double) w) / h; + if (priv->settings.storage_aspect == 0.) priv->settings.storage_aspect = ((double) w) / h; - } + ass_reconfigure(priv); + } +} + +void ass_set_storage_size(ASS_Renderer *priv, int w, int h) +{ + if (!w || !h) { + ass_msg(priv->library, MSGL_WARN, + "ass_set_storage_size: ignoring zero storage dimensions"); + return; + } + if (priv->settings.storage_width != w || + priv->settings.storage_height != h) { + priv->settings.storage_width = w; + priv->settings.storage_height = h; + priv->settings.storage_aspect = ((double) w) / h; ass_reconfigure(priv); } } diff --git a/libass/libass.sym b/libass/libass.sym index 32fd94f..2dbbfbe 100644 --- a/libass/libass.sym +++ b/libass/libass.sym @@ -6,6 +6,7 @@ ass_set_style_overrides ass_renderer_init ass_renderer_done ass_set_frame_size +ass_set_storage_size ass_set_margins ass_set_use_margins ass_set_aspect_ratio -- 2.40.0