summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2022-09-19 01:14:18 +0200
committerOneric <oneric@oneric.stub>2022-09-24 22:57:37 +0200
commit7e89ba336942217f4d85ea39dfe9fc2ddddb6dde (patch)
treeb3d863dfb6bdac22f0c92bc6db4db1c8600ac4e8
parentf08f8ea522d20dd9985544c636e45e4984a0d743 (diff)
downloadlibass-7e89ba336942217f4d85ea39dfe9fc2ddddb6dde.tar.bz2
libass-7e89ba336942217f4d85ea39dfe9fc2ddddb6dde.tar.xz
Rename orig_{width,height} and font_scale_x
font_scale_x is a PAR factor and applies to more than just font glyphs, so par_scale_x is a more accurate and natural name. orig_{width,height} can easily be confused with the video's original (storage) resolution, when in fact it is the rendering resolution (after any anamorphic desqueezing and other scaling etc) of the video content area of the whole frame. Thus rename to frame_content_*.
-rw-r--r--libass/ass_render.c52
-rw-r--r--libass/ass_render.h12
-rw-r--r--libass/ass_render_api.c16
3 files changed, 40 insertions, 40 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c
index 07efa88..a076406 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -211,27 +211,27 @@ static ASS_Image *my_draw_bitmap(unsigned char *bitmap, int bitmap_w,
*/
static double x2scr_pos(ASS_Renderer *render_priv, double x)
{
- return x * render_priv->orig_width / render_priv->font_scale_x / render_priv->track->PlayResX +
+ return x * render_priv->frame_content_width / render_priv->par_scale_x / render_priv->track->PlayResX +
render_priv->settings.left_margin;
}
static double x2scr_left(ASS_Renderer *render_priv, double x)
{
if (render_priv->state.explicit || !render_priv->settings.use_margins)
return x2scr_pos(render_priv, x);
- return x * render_priv->fit_width / render_priv->font_scale_x /
+ return x * render_priv->fit_width / render_priv->par_scale_x /
render_priv->track->PlayResX;
}
static double x2scr_right(ASS_Renderer *render_priv, double x)
{
if (render_priv->state.explicit || !render_priv->settings.use_margins)
return x2scr_pos(render_priv, x);
- return x * render_priv->fit_width / render_priv->font_scale_x /
+ return x * render_priv->fit_width / render_priv->par_scale_x /
render_priv->track->PlayResX +
(render_priv->width - render_priv->fit_width);
}
static double x2scr_pos_scaled(ASS_Renderer *render_priv, double x)
{
- return x * render_priv->orig_width / render_priv->track->PlayResX +
+ return x * render_priv->frame_content_width / render_priv->track->PlayResX +
render_priv->settings.left_margin;
}
/**
@@ -239,7 +239,7 @@ static double x2scr_pos_scaled(ASS_Renderer *render_priv, double x)
*/
static double y2scr_pos(ASS_Renderer *render_priv, double y)
{
- return y * render_priv->orig_height / render_priv->track->PlayResY +
+ return y * render_priv->frame_content_height / render_priv->track->PlayResY +
render_priv->settings.top_margin;
}
static double y2scr(ASS_Renderer *render_priv, double y)
@@ -979,18 +979,18 @@ ASS_Vector ass_layout_res(ASS_Renderer *render_priv)
ASS_Track *track = render_priv->track;
if (settings->par <= 0 || settings->par == 1 ||
- !render_priv->orig_width || !render_priv->orig_height)
+ !render_priv->frame_content_width || !render_priv->frame_content_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
+ lround(track->PlayResY * render_priv->frame_content_width / render_priv->frame_content_height
/ settings->par),
track->PlayResY
};
else
return (ASS_Vector) {
track->PlayResX,
- lround(track->PlayResX * render_priv->orig_height / render_priv->orig_width
+ lround(track->PlayResX * render_priv->frame_content_height / render_priv->frame_content_width
* settings->par)
};
}
@@ -999,8 +999,8 @@ static void init_font_scale(ASS_Renderer *render_priv)
{
ASS_Settings *settings_priv = &render_priv->settings;
- double font_scr_w = render_priv->orig_width;
- double font_scr_h = render_priv->orig_height;
+ double font_scr_w = render_priv->frame_content_width;
+ double font_scr_h = render_priv->frame_content_height;
if (!render_priv->state.explicit && render_priv->settings.use_margins) {
font_scr_w = render_priv->fit_width;
font_scr_h = render_priv->fit_height;
@@ -1148,7 +1148,7 @@ get_outline_glyph(ASS_Renderer *priv, GlyphInfo *info)
int32_t scale_base = lshiftwrapi(1, info->drawing_scale - 1);
double w = scale_base > 0 ? (1.0 / scale_base) : 0;
- scale.x = info->scale_x * w * priv->screen_scale_x / priv->font_scale_x;
+ scale.x = info->scale_x * w * priv->screen_scale_x / priv->par_scale_x;
scale.y = info->scale_y * w * priv->screen_scale_y;
desc = 64 * info->drawing_pbo;
asc = val->asc - desc;
@@ -1323,8 +1323,8 @@ static void calc_transform_matrix(ASS_Renderer *render_priv,
double dist = 20000 * render_priv->blur_scale;
z4[2] += dist;
- double scale_x = dist * render_priv->font_scale_x;
- double offs_x = info->pos.x - info->shift.x * render_priv->font_scale_x;
+ double scale_x = dist * render_priv->par_scale_x;
+ double offs_x = info->pos.x - info->shift.x * render_priv->par_scale_x;
double offs_y = info->pos.y - info->shift.y;
for (int i = 0; i < 3; i++) {
m[0][i] = z4[i] * offs_x + x4[i] * scale_x;
@@ -1387,7 +1387,7 @@ get_bitmap_glyph(ASS_Renderer *render_priv, GlyphInfo *info,
ASS_DVector bord = {
64 * info->border_x * render_priv->border_scale_x /
- render_priv->font_scale_x,
+ render_priv->par_scale_x,
64 * info->border_y * render_priv->border_scale_y,
};
double width = info->hspacing_scaled + info->advance.x;
@@ -1428,7 +1428,7 @@ get_bitmap_glyph(ASS_Renderer *render_priv, GlyphInfo *info,
double bord_x =
64 * render_priv->border_scale_x * info->border_x / tr->scale.x /
- render_priv->font_scale_x;
+ render_priv->par_scale_x;
double bord_y =
64 * render_priv->border_scale_y * info->border_y / tr->scale.y;
@@ -2143,7 +2143,7 @@ static bool parse_events(ASS_Renderer *render_priv, ASS_Event *event)
if (!drawing_text.str) {
info->hspacing_scaled = double_to_d6(info->hspacing *
- render_priv->screen_scale_x / render_priv->font_scale_x *
+ render_priv->screen_scale_x / render_priv->par_scale_x *
info->scale_x);
fix_glyph_scaling(render_priv, info);
}
@@ -2367,7 +2367,7 @@ static void calculate_rotation_params(ASS_Renderer *render_priv, ASS_DRect *bbox
while (info) {
info->shift.x = info->pos.x + double_to_d6(device_x - center.x +
info->shadow_x * render_priv->border_scale_x /
- render_priv->font_scale_x);
+ render_priv->par_scale_x);
info->shift.y = info->pos.y + double_to_d6(device_y - center.y +
info->shadow_y * render_priv->border_scale_y);
info = info->next;
@@ -2430,7 +2430,7 @@ static void render_and_combine_glyphs(ASS_Renderer *render_priv,
{
TextInfo *text_info = &render_priv->text_info;
int left = render_priv->settings.left_margin;
- device_x = (device_x - left) * render_priv->font_scale_x + left;
+ device_x = (device_x - left) * render_priv->par_scale_x + left;
unsigned nb_bitmaps = 0;
bool new_run = true;
CombinedBitmapInfo *combined_info = text_info->combined_bitmaps;
@@ -2518,7 +2518,7 @@ static void render_and_combine_glyphs(ASS_Renderer *render_priv,
assert(current_info);
ASS_Vector pos, pos_o;
- info->pos.x = double_to_d6(device_x + d6_to_double(info->pos.x) * render_priv->font_scale_x);
+ info->pos.x = double_to_d6(device_x + d6_to_double(info->pos.x) * render_priv->par_scale_x);
info->pos.y = double_to_d6(device_y) + info->pos.y;
get_bitmap_glyph(render_priv, info, &current_info->leftmost_x, &pos, &pos_o,
&offset, !current_info->bitmap_count, flags);
@@ -2558,7 +2558,7 @@ static void render_and_combine_glyphs(ASS_Renderer *render_priv,
if (info->effect_type == EF_KARAOKE_KF)
info->effect_timing = lround(d6_to_double(info->leftmost_x) +
- d6_to_double(info->effect_timing) * render_priv->font_scale_x);
+ d6_to_double(info->effect_timing) * render_priv->par_scale_x);
for (int j = 0; j < info->bitmap_count; j++) {
info->bitmaps[j].pos.x -= info->x;
@@ -2946,9 +2946,9 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
event_images->height =
text_info->height + text_info->border_bottom + text_info->border_top;
event_images->left =
- (device_x + bbox.x_min) * render_priv->font_scale_x - text_info->border_x + 0.5;
+ (device_x + bbox.x_min) * render_priv->par_scale_x - text_info->border_x + 0.5;
event_images->width =
- (bbox.x_max - bbox.x_min) * render_priv->font_scale_x
+ (bbox.x_max - bbox.x_min) * render_priv->par_scale_x
+ 2 * text_info->border_x + 0.5;
event_images->detect_collisions = render_priv->state.detect_collisions;
event_images->shift_direction = (valign == VALIGN_SUB) ? -1 : 1;
@@ -3018,16 +3018,16 @@ ass_start_frame(ASS_Renderer *render_priv, ASS_Track *track,
// PAR correction
double par = render_priv->settings.par;
if (par == 0.) {
- if (render_priv->orig_width && render_priv->orig_height) {
- double dar = ((double) render_priv->orig_width) /
- render_priv->orig_height;
+ if (render_priv->frame_content_width && render_priv->frame_content_height) {
+ double dar = ((double) render_priv->frame_content_width) /
+ render_priv->frame_content_height;
ASS_Vector layout_res = ass_layout_res(render_priv);
double sar = ((double) layout_res.x) / layout_res.y;
par = dar / sar;
} else
par = 1.0;
}
- render_priv->font_scale_x = par;
+ render_priv->par_scale_x = par;
render_priv->prev_images_root = render_priv->images_root;
render_priv->images_root = NULL;
diff --git a/libass/ass_render.h b/libass/ass_render.h
index 9034b35..2c5d515 100644
--- a/libass/ass_render.h
+++ b/libass/ass_render.h
@@ -308,16 +308,16 @@ struct ass_renderer {
int eimg_size; // allocated buffer size
// frame-global data
- int width, height; // screen dimensions
- int orig_height; // frame height ( = screen height - margins )
- int orig_width; // frame width ( = screen width - margins )
- double fit_height; // frame height without zoom & pan (fit to screen & letterboxed)
- double fit_width; // frame width without zoom & pan (fit to screen & letterboxed)
+ int width, height; // screen dimensions (the whole frame from ass_set_frame_size)
+ int frame_content_height; // content frame height ( = screen height - API margins )
+ int frame_content_width; // content frame width ( = screen width - API margins )
+ double fit_height; // content frame height without zoom & pan (fit to screen & letterboxed)
+ double fit_width; // content frame width without zoom & pan (fit to screen & letterboxed)
ASS_Track *track;
long long time; // frame's timestamp, ms
double screen_scale_x;
double screen_scale_y;
- double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
+ double par_scale_x; // x scale applied to e.g. glyphs to preserve text aspect ratio
double border_scale_x;
double border_scale_y;
double blur_scale;
diff --git a/libass/ass_render_api.c b/libass/ass_render_api.c
index 4790565..c324395 100644
--- a/libass/ass_render_api.c
+++ b/libass/ass_render_api.c
@@ -33,20 +33,20 @@ static void ass_reconfigure(ASS_Renderer *priv)
priv->width = settings->frame_width;
priv->height = settings->frame_height;
- priv->orig_width = settings->frame_width - settings->left_margin -
+ priv->frame_content_width = settings->frame_width - settings->left_margin -
settings->right_margin;
- priv->orig_height = settings->frame_height - settings->top_margin -
+ priv->frame_content_height = settings->frame_height - settings->top_margin -
settings->bottom_margin;
priv->fit_width =
- (long long) priv->orig_width * priv->height >=
- (long long) priv->orig_height * priv->width ?
+ (long long) priv->frame_content_width * priv->height >=
+ (long long) priv->frame_content_height * priv->width ?
priv->width :
- (double) priv->orig_width * priv->height / priv->orig_height;
+ (double) priv->frame_content_width * priv->height / priv->frame_content_height;
priv->fit_height =
- (long long) priv->orig_width * priv->height <=
- (long long) priv->orig_height * priv->width ?
+ (long long) priv->frame_content_width * priv->height <=
+ (long long) priv->frame_content_height * priv->width ?
priv->height :
- (double) priv->orig_height * priv->width / priv->orig_width;
+ (double) priv->frame_content_height * priv->width / priv->frame_content_width;
}
void ass_set_frame_size(ASS_Renderer *priv, int w, int h)