diff options
author | wm4 <wm4@nowhere> | 2012-12-25 22:29:49 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-01-13 20:04:12 +0100 |
commit | 717d904bbc20e06e2c6c71613d59e065845ff209 (patch) | |
tree | 6f758cff6d98e579b767952894023997618c44d5 /video/mp_image.c | |
parent | ded932dbd40e326a8d42acb8c4b8297046f08695 (diff) | |
download | mpv-717d904bbc20e06e2c6c71613d59e065845ff209.tar.bz2 mpv-717d904bbc20e06e2c6c71613d59e065845ff209.tar.xz |
mp_image: add mp_image_crop()
Actually stolen from draw_bmp.c.
Diffstat (limited to 'video/mp_image.c')
-rw-r--r-- | video/mp_image.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/video/mp_image.c b/video/mp_image.c index 4df4d2e17f..256e908198 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -335,6 +335,28 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) } } +// Crop the given image to (x0, y0)-(x1, y1) (bottom/right border exclusive) +// x0/y0 must be naturally aligned. +void mp_image_crop(struct mp_image *img, int x0, int y0, int x1, int y1) +{ + assert(x0 >= 0 && y0 >= 0); + assert(x0 <= x1 && y0 <= y1); + assert(x1 <= img->w && y1 <= img->h); + assert(!(x0 & (img->fmt.align_x - 1))); + assert(!(y0 & (img->fmt.align_y - 1))); + + for (int p = 0; p < img->num_planes; ++p) { + img->planes[p] += (y0 >> img->fmt.ys[p]) * img->stride[p] + + (x0 >> img->fmt.xs[p]) * img->fmt.bpp[p] / 8; + } + mp_image_set_size(img, x1 - x0, y1 - y0); +} + +void mp_image_crop_rc(struct mp_image *img, struct mp_rect rc) +{ + mp_image_crop(img, rc.x0, rc.y0, rc.x1, rc.y1); +} + void mp_image_clear(struct mp_image *mpi, int x0, int y0, int w, int h) { int y; |