Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples provided in crate lodepng fail greatly underestimate its abilities. Here's just one example. #47

Open
pwplus7 opened this issue Mar 3, 2021 · 1 comment

Comments

@pwplus7
Copy link

pwplus7 commented Mar 3, 2021

#![allow(non_snake_case)]

use lodepng::* ;
use std::process::Command; // used to execute OS commands that calls a PNG image viewer

fn main() {

  // PNG encode a simple tri-color image

  const W: usize = 300;  const H: usize = 600;
  let mut img = [[0_u8; 4]; W*H ];

  for frame in 1..6
  { let f8 : u8 = 30*frame as u8;
    for h in 0..H
    { for w in 0..W
      {  img[h*W +w ] =
            match h/200
              {   0  => [   f8, 0_u8, 0_u8, 255_u8],
                  1  => [ 0_u8,   f8, 0_u8, 255_u8],
                  _  => [ 0_u8, 0_u8,   f8, 255_u8],
              } ;
    }  }
    //Save image:  the buffer can be a slice of any type that has 4 bytes per element e.g. struct RGBA or [u8; 4]
    let _result =encode32_file("out.png", &img, W, H) ;
    // set up  cmd that calls The OS  PNG viewer...below the Linux feh viewer is called
    // let result =
    Command:: new("feh")
        .arg("out.png")
        .status() //.output()
        .expect("failed to execute command") ;
    }
}
@kornelski
Copy link
Owner

I'm not sure what you mean. There is an example for encoding. I don't have any example for viewing images, but that's out of scope of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants