diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b62bdc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +bee diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..291d442 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,39 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "gif" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "pixelflut" +version = "0.1.0" +dependencies = [ + "gif", + "tinyppm", +] + +[[package]] +name = "tinyppm" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed426dd7dd92db4a10e8e2dfd154551e7d980265118d5ac03bff91ce01d2f9c" + +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5cdf291 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pixelflut" +version = "0.1.0" +edition = "2021" + +[dependencies] +gif = "0.13.1" +tinyppm = "0.2.0" diff --git a/bee_movie.gif b/bee_movie.gif new file mode 100644 index 0000000..368c24a Binary files /dev/null and b/bee_movie.gif differ diff --git a/output.gif b/output.gif new file mode 100644 index 0000000..ed8f63d Binary files /dev/null and b/output.gif differ diff --git a/output.ppm b/output.ppm new file mode 100644 index 0000000..f5adb77 Binary files /dev/null and b/output.ppm differ diff --git a/rickroll-roll.gif b/rickroll-roll.gif new file mode 100644 index 0000000..b404e3e Binary files /dev/null and b/rickroll-roll.gif differ diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..818ca7a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,110 @@ +use std::net::TcpStream; +use std::io::*; +use std::fs::File; +use std::fs; +use gif::DecodeOptions; + +extern crate tinyppm; + +//const X_SIZE:i32 = 3840; +//const Y_SIZE:i32 = 1080; + +const GIF: &[u8] = include_bytes!("../testtube.gif"); + +struct RGB { + r:u8, + g:u8, + b:u8, +} + +fn my_function(filename: &String) { + let ppm_image_result = tinyppm::ppm_loader::read_image_data(filename); + let ppm_image = match ppm_image_result { + Ok(image) => image, + _ => panic!("unable to read specified image file!"), + }; + // `ppm_image` is now a struct containing image with, height and pixels +} + +fn pixel( + stream:&mut TcpStream, + x:u16, + y:u16, + px::RGB, +) -> std::io::Result<()> { + let send_str = format!("PX {} {} {:02x}{:02x}{:02x}\n", x, y, px.r, px.g, px.b); + //println!("{}", send_str); + stream.write(send_str.as_bytes()); + Ok(()) +} + +fn show_picture( + stream:&mut TcpStream, + x_pos:u16, + y_pos:u16, + width:u16, + height:u16, + buf:Vec> +) -> std::io::Result<()> { + println!("width: {} height: {}", width, height); + + let mut y = 0; + c += 1; + for row in buf { + let mut x = 0; + for px in row { + pixel(stream, x + x_pos, y + y_pos, px); + x += 1; + } + y += 1; + } + Ok(()) +} + +fn stream_gif( + stream:&mut TcpStream, + x_pos:u16, + y_pos:u16 +) -> std::io::Result<()> { + let mut decoder = DecodeOptions::new(); + decoder.set_color_output(gif::ColorOutput::RGBA); + let mut decoder = decoder.read_info(GIF).unwrap(); + + let mut frames: Vec> = Vec::new(); + let (mut width, mut height) = (0, 0); + + loop { + let frame_info = match decoder.next_frame_info().unwrap() { + Some(info) => info, + None => break, + }; + + width = frame_info.width; + height = frame_info.height; + + let mut frame: Vec = + vec![0; frame_info.width as usize * frame_info.height as usize * 4]; + + decoder.read_into_buffer(&mut frame).unwrap(); + frames.push(frame); + } + + Ok(()) +} + +fn main() -> std::io::Result<()> { + let paths = fs::read_dir("./bee").unwrap(); + + for path in paths { + println!("Name: {}", path.unwrap().path().display()) + } + + let mut stream = TcpStream::connect("wall.c3pixelflut.de:1337")?; + + stream_gif( + &mut stream, + 3500, + 0 + ); + Ok(()) +} // the stream is closed here diff --git a/testtube.gif b/testtube.gif new file mode 100644 index 0000000..6b83cdf Binary files /dev/null and b/testtube.gif differ