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

Add XBM decoder #2416

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add XBM decoder #2416

wants to merge 1 commit into from

Conversation

mstoeckl
Copy link
Contributor

@mstoeckl mstoeckl commented Feb 1, 2025

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 the image 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:

  • Is written in pure Rust, with no unsafe.
  • Has no dependencies.
  • Does not allocate any memory.
  • Does not panic or unwrap.
  • Makes a single pass over the input, does not require the reader to implement Seek, and runs in O(n) time.
  • Provides error messages on parse failure indicating where the failure occurred.

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 .

@mstoeckl mstoeckl force-pushed the xbm branch 3 times, most recently from 9b49eec to 38460f3 Compare February 2, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant