expose image types, fix impls contracts, one test
This commit is contained in:
parent
ff6e44072e
commit
9748483e74
2 changed files with 31 additions and 5 deletions
|
@ -1 +1,3 @@
|
||||||
pub mod image;
|
mod image;
|
||||||
|
pub use image::ImageBuffer as Image;
|
||||||
|
pub use image::*;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::ops::{BitOr, Deref, Shl};
|
use std::ops::{BitOr, Deref, Shl};
|
||||||
|
|
||||||
use image::{ImageBuffer, Pixel};
|
pub use image::*;
|
||||||
use num::{traits::ToBytes, Zero};
|
use num::{traits::ToBytes, Zero};
|
||||||
|
|
||||||
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
||||||
|
|
||||||
impl<P: Pixel> IntoDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
|
impl<P: Pixel> IntoDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
|
||||||
where
|
where
|
||||||
Vec<P>: Deref<Target = [P::Subpixel]>,
|
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
|
||||||
P::Subpixel: ToBytes,
|
P::Subpixel: ToBytes,
|
||||||
{
|
{
|
||||||
fn into_bytes(self) -> crate::Bytes {
|
fn into_bytes(self) -> crate::Bytes {
|
||||||
|
@ -24,7 +24,7 @@ pub struct Dimensions {
|
||||||
|
|
||||||
impl<P: Pixel> TryFromDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
|
impl<P: Pixel> TryFromDataBytes for ImageBuffer<P, Vec<P::Subpixel>>
|
||||||
where
|
where
|
||||||
Vec<P>: Deref<Target = [P::Subpixel]>,
|
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
|
||||||
P::Subpixel:
|
P::Subpixel:
|
||||||
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = 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>>
|
impl<P: Pixel> Bendable for ImageBuffer<P, Vec<P::Subpixel>>
|
||||||
where
|
where
|
||||||
Vec<P>: Deref<Target = [P::Subpixel]>,
|
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
|
||||||
P::Subpixel:
|
P::Subpixel:
|
||||||
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = P::Subpixel>,
|
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = P::Subpixel>,
|
||||||
{
|
{
|
||||||
|
@ -64,3 +64,27 @@ where
|
||||||
self
|
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
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue