fix(media-proxy): clamp the webp effort override to the encoder maximum (#1834)

This commit is contained in:
Hampus
2026-08-24 12:27:46 +02:00
committed by GitHub
parent 171dc7e5b7
commit ac76bee5a3
+18 -1
View File
@@ -14,6 +14,7 @@ use thiserror::Error;
const ANIMATED_ENCODE_FLUSH_HEADROOM_MS: i64 = 3_000;
const PNG_SIGNATURE: &[u8; 8] = b"\x89PNG\r\n\x1a\n";
const APNG_FRAME_PNG_SUFFIX: &str = ".png[strip,compression=9,filter=all]";
const VIPS_WEBP_MAX_EFFORT: u8 = 6;
static PNG_CRC_TABLE: OnceLock<[u32; 256]> = OnceLock::new();
#[derive(Clone, Debug)]
@@ -188,7 +189,7 @@ fn output_suffix(
"false"
};
let effort = effort_override
.map(|v| v.min(9))
.map(|v| v.min(VIPS_WEBP_MAX_EFFORT))
.unwrap_or_else(|| effort_for(quality, animated));
let suffix = match format {
AssetExtension::Jpeg => format!(".jpg[Q={q},strip,interlace=true,optimize_coding=true]"),
@@ -2242,6 +2243,22 @@ mod tests {
delays
}
#[test]
fn webp_effort_override_is_clamped_to_the_encoder_maximum() {
for requested in [7u8, 8, 9, 200] {
let suffix =
output_suffix(AssetExtension::Webp, "high", None, Some(requested)).unwrap();
let suffix = suffix.to_str().unwrap().to_owned();
assert!(
suffix.contains("effort=6"),
"effort={requested} produced {suffix}, but libvips webpsave rejects effort above 6 \
and silently falls back to its own default"
);
}
let suffix = output_suffix(AssetExtension::Webp, "high", None, Some(5)).unwrap();
assert!(suffix.to_str().unwrap().contains("effort=5"));
}
#[test]
fn animated_webp_default_effort_matches_fast_tier() {
assert_eq!(2, effort_for("low", true));