some image sequencing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Patrick Michl 2021-03-16 17:16:09 +01:00
parent 19f3a6daf5
commit 97bb431b62
5 changed files with 50 additions and 18 deletions

1
Cargo.lock generated
View File

@ -339,7 +339,6 @@ dependencies = [
"crossbeam", "crossbeam",
"image", "image",
"r2d2", "r2d2",
"rayon",
] ]
[[package]] [[package]]

View File

@ -9,5 +9,4 @@ edition = "2018"
[dependencies] [dependencies]
r2d2 = "*" r2d2 = "*"
image = "*" image = "*"
rayon = "*"
crossbeam = "*" crossbeam = "*"

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM ekidd/rust-musl-builder:nightly-2021-02-13 AS rust-build
USER root
RUN rustup target add x86_64-unknown-linux-musl
COPY . /app
WORKDIR /app
RUN cargo build --bins --release --target x86_64-unknown-linux-musl
FROM alpine:latest
WORKDIR /home
# Copy Rust artifacts
COPY --from=rust-build /app/target/x86_64-unknown-linux-musl/release/pixelrush ./app

View File

@ -1,35 +1,38 @@
mod pixelflut; mod pixelflut;
use std::{ use std::thread::JoinHandle;
io::{self, BufReader, Read},
thread::JoinHandle,
};
use crossbeam::channel::*; use crossbeam::channel::*;
use pixelflut::*; use pixelflut::*;
use std::fs;
use std::path::PathBuf;
enum Message { enum Message {
Pixel(u32, u32, image::Rgba<u8>), Pixel(u32, u32, image::Rgba<u8>),
Line(Vec<(u32, u32, image::Rgba<u8>)>),
Exit, Exit,
} }
fn main() -> Result<(), std::io::Error> { fn main() -> Result<(), std::io::Error> {
let mut stdin_reader = BufReader::new(io::stdin()); let entries = fs::read_dir("nyancat/").unwrap();
let mut image_buffer: Vec<u8> = Vec::new(); let mut entries: Vec<PathBuf> = entries.map(|entry| entry.unwrap().path()).collect();
let _ = stdin_reader.read_to_end(&mut image_buffer)?; let mut images: Vec<image::DynamicImage> = Vec::new();
let mut image = image::load_from_memory(&image_buffer).expect("Unable to read image format"); for entry in entries {
images.push(image::open(entry).expect("Unable to read image format"));
}
//let image = image::open("image.png").expect("Unable to read image format");
let manager = PixelflutConnectionManager::new("localhost:1234")?; let manager = PixelflutConnectionManager::new("10.3.32.187:1234")?;
let pool = r2d2::Pool::builder() let pool = r2d2::Pool::builder()
.max_size(16) .max_size(64)
.build(manager) .build(manager)
.expect("Could not initialize connection pool"); .expect("Could not initialize connection pool");
let image = image.as_rgba8().expect("Not a valid Image"); //let image = image.as_rgba8().expect("Not a valid Image");
let (sender, receiver) = unbounded::<Message>(); let (sender, receiver) = unbounded::<Message>();
let mut handles: Vec<JoinHandle<()>> = Vec::new(); let mut handles: Vec<JoinHandle<()>> = Vec::new();
for _ in 0..16 { for _ in 0..64 {
let r2 = receiver.clone(); let r2 = receiver.clone();
let p2 = pool.clone(); let p2 = pool.clone();
let handle = std::thread::spawn(move || { let handle = std::thread::spawn(move || {
@ -41,7 +44,10 @@ fn main() -> Result<(), std::io::Error> {
match r2.recv().unwrap() { match r2.recv().unwrap() {
Message::Pixel(x, y, c) => { Message::Pixel(x, y, c) => {
let _ = connection.set(x, y, c); let _ = connection.set(x, y, c);
} },
Message::Line(l) => {
let _ = connection.set_multiple(l);
},
Message::Exit => return, Message::Exit => return,
} }
} }
@ -49,8 +55,13 @@ fn main() -> Result<(), std::io::Error> {
handles.push(handle); handles.push(handle);
} }
for (x, y, p) in image.enumerate_pixels() { loop{
let _ = sender.send(Message::Pixel(x, y, p.clone())); for image in &images {
for (y, row) in image.to_rgba8().enumerate_rows() {
let row: Vec<(u32,u32,image::Rgba<u8>)> = row.into_iter().map(|(x,y,c)| (x,y,c.clone())).collect();
let _ = sender.send(Message::Line(row));
}
}
} }
(0..16).for_each(|_| { (0..16).for_each(|_| {

View File

@ -30,6 +30,7 @@ impl PixelflutConnectionManager {
} }
} }
#[derive(Copy, Clone)]
pub struct Rgba(u8, u8, u8, u8); pub struct Rgba(u8, u8, u8, u8);
impl fmt::Display for Rgba { impl fmt::Display for Rgba {
@ -59,6 +60,13 @@ impl PixelflutConnection {
let msg = format!("PX {} {} {}\n", x, y, c.into()); let msg = format!("PX {} {} {}\n", x, y, c.into());
self.write_command(&msg) self.write_command(&msg)
} }
pub fn set_multiple(&mut self, ps: Vec<(u32, u32, impl Into<Rgba>)>) -> Result<(), Error> {
let mut msg = String::from("");
for (x,y,p) in ps {
msg.push_str(&format!("PX {} {} {}\n", x, y, p.into()))
}
self.write_command(&msg)
}
pub fn get(&mut self, x: u32, y: u32) -> Result<Rgba, Error> { pub fn get(&mut self, x: u32, y: u32) -> Result<Rgba, Error> {
let msg = format!("PX {} {}\n", x, y); let msg = format!("PX {} {}\n", x, y);