Skip to main content

check_fidelity_honesty

Function check_fidelity_honesty 

Source
pub fn check_fidelity_honesty<E, D>(
    enc: E,
    dec: D,
    img: &TestImage,
) -> Conformance
where E: EncoderConfig, D: DecoderConfig, <E::Job as EncodeJob>::Enc: Encoder<Error = E::Error>,
Expand description

The resolved Fidelity report is honest against the declared capabilities and against the pixels that actually come back.

with_fidelity is best-effort and infallible, so the whole cross-codec contract rests on resolved_target_fidelity telling the truth. For each request — Lossless, then every LossyTarget arm (CodecSpecificQuality at the middle of the declared quality_range, ApproxSsim2, ApproxButteraugli, ApproxZensimB), each applied on top of a prior Lossless request so a stale setting cannot leak through — the check asserts:

  • lossless declared ⇒ a Lossless request resolves to Some(Lossless) and the decoded pixels are byte-identical to the input. Undeclared ⇒ it must not resolve to Some(Lossless) (a codec cannot claim a mode it does not declare).
  • lossy declared ⇒ a lossy request never resolves to Lossless (a codec with a lossy mode must use it when asked), and — when it also declares a quality_range — resolves to Some(Lossy(_)) rather than None. Undeclared ⇒ it must not resolve to Some(Lossy(_)): the honest outcomes are promotion to Some(Lossless) (as the reference codec does) or None.
  • Every request still encodes and decodes, and whenever the codec reports Lossless the pixels are exact — whatever was asked for.
  • The legacy getter agrees: when both is_lossless() and the resolved fidelity are Some, is_lossless() equals resolved.is_lossless().

All violations are collected and reported together. Not covered: whether a metric target was hit (needs the metric), and the deferred LosslessMode/near-lossless arm (not in the shipped enum).