From fef4481bfec74ea20e3c78cedd657977cac16434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 31 Aug 2023 22:39:04 +0200 Subject: [PATCH] m_option: make m_rect_apply center based This makes it easier to apply crops without need to manually calc the offset. I wanted for it to be top-left corner based, but maybe it was not that good idea in retrospect. Also rename scrw/scrh, since they don't refer to screen. It was copied form m_geometry apply. --- DOCS/man/options.rst | 2 +- options/m_option.c | 14 +++++--------- options/m_option.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index b271ab4a62..139e32a289 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1571,7 +1571,7 @@ Video applied to the source video rectangle (before anamorphic stretch) by the VO. A crop rectangle that is not within the video rectangle will be ignored. This works with hwdec, unlike the equivalent 'lavfi-crop'. Setting the crop - to '0x0' disables it. + to '0' disables it. When offset is omitted, the central area will be cropped. ``--video-zoom=`` Adjust the video display scale factor by the given value. The parameter is diff --git a/options/m_option.c b/options/m_option.c index 14fd119704..b7cc4f7996 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2381,20 +2381,16 @@ const m_option_type_t m_option_type_size_box = { .equal = geometry_equal, }; -void m_rect_apply(struct mp_rect *rc, int scrw, int scrh, struct m_geometry *gm) +void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm) { - *rc = (struct mp_rect){0}; - m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, scrw, scrh, gm); + *rc = (struct mp_rect){0, 0, w, h}; + m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, w, h, gm); if (!gm->xy_valid && gm->wh_valid && rc->x1 == 0 && rc->y1 == 0) return; - if (!gm->xy_valid) { - rc->x0 = 0; - rc->y0 = 0; - } if (!gm->wh_valid || rc->x1 == 0 || rc->x1 == INT_MIN) - rc->x1 = scrw - rc->x0; + rc->x1 = w - rc->x0; if (!gm->wh_valid || rc->y1 == 0 || rc->y1 == INT_MIN) - rc->y1 = scrh - rc->y0; + rc->y1 = h - rc->y0; rc->x1 += rc->x0; rc->y1 += rc->y0; } diff --git a/options/m_option.h b/options/m_option.h index 0683822988..3e86485930 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -105,7 +105,7 @@ struct m_geometry { void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh, struct m_geometry *gm); -void m_rect_apply(struct mp_rect *rc, int scrw, int scrh, struct m_geometry *gm); +void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm); struct m_channels { bool set : 1;