byteshaver 0.7.1

A configurable and efficient batch image converter written in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
//! Optimal PNG compression via the [`oxipng`] crate (plan WS3).
//!
//! oxipng operates on encoded PNG bytes, not pixels, which enables two
//! distinct modes:
//!
//! - **Passthrough (PNG→PNG):** the original input file bytes are fed
//!   straight into [`oxipng::optimize_from_memory`]. Pixels stay bit-exact;
//!   palette (PLTE), tRNS and 16-bit data are preserved and reduced
//!   losslessly, and APNG animation chunks (acTL/fcTL/fdAT) survive.
//! - **Transcode (non-PNG→PNG):** pixels are decoded through the normal
//!   pipeline, baseline-encoded with the existing png encoder module at low
//!   effort ([`CompressionType::Fast`] + [`FilterType::Adaptive`]), and then
//!   optimized. oxipng re-encodes the IDAT stream anyway, so spending effort
//!   on the baseline encode would be wasted.
//!
//! Threading: oxipng is compiled without its `parallel` feature on purpose;
//! it runs single-threaded per file and never taps into the crate-wide
//! [`ThreadBudget`](super::ThreadBudget) (byteshaver parallelizes across
//! files instead, avoiding pool oversubscription).
//!
//! Note: the EXIF policy interplay (`strip` adjustment and payload embedding
//! in transcode mode) is active when the `exif` feature is enabled.

use std::time::Duration;

use clap::ValueEnum;
use image::DynamicImage;

use crate::Error;
use crate::converter::png::{CompressionType, FilterType, encode_png};
use crate::format::ImageFormat;
use crate::input::{ImageContent, SourceImage};
#[cfg(feature = "exif")]
use crate::metadata::policy::ExifPolicy;

/// Optimization level preset, mapped onto `oxipng::Options::from_preset`.
///
/// Higher levels try more filter strategies and stronger DEFLATE settings
/// (much slower, potentially smaller). `Max` maps to
/// `oxipng::Options::max_compression()`.
#[derive(
    Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum, serde::Serialize, serde::Deserialize,
)]
pub enum OxipngLevel {
    /// Preset 0: fastest, experimental (basic filters only).
    Zero,
    /// Preset 1: fast.
    One,
    /// Preset 2: oxipng's own sane default (also the byteshaver default).
    #[default]
    Two,
    /// Preset 3: slower, more filters.
    Three,
    /// Preset 4: slower still, stronger DEFLATE.
    Four,
    /// Preset 5: exhaustive (slow) filter evaluation.
    Five,
    /// Preset 6: extremely slow, best ratio of the numeric presets.
    Six,
    /// `max_compression()`: currently identical to preset 6.
    Max,
}

impl OxipngLevel {
    /// Numeric preset of this level, `None` for [`OxipngLevel::Max`].
    #[must_use]
    pub fn preset(self) -> Option<u8> {
        match self {
            OxipngLevel::Zero => Some(0),
            OxipngLevel::One => Some(1),
            OxipngLevel::Two => Some(2),
            OxipngLevel::Three => Some(3),
            OxipngLevel::Four => Some(4),
            OxipngLevel::Five => Some(5),
            OxipngLevel::Six => Some(6),
            OxipngLevel::Max => None,
        }
    }
}

/// Interlacing handling of the optimized output.
#[derive(
    Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum, serde::Serialize, serde::Deserialize,
)]
pub enum OxipngInterlace {
    /// Leave the interlace state of the input unchanged.
    Keep,
    /// Remove interlacing (default; matches the oxipng default).
    #[default]
    None,
    /// Force Adam7 interlacing on the output.
    Adam7,
}

/// Metadata chunk stripping policy.
///
/// Standalone for now; a later merge couples this to the EXIF policy
/// (see plan WS4).
#[derive(
    Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum, serde::Serialize, serde::Deserialize,
)]
pub enum OxipngStrip {
    /// Keep all ancillary chunks (default).
    #[default]
    None,
    /// Remove all chunks that do not affect image display.
    Safe,
    /// Remove all non-critical chunks.
    All,
}

/// Filter strategies oxipng may try per image.
///
/// Explicitly configured filters replace the filter set of the chosen
/// [`OxipngLevel`] preset.
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum, serde::Serialize, serde::Deserialize)]
pub enum OxipngFilter {
    /// Same (no) filter for every row.
    None,
    /// Sub filter for every row.
    Sub,
    /// Up filter for every row.
    Up,
    /// Average filter for every row.
    Avg,
    /// Paeth filter for every row.
    Paeth,
    /// Minimum sum of absolute differences heuristic.
    MinSum,
    /// Shannon entropy heuristic.
    Entropy,
    /// Distinct-bigram-count heuristic.
    Bigrams,
    /// Bigram Shannon entropy heuristic.
    BigEnt,
    /// Brute-force DEFLATE evaluation of candidate rows.
    Brute,
}

/// Lossless reductions that can be disabled individually.
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum, serde::Serialize, serde::Deserialize)]
pub enum OxipngReduction {
    /// Bit-depth reduction (only ever performed when losslessly possible).
    BitDepth,
    /// Color-type reduction (e.g. RGBA → RGB).
    ColorType,
    /// Palette reduction.
    Palette,
    /// Grayscale reduction.
    Grayscale,
}

/// Options of the oxipng encoder with CLI defaults already resolved.
///
/// Explicitly configured flags are applied on top of the chosen
/// [`OxipngLevel`] preset (preset first, explicit overrides second).
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct OxipngOptions {
    /// Optimization level preset. Default [`OxipngLevel::Two`].
    pub level: OxipngLevel,
    /// Use zopfli DEFLATE instead of libdeflate (much slower, slightly
    /// smaller). Default false.
    pub zopfli: bool,
    /// zopfli iteration count when [`OxipngOptions::zopfli`] is set.
    /// Default 15.
    pub zopfli_iterations: u32,
    /// Interlacing handling. Default [`OxipngInterlace::None`].
    pub interlace: OxipngInterlace,
    /// Metadata chunk stripping. Default [`OxipngStrip::None`].
    pub strip: OxipngStrip,
    /// Filter strategies to try; empty keeps the preset's filter set.
    pub filters: Vec<OxipngFilter>,
    /// Allow altering transparent pixel values for better compression
    /// (lossless visually). Default false.
    pub optimize_alpha: bool,
    /// Lossless reductions to disable. Default none disabled.
    pub no_reduction: Vec<OxipngReduction>,
    /// Force 16-bit → 8-bit scaling (potentially pixel-altering).
    /// Default false.
    pub scale_16: bool,
    /// Attempt fixing broken input PNGs instead of erroring. Default false.
    pub fix_errors: bool,
    /// Per-file optimization time limit. Default unlimited.
    pub timeout: Option<Duration>,
    /// Whether the user explicitly passed `--strip` (drives the EXIF policy
    /// interplay: under the default `Strip` policy an unset `--strip` is
    /// bumped to `safe` so eXIf chunks do not silently survive).
    pub strip_explicit: bool,
    /// Active EXIF policy of the run; injected from the global config
    /// (default [`ExifPolicy::Strip`]). Only available with the `exif`
    /// feature.
    #[cfg(feature = "exif")]
    pub exif_policy: ExifPolicy,
}

impl Default for OxipngOptions {
    fn default() -> Self {
        OxipngOptions {
            level: OxipngLevel::Two,
            zopfli: false,
            zopfli_iterations: 15,
            interlace: OxipngInterlace::None,
            strip: OxipngStrip::None,
            filters: Vec::new(),
            optimize_alpha: false,
            no_reduction: Vec::new(),
            scale_16: false,
            fix_errors: false,
            timeout: None,
            strip_explicit: false,
            #[cfg(feature = "exif")]
            exif_policy: ExifPolicy::Strip,
        }
    }
}

impl OxipngOptions {
    /// Builds the native [`oxipng::Options`] from these resolved options:
    /// the level preset is applied first, explicit flags override on top.
    #[must_use]
    pub fn to_oxipng(&self) -> oxipng::Options {
        let mut opts = match self.level.preset() {
            Some(preset) => oxipng::Options::from_preset(preset),
            None => oxipng::Options::max_compression(),
        };
        if !self.filters.is_empty() {
            opts.filters = self.filters.iter().map(|f| f.to_strategy()).collect();
        }
        opts.interlace = match self.interlace {
            OxipngInterlace::Keep => None,
            OxipngInterlace::None => Some(false),
            OxipngInterlace::Adam7 => Some(true),
        };
        opts.strip = match self.strip {
            OxipngStrip::None => oxipng::StripChunks::None,
            OxipngStrip::Safe => oxipng::StripChunks::Safe,
            OxipngStrip::All => oxipng::StripChunks::All,
        };
        // EXIF policy interplay (plan WS3 §4 / WS4 §4): when metadata must
        // survive, stripping is forced off; under the default strip policy an
        // unset `--strip` is bumped to `safe` so behavior follows the policy.
        #[cfg(feature = "exif")]
        match self.exif_policy {
            ExifPolicy::Strip => {
                if !self.strip_explicit {
                    opts.strip = oxipng::StripChunks::Safe;
                }
            }
            ExifPolicy::Keep | ExifPolicy::FilterExcept(_) | ExifPolicy::KeepOnly(_) => {
                opts.strip = oxipng::StripChunks::None;
            }
        }
        opts.optimize_alpha = self.optimize_alpha;
        for reduction in &self.no_reduction {
            match reduction {
                OxipngReduction::BitDepth => opts.bit_depth_reduction = false,
                OxipngReduction::ColorType => opts.color_type_reduction = false,
                OxipngReduction::Palette => opts.palette_reduction = false,
                OxipngReduction::Grayscale => opts.grayscale_reduction = false,
            }
        }
        opts.scale_16 = self.scale_16;
        opts.fix_errors = self.fix_errors;
        opts.timeout = self.timeout;
        if self.zopfli {
            let mut zopfli = oxipng::ZopfliOptions::default();
            // 0 is not a meaningful iteration count (NonZeroU64); keep default
            if let Ok(iterations) = u64::from(self.zopfli_iterations).try_into() {
                zopfli.iteration_count = iterations;
            }
            opts.deflater = oxipng::Deflater::Zopfli(zopfli);
        }
        opts
    }
}

impl OxipngFilter {
    /// CLI name of this filter strategy.
    fn name(self) -> &'static str {
        match self {
            OxipngFilter::None => "none",
            OxipngFilter::Sub => "sub",
            OxipngFilter::Up => "up",
            OxipngFilter::Avg => "avg",
            OxipngFilter::Paeth => "paeth",
            OxipngFilter::MinSum => "minsum",
            OxipngFilter::Entropy => "entropy",
            OxipngFilter::Bigrams => "bigrams",
            OxipngFilter::BigEnt => "bigent",
            OxipngFilter::Brute => "brute",
        }
    }

    /// Maps this filter onto the native oxipng filter strategy.
    ///
    /// The heuristics-only strategies (`MinSum`, `Entropy`, `Bigrams`,
    /// `BigEnt`) map 1:1; `Brute` uses oxipng's strongest preset brute
    /// parameters (8 lines, level 5).
    #[must_use]
    pub fn to_strategy(self) -> oxipng::FilterStrategy {
        match self {
            OxipngFilter::None => oxipng::FilterStrategy::NONE,
            OxipngFilter::Sub => oxipng::FilterStrategy::SUB,
            OxipngFilter::Up => oxipng::FilterStrategy::UP,
            OxipngFilter::Avg => oxipng::FilterStrategy::AVERAGE,
            OxipngFilter::Paeth => oxipng::FilterStrategy::PAETH,
            OxipngFilter::MinSum => oxipng::FilterStrategy::MinSum,
            OxipngFilter::Entropy => oxipng::FilterStrategy::Entropy,
            OxipngFilter::Bigrams => oxipng::FilterStrategy::Bigrams,
            OxipngFilter::BigEnt => oxipng::FilterStrategy::BigEnt,
            OxipngFilter::Brute => oxipng::FilterStrategy::Brute {
                num_lines: 8,
                level: 5,
            },
        }
    }
}

impl std::fmt::Display for OxipngOptions {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let level = self
            .level
            .preset()
            .map_or_else(|| "max".to_string(), |p| p.to_string());
        let mut reductions = vec!["bit-depth", "color-type", "palette", "grayscale"];
        for reduction in &self.no_reduction {
            let name = match reduction {
                OxipngReduction::BitDepth => "bit-depth",
                OxipngReduction::ColorType => "color-type",
                OxipngReduction::Palette => "palette",
                OxipngReduction::Grayscale => "grayscale",
            };
            reductions.retain(|r| *r != name);
        }
        write!(
            f,
            "level={} zopfli={} zopfli-iterations={} interlace={:?} strip={:?} \
             optimize-alpha={} reductions=[{}] scale-16={} fix-errors={} timeout={:?}",
            level,
            self.zopfli,
            self.zopfli_iterations,
            self.interlace,
            self.strip,
            self.optimize_alpha,
            reductions.join(","),
            self.scale_16,
            self.fix_errors,
            self.timeout,
        )?;
        if !self.filters.is_empty() {
            let filters = self
                .filters
                .iter()
                .map(|f| f.name())
                .collect::<Vec<_>>()
                .join(",");
            write!(f, " filters=[{filters}]")?;
        }
        Ok(())
    }
}

/// Encoder for optimal png format using the oxipng crate.
///
/// See the module docs for the passthrough vs. transcode mode distinction.
pub struct OxipngEncoder {
    /// Optimization options.
    pub options: OxipngOptions,
}

impl OxipngEncoder {
    /// Creates an encoder with the given options.
    pub fn new(options: OxipngOptions) -> Self {
        OxipngEncoder { options }
    }

    /// Transcode mode: baseline-encode at low effort, then optimize.
    /// oxipng re-encodes the IDAT stream regardless (idat_recoding is on
    /// by default), so spending compression effort here would be wasted.
    ///
    /// When the EXIF policy resolves a payload for the source, it is embedded
    /// into the baseline PNG (`eXIf` chunk) before optimization; the strip
    /// interplay in [`OxipngOptions::to_oxipng`] guarantees the chunk
    /// survives when the policy wants it kept.
    fn transcode(
        &self,
        image: &DynamicImage,
        exif_payload: Option<&[u8]>,
    ) -> Result<Vec<u8>, Error> {
        let baseline = encode_png(
            image,
            Some(CompressionType::Fast),
            Some(FilterType::Adaptive),
            exif_payload,
        )?;
        optimize_bytes(&baseline, &self.options)
    }
}

impl super::ImageEncoder for OxipngEncoder {
    fn format(&self) -> ImageFormat {
        ImageFormat::Png
    }

    fn extension(&self) -> &'static str {
        "png"
    }

    fn describe(&self) -> String {
        format!(
            "lossless PNG re-optimizer (oxipng {})",
            super::dependency_version("oxipng")
        )
    }

    fn describe_options(&self) -> String {
        format!(
            "Using \"oxipng\" ({}) with options: {}",
            super::dependency_version("oxipng"),
            self.options
        )
    }

    fn encode_still_image(&self, image: &DynamicImage) -> Result<Vec<u8>, Error> {
        self.transcode(image, None)
    }

    fn encode(&self, input: &SourceImage) -> Result<Vec<u8>, Error> {
        // Passthrough mode: PNG input (stills and animated PNGs alike — the
        // input layer decodes APNG as a still first frame, and oxipng
        // preserves APNG chunk structure during optimization). Feeding the
        // original bytes avoids a decode/re-encode round trip and keeps the
        // result bit-exact on the pixel level. Pixel-level global flags like
        // --discard-input-alpha-channel do not apply in this mode (the
        // operation would not be a lossless passthrough anymore).
        if input.source_format == ImageFormat::Png {
            let original = std::fs::read(&input.source_path)?;
            return optimize_bytes(&original, &self.options);
        }
        match &input.content {
            ImageContent::Still(image) => {
                #[cfg(feature = "exif")]
                let payload =
                    crate::metadata::exif::resolve(&self.options.exif_policy, &input.metadata);
                #[cfg(not(feature = "exif"))]
                let payload = None;
                self.transcode(image, payload.as_deref())
            }
            ImageContent::Animated(animation) => {
                let first = animation.first_frame().ok_or_else(|| {
                    Error::from_string("Animation does not contain any frames".to_string())
                })?;
                println!(
                    "Warning: {} does not support animated input yet; encoding the first frame only",
                    self.describe()
                );
                self.encode_still_image(&DynamicImage::ImageRgba8(first.buffer.clone()))
            }
        }
    }

    fn huge_image_hint(&self) -> Option<&'static str> {
        Some(
            "the oxipng target can take very long on huge images; \
             consider a lower --level (<= 2) or --timeout-secs",
        )
    }
}

/// Optimizes already-encoded PNG bytes with the configured oxipng options.
///
/// This is the single entry point both encoder modes funnel through.
///
/// # Errors
///
/// Returns an [`Error`] if oxipng cannot decode or optimize the input bytes.
pub fn optimize_bytes(png_bytes: &[u8], options: &OxipngOptions) -> Result<Vec<u8>, Error> {
    oxipng::optimize_from_memory(png_bytes, &options.to_oxipng())
        .map_err(|e| Error::from_string(format!("oxipng optimization failed: {e}")))
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::converter::ImageEncoder as _;

    #[test]
    fn default_options_map_to_level_two_preset() {
        let opts = OxipngOptions::default().to_oxipng();
        // preset 2 == library default
        let expected = oxipng::Options::default();
        assert_eq!(opts.filters, expected.filters);
        assert_eq!(opts.deflater, expected.deflater);
        assert_eq!(opts.interlace, Some(false));
        // EXIF policy interplay: the default Strip policy with no explicit
        // `--strip` bumps stripping to `safe` (plan WS3 §4 / WS4 §4)
        #[cfg(feature = "exif")]
        assert_eq!(opts.strip, oxipng::StripChunks::Safe);
        #[cfg(not(feature = "exif"))]
        assert_eq!(opts.strip, oxipng::StripChunks::None);
        assert!(!opts.optimize_alpha);
        assert!(opts.bit_depth_reduction);
        assert!(opts.color_type_reduction);
        assert!(opts.palette_reduction);
        assert!(opts.grayscale_reduction);
        assert!(!opts.scale_16);
        assert!(!opts.fix_errors);
        assert_eq!(opts.timeout, None);
    }

    #[test]
    fn max_level_maps_to_max_compression() {
        let opts = OxipngOptions {
            level: OxipngLevel::Max,
            ..OxipngOptions::default()
        }
        .to_oxipng();
        let expected = oxipng::Options::max_compression();
        assert_eq!(opts.filters, expected.filters);
        assert_eq!(opts.deflater, expected.deflater);
        assert!(!opts.fast_evaluation);
    }

    #[test]
    fn explicit_flags_override_preset() {
        let opts = OxipngOptions {
            level: OxipngLevel::Max,
            zopfli: true,
            zopfli_iterations: 8,
            interlace: OxipngInterlace::Adam7,
            strip: OxipngStrip::Safe,
            filters: vec![OxipngFilter::None, OxipngFilter::Paeth],
            optimize_alpha: true,
            no_reduction: vec![
                OxipngReduction::BitDepth,
                OxipngReduction::ColorType,
                OxipngReduction::Palette,
                OxipngReduction::Grayscale,
            ],
            scale_16: true,
            fix_errors: true,
            timeout: Some(Duration::from_secs(30)),
            strip_explicit: true,
            #[cfg(feature = "exif")]
            exif_policy: ExifPolicy::Strip,
        }
        .to_oxipng();
        assert_eq!(opts.filters.len(), 2);
        assert!(
            opts.filters
                .contains(&oxipng::FilterStrategy::Basic(oxipng::RowFilter::Paeth))
        );
        assert_eq!(opts.interlace, Some(true));
        assert_eq!(opts.strip, oxipng::StripChunks::Safe);
        assert!(opts.optimize_alpha);
        assert!(!opts.bit_depth_reduction);
        assert!(!opts.color_type_reduction);
        assert!(!opts.palette_reduction);
        assert!(!opts.grayscale_reduction);
        assert!(opts.scale_16);
        assert!(opts.fix_errors);
        assert_eq!(opts.timeout, Some(Duration::from_secs(30)));
        match opts.deflater {
            oxipng::Deflater::Zopfli(zopfli) => {
                assert_eq!(zopfli.iteration_count.get(), 8);
            }
            other => panic!("expected zopfli deflater, got {other:?}"),
        }
    }

    #[test]
    fn interlace_keep_maps_to_none() {
        let opts = OxipngOptions {
            interlace: OxipngInterlace::Keep,
            ..OxipngOptions::default()
        }
        .to_oxipng();
        assert_eq!(opts.interlace, None);
    }

    #[test]
    fn zopfli_iteration_zero_falls_back_to_default() {
        let opts = OxipngOptions {
            zopfli: true,
            zopfli_iterations: 0,
            ..OxipngOptions::default()
        }
        .to_oxipng();
        match opts.deflater {
            oxipng::Deflater::Zopfli(zopfli) => {
                assert_eq!(zopfli.iteration_count.get(), 15);
            }
            other => panic!("expected zopfli deflater, got {other:?}"),
        }
    }

    #[test]
    fn describe_is_identity_only_and_options_carry_the_detail() {
        let encoder = OxipngEncoder::new(OxipngOptions::default());
        // plan 15 F4: the capability description stays stable while
        // options change — identity only, no option dump
        let description = encoder.describe();
        assert!(description.contains("oxipng"), "{description}");
        assert!(description.contains("10.2"), "{description}");
        assert!(!description.contains("level="), "{description}");
        // the per-run notice keeps the resolved options
        let options = encoder.describe_options();
        assert!(options.contains("oxipng"), "{options}");
        assert!(options.contains("10.2"), "{options}");
        assert!(options.contains("level=2"), "{options}");
    }
}