From e54f93bf7d144737df4b0331017164360c9121ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 22 Apr 2026 22:24:09 +0200 Subject: Fix reading of RGB0 images. We would allocate 3 bytes per pixel instead of 4. I couldn't see a way to get FFmpeg to tell us about this (unless we used FFmpeg's stride somehow maybe?) --- src/lib/image.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/lib') diff --git a/src/lib/image.cc b/src/lib/image.cc index 95de4bc03..0810fbbea 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -1219,6 +1219,17 @@ Image::bytes_per_pixel(int component) const } #endif + if ( + _pixel_format == AV_PIX_FMT_0RGB || + _pixel_format == AV_PIX_FMT_RGB0 || + _pixel_format == AV_PIX_FMT_0BGR || + _pixel_format == AV_PIX_FMT_BGR0) { + /* Each pixel has an empty byte which we need to account for when allocating, + * otherwise we'll corrupt the image. + */ + bpp[3] = bpp[0]; + } + if ((d->flags & AV_PIX_FMT_FLAG_PLANAR) == 0) { /* Not planar; sum them up */ return bpp[0] + bpp[1] + bpp[2] + bpp[3]; -- cgit v1.2.3