Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[External] Decoding HDR AVIF image consumes huge amounts of RAM #4968

Open
benstevens48 opened this issue Dec 13, 2024 · 1 comment
Open

Comments

@benstevens48
Copy link

Describe the bug

Windows 11 24H2 added support in WIC for decoding HDR AVIF images, which decode to a 64bpp floating point pixel format. However, the decoding process seems to consume a huge amount of RAM. I tested a 20 mega-pixel HDR AVIF exported from Lightroom (which uses the PQ HDR curve I think) and decoding it (in a C++ component) consumes about 2.7GB of RAM (peak in the Visual Studio debugger). The decoded image itself should only consume about 160MB of RAM, and I would expect 2 times or maybe 3 times this at most to be used during decoding. Also, maybe this is inevitable, but it's quite slow. It's much quicker to take a 64bpp PNG with PQ transfer curve, decode that to WIC without color management then use Diret2D to apply the PQ transfer curve.

Steps to reproduce the bug

See description.

Expected behavior

At most ~500MB of RAM used for decoding a 20MP HDR AVIF image, not 2.7GB.

Screenshots

No response

NuGet package version

None

Packaging type

No response

Windows version

No response

IDE

No response

Additional context

No response

@benstevens48
Copy link
Author

I have a repro but the image came from a user and I don't really want to make it public. Is there any way I can share it privately?

I discovered that the decode actually fails entirely when compiled in x86 (32-bit) mode due to an out of memory exception!

The code for the repro is very simple and looks like this. Probably don't even need the last few lines which are just to display the image.

        private async void runDecodeButton_Click(object sender, RoutedEventArgs e) {
            var bitmapImage = new BitmapImage();
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Test.avif"));
            using (var fs = await file.OpenReadAsync()) {
                await bitmapImage.SetSourceAsync(fs);
            }
            var rawPixelsPerViewPixel = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
            image.Width = bitmapImage.PixelWidth / rawPixelsPerViewPixel;
            image.Height = bitmapImage.PixelHeight / rawPixelsPerViewPixel;
            image.Source = bitmapImage;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants