expose image types, fix impls contracts, one test

This commit is contained in:
Breval Ferrari 2025-01-17 12:22:13 -05:00
parent ff6e44072e
commit 9748483e74
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
2 changed files with 31 additions and 5 deletions

View file

@ -1 +1,3 @@
pub mod image;
mod image;
pub use image::ImageBuffer as Image;
pub use image::*;

View file

@ -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<P: Pixel> IntoDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
where
Vec<P>: Deref<Target = [P::Subpixel]>,
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
P::Subpixel: ToBytes,
{
fn into_bytes(self) -> crate::Bytes {
@ -24,7 +24,7 @@ pub struct Dimensions {
impl<P: Pixel> TryFromDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
where
Vec<P>: Deref<Target = [P::Subpixel]>,
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
P::Subpixel:
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = P::Subpixel>,
{
@ -54,7 +54,7 @@ where
impl<P: Pixel> Bendable for ImageBuffer<P, Vec<P::Subpixel>>
where
Vec<P>: Deref<Target = [P::Subpixel]>,
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
P::Subpixel:
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = P::Subpixel>,
{
@ -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
}
)
)
}
}
}