#[non_exhaustive]pub enum ImageType {
Show 26 variants
Aseprite,
Astc,
Atc(AtcCompression),
Bmp,
Dds(DdsCompression),
Eac(PkmCompression),
Etc2(PkmCompression),
Exr,
Farbfeld,
Gif,
Hdr,
Heif(Compression),
Ico,
Ilbm,
Jpeg,
Jxl,
Ktx2,
Png,
Pnm,
Pvrtc(PvrtcCompression),
Psd,
Qoi,
Tga,
Tiff,
Vtf,
Webp,
}Expand description
Types of image formats that this crate can identify.
Many container formats support multiple inner compression formats. For these formats, the enum contains the inner compression type to provide more detailed information:
Dds(DdsCompression)- DirectDraw Surface with various BC compression formatsEtc2(PkmCompression)- ETC/PKM container with ETC1, ETC2, EAC variantsEac(PkmCompression)- EAC formats (unified with ETC2 detection)Atc(AtcCompression)- Adaptive Texture Compression variantsPvrtc(PvrtcCompression)- PowerVR texture compression with 2bpp/4bpp variants
§Helper Methods
The ImageType provides several helper methods to query compression information
across different container formats:
compression_family()- Groups related compression algorithmsis_block_compressed()- Checks for BC/DXT compressioncontainer_format()- Returns container format nameis_multi_compression_container()- Checks if container supports multiple compression types
§Examples
§Basic Format Detection
use ai_imagesize::{image_type, ImageType, PkmCompression};
// Create a PKM header for ETC2 format
let mut header = vec![b'P', b'K', b'M', b' ', b'2', b'0'];
header.extend_from_slice(&0x0001u16.to_be_bytes()); // ETC2 RGB
header.extend_from_slice(&[0x00, 0x40, 0x00, 0x40]); // Extended dimensions
header.extend_from_slice(&[0x00, 0x40, 0x00, 0x40]); // Original dimensions
match image_type(&header).unwrap() {
ImageType::Etc2(PkmCompression::Etc2) => println!("This is ETC2 RGB format"),
ImageType::Etc2(compression) => println!("This is ETC2 format: {:?}", compression),
other => println!("Other format: {:?}", other),
}§Using Helper Methods for Cross-Container Queries
use ai_imagesize::{ImageType, CompressionFamily, DdsCompression, PvrtcCompression};
// Query compression families across different containers
let dds_bc1 = ImageType::Dds(DdsCompression::Bc1);
let pvr_etc2 = ImageType::Pvrtc(PvrtcCompression::Etc2Rgb);
let png = ImageType::Png;
// Group related compression algorithms
assert_eq!(dds_bc1.compression_family(), Some(CompressionFamily::BlockCompression));
assert_eq!(pvr_etc2.compression_family(), Some(CompressionFamily::Etc));
assert_eq!(png.compression_family(), None); // Simple formats don't have compression
// Check for specific compression types
assert!(dds_bc1.is_block_compressed());
assert!(!pvr_etc2.is_block_compressed());
// Identify container formats
assert_eq!(dds_bc1.container_format(), Some("DDS"));
assert_eq!(pvr_etc2.container_format(), Some("PowerVR"));
assert_eq!(png.container_format(), None);
// Check multi-compression support
assert!(dds_bc1.is_multi_compression_container()); // DDS supports BC1-7, RGBA, etc.
assert!(pvr_etc2.is_multi_compression_container()); // PowerVR supports PVRTC, ETC2, EACVariants (Non-exhaustive)§
This enum is marked as non-exhaustive
Aseprite
Animated sprite image format https://github.com/aseprite/aseprite
Astc
Adaptive Scalable Texture Compression
Atc(AtcCompression)
Adaptive Texture Compression
Bmp
Standard Bitmap
Dds(DdsCompression)
DirectDraw Surface
Eac(PkmCompression)
Ericsson Texture Compression - Alpha Channel (now unified with ETC2)
Etc2(PkmCompression)
Ericsson Texture Compression 2 (includes ETC1, ETC2 variants)
Exr
OpenEXR
Farbfeld
Farbfeld https://tools.suckless.org/farbfeld/
Gif
Standard GIF
Hdr
Radiance HDR
Heif(Compression)
Image Container Format
Ico
Icon file
Ilbm
Interleaved Bitmap
Jpeg
Standard JPEG
Jxl
JPEG XL
Ktx2
Khronos Texture Container
Png
Standard PNG
Pnm
Portable Any Map
Pvrtc(PvrtcCompression)
PowerVR Texture Compression
Psd
Photoshop Document
Qoi
Quite OK Image Format https://qoiformat.org/
Tga
Truevision Graphics Adapter
Tiff
Standard TIFF
Vtf
Valve Texture Format
Webp
Standard Webp
Implementations§
Source§impl ImageType
impl ImageType
Sourcepub fn compression_family(&self) -> Option<CompressionFamily>
pub fn compression_family(&self) -> Option<CompressionFamily>
Returns the compression family for texture formats
Groups related compression algorithms regardless of their container format. Returns None for simple image formats like PNG, JPEG, etc.
§Examples
use ai_imagesize::{ImageType, CompressionFamily, DdsCompression, PvrtcCompression};
let dds_type = ImageType::Dds(DdsCompression::Bc1);
assert_eq!(dds_type.compression_family(), Some(CompressionFamily::BlockCompression));
let pvrtc_etc2_type = ImageType::Pvrtc(PvrtcCompression::Etc2Rgb);
assert_eq!(pvrtc_etc2_type.compression_family(), Some(CompressionFamily::Etc));
let png_type = ImageType::Png;
assert_eq!(png_type.compression_family(), None);Sourcepub fn is_block_compressed(&self) -> bool
pub fn is_block_compressed(&self) -> bool
Returns true if the image uses block compression (BC/DXT family)
Block compression includes BC1-7 formats (also known as DXT1-5, ATI1-2).
§Examples
use ai_imagesize::{ImageType, DdsCompression};
let bc1_type = ImageType::Dds(DdsCompression::Bc1);
assert!(bc1_type.is_block_compressed());
let png_type = ImageType::Png;
assert!(!png_type.is_block_compressed());Sourcepub fn container_format(&self) -> Option<&'static str>
pub fn container_format(&self) -> Option<&'static str>
Returns the container format name for texture formats
Returns a human-readable string identifying the container format. Returns None for simple image formats.
§Examples
use ai_imagesize::{ImageType, DdsCompression, PvrtcCompression};
let dds_type = ImageType::Dds(DdsCompression::Bc1);
assert_eq!(dds_type.container_format(), Some("DDS"));
let pvr_type = ImageType::Pvrtc(PvrtcCompression::Pvrtc2BppRgb);
assert_eq!(pvr_type.container_format(), Some("PowerVR"));
let png_type = ImageType::Png;
assert_eq!(png_type.container_format(), None);Sourcepub fn is_multi_compression_container(&self) -> bool
pub fn is_multi_compression_container(&self) -> bool
Returns true if the image format supports multiple compression types within the same container
Some container formats like PowerVR can store different compression algorithms.
§Examples
use ai_imagesize::{ImageType, PvrtcCompression, DdsCompression};
let pvr_type = ImageType::Pvrtc(PvrtcCompression::Etc2Rgb);
assert!(pvr_type.is_multi_compression_container());
let dds_type = ImageType::Dds(DdsCompression::Bc1);
assert!(dds_type.is_multi_compression_container());
let png_type = ImageType::Png;
assert!(!png_type.is_multi_compression_container());Sourcepub fn reader_size<R: BufRead + Seek>(
&self,
reader: &mut R,
) -> ImageResult<ImageSize>
pub fn reader_size<R: BufRead + Seek>( &self, reader: &mut R, ) -> ImageResult<ImageSize>
Calls the correct image size method based on the image type
§Arguments
reader- A reader for the data