Skip to content

Commit 388536a

Browse files
committed
Baseline JPEG flag
1 parent 4b45f33 commit 388536a

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

docs/USAGE.md

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414

1515
##### Advanced compression
1616

17+
- `--jpeg-chroma-subsampling <JPEG_CHROMA_SUBSAMPLING>`
18+
Sets the chroma subsampling for JPEG files. Possible values are:
19+
- `4:4:4`
20+
- `4:2:2`
21+
- `4:2:0`
22+
- `4:1:1`
23+
- `auto`
24+
25+
- `--jpeg-baseline`
26+
Forces the output to be in baseline JPEG format instead of progressive.
27+
1728
- `--png-opt-level <PNG_OPT_LEVEL>`
1829
Sets the optimization level for PNG files. Higher values result in better compression but take longer to complete.
1930
Possible values are between 0 and 6. Default is 3.

src/compressor.rs

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct CompressionOptions {
4848
pub keep_dates: bool,
4949
pub keep_structure: bool,
5050
pub jpeg_chroma_subsampling: ChromaSubsampling,
51+
pub jpeg_baseline: bool,
5152
}
5253

5354
pub fn start_compression(
@@ -252,6 +253,7 @@ fn build_compression_parameters(
252253
parameters.keep_metadata = options.exif;
253254

254255
parameters.jpeg.chroma_subsampling = options.jpeg_chroma_subsampling;
256+
parameters.jpeg.progressive = !options.jpeg_baseline;
255257

256258
parameters.png.optimization_level = options.png_opt_level;
257259
parameters.png.force_zopfli = options.zopfli;
@@ -777,6 +779,7 @@ mod tests {
777779
exif: true,
778780
png_opt_level: 0,
779781
jpeg_chroma_subsampling: ChromaSubsampling::Auto,
782+
jpeg_baseline: false,
780783
zopfli: false,
781784
base_path: PathBuf::new(),
782785
}

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ fn build_compression_options(args: &CommandLineArgs, base_path: &Path) -> Compre
139139
exif: args.exif,
140140
png_opt_level: args.png_opt_level,
141141
jpeg_chroma_subsampling: parse_jpeg_chroma_subsampling(args.jpeg_chroma_subsampling),
142+
jpeg_baseline: args.jpeg_baseline,
142143
zopfli: args.zopfli,
143144
base_path: PathBuf::from(base_path),
144145
}

src/options.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ pub struct CommandLineArgs {
5353
#[arg(long, default_value = "3")]
5454
pub png_opt_level: u8,
5555

56-
/// select level for PNG optimization, between [0-6]
56+
/// select the chroma subsampling for JPEG files
5757
#[arg(long, value_enum, default_value = "auto")]
5858
pub jpeg_chroma_subsampling: JpegChromaSubsampling,
5959

60+
/// output a baseline JPEG file, progressive (default) otherwise
61+
#[arg(long)]
62+
pub jpeg_baseline: bool,
63+
6064
/// use zopfli when optimizing PNG files (it may take a very long time to complete)
6165
#[arg(long)]
6266
pub zopfli: bool,

0 commit comments

Comments
 (0)