diff --git a/src/lib.rs b/src/lib.rs index e29ed01..2281557 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,6 +93,8 @@ pub enum Type { Flif, /// ICO files Ico, + /// AVIF files + Avif, } /// Try to determine image format from a bytes slice. diff --git a/src/patterns.rs b/src/patterns.rs index 76316f5..1a93ab6 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -23,6 +23,7 @@ const BGP: &'static [u8] = b"BPG\xfb"; const RGB: &'static [u8] = b"\x01\xda"; const FLIF: &'static [u8] = b"FLIF"; const ICO: &'static [u8] = b"\x00\x00\x01\x00"; +const AVIF: &'static [u8] = b"avif"; #[inline] fn is_pbm(bytes: &[u8]) -> bool { @@ -89,6 +90,7 @@ pub fn guess(bytes: &[u8]) -> Option { _ if &bytes[..2] == RGB => Some(Type::Rgb), _ if &bytes[..4] == FLIF => Some(Type::Flif), _ if &bytes[..4] == ICO => Some(Type::Ico), + _ if (&bytes[8..12] == AVIF) => Some(Type::Avif), _ if is_pbm(bytes) => Some(Type::Pbm), _ if is_pgm(bytes) => Some(Type::Pgm), _ if is_ppm(bytes) => Some(Type::Ppm), diff --git a/tests/images/example.avif b/tests/images/example.avif new file mode 100644 index 0000000..a1c0abd Binary files /dev/null and b/tests/images/example.avif differ diff --git a/tests/mod.rs b/tests/mod.rs index a3df817..c06c237 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -112,6 +112,11 @@ fn test_ico() { assert_result!(Some(imghdr::Type::Ico), "./tests/images/example.ico"); } +#[test] +fn test_avif() { + assert_result!(Some(imghdr::Type::Avif), "./tests/images/example.avif"); +} + #[test] fn test_not_a_image() { assert_result!(None::, "./tests/images/not-a-image.txt");