shard image across threads
parent
20c591769c
commit
cfa8044ea2
14
src/main.rs
14
src/main.rs
|
@ -1,5 +1,4 @@
|
|||
use png::{ColorType, Decoder};
|
||||
use rand::{thread_rng, Rng};
|
||||
use sscanf::sscanf;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
|
@ -14,8 +13,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let info = reader.next_frame(&mut pixelbuf)?;
|
||||
|
||||
thread::scope(|s| {
|
||||
for _ in 0..32 {
|
||||
s.spawn(|| -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
for i in 0..3 {
|
||||
let pixelbuf = &pixelbuf;
|
||||
s.spawn(move || -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let stream = TcpStream::connect("151.217.15.90:1337")?;
|
||||
// disable Nagle's algorithm
|
||||
stream.set_nodelay(true)?;
|
||||
|
@ -30,13 +30,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let size = sscanf!(&buf[..buf.len() - 1], "SIZE {u32} {u32}").unwrap();
|
||||
println!("SIZE {} {}", size.0, size.1);
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let pos = ((size.0 - info.width) / 2, (size.1 - info.height) / 2);
|
||||
loop {
|
||||
let pos = (
|
||||
rng.gen_range(0..size.0 - info.width),
|
||||
rng.gen_range(0..size.1 - info.height),
|
||||
);
|
||||
for y in 0..info.height {
|
||||
for y in (i..info.height).step_by(3) {
|
||||
for x in 0..info.width {
|
||||
match info.color_type {
|
||||
ColorType::Rgba => {
|
||||
|
|
Loading…
Reference in New Issue