Skip to content

Commit

Permalink
Update libgifski
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 14, 2020
1 parent bdee22c commit efb8a03
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 199 deletions.
62 changes: 9 additions & 53 deletions gifski-api/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions gifski-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "AGPL-3.0+"
name = "gifski"
readme = "README.md"
repository = "https://github.com/ImageOptim/gifski"
version = "0.10.2"
version = "1.0.0"
autobins = false
edition = "2018"

Expand All @@ -21,7 +21,6 @@ name = "gifski"
[dependencies]
gifsicle = { version = "1.92.0", optional = true }
clap = "2.33.0"
error-chain = "0.12.2"
gif = "0.10.3"
gif-dispose = "2.2.0"
imagequant = "2.12.5"
Expand All @@ -32,6 +31,7 @@ resize = "0.4.0"
rgb = "0.8.16"
wild = "2.0.2"
natord = "1.0.9"
quick-error = "1.2.3"

[dependencies.ffmpeg]
rev = "61a668f5e105232df4af367d332bbd54de3d9f13"
Expand All @@ -50,9 +50,12 @@ malloc = []
path = "src/lib.rs"
crate-type = ["lib", "staticlib", "cdylib"]

[profile.dev]
opt-level = 1
[profile.dev.package.imagequant]
opt-level = 3

[profile.release]
panic = "abort"
lto = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
2 changes: 1 addition & 1 deletion gifski-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It's a CLI tool, but it can also be compiled [as a C library](https://docs.rs/gi

See [releases](https://github.com/ImageOptim/gifski/releases) page for executables.

If you have [Rust](https://www.rust-lang.org/install.html) 1.31+, you can also get it with [`cargo install gifski`](https://crates.rs/crates/gifski). Run `cargo build --release --features=openmp` to build from source.
If you have [Rust](https://www.rust-lang.org/install.html) 1.42+, you can also get it with [`cargo install gifski`](https://crates.rs/crates/gifski). Run `cargo build --release --features=openmp` to build from source.

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

Expand Down
14 changes: 1 addition & 13 deletions gifski-api/gifski.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,13 @@ GifskiError gifski_set_write_callback(gifski *handle,
*
* Returns final status of write operations. Remember to check the return value!
*
* Must always be called, otherwise it will leak memory.
* After this call, the handle is freed and can't be used any more.
*
* Returns 0 (`GIFSKI_OK`) on success, and non-0 `GIFSKI_*` constant on error.
*/
GifskiError gifski_finish(gifski *g);

// Previous, deprecated name
#define gifski_drop(a) gifski_finish(a)

/**
* Deprecated. Do not use.
*/
GifskiError gifski_write(gifski *, const char *);

/**
* Optional. Allows deprecated `gifski_write` to finish.
*/
GifskiError gifski_end_adding_frames(gifski *handle);

#ifdef __cplusplus
}
#endif
22 changes: 0 additions & 22 deletions gifski-api/src/bin/error.rs

This file was deleted.

8 changes: 4 additions & 4 deletions gifski-api/src/bin/ffmpeg_source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::*;
use crate::BinResult;
use gifski::Collector;
use imgref::*;
use rgb::*;
Expand All @@ -23,9 +23,9 @@ impl Source for FfmpegDecoder {

impl FfmpegDecoder {
pub fn new(path: &Path, fps: f32) -> BinResult<Self> {
ffmpeg::init().chain_err(|| "Unable to initialize ffmpeg")?;
ffmpeg::init().map_err(|e| format!("Unable to initialize ffmpeg: {}", e))?;
let input_context = ffmpeg::format::input(&path)
.chain_err(|| format!("Unable to open video file {}", path.display()))?;
.map_err(|e| format!("Unable to open video file {}: {}", path.display(), e))?;
// take fps override into account
let frames = input_context.streams().best(ffmpeg::media::Type::Video).ok_or("The file has no video tracks")?.frames() as u64;
Ok(Self {
Expand All @@ -40,7 +40,7 @@ impl FfmpegDecoder {
let (stream_index, mut decoder, mut converter, time_base) = {
let stream = self.input_context.streams().best(ffmpeg::media::Type::Video).ok_or("The file has no video tracks")?;

let decoder = stream.codec().decoder().video().chain_err(|| "Unable to decode the codec used in the video")?;
let decoder = stream.codec().decoder().video().map_err(|e| format!("Unable to decode the codec used in the video: {}", e))?;

let converter = decoder.converter(ffmpeg::util::format::pixel::Pixel::RGBA)?;
(stream.index(), decoder, converter, stream.time_base())
Expand Down
26 changes: 15 additions & 11 deletions gifski-api/src/bin/gifski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::alloc::System;
#[cfg_attr(feature = "malloc", global_allocator)]
static A: System = System;

use gifski;
#[macro_use] extern crate clap;
#[macro_use] extern crate error_chain;

#[cfg(feature = "video")]
extern crate ffmpeg;
Expand All @@ -23,9 +21,7 @@ use crate::source::*;

use gifski::progress::{NoProgress, ProgressBar, ProgressReporter};

mod error;
use crate::error::ResultExt;
use crate::error::*;
pub type BinResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;

use clap::{App, AppSettings, Arg};

Expand All @@ -40,7 +36,15 @@ const VIDEO_FRAMES_ARG_HELP: &'static str = "one MP4/WebM video, or multiple PNG
#[cfg(not(feature = "video"))]
const VIDEO_FRAMES_ARG_HELP: &'static str = "PNG animation frames";

quick_main!(bin_main);
fn main() {
if let Err(e) = bin_main() {
eprintln!("error: {}", e);
if let Some(e) = e.source() {
eprintln!("error: {}", e);
}
std::process::exit(1);
}
}

fn bin_main() -> BinResult<()> {
let matches = App::new(crate_name!())
Expand Down Expand Up @@ -108,14 +112,14 @@ fn bin_main() -> BinResult<()> {

let output_path = Path::new(matches.value_of_os("output").ok_or("Missing output")?);
let settings = gifski::Settings {
width: parse_opt(matches.value_of("width")).chain_err(|| "Invalid width")?,
height: parse_opt(matches.value_of("height")).chain_err(|| "Invalid height")?,
quality: parse_opt(matches.value_of("quality")).chain_err(|| "Invalid quality")?.unwrap_or(100),
width: parse_opt(matches.value_of("width")).map_err(|_| "Invalid width")?,
height: parse_opt(matches.value_of("height")).map_err(|_| "Invalid height")?,
quality: parse_opt(matches.value_of("quality")).map_err(|_| "Invalid quality")?.unwrap_or(100),
once: matches.is_present("once"),
fast: matches.is_present("fast"),
};
let quiet = matches.is_present("quiet");
let fps: f32 = matches.value_of("fps").ok_or("Missing fps")?.parse().chain_err(|| "FPS must be a number")?;
let fps: f32 = matches.value_of("fps").ok_or("Missing fps")?.parse().map_err(|_| "FPS must be a number")?;

if settings.quality < 20 {
if settings.quality < 1 {
Expand Down Expand Up @@ -153,7 +157,7 @@ fn bin_main() -> BinResult<()> {
});

let file = File::create(output_path)
.chain_err(|| format!("Can't write to {}", output_path.display()))?;
.map_err(|e| format!("Can't write to {}: {}", output_path.display(), e))?;
writer.write(file, &mut *progress)?;
decode_thread.join().unwrap()?;
progress.done(&format!("gifski created {}", output_path.display()));
Expand Down
4 changes: 2 additions & 2 deletions gifski-api/src/bin/png.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::*;
use crate::source::*;
use crate::source::Source;
use crate::BinResult;
use gifski::Collector;
use std::path::PathBuf;

Expand Down
2 changes: 1 addition & 1 deletion gifski-api/src/bin/source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::*;
use crate::BinResult;
use gifski::Collector;

pub trait Source: Send {
Expand Down
Loading

0 comments on commit efb8a03

Please sign in to comment.