Skip to content

Commit

Permalink
removed unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
crckrberries committed May 9, 2024
1 parent 5547f56 commit d2de173
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
36 changes: 8 additions & 28 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use image::{
use std::fs::File;

// this module contains the command generation functions

pub fn read_gif(path: &str) -> Vec<image::Frame> {
let gif = File::open(path).expect("couldn't open gif");
let dec = gif::GifDecoder::new(gif).expect("that's not a gif!!");
Expand All @@ -31,7 +30,10 @@ pub fn process_gif(
for frame in frames {
let delay = frame.delay().numer_denom_ms().0;
let frame = imageops::resize(frame.buffer(), size[0], size[1], Nearest);
let cmds = process_image_delta(&frame, &buffer, offset, 10);

// compression value is hardcoded
// todo: dont do that
let cmds = process_image(&frame, &buffer, offset, 10);
frame_list.push(frame::Frame {
commands: cmds,
delay,
Expand All @@ -46,7 +48,7 @@ pub fn wipe(size: [u32; 2]) -> Vec<String> {
let mut commands: Vec<String> = Vec::new();
for x in 0..size[0] {
for y in 0..size[1] {
let str = format!("PX {} {} 202020\n", x, y,);
let str = format!("PX {} {} 202020\n", x, y,); // #202020 goated color
commands.push(str);
}
}
Expand All @@ -69,30 +71,6 @@ pub fn read_image(path: &str, size: [u32; 2]) -> ImageBuffer<image::Rgba<u8>, Ve
}

pub fn process_image(
image: &ImageBuffer<image::Rgba<u8>, Vec<u8>>,
offset: [u32; 2],
) -> Vec<String> {
let mut commands: Vec<String> = Vec::new();
for x in 0..image.width() {
for y in 0..image.height() {
let pixel = image.get_pixel(x, y); // gets the pixel

let str = format!(
// creates the command
"PX {} {} {}\n",
x + offset[0],
y + offset[1],
frame::Color::hexify_rgb(pixel[0], pixel[1], pixel[2], pixel[3])
);
commands.push(str); // pushes to command to list of commands
}
}

println!("Processed frame");
commands
}

pub fn process_image_delta(
image: &ImageBuffer<image::Rgba<u8>, Vec<u8>>,
buffer: &ImageBuffer<image::Rgba<u8>, Vec<u8>>,
offset: [u32; 2],
Expand Down Expand Up @@ -151,7 +129,9 @@ mod tests {
];

let img = read_image("src/test/test.jpg", [4, 4]);
let cmds = process_image(&img, [0, 0]);
let buffer = image::ImageBuffer::new(4, 4);

let cmds = process_image(&img, &buffer, [0, 0], 0);
assert_eq!(cmds, correct);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ fn main() -> io::Result<()> {
match cli.cmd {
Commands::Img { path } => {
let img = cmd::read_image(&path, size);
let cmds = cmd::process_image(&img, offset); // processes image, generating commands
let buffer = image::ImageBuffer::new(size[0], size[1]);

let cmds = cmd::process_image(&img, &buffer, offset, 0); // processes image, generating commands
frames.push(frame::Frame {
commands: cmds,
delay: 0,
Expand Down

0 comments on commit d2de173

Please sign in to comment.