Skip to content

Commit

Permalink
release: 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Apr 24, 2024
2 parents 095c364 + 6fa7971 commit 46c2d70
Show file tree
Hide file tree
Showing 21 changed files with 1,416 additions and 1,194 deletions.
6 changes: 3 additions & 3 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Project Dependencies
Package: flaca
Version: 3.0.0
Generated: 2024-04-13 07:52:07 UTC
Version: 3.0.1
Generated: 2024-04-24 05:50:28 UTC

| Package | Version | Author(s) | License |
| ---- | ---- | ---- | ---- |
Expand Down Expand Up @@ -30,7 +30,7 @@
| [libdeflater](https://github.com/adamkewley/libdeflater) | 1.20.0 | [Adam Kewley](mailto:[email protected]) | Apache-2.0 |
| [log](https://github.com/rust-lang/log) | 0.4.21 | The Rust Project Developers | Apache-2.0 or MIT |
| [mozjpeg-sys](https://github.com/kornelski/mozjpeg-sys.git) | 2.1.0 | [Kornel](mailto:[email protected]) | IJG AND Zlib AND BSD-3-Clause |
| [oxipng](https://github.com/shssoichiro/oxipng) | 9.0.0 | [Joshua Holmer](mailto:[email protected]) | MIT |
| [oxipng](https://github.com/shssoichiro/oxipng) | 9.1.1 | [Joshua Holmer](mailto:[email protected]) | MIT |
| [radium](https://github.com/bitvecto-rs/radium) | 0.7.0 | [Nika Layzell](mailto:[email protected]) and [myrrlyn](mailto:[email protected]) | MIT |
| [rayon](https://github.com/rayon-rs/rayon) | 1.10.0 | [Niko Matsakis](mailto:[email protected]) and [Josh Stone](mailto:[email protected]) | Apache-2.0 or MIT |
| [rayon-core](https://github.com/rayon-rs/rayon) | 1.12.1 | [Niko Matsakis](mailto:[email protected]) and [Josh Stone](mailto:[email protected]) | Apache-2.0 or MIT |
Expand Down
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flaca"
version = "3.0.0"
version = "3.0.1"
license = "WTFPL"
authors = ["Josh Stoik <[email protected]>"]
edition = "2021"
Expand Down Expand Up @@ -61,6 +61,12 @@ short = "-V"
long = "--version"
description = "Print version information and exit."

[[package.metadata.bashman.options]]
short = "-j"
label = "<NUM>"
description = "Limit parallelization to this many threads (instead of giving each logical core its own image to work on). If negative, the value will be subtracted from the total number of logical cores."
path = false

[[package.metadata.bashman.options]]
short = "-l"
long = "--list"
Expand Down Expand Up @@ -118,7 +124,7 @@ version = "=2.1.0"
features = [ "jpegtran" ]

[dependencies.oxipng]
version = "=9.0.0"
version = "=9.1.1"
default-features = false

[build-dependencies]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following flags and options are available:
| Short | Long | Value | Description |
| ----- | ---- | ----- | ----------- |
| `-h` | `--help` | | Print help information and exit. |
| `-j` | | `<NUM>` | Limit parallelization to this many threads (instead of using all logical cores). |
| `-l` | `--list` | `<FILE>` | Read (absolute) image and/or directory paths from this text file — or STDIN if "-" — one entry per line, instead of or in addition to the trailing `<PATH(S)>`. |
| | `--no-jpeg` | | Skip JPEG images. |
| | `--no-png` | | Skip PNG Images. |
Expand All @@ -80,11 +81,14 @@ flaca /path/to/image.jpg
flaca -p /path/to/assets

# Tackle a whole folder, but only look for JPEG images.
flaca -p --no-png /path/to/assets
flaca --no-png /path/to/assets

# Or load it up with a lot of places separately:
flaca /path/to/assets /path/to/favicon.png …

# Limit parallel processing to two images at a time.
flaca -j2 /path/to/assets

# Zopfli compression is slow and scales more or less linearly with the number
# of iterations set. Flaca uses the same default as zopflipng: 60 for small
# images, 20 for larger ones. If you're willing to trade longer processing
Expand Down
26 changes: 21 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ fn build_ffi() {

// Build Zopfli first.
let mut c = cc::Build::new();
c.includes(&[repo, &lodepng_src, &zopfli_src])
c.includes([repo, &lodepng_src, &zopfli_src])
.cpp(false)
.flag_if_supported("-W")
.flag_if_supported("-ansi")
.flag_if_supported("-pedantic")
.pic(true)
.static_flag(true)
.files(&[
.files([
zopfli_src.join("zopfli.c"),
lodepng_src.join("lodepng.c"),
])
.define("LODEPNG_NO_COMPILE_DISK", None)
.define("LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS", None)
.define("LODEPNG_NO_COMPILE_CPP", None)
.define("LODEPNG_NO_COMPILE_DISK", None)
.compile("zopflipng");

bindings(repo, &lodepng_src, &zopfli_src);
Expand All @@ -101,11 +102,21 @@ fn build_ffi() {
fn build_symbols() {
use std::fmt::Write;

let mut out = r"#[allow(dead_code)]
let mut out = r"#[repr(usize)]
#[derive(Clone, Copy)]
/// # Whackadoodle Deflate Indices.
pub(crate) enum DeflateSym {".to_owned();
for i in 0..19 {
write!(&mut out, "\n\tD{i:02} = {i}_usize,").unwrap();
}
out.push_str(r"
}
#[allow(dead_code)]
#[repr(u16)]
#[derive(Clone, Copy)]
/// # Distance Symbols.
pub(crate) enum Dsym {".to_owned();
pub(crate) enum Dsym {");
for i in 0..32 {
write!(&mut out, "\n\tD{i:02} = {i}_u16,").unwrap();
}
Expand Down Expand Up @@ -187,6 +198,11 @@ pub(crate) const DISTANCE_VALUES: &[u16; 32_768] = &[");
/// commented-out code can be re-enabled if they ever need to be updated.
fn bindings(repo: &Path, lodepng_src: &Path, zopfli_src: &Path) {
let bindings = bindgen::Builder::default()
.clang_args([
"-DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS",
"-DLODEPNG_NO_COMPILE_CPP",
"-DLODEPNG_NO_COMPILE_DISK",
])
.header(lodepng_src.join("lodepng.h").to_string_lossy())
.header(repo.join("rust.h").to_string_lossy())
.header(zopfli_src.join("zopfli.h").to_string_lossy())
Expand Down
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export CXX := "clang++"
mv "{{ justfile_directory() }}/target" "{{ cargo_dir }}"


# Bench PNG Compression.
[no-cd]
@bench-png BIN:
[ -f "{{ BIN }}" ] || exit 1
just _bench-reset
"{{ absolute_path(BIN) }}" -p --no-jpeg "{{ bench_dir }}"
cd "{{ bench_dir }}" && b3sum -c png.b3 --quiet


@clean:
# Most things go here.
[ ! -d "{{ cargo_dir }}" ] || rm -rf "{{ cargo_dir }}"
Expand Down
1 change: 1 addition & 0 deletions release/completions/flaca.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _basher___flaca() {
opts+=("-V")
opts+=("--version")
fi
[[ " ${COMP_LINE} " =~ " -j " ]] || opts+=("-j")
if [[ ! " ${COMP_LINE} " =~ " -l " ]] && [[ ! " ${COMP_LINE} " =~ " --list " ]]; then
opts+=("-l")
opts+=("--list")
Expand Down
7 changes: 5 additions & 2 deletions release/man/flaca.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FLACA" "1" "April 2024" "Flaca v3.0.0" "User Commands"
.TH "FLACA" "1" "April 2024" "Flaca v3.0.1" "User Commands"
.SH NAME
Flaca \- Manual page for flaca v3.0.0.
Flaca \- Manual page for flaca v3.0.1.
.SH DESCRIPTION
Brute\-force, lossless JPEG and PNG compression.
.SS USAGE:
Expand All @@ -24,6 +24,9 @@ Show progress bar while minifying.
Print version information and exit.
.SS OPTIONS:
.TP
\fB\-j\fR <NUM>
Limit parallelization to this many threads (instead of giving each logical core its own image to work on). If negative, the value will be subtracted from the total number of logical cores.
.TP
\fB\-l\fR, \fB\-\-list\fR <FILE>
Read (absolute) image and/or directory paths from this text file — or STDIN if '\-' — one entry per line, instead of or in addition to (actually trailing) <PATH(S)>.
.TP
Expand Down
11 changes: 11 additions & 0 deletions skel/assets/png.b3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
b53eca68578abeab039f7492aa08cc08aca2ee8373f5f35e4d51cfec69ab5c89 ./png/01.png
385eb82425d1d39d84155ad812d7a2e9c7f4f989b9be8901f227d9b0b3716e60 ./png/02.png
a71b84ad1980fb75b0357c9a2440a53af16363f66aaed484559ea95075f85d48 ./png/03.png
71f3a81b8f0800987434a87a256f88fc0fa992a0082e9dc94cd47a7bf69cb7f6 ./png/04.png
f305df54a410b781b5798c96c2423a90fd80744fa6a1b6e42938b866ae465bcc ./png/05.png
3cbbc3be80e8de2d9a3c1d97b11ca110d2922c0dcfcb7de1ff6952fa0addbe0b ./png/06.png
97fff17e466418ba255a5a1ecbe463c72d03bfca7c7c597f0ee8f831588a51e5 ./png/poe.png
4da3d1e65804d00be0d376234c3c1ee25469105bf32966e05adb65e870d6eb5e ./png/small.png
e0eb307123913aa8b3a864790ab904d340a7e4e85192d27cb1d16e15c14d3319 ./png/small-bw.png
3ca8474dff6526979ca43cba37a71b9ffdaa9646bd89811c3abdce0b56b85ca2 ./png/small-bwa.png
6d73e93975587d16ce907ace61f7ac818aaa2c0f2884ecb489112c8d6f5c5aac ./wolf.jpg
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub(super) enum FlacaError {
Killed,
/// # No Images.
NoImages,
/// # No Threads.
NoThreads,
/// # Progress Passthrough.
Progress(ProglessError),
/// # Invalid Zopfli Iterations.
Expand Down Expand Up @@ -58,6 +60,7 @@ impl FlacaError {
Self::Argue(e) => e.as_str(),
Self::Killed => "The process was aborted early.",
Self::NoImages => "No images were found.",
Self::NoThreads => "Unable to initialize threadpool.",
Self::Progress(e) => e.as_str(),
Self::ZopfliIterations => "The number of (zopfli) lz77 iterations must be between 1..=2_147_483_647.",
}
Expand Down
15 changes: 10 additions & 5 deletions src/image/lodepng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ use super::{
deflate_part,
ffi::EncodedImage,
SplitPoints,
ZopfliState,
};



// Generated by build.rs.
include!(concat!(env!("OUT_DIR"), "/lodepng-bindgen.rs"));



const ZOPFLI_MASTER_BLOCK_SIZE: usize = 1_000_000;


Expand All @@ -53,6 +52,7 @@ pub(crate) extern "C" fn flaca_png_deflate(
}

// Initialize a reusable split-point buffer.
let mut state = ZopfliState::new();
let mut splits = SplitPoints::new();
let mut dst = ZopfliOut {
bp: 0,
Expand All @@ -70,7 +70,8 @@ pub(crate) extern "C" fn flaca_png_deflate(
else { (false, ZOPFLI_MASTER_BLOCK_SIZE) };

// Crunch the part!
deflate_part(
let res = deflate_part(
&mut state,
&mut splits,
numiterations,
last_part,
Expand All @@ -79,6 +80,12 @@ pub(crate) extern "C" fn flaca_png_deflate(
&mut dst,
);

#[cfg(debug_assertions)] if let Err(e) = res { panic!("{e}"); }

// For non-debug purposes, just let lodepng know we failed when thre's
// an error so it can skip the rest of the processing.
if res.is_err() { return 1; }

// Onward and upward!
i += size;
}
Expand Down Expand Up @@ -278,8 +285,6 @@ impl LodePNGState {

enc.encoder.filter_palette_zero = 0;
enc.encoder.filter_strategy = strategy;
enc.encoder.add_id = 0;
enc.encoder.text_compression = 1;

// For final compression, enable the custom zopfli deflater.
if slow {
Expand Down
1 change: 1 addition & 0 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::path::Path;
use zopflipng::{
deflate_part,
SplitPoints,
ZopfliState,
};


Expand Down
Loading

0 comments on commit 46c2d70

Please sign in to comment.