~jpl8/piet_interpreter

eb56b64df18171ce846d6c0c6095b5b74b43f0bd — jpl 2 years ago 2b51bf1
add gif support
A images/Piet-4.gif => images/Piet-4.gif +0 -0
A images/artistic_hello_world.png => images/artistic_hello_world.png +0 -0
A images/fibbig.gif => images/fibbig.gif +0 -0
A images/hi_gif.gif => images/hi_gif.gif +0 -0
A images/test_gif.gif => images/test_gif.gif +0 -0
M src/translator.rs => src/translator.rs +16 -17
@@ 1,7 1,7 @@
use image::{self, DynamicImage, Rgb};
use image::{self,Rgb};
use image::io::Reader as ImageReader;

use std::io::{self, Error, ErrorKind};
use std::io::{self};
use std::path::Path;

use crate::piet_img::{PietImage, Codel};


@@ 10,32 10,31 @@ pub fn png_to_piet_img<P>(path: P) -> io::Result<PietImage>
where P: AsRef<Path> 
{

    let img = ImageReader::open(path).expect("Failed to open given path!")
                                .decode().expect("Failed to decode!");
    let img_read = ImageReader::open(path)?;

    let img = img_read.decode().expect("Failed to decode! Image type unsupported!");
    let rgb_img = img.to_rgb8();


    if let DynamicImage::ImageRgb8(rgb_img) = img {
    let codels = rgb_img.rows().map(|row| row.into_iter()
                                    .map(|Rgb(bytes)| Codel::from_bytes(*bytes))
                                    .collect()
                                   ).collect();

        let codels = rgb_img.rows().map(|row| row.into_iter()
                                        .map(|Rgb(bytes)| Codel::from_bytes(*bytes))
                                        .collect()
                                       ).collect();
    let codel_size = codel_size(&codels);

        let codel_size = codel_size(&codels);
    let dimensions = (rgb_img.dimensions().0 / codel_size,
                     rgb_img.dimensions().1 / codel_size);

        let dimensions = (rgb_img.dimensions().0 / codel_size,
                         rgb_img.dimensions().1 / codel_size);


        let upscaled_codels = codels.into_iter().step_by((codel_size) as usize)
    let upscaled_codels = codels.into_iter().step_by((codel_size) as usize)
            .map(|row| row.into_iter().step_by((codel_size) as usize).collect())
            .collect();

        return Ok(PietImage::new(dimensions, upscaled_codels));
    }

    Err(Error::new(ErrorKind::InvalidInput, "Failed to convert to PietImage!"))
    return Ok(PietImage::new(dimensions, upscaled_codels));
    

}

pub fn codel_size(codels: &Vec<Vec<Codel>>) -> u32 {