From 9748483e74148a323dc673ac25a5e2af33cde8f6 Mon Sep 17 00:00:00 2001 From: p6nj Date: Fri, 17 Jan 2025 12:22:13 -0500 Subject: [PATCH] expose image types, fix impls contracts, one test --- bingus/src/img.rs | 4 +++- bingus/src/img/image.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/bingus/src/img.rs b/bingus/src/img.rs index 14995d4..bb13e63 100644 --- a/bingus/src/img.rs +++ b/bingus/src/img.rs @@ -1 +1,3 @@ -pub mod image; +mod image; +pub use image::ImageBuffer as Image; +pub use image::*; diff --git a/bingus/src/img/image.rs b/bingus/src/img/image.rs index a4a657f..ceb852d 100644 --- a/bingus/src/img/image.rs +++ b/bingus/src/img/image.rs @@ -1,13 +1,13 @@ use std::ops::{BitOr, Deref, Shl}; -use image::{ImageBuffer, Pixel}; +pub use image::*; use num::{traits::ToBytes, Zero}; use crate::{Bendable, IntoDataBytes, TryFromDataBytes}; impl IntoDataBytes for ImageBuffer> where - Vec

: Deref, + Vec: Deref, P::Subpixel: ToBytes, { fn into_bytes(self) -> crate::Bytes { @@ -24,7 +24,7 @@ pub struct Dimensions { impl TryFromDataBytes for ImageBuffer> where - Vec

: Deref, + Vec: Deref, P::Subpixel: ToBytes + Zero + Shl + BitOr, { @@ -54,7 +54,7 @@ where impl Bendable for ImageBuffer> where - Vec

: Deref, + Vec: Deref, P::Subpixel: ToBytes + Zero + Shl + BitOr, { @@ -64,3 +64,27 @@ where self } } + +#[cfg(test)] +mod tests { + #[cfg(test)] + mod ser_de { + use super::super::{Dimensions, IntoDataBytes, TryFromDataBytes}; + use image::RgbImage; + + #[test] + fn empty() { + let image = RgbImage::new(0, 0); + assert_eq!( + Ok(image.clone()), + RgbImage::try_from_bytes( + image.into_bytes(), + Dimensions { + width: 0, + height: 0 + } + ) + ) + } + } +}