embedded-png 0.1.1

PNG rendering with embedded-graphics
Documentation
//! DOC not suitable for 16bits usize
#![no_std]

//extern crate core;

mod colors;
mod error;
mod inflate;
mod png;
mod types;

pub use crate::colors::{AlphaColor, DontDraw, IgnoreAlpha, WithBackground};
pub use crate::inflate::ChunkDecompressor;
pub use crate::png::ParsedPng;

/*
pub type Png<C> = BufferedPng<C>;


pub struct BufferedPng<C> {
    pub header: PngHeader,
    pub data: Vec<C>,
}

impl<C: PixelColor + Default + From<Rgb888>> BufferedPng<C> {
    // TODO from_bytes
    pub fn from_slice(bytes: &[u8]) -> Result<Self, DecodeError> {
        // TODO decode / uncompress using iterators
        let mut undecoded = pre_decode(bytes)?;

        // For now, output data is always RGBA, 1 byte per channel.
        let mut data = vec![C::default(); undecoded.header.width as usize * undecoded.header.height as usize];
        let width =  undecoded.header.width as usize;

        undecoded.process_scanlines(|scanline_iter,xy_calculator,y| {
                for (idx, (r, g, b, a)) in scanline_iter.enumerate() {
                    let (x, y) = xy_calculator.get_xy(idx, y);
                    let i = (y * width) + x;
                    data[i] = C::from(Rgb888::new(r, g, b));
                }
            },
        )?;

        Ok(Png {header: undecoded.header, data })

    }
}

impl<C: PixelColor> OriginDimensions for BufferedPng<C> {
    fn size(&self) -> Size {
        Size::new(self.header.width, self.header.height)
    }
}

impl<C: PixelColor> ImageDrawable for BufferedPng<C> {
    type Color = C;

    fn draw<D>(&self, target: &mut D) -> Result<(), D::Error> where D: DrawTarget<Color=Self::Color> {
        let area = self.bounding_box();
        target.fill_contiguous(&area, self.data.iter().copied())
    }

    fn draw_sub_image<D>(&self, target: &mut D, area: &Rectangle) -> Result<(), D::Error> where D: DrawTarget<Color=Self::Color> {
        let mut index = area.top_left.x + area.top_left.y * self.header.width as i32;
        let line_size = Size::new(area.size.width, 1);
        for i in 0 ..  area.size.height as i32 {
            let pos = Point::new(0, i);
            let target_area = Rectangle::new(pos, line_size);
            let data = &self.data[index as usize .. index as usize + area.size.width as usize];
            target.fill_contiguous(&target_area, data.iter().copied())?;
            index += self.header.width as i32;
        }
        Ok(())
    }
}
*/

fn read_u32(bytes: &[u8], offset: usize) -> u32 {
    u32::from_be_bytes([
        bytes[offset],
        bytes[offset + 1],
        bytes[offset + 2],
        bytes[offset + 3],
    ])
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        //let result = add(2, 2);
        assert_eq!(4, 4);
    }
}