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",
"image",
"r2d2",
"rayon",
]
[[package]]

View File

@ -9,5 +9,4 @@ edition = "2018"
[dependencies]
r2d2 = "*"
image = "*"
rayon = "*"
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;
use std::{
io::{self, BufReader, Read},
thread::JoinHandle,
};
use std::thread::JoinHandle;
use crossbeam::channel::*;
use pixelflut::*;
use std::fs;
use std::path::PathBuf;
enum Message {
Pixel(u32, u32, image::Rgba<u8>),
Line(Vec<(u32, u32, image::Rgba<u8>)>),
Exit,
}
fn main() -> Result<(), std::io::Error> {
let mut stdin_reader = BufReader::new(io::stdin());
let mut image_buffer: Vec<u8> = Vec::new();
let _ = stdin_reader.read_to_end(&mut image_buffer)?;
let mut image = image::load_from_memory(&image_buffer).expect("Unable to read image format");
let entries = fs::read_dir("nyancat/").unwrap();
let mut entries: Vec<PathBuf> = entries.map(|entry| entry.unwrap().path()).collect();
let mut images: Vec<image::DynamicImage> = Vec::new();
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()
.max_size(16)
.max_size(64)
.build(manager)
.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 mut handles: Vec<JoinHandle<()>> = Vec::new();
for _ in 0..16 {
for _ in 0..64 {
let r2 = receiver.clone();
let p2 = pool.clone();
let handle = std::thread::spawn(move || {
@ -41,7 +44,10 @@ fn main() -> Result<(), std::io::Error> {
match r2.recv().unwrap() {
Message::Pixel(x, y, c) => {
let _ = connection.set(x, y, c);
}
},
Message::Line(l) => {
let _ = connection.set_multiple(l);
},
Message::Exit => return,
}
}
@ -49,8 +55,13 @@ fn main() -> Result<(), std::io::Error> {
handles.push(handle);
}
for (x, y, p) in image.enumerate_pixels() {
let _ = sender.send(Message::Pixel(x, y, p.clone()));
loop{
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(|_| {

View File

@ -30,6 +30,7 @@ impl PixelflutConnectionManager {
}
}
#[derive(Copy, Clone)]
pub struct Rgba(u8, u8, u8, u8);
impl fmt::Display for Rgba {
@ -59,6 +60,13 @@ impl PixelflutConnection {
let msg = format!("PX {} {} {}\n", x, y, c.into());
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> {
let msg = format!("PX {} {}\n", x, y);