encode

Function encode 

Source
pub fn encode<W: Write>(
    sink: W,
    width: u32,
    height: u32,
    image: &[u8],
) -> Result<()>
Expand description

Encode an RGBA image.

Examples found in repository?
examples/simple.rs (lines 31-36)
7fn main() {
8    const TAU: f64 = 6.28319;
9    const THIRD: f64 = TAU / 3.0;
10
11    let width = 100;
12    let height = 100;
13    let mut rainbow = vec![0; width * height * 4];
14
15    for y in 0..height {
16        for x in 0..width {
17            let off = 4 * (y * width + x);
18            let del = TAU * (x + y) as f64 / (width + height) as f64;
19
20            let r = ((del + 0.0 * THIRD).cos() + 1.0) * 127.5;
21            let g = ((del + 1.0 * THIRD).cos() + 1.0) * 127.5;
22            let b = ((del + 2.0 * THIRD).cos() + 1.0) * 127.5;
23
24            rainbow[off + 0] = r as u8;
25            rainbow[off + 1] = g as u8;
26            rainbow[off + 2] = b as u8;
27            rainbow[off + 3] = 255;
28        }
29    }
30
31    repng::encode(
32        File::create("rainbow.png").unwrap(),
33        width as u32,
34        height as u32,
35        &rainbow,
36    ).unwrap();
37}