Sergio0694 / ComputeSharp

A .NET library to run C# code in parallel on the GPU through DX12, D2D1, and dynamically generated HLSL compute and pixel shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
MIT License
2.65k stars 122 forks source link

Support saving textures to non-built in ContainerFormats #800

Open elyoh opened 1 month ago

elyoh commented 1 month ago

Rationale

WIC is extensible and allows users to register other ContainerFormats for use. Today, if a user has installed the HEIF Image Extensions from the Microsoft Store, they can load an image in that format by passing a FileStream to the texture.

During save, the output format is either determined from the file extension (see #799) or the provided ImageFormat. Only built in ContainerFormats can be used.

Proposed API

The proposed API would allow users to specify the output format using a ContainerFormat provided in the form of a Guid instead.

Drawbacks

Unknown.

Alternatives

Unknown.

Other thoughts

In .NET WPF, a custom WIC encoder can be constructed from the ContainerFormat Guid. For example using BitmapEncoder.Create(new("E1E62521-6787-405B-A339-500715B5763F")) hooks up the HEIF Image Extensions from the Microsoft Store and allows users to save images in this format. Note this only works on later .NET and not in the .NET Framework due to a bug (https://github.com/dotnet/wpf/issues/6344).