From 17a380cd78814ae2a9a216e23cbcc56d43e84836 Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 11 Nov 2019 16:20:29 +0000 Subject: [PATCH] Properly fix GIF looping when the quality is less than 100% (#160) --- gifski-api/Cargo.lock | 150 +++++++++++--------- gifski-api/Cargo.toml | 4 +- gifski-api/gifski.xcodeproj/project.pbxproj | 2 +- gifski-api/src/c_api.rs | 52 ++++--- gifski-api/src/encodegifsicle.rs | 4 +- gifski-api/src/progress.rs | 4 +- 6 files changed, 118 insertions(+), 98 deletions(-) diff --git a/gifski-api/Cargo.lock b/gifski-api/Cargo.lock index 4dbd9158..4fbb0729 100644 --- a/gifski-api/Cargo.lock +++ b/gifski-api/Cargo.lock @@ -16,41 +16,38 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "arrayvec" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "atty" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "backtrace" -version = "0.3.38" +version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -79,12 +76,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -106,7 +103,7 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -117,7 +114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -131,23 +128,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crossbeam-deque" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -168,6 +165,16 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-utils" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "either" version = "1.5.3" @@ -187,7 +194,7 @@ name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -198,7 +205,7 @@ source = "git+https://github.com/kornelski/rust-ffmpeg.git#0eea6d01eab7baf35b445 dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "ffmpeg-sys 4.0.2 (git+https://github.com/meh/rust-ffmpeg-sys)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -207,10 +214,10 @@ version = "4.0.2" source = "git+https://github.com/meh/rust-ffmpeg-sys#4f14151b9b8134f1f029d49d02cbea5c7337dedb" dependencies = [ "bindgen 0.32.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -238,13 +245,13 @@ name = "gifsicle" version = "1.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "gifski" -version = "0.9.2" +version = "0.9.3" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,13 +280,21 @@ name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "hermit-abi" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "imagequant" version = "2.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "imagequant-sys 2.12.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -287,7 +302,7 @@ name = "imagequant-sys" version = "2.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", "openmp-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -313,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.62" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -331,7 +346,7 @@ name = "lodepng" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -361,7 +376,7 @@ name = "memchr" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -371,7 +386,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memoffset" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -382,11 +397,6 @@ name = "natord" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "nodrop" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "nom" version = "3.2.1" @@ -397,10 +407,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -413,7 +424,7 @@ name = "openmp-sys" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -421,7 +432,7 @@ name = "pbr" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -434,7 +445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pkg-config" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -458,7 +469,7 @@ name = "rayon" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -468,11 +479,11 @@ name = "rayon-core" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -559,7 +570,7 @@ name = "termion" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -586,7 +597,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -626,7 +637,7 @@ name = "which" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -669,23 +680,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)" = "690a62be8920ccf773ee00ef0968649b0e724cda8bd5b12286302b4ae955fdf5" -"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" +"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum bindgen 0.32.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b242e11a8f446f5fc7b76b37e81d737cabca562a927bd33766dac55b5f1177f" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" -"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" "checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum clang-sys 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e414af9726e1d11660801e73ccc7fb81803fb5f49e5903a25b348b2b3b480d2e" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" -"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" -"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" +"checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" +"checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" +"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" @@ -696,12 +708,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gifsicle 1.92.0 (registry+https://github.com/rust-lang/crates.io-index)" = "430b8c1b679b0814dfe7e2912e4f3766f00f5e95d1b3570d3a1c6e08c2395ec4" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum imagequant 2.11.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a80fc16cab2203b5ed3bc10d3a957ff2789366b2eebcc7905e87b6277cee0019" "checksum imagequant-sys 2.12.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdae38117d89989b2c2352cec3d7dca12a207b48b4e20e183b7d0d6b1fd390c" "checksum imgref 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a45f5dd9db42f924c8e75d53777c4ea87a024b162ddb4af5dbe7c1add901a212" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fd38073de8f7965d0c17d30546d4bb6da311ab428d1c7a3fc71dff7f9d4979b9" "checksum lodepng 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40ed9859b15e009b494528f32ad054c5baf67afabf3c05d27973ea151563d430" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" @@ -709,16 +722,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" -"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" +"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" "checksum natord 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b" -"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" +"checksum num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "155394f924cdddf08149da25bfb932d226b4a593ca7468b08191ff6335941af5" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum openmp-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "60a5c0c0eae12a4db51e0d1d461687a873b154940d25e8e060db16e308cbe4da" "checksum pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4403eb718d70c03ee279e51737782902c68cca01e870a33b6a2f9dfb50b9cd83" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -"checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea" +"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" "checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123" diff --git a/gifski-api/Cargo.toml b/gifski-api/Cargo.toml index 6290957a..ddf34b53 100644 --- a/gifski-api/Cargo.toml +++ b/gifski-api/Cargo.toml @@ -4,13 +4,13 @@ categories = ["multimedia::video", "command-line-utilities"] description = "pngquant-based GIF maker for nice-looking animGIFs" documentation = "https://docs.rs/gifski" homepage = "https://gif.ski" -include = ["/README.md", "/Cargo.toml", "/src/*.rs", "/src/bin/*.rs"] +include = ["/README.md", "/Cargo.toml", "/src/**/*.rs", "/src/bin/*.rs"] keywords = ["gif", "encoder", "converter", "maker", "gifquant"] license = "AGPL-3.0+" name = "gifski" readme = "README.md" repository = "https://github.com/ImageOptim/gifski" -version = "0.9.2" +version = "0.9.3" autobins = false edition = "2018" diff --git a/gifski-api/gifski.xcodeproj/project.pbxproj b/gifski-api/gifski.xcodeproj/project.pbxproj index e94c437f..e993be6a 100644 --- a/gifski-api/gifski.xcodeproj/project.pbxproj +++ b/gifski-api/gifski.xcodeproj/project.pbxproj @@ -49,7 +49,7 @@ /* Begin PBXLegacyTarget section */ CA60FB6F97415B50F10B8D0B /* Cargo */ = { isa = PBXLegacyTarget; - buildArgumentsString = "build $(CARGO_FLAGS)"; + buildArgumentsString = "build --features=gifsicle $(CARGO_FLAGS)"; buildConfigurationList = CA6045D4FC1B1EBBFEF4C27E /* Build configuration list for PBXLegacyTarget "Cargo" */; buildPhases = ( ); diff --git a/gifski-api/src/c_api.rs b/gifski-api/src/c_api.rs index 45faf0c5..110cc7ce 100644 --- a/gifski-api/src/c_api.rs +++ b/gifski-api/src/c_api.rs @@ -29,7 +29,7 @@ use std::fs::File; use std::ffi::CStr; use std::path::{PathBuf, Path}; mod c_api_error; -use c_api_error::*; +use self::c_api_error::*; /// Settings for creating a new encoder instance. See `gifski_new` #[repr(C)] @@ -56,9 +56,13 @@ pub struct ARGB8 { pub b: u8, } -/// Opaque handle used in methods. Note that the handle pointer is actually `Arc`, +/// Opaque handle used in methods. Note that the handle pointer is actually `Arc`, /// but `Arc::into_raw` is nice enough to point past the counter. +#[repr(C)] pub struct GifskiHandle { + _opaque: usize, +} +pub struct GifskiHandleInternal { writer: Mutex>, collector: Mutex>, progress: Mutex>, @@ -84,12 +88,12 @@ pub unsafe extern "C" fn gifski_new(settings: *const GifskiSettings) -> *const G }; if let Ok((collector, writer)) = new(s) { - Arc::into_raw(Arc::new(GifskiHandle { + Arc::into_raw(Arc::new(GifskiHandleInternal { writer: Mutex::new(Some(writer)), write_thread: Mutex::new((false, None)), collector: Mutex::new(Some(collector)), progress: Mutex::new(None), - })) + })) as *const GifskiHandle } else { ptr::null_mut() } @@ -105,7 +109,7 @@ pub unsafe extern "C" fn gifski_add_frame_png_file(handle: *const GifskiHandle, if file_path.is_null() { return GifskiError::NULL_ARG; } - let g = match handle.as_ref() { + let g = match borrow(handle) { Some(g) => g, None => return GifskiError::NULL_ARG, }; @@ -141,7 +145,7 @@ pub unsafe extern "C" fn gifski_add_frame_rgba(handle: *const GifskiHandle, inde } fn add_frame_rgba(handle: *const GifskiHandle, index: u32, frame: ImgVec, delay: u16) -> GifskiError { - let g = match unsafe { handle.as_ref() } { + let g = match unsafe { borrow(handle) } { Some(g) => g, None => return GifskiError::NULL_ARG, }; @@ -195,7 +199,7 @@ pub unsafe extern "C" fn gifski_add_frame_rgb(handle: *const GifskiHandle, index /// Optional. Allows deprecated `gifski_write` to finish. #[no_mangle] pub unsafe extern "C" fn gifski_end_adding_frames(handle: *const GifskiHandle) -> GifskiError { - let g = match handle.as_ref() { + let g = match borrow(handle) { Some(g) => g, None => return GifskiError::NULL_ARG, }; @@ -218,8 +222,8 @@ pub unsafe extern "C" fn gifski_end_adding_frames(handle: *const GifskiHandle) - /// /// Must be called before `gifski_set_file_output()` to take effect. #[no_mangle] -pub unsafe extern "C" fn gifski_set_progress_callback(handle: *const GifskiHandle, cb: unsafe fn(*mut c_void) -> c_int, user_data: *mut c_void) { - let g = match handle.as_ref() { +pub unsafe extern "C" fn gifski_set_progress_callback(handle: *const GifskiHandle, cb: unsafe extern fn(*mut c_void) -> c_int, user_data: *mut c_void) { + let g = match borrow(handle) { Some(g) => g, None => return, }; @@ -236,7 +240,7 @@ pub unsafe extern "C" fn gifski_set_progress_callback(handle: *const GifskiHandl /// Returns 0 (`GIFSKI_OK`) on success, and non-0 `GIFSKI_*` constant on error. #[no_mangle] pub unsafe extern "C" fn gifski_write(handle: *const GifskiHandle, destination: *const c_char) -> GifskiError { - let g = match handle.as_ref() { + let g = match borrow(handle) { Some(g) => g, None => return GifskiError::NULL_ARG, }; @@ -277,7 +281,7 @@ pub unsafe extern "C" fn gifski_set_file_output(handle: *const GifskiHandle, des } -fn prepare_for_file_writing(g: &GifskiHandle, destination: *const c_char) -> Result<(File, PathBuf), GifskiError> { +fn prepare_for_file_writing(g: &GifskiHandleInternal, destination: *const c_char) -> Result<(File, PathBuf), GifskiError> { if destination.is_null() { return Err(GifskiError::NULL_ARG); } @@ -298,7 +302,7 @@ fn prepare_for_file_writing(g: &GifskiHandle, destination: *const c_char) -> Res } struct CallbackWriter { - cb: unsafe fn(usize, *const u8, *mut c_void) -> c_int, + cb: unsafe extern fn(usize, *const u8, *mut c_void) -> c_int, user_data: *mut c_void, } @@ -334,7 +338,7 @@ impl io::Write for CallbackWriter { /// /// Returns 0 (`GIFSKI_OK`) on success, and non-0 `GIFSKI_*` constant on error. #[no_mangle] -pub unsafe extern "C" fn gifski_set_write_callback(handle: *const GifskiHandle, cb: Option c_int>, user_data: *mut c_void) -> GifskiError { +pub unsafe extern "C" fn gifski_set_write_callback(handle: *const GifskiHandle, cb: Option c_int>, user_data: *mut c_void) -> GifskiError { if handle.is_null() { return GifskiError::NULL_ARG; } @@ -359,7 +363,7 @@ pub unsafe extern "C" fn gifski_set_write_callback(handle: *const GifskiHandle, } -fn gifski_write_sync_internal(g: &GifskiHandle, file: W, path: Option) -> GifskiError { +fn gifski_write_sync_internal(g: &GifskiHandleInternal, file: W, path: Option) -> GifskiError { if let Some(writer) = g.writer.lock().unwrap().take() { let mut tmp; let mut progress: &mut dyn ProgressReporter = &mut NoProgress {}; @@ -383,8 +387,14 @@ fn gifski_write_sync_internal(g: &GifskiHandle, file: W, path: } } +unsafe fn borrow<'a>(handle: *const GifskiHandle) -> Option<&'a GifskiHandleInternal> { + let g = handle as *const GifskiHandleInternal; + g.as_ref() +} + /// get refcount++ without dropping the handle -unsafe fn retain(arc_ptr: *const T) -> Arc { +unsafe fn retain(arc_ptr: *const GifskiHandle) -> Arc { + let arc_ptr = arc_ptr as *const GifskiHandleInternal; let tmp = Arc::from_raw(arc_ptr); let g = Arc::clone(&tmp); let _ = Arc::into_raw(tmp); @@ -405,7 +415,7 @@ pub unsafe extern "C" fn gifski_finish(g: *const GifskiHandle) -> GifskiError { if g.is_null() { return GifskiError::NULL_ARG; } - let g = Arc::from_raw(g); + let g = Arc::from_raw(g as *const GifskiHandleInternal); // dropping of the collector (if any) completes writing *g.collector.lock().unwrap() = None; @@ -429,7 +439,7 @@ fn c_cb() { })}; assert!(!g.is_null()); let mut called = false; - unsafe fn cb(_s: usize, _buf: *const u8, user_data: *mut c_void) -> c_int { + unsafe extern fn cb(_s: usize, _buf: *const u8, user_data: *mut c_void) -> c_int { let called = user_data as *mut bool; *called = true; 0 @@ -452,7 +462,7 @@ fn cant_write_after_finish() { })}; assert!(!g.is_null()); let mut called = false; - unsafe fn cb(_s: usize, _buf: *const u8, user_data: *mut c_void) -> c_int { + unsafe extern fn cb(_s: usize, _buf: *const u8, user_data: *mut c_void) -> c_int { let called = user_data as *mut bool; *called = true; 0 @@ -472,7 +482,7 @@ fn c_write_failure_propagated() { fast: false, })}; assert!(!g.is_null()); - unsafe fn cb(_s: usize, _buf: *const u8, _user: *mut c_void) -> c_int { + unsafe extern fn cb(_s: usize, _buf: *const u8, _user: *mut c_void) -> c_int { GifskiError::WRITE_ZERO as c_int } unsafe { @@ -491,7 +501,7 @@ fn cant_write_twice() { fast: false, })}; assert!(!g.is_null()); - unsafe fn cb(_s: usize, _buf: *const u8, _user: *mut c_void) -> c_int { + unsafe extern fn cb(_s: usize, _buf: *const u8, _user: *mut c_void) -> c_int { GifskiError::WRITE_ZERO as c_int } unsafe { @@ -516,7 +526,7 @@ fn c_incomplete() { unsafe { assert_eq!(GifskiError::NULL_ARG, gifski_add_frame_rgba(g, 0, 1, 1, ptr::null(), 5)); } - fn cb(_: *mut c_void) -> c_int { + extern fn cb(_: *mut c_void) -> c_int { 1 } unsafe { diff --git a/gifski-api/src/encodegifsicle.rs b/gifski-api/src/encodegifsicle.rs index e9149991..10616284 100644 --- a/gifski-api/src/encodegifsicle.rs +++ b/gifski-api/src/encodegifsicle.rs @@ -76,9 +76,7 @@ impl Encoder for Gifsicle<'_> { }; gfs.screen_width = image.width() as _; gfs.screen_height = image.height() as _; - if settings.once { - gfs.loopcount = 1; - } + gfs.loopcount = if settings.once {1} else {0}; // 0 means infinite unsafe { self.gif_writer = Gif_IncrementalWriteFileInit(gfs, &self.info, ptr::null_mut()); if self.gif_writer.is_null() { diff --git a/gifski-api/src/progress.rs b/gifski-api/src/progress.rs index d46cb5c4..e1590461 100644 --- a/gifski-api/src/progress.rs +++ b/gifski-api/src/progress.rs @@ -16,14 +16,14 @@ pub struct NoProgress {} /// For C pub struct ProgressCallback { - callback: unsafe fn(*mut c_void) -> c_int, + callback: unsafe extern fn(*mut c_void) -> c_int, arg: *mut c_void, } unsafe impl Send for ProgressCallback {} impl ProgressCallback { - pub fn new(callback: unsafe fn(*mut c_void) -> c_int, arg: *mut c_void) -> Self { + pub fn new(callback: unsafe extern fn(*mut c_void) -> c_int, arg: *mut c_void) -> Self { Self { callback, arg, }