Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds a decoder for XBM files, covering the easy part of #2410 .
My motivation for adding this is that, even though the XBM format is old and inefficient,
.xbm
files still stick around on Linux systems and I'd like for image viewers using theimage
crate to be able to interpret them.Since XBM is not a very common format, the decoder is disabled by default and is not included in the default feature list. (I only see XBM files used for icons and cursors, for which PNG and binary PBM are better choices.)
I've tried to make this implementation as reliable and unlikely to need further improvement as I can:
unsafe
.Seek
, and runs in O(n) time.Note: this PR was in large part made by looking at how the other image formats are handled. I was not able to test the xbm fuzzer due to a random LLVM symbol error that I am still trying to figure out (Edit: updating libfuzzer-sys version to 0.4.9 in
fuzz/Cargo.toml
fixes it for me. Edit 2: have now fuzzed this for a few hours using a seed corpus of valid images, without crashes).I plan to make a PR for XPM decoding later, depending on what feedback and improvements this gets. (The XPM decoder has already been written and is at https://github.com/mstoeckl/image/commits/xpm/, but I'm holding off on further improvements until I know what is needed. I could also make a parallel PR for it now, if you'd like.)
Update: for draft branches using the possible new image-extras repository and decoding hook framework, see https://github.com/mstoeckl/image/commits/xbm-hook and https://github.com/mstoeckl/image-extras/commits/xbm .