#![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") ;
}
}