~jpl8/piet_interpreter

2b51bf1fb0ed268ae93db1d5c0e8339ed71b2fe8 — jpl 3 years ago 5e08ebe
converted hacky loops in png_to_piet_img into iterators and maps
3 files changed, 5 insertions(+), 13 deletions(-)

A images/Piet_hello2_big_upscaled.png
A images/Piet_hello_big_upscaled.png
M src/translator.rs
A images/Piet_hello2_big_upscaled.png => images/Piet_hello2_big_upscaled.png +0 -0
A images/Piet_hello_big_upscaled.png => images/Piet_hello_big_upscaled.png +0 -0
M src/translator.rs => src/translator.rs +5 -13
@@ 16,15 16,11 @@ where P: AsRef<Path>


    if let DynamicImage::ImageRgb8(rgb_img) = img {
        let mut codels: Vec<Vec<Codel>> = vec!();
        for row in rgb_img.rows() {
            codels.push(vec!());
            let len = codels.len();
            for Rgb(bytes) in row {
                let codel = Codel::from_bytes(*bytes);
                codels[len - 1].push(codel);
           }
        }

        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);



@@ 32,14 28,10 @@ where P: AsRef<Path>
                         rgb_img.dimensions().1 / codel_size);


        eprintln!("dimensions: {:?}", dimensions);

        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();

        eprintln!("upscaled_codels: {:#?}", upscaled_codels);

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