use crate::core::traits::PixelBound;
use crate::core::*;
use ndarray::Data;
use num_traits::cast::{FromPrimitive, NumCast};
use num_traits::{Num, NumAssignOps};
use std::fmt::Display;
use std::fs::{read, File};
use std::io::prelude::*;
use std::path::Path;
pub trait Encoder<T, U, C>
where
U: Data<Elem = T>,
T: Copy + Clone + Num + NumAssignOps + NumCast + PartialOrd + Display + PixelBound,
C: ColourModel,
{
fn encode(&self, image: &ImageBase<U, C>) -> Vec<u8>;
fn encode_file<P: AsRef<Path>>(
&self,
image: &ImageBase<U, C>,
filename: P,
) -> std::io::Result<()> {
let mut file = File::create(filename)?;
file.write_all(&self.encode(image))?;
Ok(())
}
}
pub trait Decoder<T, C>
where
T: Copy
+ Clone
+ FromPrimitive
+ Num
+ NumAssignOps
+ NumCast
+ PartialOrd
+ Display
+ PixelBound,
C: ColourModel,
{
fn decode(&self, bytes: &[u8]) -> std::io::Result<Image<T, C>>;
fn decode_file<P: AsRef<Path>>(&self, filename: P) -> std::io::Result<Image<T, C>> {
let bytes = read(filename)?;
self.decode(&bytes)
}
}
pub mod netpbm;