Skip to content

Commit bb9b8fa

Browse files
authored
Update to gif.ski 1.10.0 (#292)
1 parent 4add126 commit bb9b8fa

File tree

16 files changed

+939
-553
lines changed

16 files changed

+939
-553
lines changed

gifski-api/Cargo.lock

Lines changed: 179 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gifski-api/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "AGPL-3.0-or-later"
1010
name = "gifski"
1111
readme = "README.md"
1212
repository = "https://github.com/ImageOptim/gifski"
13-
version = "1.8.1"
13+
version = "1.10.0"
1414
autobins = false
1515
edition = "2021"
1616
rust-version = "1.63"
@@ -25,11 +25,11 @@ name = "tests"
2525
required-features = ["png"]
2626

2727
[dependencies]
28-
gifsicle = { version = "1.92.5", optional = true }
29-
clap = { version = "3.1.18", features = ["cargo"], optional = true }
30-
gif = "0.12.0"
28+
gifsicle = { version = "1.93.0", optional = true }
29+
clap = { version = "4.1.1", features = ["cargo"], optional = true }
30+
gif = { version = "0.12.0", default-features = false, features = ["std", "raii_no_panic"] }
3131
gif-dispose = "4.0.0"
32-
imagequant = "4.0.4"
32+
imagequant = "4.1.0"
3333
imgref = "1.9.4"
3434
lodepng = { version = "3.7.2", optional = true }
3535
pbr = { version = "1.0.4", optional = true }
@@ -44,6 +44,7 @@ loop9 = "0.1.3"
4444
# noisy-float 0.2 bug
4545
num-traits = { version = "0.2.15", features = ["i128", "std"] }
4646
crossbeam-utils = "0.8.12"
47+
scopeguard = "1.1.0"
4748

4849
[dependencies.ffmpeg]
4950
package = "ffmpeg-next"

gifski-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See [releases](https://github.com/ImageOptim/gifski/releases) page for executabl
1414

1515
If you have [Homebrew](https://brew.sh/), you can also get it with `brew install gifski`.
1616

17-
If you have [Rust](https://www.rust-lang.org/install.html) 1.60+, you can also build it from source with [`cargo install gifski`](https://lib.rs/crates/gifski).
17+
If you have [Rust from rustup](https://www.rust-lang.org/install.html) (1.63+), you can also build it from source with [`cargo install gifski`](https://lib.rs/crates/gifski).
1818

1919
## Usage
2020

gifski-api/src/bin/ffmpeg_source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct FfmpegDecoder {
1414
}
1515

1616
impl Source for FfmpegDecoder {
17-
fn total_frames(&self) -> u64 {
18-
self.frames
17+
fn total_frames(&self) -> Option<u64> {
18+
Some(self.frames)
1919
}
2020
fn collect(&mut self, dest: &mut Collector) -> BinResult<()> {
2121
self.collect_frames(dest)
@@ -70,7 +70,7 @@ impl FfmpegDecoder {
7070
};
7171

7272

73-
let mut add_frame = |rgba_frame: &ffmpeg::util::frame::Video, pts: f64, pos: i64| -> BinResult<()> {
73+
let add_frame = |rgba_frame: &ffmpeg::util::frame::Video, pts: f64, pos: i64| -> BinResult<()> {
7474
let stride = rgba_frame.stride(0) as usize;
7575
if stride % 4 != 0 {
7676
Err("incompatible video")?;

gifski-api/src/bin/gif.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! This is for reading GIFs as an input for re-encoding as another GIF
2+
3+
use std::fs::File;
4+
use gif::Decoder;
5+
use gifski::Collector;
6+
use std::path::Path;
7+
use crate::{source::{Fps, Source}, BinResult};
8+
9+
pub struct GifDecoder {
10+
speed: f32,
11+
decoder: Decoder<File>,
12+
screen: gif_dispose::Screen,
13+
}
14+
15+
impl GifDecoder {
16+
pub fn new(path: &Path, fps: Fps) -> BinResult<Self> {
17+
let file = std::fs::File::open(path)?;
18+
19+
let mut gif_opts = gif::DecodeOptions::new();
20+
// Important:
21+
gif_opts.set_color_output(gif::ColorOutput::Indexed);
22+
23+
let decoder = gif_opts.read_info(file)?;
24+
let screen = gif_dispose::Screen::new_decoder(&decoder);
25+
26+
Ok(Self {
27+
speed: fps.speed,
28+
decoder,
29+
screen,
30+
})
31+
}
32+
}
33+
34+
impl Source for GifDecoder {
35+
fn total_frames(&self) -> Option<u64> { None }
36+
fn collect(&mut self, c: &mut Collector) -> BinResult<()> {
37+
let mut idx = 0;
38+
let mut delay_ts = 0;
39+
while let Some(frame) = self.decoder.read_next_frame()? {
40+
self.screen.blit_frame(frame)?;
41+
let pixels = self.screen.pixels.clone();
42+
let presentation_timestamp = f64::from(delay_ts) * (self.speed as f64 / 100.);
43+
c.add_frame_rgba(idx, pixels, presentation_timestamp)?;
44+
idx += 1;
45+
delay_ts += frame.delay as u32;
46+
}
47+
Ok(())
48+
}
49+
}

0 commit comments

Comments
 (0)