diff options
-rw-r--r-- | libass/ass.h | 13 | ||||
-rw-r--r-- | libass/ass_render.c | 15 | ||||
-rw-r--r-- | libass/ass_render.h | 3 | ||||
-rw-r--r-- | libass/ass_render_api.c | 16 |
4 files changed, 28 insertions, 19 deletions
diff --git a/libass/ass.h b/libass/ass.h index bd32458..1e662ba 100644 --- a/libass/ass.h +++ b/libass/ass.h @@ -167,8 +167,11 @@ 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. + * \brief Set the source image size in pixels. + * This is used to calculate the source aspect ratio and the blur scale. If + * a custom pixel aspect ratio is set with ass_set_aspect_ratio(), the source + * image size has no influence on the aspect ratio. + * The source image size can be reset to default by setting w and h to 0. * \param priv renderer handle * \param w width * \param h height @@ -202,6 +205,12 @@ void ass_set_use_margins(ASS_Renderer *priv, int use); /** * \brief Set aspect ratio parameters. + * You can also pass a pixel aspect ratio as dar, and set sar to 1.0. libass + * uses dar/sar as final pixel aspect ratio, and doesn't use dar or sar for + * anything else. If the pixel aspect ratio is 0 (setting dar=0 and sar=1), or + * if the aspect ratio has never been set by calling this function, libass will + * calculate a fallback value out of frame size and storage size. If the + * storage size has not been set, a pixel aspect ratio of 1 is assumed. * \param priv renderer handle * \param dar display aspect ratio (DAR), prescaled for output PAR * \param sar storage aspect ratio (SAR) diff --git a/libass/ass_render.c b/libass/ass_render.c index de27641..67ecb9c 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -2264,8 +2264,19 @@ ass_start_frame(ASS_Renderer *render_priv, ASS_Track *track, ass_shaper_set_level(render_priv->shaper, render_priv->settings.shaper); // PAR correction - render_priv->font_scale_x = render_priv->settings.aspect / - render_priv->settings.storage_aspect; + double par = render_priv->settings.par; + if (par == 0.) { + if (settings_priv->frame_width && settings_priv->frame_height && + settings_priv->storage_width && settings_priv->storage_height) { + double dar = ((double) settings_priv->frame_width) / + settings_priv->frame_height; + double sar = ((double) settings_priv->storage_width) / + settings_priv->storage_height; + par = sar / dar; + } else + par = 1.0; + } + render_priv->font_scale_x = par; render_priv->prev_images_root = render_priv->images_root; render_priv->images_root = 0; diff --git a/libass/ass_render.h b/libass/ass_render.h index 53343fd..ecfca61 100644 --- a/libass/ass_render.h +++ b/libass/ass_render.h @@ -79,8 +79,7 @@ typedef struct { int right_margin; 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 storage_aspect; // pixel ratio of the source image + double par; // user defined pixel aspect ratio (0 = unset) ASS_Hinting hinting; ASS_ShapingLevel shaper; diff --git a/libass/ass_render_api.c b/libass/ass_render_api.c index babc442..80af81f 100644 --- a/libass/ass_render_api.c +++ b/libass/ass_render_api.c @@ -57,26 +57,16 @@ 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.) - 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); } } @@ -111,9 +101,9 @@ void ass_set_use_margins(ASS_Renderer *priv, int use) void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar) { - if (priv->settings.aspect != dar || priv->settings.storage_aspect != sar) { - priv->settings.aspect = dar; - priv->settings.storage_aspect = sar; + double par = dar / sar; + if (priv->settings.par != par) { + priv->settings.par = par; ass_reconfigure(priv); } } |