diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-08-25 19:21:21 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-08-31 17:37:42 +0000 |
commit | f3f1a79fe3ad9bdae344559ec5802c184af41112 (patch) | |
tree | 8ad67cec885e18f6d0618dc9b220288574e1e98f /common | |
parent | f3211db7911c89883dc392ddeef8ffe53aeb49b0 (diff) | |
download | mpv-f3f1a79fe3ad9bdae344559ec5802c184af41112.tar.bz2 mpv-f3f1a79fe3ad9bdae344559ec5802c184af41112.tar.xz |
vo: add --video-crop
Just cropping by VO that works with hwdec.
Fixes: #12222
Diffstat (limited to 'common')
-rw-r--r-- | common/common.c | 31 | ||||
-rw-r--r-- | common/common.h | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/common/common.c b/common/common.c index 79f135a516..e59db7e906 100644 --- a/common/common.c +++ b/common/common.c @@ -126,6 +126,37 @@ bool mp_rect_equals(const struct mp_rect *rc1, const struct mp_rect *rc2) rc1->x1 == rc2->x1 && rc1->y1 == rc2->y1; } +// Rotate mp_rect by 90 degrees increments +void mp_rect_rotate(struct mp_rect *rc, int w, int h, int rotation) +{ + rotation %= 360; + + if (rotation >= 180) { + rotation -= 180; + MPSWAP(int, rc->x0, rc->x1); + MPSWAP(int, rc->y0, rc->y1); + } + + if (rotation == 90) { + *rc = (struct mp_rect) { + .x0 = rc->y1, + .y0 = rc->x0, + .x1 = rc->y0, + .y1 = rc->x1, + }; + } + + if (rc->x1 < rc->x0) { + rc->x0 = w - rc->x0; + rc->x1 = w - rc->x1; + } + + if (rc->y1 < rc->y0) { + rc->y0 = h - rc->y0; + rc->y1 = h - rc->y1; + } +} + // Compute rc1-rc2, put result in res_array, return number of rectangles in // res_array. In the worst case, there are 4 rectangles, so res_array must // provide that much storage space. diff --git a/common/common.h b/common/common.h index 93a8ded918..a30a5d6e0c 100644 --- a/common/common.h +++ b/common/common.h @@ -109,6 +109,7 @@ bool mp_rect_contains(struct mp_rect *rc, int x, int y); bool mp_rect_equals(const struct mp_rect *rc1, const struct mp_rect *rc2); int mp_rect_subtract(const struct mp_rect *rc1, const struct mp_rect *rc2, struct mp_rect res_array[4]); +void mp_rect_rotate(struct mp_rect *rc, int w, int h, int rotation); unsigned int mp_log2(uint32_t v); uint32_t mp_round_next_power_of_2(uint32_t v); |