rimg 0.1.0

RImg aims to be a Rust implementation of CImg, the C++ Image Template Image Processing Toolkit
Documentation
pub struct Img<T> {
    width: usize,
    heigth: usize,
    depth: usize,
    spectrum: usize,
    data: Vec<T>,
}

impl<T: Copy> Img<T> {
    /// Creates a new Image instance
    /// 
    /// ## Examples
    /// 
    /// ```
    /// # use rimg::Img;
    /// // creates a 256x256 sized RGB image filled in black
    /// let _img = Img::new(256, 256, 1, 3, 0);
    /// ```
    pub fn new(width: usize, heigth: usize, depth: usize, spectrum: usize, value: T) -> Img<T> {
        let data_size = width * heigth * depth * spectrum;
        let mut data: Vec<T> = Vec::with_capacity(data_size);
        for _i in 0..data_size {
            data.push(value);
        }
        Img::<T> {
            width,
            heigth,
            depth,
            spectrum,
            data
        }
    }

    /// Returns the image heigth.
    /// 
    /// ## Examples
    /// 
    /// ```
    /// # use rimg::Img;
    /// # let img = Img::new(256, 256, 1, 3, 0);
    /// assert_eq!(256, img.heigth());
    /// ```
    pub fn heigth(&self) -> usize {
        self.heigth
    }

    /// Returns the image width.
    /// 
    /// ## Examples
    /// 
    /// ```
    /// # use rimg::Img;
    /// # let img = Img::new(256, 256, 1, 3, 0);
    /// assert_eq!(256, img.width());
    /// ```
    pub fn width(&self) -> usize {
        self.width
    }

    /// Returns the image depth.
    /// 
    /// ## Examples
    /// 
    /// ```
    /// # use rimg::Img;
    /// # let img = Img::new(256, 256, 1, 3, 0);
    /// assert_eq!(1, img.depth());
    /// ```
    pub fn depth(&self) -> usize {
        self.depth
    }

    /// Returns the image spectrum.
    /// 
    /// ## Examples
    /// 
    /// ```
    /// # use rimg::Img;
    /// # let img = Img::new(256, 256, 1, 3, 0);
    /// assert_eq!(3, img.spectrum());
    /// ```
    pub fn spectrum(&self) -> usize {
        self.spectrum
    }
}

#[cfg(test)]
mod tests {
    use crate::Img;

    fn create_img() -> Img<u8> {
        Img::new(128, 256, 1, 3, 0)
    }

    #[test]
    fn test_width() {
        let img = create_img();
        assert_eq!(128, img.width());
    }

    #[test]
    fn test_heigth() {
        let img = create_img();
        assert_eq!(256, img.heigth());
    }

    #[test]
    fn test_depth() {
        let img = create_img();
        assert_eq!(1, img.depth());
    }

    #[test]
    fn test_spectrum() {
        let img = create_img();
        assert_eq!(3, img.spectrum());
    }
}