Skip to content

Commit

Permalink
Add RIAPI jpeg.turbo=true to restore original performance at the expe…
Browse files Browse the repository at this point in the history
…nse of file size, as the default changed in v1.3.1-rc30
  • Loading branch information
lilith committed Apr 22, 2020
1 parent 6f7d562 commit c24a79c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion imageflow_riapi/src/ir4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ impl Ir4Expand{

let encoder = match format {
OutputFormat::Gif => s::EncoderPreset::Gif,
OutputFormat::Jpeg => s::EncoderPreset::Mozjpeg {
OutputFormat::Jpeg if Some(true) == i.jpeg_turbo => s::EncoderPreset::LibjpegTurbo {
quality: Some(i.quality.unwrap_or(90)),
progressive: i.jpeg_progressive,
optimize_huffman_coding: i.jpeg_progressive
},
OutputFormat::Jpeg=> s::EncoderPreset::Mozjpeg {
quality: Some(i.quality.unwrap_or(90) as u8),
progressive: i.jpeg_progressive
},
Expand Down
12 changes: 9 additions & 3 deletions imageflow_riapi/src/ir4/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ pub enum ScalingColorspace {

}

pub static IR4_KEYS: [&'static str;66] = ["mode", "anchor", "flip", "sflip", "scale", "cache", "process",
pub static IR4_KEYS: [&'static str;67] = ["mode", "anchor", "flip", "sflip", "scale", "cache", "process",
"quality", "zoom", "crop", "cropxunits", "cropyunits",
"w", "h", "width", "height", "maxwidth", "maxheight", "format", "thumbnail",
"autorotate", "srotate", "rotate", "ignoreicc", //really? : "precise_scaling_ratio",
"stretch", "webp.lossless", "webp.quality",
"frame", "page", "subsampling", "colors", "f.sharpen", "f.sharpen_when", "down.colorspace",
"404", "bgcolor", "paddingcolor", "bordercolor", "preset", "floatspace", "jpeg_idct_downscale_linear", "watermark",
"s.invert", "s.sepia", "s.grayscale", "s.alpha", "s.brightness", "s.contrast", "s.saturation", "trim.threshold",
"trim.percentpadding", "a.blur", "a.sharpen", "a.removenoise", "a.balancewhite", "dither","jpeg.progressive",
"trim.percentpadding", "a.blur", "a.sharpen", "a.removenoise", "a.balancewhite", "dither","jpeg.progressive", "jpeg.turbo",
"encoder", "decoder", "builder", "s.roundcorners.", "paddingwidth", "paddingheight", "margin", "borderwidth", "decoder.min_precise_scaling_ratio"];


Expand Down Expand Up @@ -278,6 +278,7 @@ impl Instructions{
add(&mut m, "s.saturation", self.s_saturation);
add(&mut m, "s.sepia", self.s_sepia);
add(&mut m, "jpeg.progressive", self.jpeg_progressive);
add(&mut m, "jpeg.turbo", self.jpeg_turbo);


add(&mut m, "s.grayscale", self.s_grayscale.map(|v| format!("{:?}", v).to_lowercase()));
Expand Down Expand Up @@ -371,6 +372,7 @@ impl Instructions{

let _ = p.parse_test_pair("fastscale", "true");
i.jpeg_progressive = p.parse_bool("jpeg.progressive");
i.jpeg_turbo = p.parse_bool("jpeg.turbo");

i
}
Expand Down Expand Up @@ -764,6 +766,7 @@ pub struct Instructions{
pub min_precise_scaling_ratio: Option<f64>,
pub down_colorspace: Option<ScalingColorspace>,
pub jpeg_progressive: Option<bool>,
pub jpeg_turbo: Option<bool>,
}
#[derive(Debug,Copy, Clone,PartialEq)]
pub enum Anchor1D{
Expand Down Expand Up @@ -867,6 +870,8 @@ fn test_url_parsing() {
t("quality=85", Instructions { quality: Some(85), ..Default::default() }, vec![]);
t("webp.quality=85", Instructions { webp_quality: Some(85f64), ..Default::default() }, vec![]);
t("webp.lossless=true", Instructions { webp_lossless: Some(true), ..Default::default() }, vec![]);
t("jpeg.progressive=true", Instructions { jpeg_progressive: Some(true), ..Default::default() }, vec![]);
t("jpeg.turbo=true", Instructions { jpeg_turbo: Some(true), ..Default::default() }, vec![]);
t("zoom=0.02", Instructions { zoom: Some(0.02f64), ..Default::default() }, vec![]);
t("trim.threshold=80&trim.percentpadding=0.02", Instructions { trim_whitespace_threshold: Some(80), trim_whitespace_padding_percent: Some(0.02f64), ..Default::default() }, vec![]);
t("w=10&f.sharpen=80.5", Instructions { w: Some(10), f_sharpen: Some(80.5f64), ..Default::default() }, vec![]);
Expand Down Expand Up @@ -963,5 +968,6 @@ fn test_tostr(){
t("f.sharpen_when=sizediffers", Instructions{ f_sharpen_when: Some(SharpenWhen::SizeDiffers), ..Default::default()});
t("s.grayscale=bt709", Instructions{s_grayscale: Some(GrayscaleAlgorithm::Bt709), ..Default::default()});
t("s.alpha=0&s.brightness=0.1&s.contrast=1&s.saturation=-0.1&s.sepia=true", Instructions { s_alpha: Some(0f64), s_contrast: Some(1f64), s_sepia: Some(true), s_brightness: Some(0.1f64), s_saturation: Some(-0.1f64), ..Default::default() });

t("jpeg.progressive=true", Instructions { jpeg_progressive: Some(true), ..Default::default() });
t("jpeg.turbo=true", Instructions { jpeg_turbo: Some(true), ..Default::default() });
}

2 comments on commit c24a79c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • esults
  • jpegsize
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
jsoref
megapixels
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/42f15d0ed3748dd6a1b8c1f026d297f0625fb5eb.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
esults
jpegsize
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/c24a79c21e6ff4178f5e3a619ab18bba8a592442.txt'

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • esults
  • jpegsize
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
jsoref
megapixels
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/42f15d0ed3748dd6a1b8c1f026d297f0625fb5eb.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
esults
jpegsize
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/c24a79c21e6ff4178f5e3a619ab18bba8a592442.txt'

Please sign in to comment.