LibGfx/AVIF: Always reduce decoding output to a bit depth of 8

Gfx::Bitmap only supports a bit depth of 8, therefore we refused to
load AVIF images which didn't have this bit depth.

However, we can tell the libavif decoder to reduce the output depth by
setting avifRGBImage.depth to 8. This allows us to support any input
depth.

Makes images load on https://www.ikea.com/ which uses Cloudflare Images
to re-encode their images to 16-bit AVIF.
This commit is contained in:
Luke Wilde 2025-06-16 18:51:34 +01:00 committed by Jelle Raaijmakers
commit ffae0d8b2d
Notes: github-actions[bot] 2025-06-18 12:28:46 +00:00
2 changed files with 10 additions and 4 deletions

View file

@ -83,9 +83,6 @@ static ErrorOr<void> decode_avif_header(AVIFLoadingContext& context)
if (result != AVIF_RESULT_OK)
return Error::from_string_literal("Failed to decode AVIF");
if (context.decoder->image->depth != 8)
return Error::from_string_literal("Unsupported bitdepth");
// Image header now decoded, save some results for fast access in other parts of the plugin.
context.size = IntSize { context.decoder->image->width, context.decoder->image->height };
context.has_alpha = context.decoder->alphaPresent == 1;
@ -114,6 +111,7 @@ static ErrorOr<void> decode_avif_image(AVIFLoadingContext& context)
rgb.pixels = bitmap->scanline_u8(0);
rgb.rowBytes = bitmap->pitch();
rgb.format = avifRGBFormat::AVIF_RGB_FORMAT_BGRA;
rgb.depth = 8;
avifResult result = avifImageYUVToRGB(context.decoder->image, &rgb);
if (result != AVIF_RESULT_OK)