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?) --- run/tests | 2 +- src/lib/image.cc | 11 +++++++++++ test/image_test.cc | 12 ++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/run/tests b/run/tests index 839dc8dd4..1c1a4de11 100755 --- a/run/tests +++ b/run/tests @@ -3,7 +3,7 @@ # e.g. --run_tests=foo set -e -PRIVATE_GIT="7cbcb10afc73ab559ae9b907881881892aa6d57f" +PRIVATE_GIT="eaa907382be3276e8275858219bd73c816ff5c77" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $DIR/environment 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]; diff --git a/test/image_test.cc b/test/image_test.cc index 807f88d04..6d566aac7 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -759,3 +759,15 @@ BOOST_AUTO_TEST_CASE(over_crop_test) check_image("test/data/" + filename, "build/test/" + filename); } + +BOOST_AUTO_TEST_CASE(rgb0_image_test) +{ + auto proxy = make_shared(TestPaths::private_data() / "rgb0.tif"); + write_image( + proxy->image(Image::Alignment::PADDED).image->convert_pixel_format( + dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, Image::Alignment::COMPACT, false + ), "build/test/rgb0.png" + ); + check_image(TestPaths::private_data() / "rgb0.png", "build/test/rgb0.png"); +} + -- cgit v1.2.3