Skip to content

Commit

Permalink
INCREDIBLY hacky solution to first frame of gifs being buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
crckrberries committed May 9, 2024
1 parent d2de173 commit f70915b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ pub fn process_gif(
) -> Vec<frame::Frame> {
let mut frame_list: Vec<frame::Frame> = vec![];
let mut buffer = image::ImageBuffer::new(size[0], size[1]);
let mut firstframe = true; // hack
for frame in frames {
let delay = frame.delay().numer_denom_ms().0;
let frame = imageops::resize(frame.buffer(), size[0], size[1], Nearest);

// compression value is hardcoded
// todo: dont do that
let cmds = process_image(&frame, &buffer, offset, 10);
let cmds = process_image(&frame, &buffer, offset, 10, firstframe);
frame_list.push(frame::Frame {
commands: cmds,
delay,
});
buffer = frame;
firstframe = false;
}

frame_list
Expand Down Expand Up @@ -75,6 +77,7 @@ pub fn process_image(
buffer: &ImageBuffer<image::Rgba<u8>, Vec<u8>>,
offset: [u32; 2],
compression: u8,
first: bool,
) -> Vec<String> {
let mut commands: Vec<String> = Vec::new();
for x in 0..image.width() {
Expand All @@ -85,6 +88,7 @@ pub fn process_image(
if pixel[0].abs_diff(buf_px[0]) > compression
|| pixel[1].abs_diff(buf_px[1]) > compression
|| pixel[2].abs_diff(buf_px[2]) > compression
|| first
{
let str = format!(
// creates the command
Expand Down Expand Up @@ -131,7 +135,7 @@ mod tests {
let img = read_image("src/test/test.jpg", [4, 4]);
let buffer = image::ImageBuffer::new(4, 4);

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

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn main() -> io::Result<()> {
let img = cmd::read_image(&path, size);
let buffer = image::ImageBuffer::new(size[0], size[1]);

let cmds = cmd::process_image(&img, &buffer, offset, 0); // processes image, generating commands
let cmds = cmd::process_image(&img, &buffer, offset, 0, true); // processes image, generating commands
frames.push(frame::Frame {
commands: cmds,
delay: 0,
Expand Down
Binary file added src/test/plink.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f70915b

Please sign in to comment.