From 77f730f63c340fc88e8c3db0cb73cff1807d7432 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 22 May 2020 14:18:35 +0200 Subject: mp_image: add helper for clearing regions outside of a rectangle Not sure if generally useful; the following commit uses it. --- video/mp_image.c | 14 ++++++++++++++ video/mp_image.h | 2 ++ 2 files changed, 16 insertions(+) (limited to 'video') diff --git a/video/mp_image.c b/video/mp_image.c index 81d2b7e04f..0e95a59808 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -678,6 +678,20 @@ void mp_image_clear(struct mp_image *img, int x0, int y0, int x1, int y1) } } +void mp_image_clear_rc(struct mp_image *mpi, struct mp_rect rc) +{ + mp_image_clear(mpi, rc.x0, rc.y0, rc.x1, rc.y1); +} + +// Clear the are of the image _not_ covered by rc. +void mp_image_clear_rc_inv(struct mp_image *mpi, struct mp_rect rc) +{ + struct mp_rect clr[4]; + int cnt = mp_rect_subtract(&(struct mp_rect){0, 0, mpi->w, mpi->h}, &rc, clr); + for (int n = 0; n < cnt; n++) + mp_image_clear_rc(mpi, clr[n]); +} + void mp_image_vflip(struct mp_image *img) { for (int p = 0; p < img->num_planes; p++) { diff --git a/video/mp_image.h b/video/mp_image.h index 5b7eada496..dd82251464 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -137,6 +137,8 @@ void mp_image_setrefp(struct mp_image **p_img, struct mp_image *new_value); void mp_image_unrefp(struct mp_image **p_img); void mp_image_clear(struct mp_image *mpi, int x0, int y0, int x1, int y1); +void mp_image_clear_rc(struct mp_image *mpi, struct mp_rect rc); +void mp_image_clear_rc_inv(struct mp_image *mpi, struct mp_rect rc); void mp_image_crop(struct mp_image *img, int x0, int y0, int x1, int y1); void mp_image_crop_rc(struct mp_image *img, struct mp_rect rc); void mp_image_vflip(struct mp_image *img); -- cgit v1.2.3