From 20e584f60bdac96ed915151cf0f92d8282c0a0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Mon, 18 Sep 2023 13:28:59 +0200 Subject: [PATCH] options: make video-crop validation more strict --- DOCS/man/options.rst | 2 +- TOOLS/lua/autocrop.lua | 4 ++-- options/m_option.c | 16 +++++++++------- player/command.c | 3 +-- player/video.c | 3 +-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index baad2f6e1f..f6fde85955 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1574,7 +1574,7 @@ Video This works with hwdec, unlike the equivalent 'lavfi-crop'. When offset is omitted, the central area will be cropped. Setting the crop to empty one ``--video-crop=0x0+0+0`` overrides container crop and disables cropping. - Setting the crop to ``--video-crop=0`` disables manual cropping and restores + Setting the crop to ``--video-crop=""`` disables manual cropping and restores the container crop if it's specified. ``--video-zoom=`` diff --git a/TOOLS/lua/autocrop.lua b/TOOLS/lua/autocrop.lua index 8c3adfb0c7..b6144aeea1 100644 --- a/TOOLS/lua/autocrop.lua +++ b/TOOLS/lua/autocrop.lua @@ -124,8 +124,8 @@ end function remove_filter(label) if options.use_vo_crop and label == labels.crop then - if mp.get_property('video-crop') ~= '0x0' then - mp.command(string.format("%s set video-crop 0", command_prefix)) + if mp.get_property('video-crop') ~= "" then + mp.command(string.format("%s set video-crop ''", command_prefix)) return true end return false diff --git a/options/m_option.c b/options/m_option.c index 01f4da9195..892c38b422 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2393,8 +2393,10 @@ void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm) rc->x1 = w - rc->x0; if (!gm->wh_valid || rc->y1 == 0 || rc->y1 == INT_MIN) rc->y1 = h - rc->y0; - rc->x1 += rc->x0; - rc->y1 += rc->y0; + if (gm->wh_valid && (gm->w || gm->h)) + rc->x1 += rc->x0; + if (gm->wh_valid && (gm->w || gm->h)) + rc->y1 += rc->y0; } static int parse_rect(struct mp_log *log, const m_option_t *opt, @@ -2408,12 +2410,12 @@ static int parse_rect(struct mp_log *log, const m_option_t *opt, if (!parse_geometry_str(&gm, param)) goto exit; - if (gm.x_sign || gm.y_sign || gm.ws || - (gm.wh_valid && (gm.w < 0 || gm.h < 0)) || - (gm.xy_valid && (gm.x < 0 || gm.y < 0))) - { + bool invalid = gm.x_sign || gm.y_sign || gm.ws; + invalid |= gm.wh_valid && (gm.w < 0 || gm.h < 0); + invalid |= gm.wh_valid && !gm.xy_valid && gm.w <= 0 && gm.h <= 0; + + if (invalid) goto exit; - } if (dst) *((struct m_geometry *)dst) = gm; diff --git a/player/command.c b/player/command.c index 6416ba6db3..15177ca67c 100644 --- a/player/command.c +++ b/player/command.c @@ -2338,8 +2338,7 @@ static struct mp_image_params get_video_out_params(struct MPContext *mpctx) struct mp_image_params o_params = mpctx->vo_chain->filter->output_params; if (mpctx->video_out) { struct m_geometry *gm = &mpctx->video_out->opts->video_crop; - if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->w_per > 0 || - gm->h > 0 || gm->h_per > 0))) + if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->h > 0))) { m_rect_apply(&o_params.crop, o_params.w, o_params.h, gm); } diff --git a/player/video.c b/player/video.c index 6f5a69bcc7..e4b34b0790 100644 --- a/player/video.c +++ b/player/video.c @@ -1015,8 +1015,7 @@ static void apply_video_crop(struct MPContext *mpctx, struct vo *vo) for (int n = 0; n < mpctx->num_next_frames; n++) { struct m_geometry *gm = &vo->opts->video_crop; struct mp_image_params p = mpctx->next_frames[n]->params; - if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->w_per > 0 || - gm->h > 0 || gm->h_per > 0))) + if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->h > 0))) { m_rect_apply(&p.crop, p.w, p.h, gm); }