Compare commits
No commits in common. "cfa8044ea2e53d58f21e2fd29abf7941b84f08a3" and "b130138c2be7a020eb0895ec4ac25b59eb891e7c" have entirely different histories.
cfa8044ea2
...
b130138c2b
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB |
BIN
kame-mosaic.apng
BIN
kame-mosaic.apng
Binary file not shown.
|
Before Width: | Height: | Size: 290 KiB |
35
src/main.rs
35
src/main.rs
|
|
@ -1,4 +1,5 @@
|
||||||
use png::{ColorType, Decoder};
|
use png::{ColorType, Decoder};
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
use sscanf::sscanf;
|
use sscanf::sscanf;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
@ -7,16 +8,15 @@ 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("kame-mosaic.apng")?);
|
let decoder = Decoder::new(File::open("nopslide.png")?);
|
||||||
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)?;
|
||||||
|
|
||||||
thread::scope(|s| {
|
thread::scope(|s| {
|
||||||
for i in 0..3 {
|
for _ in 0..32 {
|
||||||
let pixelbuf = &pixelbuf;
|
s.spawn(|| -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
s.spawn(move || -> Result<(), Box<dyn Error + Send + Sync>> {
|
let stream = TcpStream::connect("151.217.15.79:1337")?;
|
||||||
let stream = TcpStream::connect("151.217.15.90:1337")?;
|
|
||||||
// disable Nagle's algorithm
|
// disable Nagle's algorithm
|
||||||
stream.set_nodelay(true)?;
|
stream.set_nodelay(true)?;
|
||||||
let mut reader = BufReader::new(stream.try_clone()?);
|
let mut reader = BufReader::new(stream.try_clone()?);
|
||||||
|
|
@ -28,27 +28,16 @@ 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 pos = ((size.0 - info.width) / 2, (size.1 - info.height) / 2);
|
let mut rng = thread_rng();
|
||||||
loop {
|
loop {
|
||||||
for y in (i..info.height).step_by(3) {
|
let pos = (
|
||||||
for x in 0..info.width {
|
rng.gen_range(0..size.0 - info.width),
|
||||||
|
rng.gen_range(0..size.1 - info.height),
|
||||||
|
);
|
||||||
|
for x in 0..info.width {
|
||||||
|
for y in 0..info.height {
|
||||||
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