pnm decoding and encoding
fix
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/lib.rs | 6 | ||||
| -rw-r--r-- | src/pam.rs | 4 | ||||
| -rw-r--r-- | src/pbm.rs | 12 | ||||
| -rw-r--r-- | src/pgm.rs | 8 | ||||
| -rw-r--r-- | src/ppm.rs | 12 |
6 files changed, 25 insertions, 21 deletions
@@ -1,7 +1,7 @@ [package] name = "pnm" -version = "0.1.0" -edition = "2021" +version = "0.1.1" +edition = "2024" description = "portable anymap format encoding and decoding" authors = ["bend-n <[email protected]>"] license = "MIT" @@ -19,8 +19,8 @@ //! //! assert_eq!(pnm::encode(out), data); //! ``` -#![allow(incomplete_features)] -#![feature(ptr_sub_ptr, let_chains, iter_array_chunks)] +#![allow(incomplete_features, unsafe_op_in_unsafe_fn)] +#![feature(iter_array_chunks)] #![warn( clippy::missing_const_for_fn, clippy::suboptimal_flops, @@ -28,7 +28,7 @@ clippy::use_self )] -use fimg::{uninit, DynImage, Image}; +use fimg::{DynImage, Image, uninit}; pub mod decode; pub(crate) mod encode; pub mod pam; @@ -147,10 +147,10 @@ unsafe fn encode_into<const N: usize>( for &x in buf { o.push(x ^ 1) } - o.sub_ptr(out) + o.offset_from_unsigned(out) } else { o.copy_from(buf.as_ptr(), buf.len()); - o.sub_ptr(out) + buf.len() + o.offset_from_unsigned(out) + buf.len() } } @@ -47,7 +47,7 @@ pub mod plain { // SAFETY: iterator over `pixels` elements. unsafe { out.push(b == b'1') }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -69,7 +69,7 @@ pub mod plain { // SAFETY: iterator over `pixels` elements. unsafe { out.push((b == b'0') as u8 * 0xff) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -94,7 +94,7 @@ pub mod plain { // cosmetic o.push(b'\n'); } - o.sub_ptr(out) + o.offset_from_unsigned(out) } #[doc = include_str!("est.md")] @@ -162,7 +162,7 @@ pub mod raw { }) .for_each(|x| o.push(x)); - o.sub_ptr(out) + o.offset_from_unsigned(out) } #[doc = include_str!("decode_body_into.md")] @@ -185,7 +185,7 @@ pub mod raw { // SAFETY: took `width` * `height` pixels. unsafe { out.push(x) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -216,7 +216,7 @@ pub mod raw { // SAFETY: took `height` * `width` pixels. unsafe { out.push(x) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -56,7 +56,7 @@ pub mod plain { // SAFETY: iterator over `pixels` elements. unsafe { out.push(b) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -79,7 +79,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 +135,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 +146,7 @@ pub mod raw { // SAFETY: took `pixels` pixels. unsafe { out.push(b) }; } - if unsafe { out.sub_ptr(into.buf().as_mut_ptr().cast()) < pixels as usize } { + if unsafe { out.offset_from_unsigned(into.buf().as_mut_ptr().cast()) < pixels as usize } { return Err(Error::MissingData); } // SAFETY: checked that the pixels have been initialized. @@ -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. |