pub struct ImageFormatRegistry { /* private fields */ }Expand description
A collection of ImageFormatDefinitions with lookup methods.
Use common() for the default registry
containing all built-in formats. Use from_vec()
or from_static() for custom registries.
§Example
use zencodec::{ImageFormatRegistry, ImageFormatDefinition};
// Default: all built-in formats
let reg = ImageFormatRegistry::common();
assert_eq!(reg.detect(jpeg_bytes), Some(ImageFormat::Jpeg));
// Custom: build your own
let reg = ImageFormatRegistry::from_vec(vec![&JPEG2000]);Implementations§
Source§impl ImageFormatRegistry
impl ImageFormatRegistry
Sourcepub fn common() -> Self
pub fn common() -> Self
Registry containing all built-in format definitions.
Detection order follows priority: JPEG, PNG, GIF, WebP, AVIF, JXL, HEIC, BMP, farbfeld, PNM, TIFF, ICO, QOI. AVIF is checked before HEIC so that ambiguous ISOBMFF containers (mif1/msf1 with both brands) resolve to AVIF.
Zero allocation — backed by a static slice.
Sourcepub fn from_static(defs: &'static [&'static ImageFormatDefinition]) -> Self
pub fn from_static(defs: &'static [&'static ImageFormatDefinition]) -> Self
Registry backed by a static slice. Zero allocation.
Sourcepub fn from_vec(defs: Vec<&'static ImageFormatDefinition>) -> Self
pub fn from_vec(defs: Vec<&'static ImageFormatDefinition>) -> Self
Create a registry from an owned list of definitions.
Sourcepub fn formats(&self) -> &[&'static ImageFormatDefinition]
pub fn formats(&self) -> &[&'static ImageFormatDefinition]
The format definitions in this registry, in detection priority order.
Sourcepub fn detect(&self, data: &[u8]) -> Option<ImageFormat>
pub fn detect(&self, data: &[u8]) -> Option<ImageFormat>
Detect format from magic bytes.
Checks definitions in order, returns the first match. Returns None
if no definition matches.
Sourcepub fn from_extension(&self, ext: &str) -> Option<ImageFormat>
pub fn from_extension(&self, ext: &str) -> Option<ImageFormat>
Detect format from file extension (case-insensitive).
Sourcepub fn from_mime_type(&self, mime: &str) -> Option<ImageFormat>
pub fn from_mime_type(&self, mime: &str) -> Option<ImageFormat>
Detect format from MIME type (case-insensitive).
Trait Implementations§
Source§impl Clone for ImageFormatRegistry
impl Clone for ImageFormatRegistry
Source§fn clone(&self) -> ImageFormatRegistry
fn clone(&self) -> ImageFormatRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more