Skip to content

Commit

Permalink
Merge pull request #1230 from HeroicKatora/pbm-rgba-decoding-1226
Browse files Browse the repository at this point in the history
Fix PBM ascii decoding
  • Loading branch information
HeroicKatora authored May 28, 2020
2 parents 1b279e2 + 2e86692 commit 092db1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pnm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl Sample for PbmBit {
let count = (width*height*samples) as usize;
let raw_samples = reader.bytes()
.filter_map(|ascii| match ascii {
Ok(b'0') => Some(Ok(1)),
Ok(b'0') => Some(Ok(255)),
Ok(b'1') => Some(Ok(0)),
Err(err) => Some(Err(ImageError::IoError(err))),
Ok(b'\t')
Expand Down Expand Up @@ -1096,7 +1096,7 @@ ENDHDR

let mut image = vec![0; decoder.total_bytes() as usize];
decoder.read_image(&mut image).unwrap();
assert_eq!(image, vec![1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]);
assert_eq!(image, vec![255, 0, 0, 255, 0, 0, 0, 255, 0, 0, 255, 0]);
match PnmDecoder::new(&pbmbinary[..]).unwrap().into_inner() {
(
_,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ ENDHDR

let mut image = vec![0; decoder.total_bytes() as usize];
decoder.read_image(&mut image).unwrap();
assert_eq!(image, vec![1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]);
assert_eq!(image, vec![255, 0, 0, 255, 0, 0, 0, 255, 0, 0, 255, 0]);
match PnmDecoder::new(&pbmbinary[..]).unwrap().into_inner() {
(
_,
Expand Down
16 changes: 16 additions & 0 deletions src/pnm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ mod tests {
assert_eq!(loaded_image, buffer_u8);
}

#[test]
fn roundtrip_gray() {
#[rustfmt::skip]
let buf: [u8; 16] = [
0, 0, 0, 255,
255, 255, 255, 255,
255, 0, 255, 0,
255, 0, 0, 0,
];

execute_roundtrip_default(&buf, 4, 4, ColorType::L8);
execute_roundtrip_with_subtype(&buf, 4, 4, ColorType::L8, PNMSubtype::ArbitraryMap);
execute_roundtrip_with_subtype(&buf, 4, 4, ColorType::L8, PNMSubtype::Graymap(SampleEncoding::Ascii));
execute_roundtrip_with_subtype(&buf, 4, 4, ColorType::L8, PNMSubtype::Graymap(SampleEncoding::Binary));
}

#[test]
fn roundtrip_rgb() {
#[rustfmt::skip]
Expand Down

0 comments on commit 092db1e

Please # to comment.