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

Limitations of detecting ImageFormat / ContainerFormat from file extension #799

Closed
elyoh opened this issue May 31, 2024 · 1 comment · Fixed by #844
Closed

Limitations of detecting ImageFormat / ContainerFormat from file extension #799

elyoh opened this issue May 31, 2024 · 1 comment · Fixed by #844
Labels
enhancement ✨ An improvement to existing APIs

Comments

@elyoh
Copy link
Contributor

elyoh commented May 31, 2024

public static Guid GetForFilename(ReadOnlySpan<char> filename)

When loading / saving a texture back to a file, we find that WICFormatHelper.GetForFilename performs a case sensitive search on the file extension to determine the desired format. However, at least on Windows, file extensions are case insensitive and therefore this unexpectedly gives an ArgumentException for upper or (pathological) mixed case extensions.

Further, the list of supported extensions also appears incomplete. Taking the results returned by .NET WPF's System.Windows.Media.Imaging.BitmapDecoder.CodecInfo.FileExtensions as a baseline, we might expect at least the following to be mapped as well:
.dib, .rle => GUID.GUID_ContainerFormatBmp
.jpe, .jfif, .exif => GUID.GUID_ContainerFormatJpeg
.tif => GUID.GUID_ContainerFormatTiff

Clearly users can work round the above by using the SaveTexture overload which passes a FileStream and ImageFormat directly but it would be nice if the above concerns were addressed.

@rickbrew
Copy link
Collaborator

rickbrew commented May 31, 2024

Since this is using WIC then it should be possible in principle to support and correctly map all of the file extensions that WIC specifies support for.

See IWICBitmapCodecInfo::GetFileExtensions

It'd require a linear scan through all of the codecs and their extensions, but that shouldn't be very expensive (compared to the decoding and file I/O ...).

elyoh added a commit to elyoh/ComputeSharp that referenced this issue Aug 27, 2024
…ile extension

Fixes Sergio0694#799.

Ensures case insensitive comparison of the file extension.
Manually maps all supported file extensions listed by built in container formats.
elyoh added a commit to elyoh/ComputeSharp that referenced this issue Aug 27, 2024
@Sergio0694 Sergio0694 added the enhancement ✨ An improvement to existing APIs label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ An improvement to existing APIs
Projects
None yet
3 participants