URI: 
       Switched to gifsky. - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
  HTML git clone https://git.drkhsh.at/icy_draw.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 25110cc014dbdd556e0b0479878c158c04473385
   DIR parent 40aec6fb46119f8302bf7add1ad50fa96c9f4b5f
  HTML Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Wed,  4 Oct 2023 10:42:10 +0200
       
       Switched to gifsky.
       
       Diffstat:
         M Cargo.toml                          |      16 +++++++++-------
         M src/ui/editor/animation/gif_encode… |      39 +++++++++++++++++++++-----------
       
       2 files changed, 35 insertions(+), 20 deletions(-)
       ---
   DIR diff --git a/Cargo.toml b/Cargo.toml
       @@ -27,19 +27,21 @@ open = "5.0.0"
        dark-light = "1.0.0"
        zip = "0.6.6"
        notify = "6.1.1"
       -gif = "0.12.0"
       +gifski = "1.12.2"
       +imgref = "1.9.4"
       +rgb = "0.8.36"
        thiserror = "1.0"
        anyhow = "1.0.75"
        
        video-rs = { version = "0.4", features = ["ndarray"] }
        ndarray = "0.15.6"
        
       -icy_engine = { git ="https://github.com/mkrueger/icy_engine" }
       -icy_engine_egui = { git ="https://github.com/mkrueger/icy_engine_egui" }
       -view_library = { git ="https://github.com/mkrueger/icy_view" }
       -#icy_engine = { path = "../icy_engine" }
       -#icy_engine_egui = { path = "../icy_engine_egui" }
       -#view_library = { path = "../icy_view/view_library" }
       +#icy_engine = { git ="https://github.com/mkrueger/icy_engine" }
       +#icy_engine_egui = { git ="https://github.com/mkrueger/icy_engine_egui" }
       +#view_library = { git ="https://github.com/mkrueger/icy_view" }
       +icy_engine = { path = "../icy_engine" }
       +icy_engine_egui = { path = "../icy_engine_egui" }
       +view_library = { path = "../icy_view/view_library" }
        
        egui_code_editor = "0.1.8"
        mlua = { version = "0.9.1", features = ["lua54", "vendored"] }
   DIR diff --git a/src/ui/editor/animation/gif_encoder.rs b/src/ui/editor/animation/gif_encoder.rs
       @@ -1,5 +1,9 @@
        use std::{fs::File, path::Path, sync::mpsc::Sender};
        
       +use gifski::{progress::NoProgress, Repeat};
       +use imgref::ImgVec;
       +use rgb::RGBA8;
       +
        use crate::TerminalResult;
        
        use super::encoding::AnimationEncoder;
       @@ -15,20 +19,29 @@ impl AnimationEncoder for GifEncoder {
            }
        
            fn encode(&self, path: &Path, frames: Vec<(Vec<u8>, u32)>, width: usize, height: usize, sender: Sender<usize>) -> TerminalResult<()> {
       -        let mut image = File::create(path)?;
       -        let width = width as u16;
       -        let height = height as u16;
       -
       -        let Ok(mut encoder) = ::gif::Encoder::new(&mut image, width, height, &[]) else {
       -            return Err(anyhow::anyhow!("Could not create encoder"));
       -        };
       -        encoder.set_repeat(::gif::Repeat::Infinite).unwrap();
       -
       -        for (i, (mut data, _)) in frames.into_iter().enumerate() {
       -            sender.send(i)?;
       -            let gif_frame = ::gif::Frame::from_rgba(width, height, &mut data);
       -            encoder.write_frame(&gif_frame)?;
       +        
       +        let settings = gifski::Settings { width: Some(width as u32), height: Some(height as u32), quality: 100, fast: true, repeat: Repeat::Infinite };
       +
       +        let (c, w) = gifski::new(settings)?;
       +        let mut time = 0.0;
       +        let mut pb = NoProgress {};
       +        let path = path.to_path_buf();
       +        std::thread::spawn(move || w.write(std::fs::File::create(path).unwrap(), &mut pb) .unwrap());
       +
       +        for (frame_idx, (data, duration)) in frames.into_iter().enumerate() {
       +            sender.send(frame_idx)?;
       +            let mut n = 0; 
       +            let mut d = Vec::new();
       +            while n < data.len() {
       +                d.push(rgb::RGBA::new (data[n], data[n+1], data[n+2], data[n+3]));
       +                n += 4;
       +            }
       +
       +            let img: ImgVec<RGBA8> = imgref::Img::new( d, width, height);
       +            c.add_frame_rgba(frame_idx, img, time / 1000.0)?;
       +            time += duration as f64;
                }
       +
                Ok(())
            }
        }