Skip to content

Commit

Permalink
switch to jpegli
Browse files Browse the repository at this point in the history
  • Loading branch information
arranf committed Apr 21, 2024
1 parent f2d83a1 commit 477736b
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 126 deletions.
66 changes: 25 additions & 41 deletions Cargo.lock

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

39 changes: 31 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,31 @@ path = "./src/main.rs"
required-features = ["build-binary"]

[features]
default = ["resize", "quantization", "mozjpeg", "oxipng", "webp", "avif", "threads", "metadata"]
default = [
"resize",
"quantization",
"jpegli",
"oxipng",
"webp",
"avif",
"threads",
"metadata",
]

# Used for binary
build-binary = ["dep:anyhow", "dep:clap", "dep:indoc", "dep:rayon", "dep:pretty_env_logger", "dep:zune-imageprocs", "dep:glob", "zune-image/default"]
build-binary = [
"dep:anyhow",
"dep:clap",
"dep:indoc",
"dep:rayon",
"dep:pretty_env_logger",
"dep:zune-imageprocs",
"dep:glob",
"zune-image/default",
]

# Enables utilization of threads
threads = ["imagequant?/threads", "mozjpeg?/parallel", "oxipng?/parallel"]
threads = ["imagequant?/threads", "oxipng?/parallel"]
# Enables metadata support
metadata = ["dep:kamadak-exif"]

Expand All @@ -39,8 +57,8 @@ resize = ["dep:fast_image_resize"]
# Enables quantize operation
quantization = ["dep:imagequant", "dep:rgb"]

# Enables mozjpeg codec
mozjpeg = ["dep:mozjpeg"]
# Enables jpegli codec
jpegli = ["dep:jpegli"]
# Enables oxipng codec
oxipng = ["dep:oxipng"]
# Enables webp codec
Expand All @@ -55,11 +73,16 @@ zune-image = { version = "0.4.15", default-features = false }
fast_image_resize = { version = "3.0.4", optional = true }
imagequant = { version = "4.3.0", default-features = false, optional = true }
rgb = { version = "0.8.37", optional = true }
mozjpeg = { version = "0.10.7", default-features = false, features = ["with_simd"], optional = true }
oxipng = { version = "9.0", default-features = false, features = ["zopfli", "filetime"], optional = true }
jpegli = { version = "0.1", optional = true }
oxipng = { version = "9.0", default-features = false, features = [
"zopfli",
"filetime",
], optional = true }
webp = { version = "0.2.6", default-features = false, optional = true }
ravif = { version = "0.11.4", optional = true }
libavif = { version = "0.13.0", default-features = false, features = ["codec-aom"], optional = true }
libavif = { version = "0.13.0", default-features = false, features = [
"codec-aom",
], optional = true }

# cli
anyhow = { version = "1.0.80", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn cli() -> Command {
| hdr | O | O | |
| jpeg | O | O | |
| jpeg_xl(jxl) | O | O | |
| mozjpeg(moz) | O | O | |
| jpegli(moz) | O | O | |
| oxipng(oxi) | O | O | Static only |
| png | O | O | Static only |
| ppm | O | O | |
Expand Down
8 changes: 4 additions & 4 deletions src/cli/codecs/mozjpeg.rs → src/cli/codecs/jpegli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use clap::{arg, value_parser, Command};

use crate::cli::common::CommonArgs;

pub fn mozjpeg() -> Command {
Command::new("mozjpeg")
pub fn jpegli() -> Command {
Command::new("jpegli")
.alias("moz")
.about("Encode images into JPEG format using MozJpeg codec. (RECOMMENDED and Small)")
.about("Encode images into JPEG format using jpegli codec. (RECOMMENDED and Small)")
.args([
arg!(-q --quality <NUM> "Quality, values 60-80 are recommended.")
.value_parser(value_parser!(u8).range(1..=100))
Expand All @@ -14,7 +14,7 @@ pub fn mozjpeg() -> Command {
.value_parser(value_parser!(u8).range(1..=100)),
arg!(--baseline "Set to use baseline encoding (by default is progressive)."),
arg!(--no_optimize_coding "Set to make files larger for no reason."),
arg!(--smoothing <NUM> "Use MozJPEG's smoothing.")
arg!(--smoothing <NUM> "Use jpegli's smoothing.")
.value_parser(value_parser!(u8).range(1..=100)),
arg!(--colorspace <COLOR> "Set color space of JPEG being written.")
.value_parser(["ycbcr", "grayscale", "rgb"])
Expand Down
6 changes: 3 additions & 3 deletions src/cli/codecs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use clap::Command;

use self::{
avif::avif, farbfeld::farbfeld, jpeg::jpeg, jpeg_xl::jpeg_xl, mozjpeg::mozjpeg, oxipng::oxipng,
avif::avif, farbfeld::farbfeld, jpeg::jpeg, jpeg_xl::jpeg_xl, jpegli::jpegli, oxipng::oxipng,
png::png, ppm::ppm, qoi::qoi, webp::webp,
};

mod avif;
mod farbfeld;
mod jpeg;
mod jpeg_xl;
mod mozjpeg;
mod jpegli;
mod oxipng;
mod png;
mod ppm;
Expand All @@ -23,7 +23,7 @@ impl Codecs for Command {
farbfeld(),
jpeg(),
jpeg_xl(),
mozjpeg(),
jpegli(),
oxipng(),
png(),
ppm(),
Expand Down
13 changes: 6 additions & 7 deletions src/cli/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,18 @@ pub fn encoder(
Ok((Box::new(JpegEncoder::new_with_options(options)), "jpg"))
}
"jpeg_xl" => Ok((Box::new(JxlEncoder::new()), "jxl")),
#[cfg(feature = "mozjpeg")]
"mozjpeg" => {
use mozjpeg::qtable;
use rimage::codecs::mozjpeg::{MozJpegEncoder, MozJpegOptions};
#[cfg(feature = "jpegli")]
"jpegli" => {
use jpegli::qtable;
use rimage::codecs::jpegli::{JpegliEncoder, JpegliOptions};

let quality = *matches.get_one::<u8>("quality").unwrap() as f32;
let chroma_quality = matches
.get_one::<u8>("chroma_quality")
.map(|q| *q as f32)
.unwrap_or(quality);

let options = MozJpegOptions {
let options = JpegliOptions {
quality,
progressive: !matches.get_flag("baseline"),
optimize_coding: !matches.get_flag("no_optimize_coding"),
Expand All @@ -196,7 +196,6 @@ pub fn encoder(
"grayscale" => mozjpeg::ColorSpace::JCS_GRAYSCALE,
_ => unreachable!(),
},
trellis_multipass: matches.get_flag("multipass"),
chroma_subsample: matches.get_one::<u8>("subsample").copied(),

luma_qtable: matches
Expand Down Expand Up @@ -246,7 +245,7 @@ pub fn encoder(
}),
};

Ok((Box::new(MozJpegEncoder::new_with_options(options)), "jpg"))
Ok((Box::new(JpegliEncoder::new_with_options(options)), "jpg"))
}
#[cfg(feature = "oxipng")]
"oxipng" => {
Expand Down
Loading

0 comments on commit 477736b

Please sign in to comment.