This commit is contained in:
Rubydragon 2024-12-28 12:10:41 +01:00
parent 20e75fe0b1
commit eb807570f1
9 changed files with 159 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
bee

39
Cargo.lock generated Normal file
View File

@ -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"

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "pixelflut"
version = "0.1.0"
edition = "2021"
[dependencies]
gif = "0.13.1"
tinyppm = "0.2.0"

BIN
bee_movie.gif Normal file

Binary file not shown.

BIN
output.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 MiB

BIN
output.ppm Normal file

Binary file not shown.

BIN
rickroll-roll.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

110
src/main.rs Normal file
View File

@ -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<Vec<RGB>>
) -> 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<u8>> = 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<u8> =
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

BIN
testtube.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB