Skip to content

Commit

Permalink
release: 3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed May 12, 2024
2 parents baf8a6c + 32f4f74 commit cc132c0
Show file tree
Hide file tree
Showing 22 changed files with 798 additions and 499 deletions.
19 changes: 10 additions & 9 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Project Dependencies
Package: flaca
Version: 3.0.2
Generated: 2024-04-25 03:55:30 UTC
Version: 3.0.3
Generated: 2024-05-12 06:16:35 UTC

| Package | Version | Author(s) | License |
| ---- | ---- | ---- | ---- |
| [ahash](https://github.com/tkaitchuck/ahash) | 0.8.11 | [Tom Kaitchuck](mailto:[email protected]) | Apache-2.0 or MIT |
| [argyle](https://github.com/Blobfolio/argyle) | 0.7.2 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
| [bitvec](https://github.com/bitvecto-rs/bitvec) | 1.0.1 | | MIT |
| [bumpalo](https://github.com/fitzgen/bumpalo) | 3.16.0 | [Nick Fitzgerald](mailto:[email protected]) | Apache-2.0 or MIT |
| [bytecount](https://github.com/llogiq/bytecount) | 0.6.7 | [Andre Bogus](mailto:[email protected]) and [Joshua Landau](mailto:[email protected]) | Apache-2.0 or MIT |
| [bytecount](https://github.com/llogiq/bytecount) | 0.6.8 | [Andre Bogus](mailto:[email protected]) and [Joshua Landau](mailto:[email protected]) | Apache-2.0 or MIT |
| [bytemuck](https://github.com/Lokathor/bytemuck) | 1.15.0 | [Lokathor](mailto:[email protected]) | Apache-2.0, MIT, or Zlib |
| [cfg-if](https://github.com/alexcrichton/cfg-if) | 1.0.0 | [Alex Crichton](mailto:[email protected]) | Apache-2.0 or MIT |
| [crc32fast](https://github.com/srijs/rust-crc32fast) | 1.4.0 | [Sam Rijs](mailto:[email protected]) and [Alex Crichton](mailto:[email protected]) | 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 |
Expand All @@ -20,12 +21,12 @@
| [dowser](https://github.com/Blobfolio/dowser) | 0.9.0 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
| [either](https://github.com/rayon-rs/either) | 1.11.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.2 | [Stjepan Glavina](mailto:[email protected]) | Apache-2.0 or MIT |
| [fastrand](https://github.com/smol-rs/fastrand) | 2.1.0 | [Stjepan Glavina](mailto:[email protected]) | Apache-2.0 or MIT |
| [funty](https://github.com/myrrlyn/funty) | 2.0.0 | [myrrlyn](mailto:[email protected]) | MIT |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.13.3 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.14.3 | [Amanieu d'Antras](mailto:[email protected]) | Apache-2.0 or MIT |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.13.4 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.14.5 | [Amanieu d'Antras](mailto:[email protected]) | Apache-2.0 or MIT |
| [indexmap](https://github.com/indexmap-rs/indexmap) | 2.2.6 | | Apache-2.0 or MIT |
| [libc](https://github.com/rust-lang/libc) | 0.2.153 | The Rust Project Developers | Apache-2.0 or MIT |
| [libc](https://github.com/rust-lang/libc) | 0.2.154 | The Rust Project Developers | Apache-2.0 or MIT |
| [libdeflate-sys](https://github.com/adamkewley/libdeflater) | 1.20.0 | [Adam Kewley](mailto:[email protected]) | Apache-2.0 |
| [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 |
Expand All @@ -39,8 +40,8 @@
| [tap](https://github.com/myrrlyn/tap) | 1.0.1 | [Elliott Linder](mailto:[email protected]) and [myrrlyn](mailto:[email protected]) | MIT |
| [tempfile](https://github.com/Stebalien/tempfile) | 3.10.1 | [Steven Allen](mailto:[email protected]), The Rust Project Developers, [Ashley Mannix](mailto:[email protected]), and [Jason White](mailto:[email protected]) | Apache-2.0 or MIT |
| [terminal_size](https://github.com/eminence/terminal-size) | 0.3.0 | [Andrew Chin](mailto:[email protected]) | Apache-2.0 or MIT |
| [unicode-width](https://github.com/unicode-rs/unicode-width) | 0.1.11 | [kwantam](mailto:[email protected]) and [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 or MIT |
| [unicode-width](https://github.com/unicode-rs/unicode-width) | 0.1.12 | [kwantam](mailto:[email protected]) and [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 or MIT |
| [write_atomic](https://github.com/Blobfolio/write_atomic) | 0.5.0 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
| [wyz](https://github.com/myrrlyn/wyz) | 0.5.1 | [myrrlyn](mailto:[email protected]) | MIT |
| [zerocopy](https://github.com/google/zerocopy) | 0.7.32 | [Joshua Liebow-Feeser](mailto:[email protected]) | Apache-2.0, BSD-2-Clause, or MIT |
| [zerocopy](https://github.com/google/zerocopy) | 0.7.34 | [Joshua Liebow-Feeser](mailto:[email protected]) | Apache-2.0, BSD-2-Clause, or MIT |
| [zopflipng](https://github.com/google/zopfli) | | Google | Apache-2.0 |
5 changes: 3 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.2"
version = "3.0.3"
license = "WTFPL"
authors = ["Josh Stoik <[email protected]>"]
edition = "2021"
Expand Down Expand Up @@ -54,7 +54,7 @@ description = "Skip PNG images."
[[package.metadata.bashman.switches]]
short = "-p"
long = "--progress"
description = "Show progress bar while minifying."
description = "Show pretty progress while minifying."

[[package.metadata.bashman.switches]]
short = "-V"
Expand Down Expand Up @@ -108,6 +108,7 @@ items = [
[dependencies]
argyle = "0.7.*"
bumpalo = "=3.16.0"
crc32fast = "1.4.*"
ctrlc = "=3.4.4"
dactyl = "0.7.*"
dowser = "0.9.*"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The following flags and options are available:
| | `--no-jpeg` | | Skip JPEG images. |
| | `--no-png` | | Skip PNG Images. |
| `-z` | `--zopfli-iterations` | Override the number of zopfli iterations when compressing PNGs. |
| `-p` | `--progress` | | Show progress while minifying. |
| `-p` | `--progress` | | Show pretty progress while minifying. |
| `-V` | `--version` | | Print version information and exit. |

You can feed it any number of file or directory paths in one go, and/or toss it a text file using the `-l` option. Directories are recursively searched.
Expand Down
12 changes: 7 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn build_ffi() {
])
.define("LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS", None)
.define("LODEPNG_NO_COMPILE_CPP", None)
.define("LODEPNG_NO_COMPILE_CRC", None)
.define("LODEPNG_NO_COMPILE_DISK", None)
.compile("zopflipng");

Expand All @@ -102,12 +103,12 @@ fn build_ffi() {
fn build_symbols() {
use std::fmt::Write;

let mut out = r"#[repr(usize)]
#[derive(Clone, Copy)]
let mut out = r"#[repr(u8)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
/// # Whackadoodle Deflate Indices.
pub(crate) enum DeflateSym {".to_owned();
for i in 0..19 {
write!(&mut out, "\n\tD{i:02} = {i}_usize,").unwrap();
write!(&mut out, "\n\tD{i:02} = {i}_u8,").unwrap();
}
out.push_str(r"
}
Expand Down Expand Up @@ -201,6 +202,7 @@ fn bindings(repo: &Path, lodepng_src: &Path, zopfli_src: &Path) {
.clang_args([
"-DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS",
"-DLODEPNG_NO_COMPILE_CPP",
"-DLODEPNG_NO_COMPILE_CRC",
"-DLODEPNG_NO_COMPILE_DISK",
])
.header(lodepng_src.join("lodepng.h").to_string_lossy())
Expand Down Expand Up @@ -254,8 +256,8 @@ fn bindings(repo: &Path, lodepng_src: &Path, zopfli_src: &Path) {
}

// Allow dead code for these two enum variants we aren't using.
for i in ["LCT_MAX_OCTET_VALUE = 255,", "LFS_PREDEFINED = 8,"] {
out = out.replace(i, &format!("#[allow(dead_code)] {i}"));
for i in ["pub enum LodePNGFilterStrategy", "pub enum LodePNGColorType"] {
out = out.replace(i, &format!("#[allow(dead_code)]\n{i}"));
}

// Switch from pub to pub(super).
Expand Down
10 changes: 4 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ doc_dir := justfile_directory() + "/doc"
release_dir := justfile_directory() + "/release"
skel_dir := justfile_directory() + "/skel"

export RUSTFLAGS := "-Ctarget-cpu=x86-64-v3 -Clinker=clang -Clink-arg=-fuse-ld=lld"
export RUSTFLAGS := "-Ctarget-cpu=x86-64-v3 -Cllvm-args=--cost-kind=throughput -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld"
export CC := "clang"
export CXX := "clang++"
export CFLAGS := "-Wall -Wextra -flto -march=x86-64-v3"
export CXXFLAGS := "-Wall -Wextra -flto -march=x86-64-v3"



Expand Down Expand Up @@ -95,13 +97,9 @@ export CXX := "clang++"

# Build Docs.
@doc:
# Make sure nightly is installed; this version generates better docs.
env RUSTUP_PERMIT_COPY_RENAME=true rustup install nightly

# Make the docs.
cargo +nightly doc \
cargo rustdoc \
--release \
--no-deps \
--target-dir "{{ cargo_dir }}"

# Move the docs and clean up ownership.
Expand Down
6 changes: 3 additions & 3 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.2" "User Commands"
.TH "FLACA" "1" "May 2024" "Flaca v3.0.3" "User Commands"
.SH NAME
Flaca \- Manual page for flaca v3.0.2.
Flaca \- Manual page for flaca v3.0.3.
.SH DESCRIPTION
Brute\-force, lossless JPEG and PNG compression.
.SS USAGE:
Expand All @@ -18,7 +18,7 @@ Skip JPEG images.
Skip PNG images.
.TP
\fB\-p\fR, \fB\-\-progress\fR
Show progress bar while minifying.
Show pretty progress while minifying.
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version information and exit.
Expand Down
Binary file added skel/assets/herring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skel/assets/jpg/21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skel/assets/jpg/22.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skel/assets/jpg/23.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 35 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,41 @@ use std::{


#[derive(Debug, Copy, Clone)]
/// # Error type.
/// # Encoding Errors.
pub(super) enum EncodingError {
/// # Empty File.
Empty,
/// # Wrong/Unknown Format.
Format,
/// # Read Error.
Read,
/// # Intentionally Skipped.
Skipped,
/// # Vanished.
Vanished,
/// # Write Error.
Write,
}

impl EncodingError {
#[must_use]
/// # As Str.
pub(super) const fn as_str(self) -> &'static str {
match self {
Self::Empty => "empty file",
Self::Format => "invalid format",
Self::Read => "read error",
Self::Skipped => "",
Self::Vanished => "vanished!",
Self::Write => "write error",
}
}
}



#[derive(Debug, Copy, Clone)]
/// # General/Deal-Breaking Errors.
pub(super) enum FlacaError {
/// # Argyle Passthrough.
Argue(ArgyleError),
Expand Down
57 changes: 40 additions & 17 deletions src/image/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,14 @@ impl From<u8> for ImageKind {
impl ImageKind {
/// # Is JPEG?
pub(crate) fn is_jpeg(src: &[u8]) -> bool {
const END: [u8; 2] = [0xFF, 0xD9];

12 < src.len() &&
src[..3] == [0xFF, 0xD8, 0xFF] &&
match src[3] {
0xE0 =>
src[6..11] == [b'J', b'F', b'I', b'F', 0x00] ||
src[src.len() - 2..] == END,
0xE1 => src[6..11] ==
[b'E', b'x', b'i', b'f', 0x00] ||
src[src.len() - 2..] == END,
0xE8 => src[6..12] ==
[b'S', b'P', b'I', b'F', b'F', 0x00] ||
src[src.len() - 2..] == END,
0xDB | 0xE2..=0xEF => src[src.len() - 2..] == END,
_ => false,
}
(
(src[3] == 0xE0 && src[6..11] == [b'J', b'F', b'I', b'F', 0x00]) ||
(src[3] == 0xE1 && src[6..11] == [b'E', b'x', b'i', b'f', 0x00]) ||
(src[3] == 0xE8 && src[6..12] == [b'S', b'P', b'I', b'F', b'F', 0x00]) ||
(matches!(src[3], 0xDB | 0xE0..=0xEF) && src[src.len() - 2..] == [0xFF, 0xD9])
)
}

/// # Is PNG?
Expand Down Expand Up @@ -116,10 +107,42 @@ mod tests {
test_kind!(
"./skel/assets/empty.jpg" None,
"./skel/assets/executable.sh" None,
"./skel/assets/herring.png" None,
"./skel/assets/jpg/01.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/02.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/03.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/04.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/05.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/06.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/07.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/08.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/09.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/10.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/11.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/12.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/13.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/14.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/15.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/16.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/17.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/18.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/19.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/20.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/21.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/22.jpg" Some(ImageKind::Jpeg),
"./skel/assets/jpg/23.jpg" Some(ImageKind::Jpeg),
"./skel/assets/png/01.png" Some(ImageKind::Png),
"./skel/assets/png/02.png" Some(ImageKind::Png),
"./skel/assets/wolf.png" Some(ImageKind::Jpeg),
"./skel/assets/wolf.jpg" Some(ImageKind::Png)
"./skel/assets/png/03.png" Some(ImageKind::Png),
"./skel/assets/png/04.png" Some(ImageKind::Png),
"./skel/assets/png/05.png" Some(ImageKind::Png),
"./skel/assets/png/06.png" Some(ImageKind::Png),
"./skel/assets/png/poe.png" Some(ImageKind::Png),
"./skel/assets/png/small-bw.png" Some(ImageKind::Png),
"./skel/assets/png/small-bwa.png" Some(ImageKind::Png),
"./skel/assets/png/small.png" Some(ImageKind::Png),
"./skel/assets/wolf.jpg" Some(ImageKind::Png),
"./skel/assets/wolf.png" Some(ImageKind::Jpeg)
);
}
}
13 changes: 13 additions & 0 deletions src/image/lodepng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ pub(crate) extern "C" fn flaca_png_deflate(
0
}

#[no_mangle]
#[inline(always)]
#[allow(unsafe_code, clippy::inline_always)]
/// # Lodepng CRC32.
///
/// Replace lodepng's native CRC32 hashing method with Rust's (faster)
/// `crc32fast`.
pub(crate) extern "C" fn lodepng_crc32(buf: *const c_uchar, len: usize) -> c_uint {
let mut h = crc32fast::Hasher::new();
h.update(unsafe { std::slice::from_raw_parts(buf, len) });
h.finalize()
}



#[derive(Debug)]
Expand Down
Loading

0 comments on commit cc132c0

Please sign in to comment.