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
//! Source encoding detection traits.
//!
//! [`SourceEncodingDetails`] provides a codec-agnostic interface for
//! querying properties of the encoder that produced an image file.
//! Each codec's probe type (e.g. `WebPProbe`, `JpegProbe`) implements
//! this trait, providing both the generic quality number and full
//! codec-specific details via downcasting.
//!
//! # Usage
//!
//! ```rust,ignore
//! use zencodec::decode::{DecodeOutput, SourceEncodingDetails};
//!
//! let output: DecodeOutput = /* decode an image */;
//!
//! if let Some(details) = output.source_encoding_details() {
//! // Generic quality (0-100, same scale as EncoderConfig::with_generic_quality)
//! if let Some(q) = details.source_generic_quality() {
//! println!("Source quality: {:.0}", q);
//! }
//!
//! // Codec-specific details via downcast
//! if let Some(webp) = details.codec_details::<zenwebp::detect::WebPProbe>() {
//! println!("VP8 quantizer: {:?}", webp.bitstream);
//! }
//! }
//! ```
use Any;
/// Codec-agnostic interface for source encoding properties.
///
/// Implemented by each codec's probe/detect type to provide both a
/// generic quality number and codec-specific details. The generic
/// quality uses the same 0.0–100.0 scale as
/// [`EncoderConfig::with_generic_quality()`](crate::encode::EncoderConfig::with_generic_quality).
///
/// # Downcasting
///
/// Use `codec_details::<T>()` to access the concrete probe type for
/// codec-specific fields:
///
/// ```rust,ignore
/// if let Some(jpeg) = details.codec_details::<zenjpeg::detect::JpegProbe>() {
/// println!("Encoder: {:?}", jpeg.encoder);
/// }
/// ```
// ── Design note ────────────────────────────────────────────────────────
//
// This trait intentionally has very few methods. Only properties that are
// meaningful across ALL image formats belong here (quality, lossless).
//
// Codec-specific details — color type, bit depth, palette size, chroma
// subsampling, encoder family, quantizer tables, etc. — belong as fields
// or methods on the concrete probe struct (e.g. `PngProbe`, `JpegProbe`).
// Callers access them via downcast:
//
// if let Some(png) = details.codec_details::<PngProbe>() {
// println!("{}bpp, palette: {:?}", png.bits_per_pixel(), png.palette_size);
// }
//
// This keeps the trait stable and avoids a combinatorial explosion of
// optional methods that only apply to a subset of codecs.
// ───────────────────────────────────────────────────────────────────────
// Downcast helper — avoids requiring callers to import `core::any::Any`.