use kame turtle
This commit is contained in:
parent
019d87ba62
commit
20c591769c
BIN
ipv4_nein_danke.png
Normal file
BIN
ipv4_nein_danke.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
BIN
kame-mosaic.apng
Normal file
BIN
kame-mosaic.apng
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 290 KiB |
21
src/main.rs
21
src/main.rs
|
|
@ -8,7 +8,7 @@ use std::net::TcpStream;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let decoder = Decoder::new(File::open("nopslide.png")?);
|
let decoder = Decoder::new(File::open("kame-mosaic.apng")?);
|
||||||
let mut reader = decoder.read_info()?;
|
let mut reader = decoder.read_info()?;
|
||||||
let mut pixelbuf = vec![0; reader.output_buffer_size()];
|
let mut pixelbuf = vec![0; reader.output_buffer_size()];
|
||||||
let info = reader.next_frame(&mut pixelbuf)?;
|
let info = reader.next_frame(&mut pixelbuf)?;
|
||||||
|
|
@ -28,6 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
// XXX sscanf does not like \n after numbers ... O_o
|
// XXX sscanf does not like \n after numbers ... O_o
|
||||||
// XXX sscanf returns Result<(), Box<dyn Error>> which is not + Send + Sync
|
// XXX sscanf returns Result<(), Box<dyn Error>> which is not + Send + Sync
|
||||||
let size = sscanf!(&buf[..buf.len() - 1], "SIZE {u32} {u32}").unwrap();
|
let size = sscanf!(&buf[..buf.len() - 1], "SIZE {u32} {u32}").unwrap();
|
||||||
|
println!("SIZE {} {}", size.0, size.1);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -35,9 +36,23 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
rng.gen_range(0..size.0 - info.width),
|
rng.gen_range(0..size.0 - info.width),
|
||||||
rng.gen_range(0..size.1 - info.height),
|
rng.gen_range(0..size.1 - info.height),
|
||||||
);
|
);
|
||||||
for x in 0..info.width {
|
for y in 0..info.height {
|
||||||
for y in 0..info.height {
|
for x in 0..info.width {
|
||||||
match info.color_type {
|
match info.color_type {
|
||||||
|
ColorType::Rgba => {
|
||||||
|
let offset = ((x + y * info.width) * 4) as usize;
|
||||||
|
if pixelbuf[offset + 3] != 0 {
|
||||||
|
write!(
|
||||||
|
writer,
|
||||||
|
"PX {} {} {:02x}{:02x}{:02x}\n",
|
||||||
|
x + pos.0,
|
||||||
|
y + pos.1,
|
||||||
|
pixelbuf[offset],
|
||||||
|
pixelbuf[offset + 1],
|
||||||
|
pixelbuf[offset + 2]
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
ColorType::GrayscaleAlpha => {
|
ColorType::GrayscaleAlpha => {
|
||||||
let offset = ((x + y * info.width) * 2) as usize;
|
let offset = ((x + y * info.width) * 2) as usize;
|
||||||
if pixelbuf[offset + 1] != 0 {
|
if pixelbuf[offset + 1] != 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue