pnm decoding and encoding
| -rw-r--r-- | src/pam.rs | 12 | ||||
| -rw-r--r-- | src/pgm.rs | 7 | ||||
| -rw-r--r-- | src/ppm.rs | 7 |
3 files changed, 10 insertions, 16 deletions
@@ -141,15 +141,15 @@ unsafe fn encode_into<const N: usize>( o.put(*b"TUPLTYPE "); o.put(*tupltype); o.put(*b"\nENDHDR\n"); - for &x in buf { - if &tupltype[..] == b"BLACKANDWHITE" { + if tupltype[..] == *b"BLACKANDWHITE" { + for &x in buf { o.push(x ^ 1) - } else { - o.push(x) } + o.sub_ptr(out) + } else { + o.copy_from(buf.as_ptr(), buf.len()); + o.sub_ptr(out) + buf.len() } - - o.sub_ptr(out) } #[derive(Copy, Clone, Debug)] @@ -131,11 +131,8 @@ pub mod raw { o.push(b' '); encodeu32(x.height(), &mut o); o.put(*b" 255\n"); - for &x in *x.buffer() { - o.push(x) - } - - o.sub_ptr(out) + o.copy_from(x.buffer().as_ptr(), x.len()); + o.sub_ptr(out) + x.len() } #[doc = include_str!("decode_body_into.md")] @@ -131,11 +131,8 @@ pub mod raw { o.push(b' '); encodeu32(x.height(), &mut o); o.put(*b" 255\n"); - for &x in *x.buffer() { - o.push(x) - } - - o.sub_ptr(out) + o.copy_from(x.buffer().as_ptr(), x.len()); + o.sub_ptr(out) + x.len() } #[doc = include_str!("decode_body_into.md")] |