2019-12-16 18:24:48 +11:00
|
|
|
use minifb::{Key, ScaleMode, Window, WindowOptions};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
use std::fs::File;
|
|
|
|
// The decoder is a build for reader and can be used to set various decoding options
|
|
|
|
// via `Transformations`. The default output transformation is `Transformations::EXPAND
|
|
|
|
// | Transformations::STRIP_ALPHA`.
|
|
|
|
let decoder = png::Decoder::new(File::open("resources/uv.png").unwrap());
|
2021-12-07 00:17:01 +11:00
|
|
|
let mut reader = decoder.read_info().unwrap();
|
2019-12-16 18:24:48 +11:00
|
|
|
// Allocate the output buffer.
|
2021-12-07 00:17:01 +11:00
|
|
|
let mut buf = vec![0; reader.output_buffer_size()];
|
2019-12-16 18:24:48 +11:00
|
|
|
// Read the next frame. Currently this function should only called once.
|
|
|
|
// The default options
|
|
|
|
reader.next_frame(&mut buf).unwrap();
|
|
|
|
// convert buffer to u32
|
|
|
|
|
|
|
|
let u32_buffer: Vec<u32> = buf
|
|
|
|
.chunks(3)
|
|
|
|
.map(|v| ((v[0] as u32) << 16) | ((v[1] as u32) << 8) | v[2] as u32)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let mut window = Window::new(
|
|
|
|
"Noise Test - Press ESC to exit",
|
2021-12-07 00:17:01 +11:00
|
|
|
reader.info().width as usize,
|
|
|
|
reader.info().height as usize,
|
2019-12-16 18:24:48 +11:00
|
|
|
WindowOptions {
|
|
|
|
resize: true,
|
|
|
|
scale_mode: ScaleMode::Center,
|
|
|
|
..WindowOptions::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.expect("Unable to open Window");
|
|
|
|
|
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
|
|
|
window
|
2021-12-07 00:17:01 +11:00
|
|
|
.update_with_buffer(
|
|
|
|
&u32_buffer,
|
|
|
|
reader.info().width as usize,
|
|
|
|
reader.info().height as usize,
|
|
|
|
)
|
2019-12-16 18:24:48 +11:00
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
}
|