pnm decoding and encoding
Diffstat (limited to 'src/ppm.rs')
| -rw-r--r-- | src/ppm.rs | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -56,7 +56,9 @@ pub mod plain { // SAFETY: iterator over `pixels` elements. unsafe { out.put(b) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < (pixels as usize * 3) } { + if unsafe { + out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < (pixels as usize * 3) + } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -79,7 +81,7 @@ pub mod plain { // cosmetic o.push(b'\n'); } - o.sub_ptr(out) + o.offset_from_unsigned(out) } #[doc = include_str!("est.md")] @@ -135,7 +137,7 @@ pub mod raw { encodeu32(x.height(), &mut o); o.put(*b" 255\n"); o.copy_from(x.buffer().as_ptr(), x.len()); - o.sub_ptr(out) + x.len() + o.offset_from_unsigned(out) + x.len() } #[doc = include_str!("decode_body_into.md")] @@ -146,7 +148,9 @@ pub mod raw { // SAFETY: took `pixels` pixels. unsafe { out.put(b) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < (pixels as usize * 3) } { + if unsafe { + out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < (pixels as usize * 3) + } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. |