Skip to content

Commit

Permalink
release: 2.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Feb 8, 2024
2 parents d3ea252 + bc66367 commit 5123842
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 60 deletions.
22 changes: 11 additions & 11 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
# Project Dependencies
Package: flaca
Version: 2.4.5
Generated: 2024-01-21 05:28:01 UTC
Version: 2.4.6
Generated: 2024-02-08 20:08:35 UTC

| Package | Version | Author(s) | License |
| ---- | ---- | ---- | ---- |
| [ahash](https://github.com/tkaitchuck/ahash) | 0.8.7 | [Tom Kaitchuck](mailto:tom.kaitchuck@gmail.com) | Apache-2.0 or MIT |
| [argyle](https://github.com/Blobfolio/argyle) | 0.7.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [argyle](https://github.com/Blobfolio/argyle) | 0.7.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [bitvec](https://github.com/bitvecto-rs/bitvec) | 1.0.1 | | MIT |
| [bytecount](https://github.com/llogiq/bytecount) | 0.6.7 | [Andre Bogus](mailto:bogusandre@gmail.de) and [Joshua Landau](mailto:joshua@landau.ws) | Apache-2.0 or MIT |
| [bytemuck](https://github.com/Lokathor/bytemuck) | 1.14.0 | [Lokathor](mailto:zefria@gmail.com) | Apache-2.0, MIT, or Zlib |
| [bytemuck](https://github.com/Lokathor/bytemuck) | 1.14.2 | [Lokathor](mailto:zefria@gmail.com) | Apache-2.0, MIT, or Zlib |
| [cfg-if](https://github.com/alexcrichton/cfg-if) | 1.0.0 | [Alex Crichton](mailto:alex@alexcrichton.com) | Apache-2.0 or MIT |
| [crossbeam-deque](https://github.com/crossbeam-rs/crossbeam) | 0.8.5 | | Apache-2.0 or MIT |
| [crossbeam-epoch](https://github.com/crossbeam-rs/crossbeam) | 0.9.18 | | Apache-2.0 or MIT |
| [crossbeam-utils](https://github.com/crossbeam-rs/crossbeam) | 0.8.19 | | Apache-2.0 or MIT |
| [ctrlc](https://github.com/Detegr/rust-ctrlc.git) | 3.4.2 | [Antti Keränen](mailto:detegr@gmail.com) | Apache-2.0 or MIT |
| [dactyl](https://github.com/Blobfolio/dactyl) | 0.6.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [dowser](https://github.com/Blobfolio/dowser) | 0.8.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [dactyl](https://github.com/Blobfolio/dactyl) | 0.7.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [dowser](https://github.com/Blobfolio/dowser) | 0.8.2 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [either](https://github.com/bluss/either) | 1.9.0 | bluss | Apache-2.0 or MIT |
| [equivalent](https://github.com/cuviper/equivalent) | 1.0.1 | | Apache-2.0 or MIT |
| [fastrand](https://github.com/smol-rs/fastrand) | 2.0.1 | [Stjepan Glavina](mailto:stjepang@gmail.com) | Apache-2.0 or MIT |
| [funty](https://github.com/myrrlyn/funty) | 2.0.0 | [myrrlyn](mailto:self@myrrlyn.dev) | MIT |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.11.8 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.12.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.14.3 | [Amanieu d'Antras](mailto:amanieu@gmail.com) | Apache-2.0 or MIT |
| [indexmap](https://github.com/bluss/indexmap) | 2.1.0 | | Apache-2.0 or MIT |
| [libc](https://github.com/rust-lang/libc) | 0.2.152 | The Rust Project Developers | Apache-2.0 or MIT |
| [indexmap](https://github.com/indexmap-rs/indexmap) | 2.2.2 | | Apache-2.0 or MIT |
| [libc](https://github.com/rust-lang/libc) | 0.2.153 | The Rust Project Developers | Apache-2.0 or MIT |
| [libdeflate-sys](https://github.com/adamkewley/libdeflater) | 1.19.0 | [Adam Kewley](mailto:contact@adamkewley.com) | Apache-2.0 |
| [libdeflater](https://github.com/adamkewley/libdeflater) | 1.19.0 | [Adam Kewley](mailto:contact@adamkewley.com) | Apache-2.0 |
| [log](https://github.com/rust-lang/log) | 0.4.20 | The Rust Project Developers | Apache-2.0 or MIT |
| [mozjpeg-sys](https://github.com/kornelski/mozjpeg-sys.git) | 2.0.5 | [Kornel](mailto:kornel@geekhood.net) | IJG AND Zlib AND BSD-3-Clause |
| [mozjpeg-sys](https://github.com/kornelski/mozjpeg-sys.git) | 2.0.6 | [Kornel](mailto:kornel@geekhood.net) | IJG AND Zlib AND BSD-3-Clause |
| [oxipng](https://github.com/shssoichiro/oxipng) | 9.0.0 | [Joshua Holmer](mailto:jholmer.in@gmail.com) | MIT |
| [radium](https://github.com/bitvecto-rs/radium) | 0.7.0 | [Nika Layzell](mailto:nika@thelayzells.com) and [myrrlyn](mailto:self@myrrlyn.dev) | MIT |
| [rayon](https://github.com/rayon-rs/rayon) | 1.8.1 | [Niko Matsakis](mailto:niko@alum.mit.edu) and [Josh Stone](mailto:cuviper@gmail.com) | Apache-2.0 or MIT |
| [rayon-core](https://github.com/rayon-rs/rayon) | 1.12.1 | [Niko Matsakis](mailto:niko@alum.mit.edu) and [Josh Stone](mailto:cuviper@gmail.com) | Apache-2.0 or MIT |
| [rgb](https://github.com/kornelski/rust-rgb) | 0.8.37 | [Kornel Lesiński](mailto:kornel@geekhood.net) | MIT |
| [rustc-hash](https://github.com/rust-lang-nursery/rustc-hash) | 1.1.0 | The Rust Project Developers | Apache-2.0 or MIT |
| [tap](https://github.com/myrrlyn/tap) | 1.0.1 | [Elliott Linder](mailto:elliott.darfink@gmail.com) and [myrrlyn](mailto:self@myrrlyn.dev) | MIT |
| [tempfile](https://github.com/Stebalien/tempfile) | 3.9.0 | [Steven Allen](mailto:steven@stebalien.com), The Rust Project Developers, [Ashley Mannix](mailto:ashleymannix@live.com.au), and [Jason White](mailto:me@jasonwhite.io) | Apache-2.0 or MIT |
| [tempfile](https://github.com/Stebalien/tempfile) | 3.10.0 | [Steven Allen](mailto:steven@stebalien.com), The Rust Project Developers, [Ashley Mannix](mailto:ashleymannix@live.com.au), and [Jason White](mailto:me@jasonwhite.io) | Apache-2.0 or MIT |
| [term_size](https://github.com/kbknapp/term_size-rs.git) | 0.3.2 | [Kevin K.](mailto:kbknapp@gmail.com) and [Benjamin Sago](mailto:ogham@bsago.me) | Apache-2.0 or MIT |
| [unicode-width](https://github.com/unicode-rs/unicode-width) | 0.1.11 | [kwantam](mailto:kwantam@gmail.com) and [Manish Goregaokar](mailto:manishsmail@gmail.com) | Apache-2.0 or MIT |
| [write_atomic](https://github.com/Blobfolio/write_atomic) | 0.5.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flaca"
version = "2.4.5"
version = "2.4.6"
license = "WTFPL"
authors = ["Josh Stoik <josh@blobfolio.com>"]
edition = "2021"
Expand Down Expand Up @@ -103,18 +103,18 @@ items = [
[dependencies]
argyle = "0.7.*"
ctrlc = "3.4.*"
dactyl = "0.6.*"
dactyl = "0.7.*"
dowser = "0.8.*"
libc = "0.2.*"
rayon = "1.8.*"
write_atomic = "0.5.*"

[dependencies.fyi_msg]
version = "0.11.*"
version = "0.12.*"
features = [ "progress" ]

[dependencies.mozjpeg-sys]
version = "=2.0.5"
version = "=2.0.6"
features = [ "jpegtran" ]

[dependencies.oxipng]
Expand Down
12 changes: 9 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ const E_PNG: Extension = {};
write(&out_path, out.as_bytes());
}

/// # Build Zopflipng.
/// # Build `zopfli`/`lodepng`.
///
/// Rust's Zopfli implementation is insufficient for our needs; we have to link
/// to the static libs for some FFI action instead.
/// The Rust ports of these libraries are missing features that noticeably
/// affect PNG compression, and are quite a bit slower than the original C
/// libraries as well. Unless/until that changes, we'll have to work with the
/// originals.
///
/// The relevant `zopflipng` bits, though, were easily ported to the Flaca
/// library proper, so we can at least avoid the headaches associated with C++
/// interop!
fn build_ffi() {
// Define some paths.
let repo = Path::new("skel/vendor");
Expand Down
4 changes: 2 additions & 2 deletions release/man/flaca.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FLACA" "1" "January 2024" "Flaca v2.4.5" "User Commands"
.TH "FLACA" "1" "February 2024" "Flaca v2.4.6" "User Commands"
.SH NAME
Flaca \- Manual page for flaca v2.4.5.
Flaca \- Manual page for flaca v2.4.6.
.SH DESCRIPTION
Brute\-force, lossless JPEG and PNG compression.
.SS USAGE:
Expand Down
9 changes: 1 addition & 8 deletions skel/vendor/custom_png_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ unsigned custom_png_deflate(unsigned char** out, size_t* outsize,
const unsigned char* in, size_t insize,
const LodePNGCompressSettings* settings) {
unsigned char bp = 0;
int numiterations = *(int*)settings->custom_context;
ZopfliOptions options;
ZopfliInitOptions(&options);

if (numiterations <= 0) {
options.numiterations = insize < 200000 ? 60 : 20;
}
else {
options.numiterations = numiterations;
}
options.numiterations = flaca_zopfli_iterations(insize);

ZopfliDeflate(&options, 2, 1, in, insize, &bp, out, outsize);
return 0;
Expand Down
7 changes: 7 additions & 0 deletions skel/vendor/custom_png_deflate.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "lodepng/lodepng.h"
#include "zopfli/deflate.h"

/*
Rust Extern: Zopfli Iterations
This returns the number of iterations to use during compression.
*/
extern int flaca_zopfli_iterations(size_t);

/*
Custom PNG Deflate
Expand Down
3 changes: 1 addition & 2 deletions src/image/lodepng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub(super) enum LodePNGFilterStrategy {
LFS_FOUR = 4,
LFS_MINSUM = 5,
LFS_ENTROPY = 6,
// LFS_BRUTE_FORCE = 7, // This strategy is redundant.
LFS_BRUTE_FORCE = 7,
// LFS_PREDEFINED = 8, // This strategy is redundant.
}

Expand Down Expand Up @@ -349,7 +349,6 @@ impl LodePNGState {
if slow {
enc.encoder.zlibsettings.windowsize = 32_768;
enc.encoder.zlibsettings.custom_deflate = Some(custom_png_deflate);
enc.encoder.zlibsettings.custom_context = super::zopfli_iterations().cast::<c_void>();
}
else {
enc.encoder.zlibsettings.windowsize = 8_192;
Expand Down
30 changes: 1 addition & 29 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,7 @@ mod zopflipng;

use kind::ImageKind;
use oxipng::Options as OxipngOptions;
use std::{
os::raw::c_int,
path::Path,
sync::Once,
};



/// # Number of Zopfli Iterations.
static mut ITERATIONS: c_int = 0;
static INIT_ITERATIONS: Once = Once::new();

#[allow(unsafe_code, clippy::cast_lossless)]
/// # Set Iteration Count.
pub(super) fn set_zopfli_iterations(num: i32) {
if 0 < num {
// Safety: this is called by main.rs before any processing begins.
unsafe {
INIT_ITERATIONS.call_once(|| { ITERATIONS = num; });
}
}
}

#[allow(unsafe_code)]
/// # Return Iteration Count.
fn zopfli_iterations() -> *const c_int {
// Safety: mutations, if any, will have already happened by this point.
unsafe { &ITERATIONS }
}
use std::path::Path;



Expand Down
1 change: 1 addition & 0 deletions src/image/zopflipng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn best_strategy(dec: &LodePNGState, img: &DecodedImage) -> LodePNGFilterStrateg
LodePNGFilterStrategy::LFS_FOUR,
LodePNGFilterStrategy::LFS_MINSUM,
LodePNGFilterStrategy::LFS_ENTROPY,
LodePNGFilterStrategy::LFS_BRUTE_FORCE,
]
.into_iter()
.filter_map(|s| encode(dec, img, s, false).map(|out| (out.size, s)))
Expand Down
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ use std::sync::{
SeqCst,
},
},
OnceLock,
};



// The E_JPEG, E_JPG, and E_PNG constants are generated by build.rs.
include!(concat!(env!("OUT_DIR"), "/flaca-extensions.rs"));

/// # Number of Zopfli Iterations.
pub(crate) static ZOPFLI_ITERATIONS: OnceLock<i32> = OnceLock::new();



/// # Main.
Expand Down Expand Up @@ -128,7 +132,7 @@ fn _main() -> Result<(), FlacaError> {
let n = i32::btoi(n)
.filter(|n| 0 < *n)
.ok_or(FlacaError::ZopfliIterations)?;
image::set_zopfli_iterations(n);
let _res = ZOPFLI_ITERATIONS.set(n);
}

let paths = Dowser::default()
Expand Down Expand Up @@ -212,6 +216,21 @@ fn _main() -> Result<(), FlacaError> {
else { Ok(()) }
}

#[no_mangle]
#[allow(unsafe_code)]
/// # Share Zopfli Iterations w/ C.
///
/// This will return the user-specified value (if any), otherwise 60 for small
/// images and 20 for large ones (same as zopflipng does).
///
/// (This is used by the C `custom_png_deflate()` method.)
pub(crate) extern "C" fn flaca_zopfli_iterations(size: usize) -> i32 {
let num = *ZOPFLI_ITERATIONS.get_or_init(|| 0);
if num > 0 { num }
else if size < 200_000 { 60 }
else { 20 }
}

#[cold]
/// # Print Help.
fn helper() {
Expand Down

0 comments on commit 5123842

Please sign in to comment.