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

PBM encoder is incorrect for ASCII, aka PnmSubtype::Bitmap(SampleEncoding::Ascii) #2242

Open
timboldt opened this issue May 23, 2024 · 1 comment

Comments

@timboldt
Copy link

Encoding a PNM bitmap as binary (type P4) works correctly, but encoding it as ASCII (type P1) results in the wrong sample format.

Specification: https://netpbm.sourceforge.net/doc/pbm.html

Expected

I expected a file with samples of 1s and 0s.

P1
24 7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
etc.

NOTE: The spaces are optional.

Actual behaviour

I got samples with values between 0 and 255, i.e. the bits were combined into bytes and then written out as byte values in decimal.

P1
24 7
0 0 0
121  231 158
etc.

Reproduction steps

let f = File::create("pic.pbm")?;
let mut writer = BufWriter::new(f);
let encoder =
    PnmEncoder::new(&mut writer).with_subtype(PnmSubtype::Bitmap(SampleEncoding::Ascii));
imgbuf.write_with_encoder(encoder)?;

P.S. If you can point me in the right direction, I'm happy to send a PR to address this.

@fintelia
Copy link
Contributor

The relevant code is in https://github.com/image-rs/image/blob/main/src/codecs/pnm/encoder.rs

The easiest thing might be to either step through it with a debugger or add some println! calls to see which code path is being taken

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

No branches or pull requests

2 participants