From 6eb0dc54477aebe49c14fc17046cd08493177630 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 2 Nov 2019 18:49:17 +0100 Subject: zimg: support subsampled chroma with non-aligned image sizes --- video/zimg.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/video/zimg.c b/video/zimg.c index 16987f3561..04a500705d 100644 --- a/video/zimg.c +++ b/video/zimg.c @@ -641,8 +641,15 @@ static bool setup_format(zimg_image_format *zfmt, struct mp_zimg_repack *r, r->zplanes = desc.num_planes; - zfmt->width = fmt.w; - zfmt->height = fmt.h; + // Note: formats with subsampled chroma may have odd width or height in mpv + // and FFmpeg. This is because the width/height is actually a cropping + // rectangle. Reconstruct the image allocation size and set the cropping. + zfmt->width = MP_ALIGN_UP(fmt.w, desc.chroma_w); + zfmt->height = MP_ALIGN_UP(fmt.h, desc.chroma_h); + if (zfmt->width != fmt.w) + zfmt->active_region.width = fmt.w; + if (zfmt->height != fmt.h) + zfmt->active_region.height = fmt.h; zfmt->subsample_w = mp_log2(desc.chroma_w); zfmt->subsample_h = mp_log2(desc.chroma_h); -- cgit v1.2.3