From 2c0e0df1eec427988ad226ae400a03f9f4f0301c Mon Sep 17 00:00:00 2001 From: RSUU Date: Tue, 21 May 2024 21:20:27 +0800 Subject: [PATCH 1/4] Distinguish between HEIF and HEIC Signed-off-by: RSUU --- src/{formats => container}/heif.rs | 38 ++++++++++++++++++++---------- src/container/mod.rs | 1 + src/formats/avif.rs | 25 -------------------- src/formats/mod.rs | 17 ++++++------- src/lib.rs | 12 ++++++---- tests/avif.rs | 30 ++++++++++++++++++++--- tests/heic.rs | 34 ++++++++++++++++++++++---- 7 files changed, 99 insertions(+), 58 deletions(-) rename src/{formats => container}/heif.rs (87%) create mode 100644 src/container/mod.rs delete mode 100644 src/formats/avif.rs diff --git a/src/formats/heif.rs b/src/container/heif.rs similarity index 87% rename from src/formats/heif.rs rename to src/container/heif.rs index 76f4f80..e3aa81b 100644 --- a/src/formats/heif.rs +++ b/src/container/heif.rs @@ -1,8 +1,15 @@ use crate::util::*; use crate::{ImageError, ImageResult, ImageSize}; +use std::convert::TryInto; use std::io::{BufRead, Seek, SeekFrom}; +pub enum Heif { + Avif, + Heic, + Unknown, +} + pub fn size(reader: &mut R) -> ImageResult { reader.seek(SeekFrom::Start(0))?; // Read the ftyp header size @@ -75,34 +82,39 @@ pub fn size(reader: &mut R) -> ImageResult { }) } -pub fn matches(header: &[u8]) -> bool { +pub fn matches(header: &[u8]) -> Option { if header.len() < 12 || &header[4..8] != b"ftyp" { - return false; + return None; } - let header_brand = &header[8..12]; + let header_brand: [u8; 4] = header[8..12].try_into().unwrap(); // Since other non-heif files may contain ftype in the header // we try to use brands to distinguish image files specifically. // List of brands from here: https://mp4ra.org/#/brands - let valid_brands = [ - // HEIF specific + #[rustfmt::skip] + // HEIC specific + let heic_brands = [ b"avci", b"avcs", b"heic", b"heim", b"heis", b"heix", b"hevc", b"hevm", b"hevs", b"hevx", b"jpeg", b"jpgs", b"mif1", b"msf1", b"mif2", b"pred", - // AVIF specific + ]; + + #[rustfmt::skip] + // AVIF specific + let avif_brands = [ b"avif", b"avio", b"avis", b"MA1A", b"MA1B", ]; - for brand in valid_brands { - if brand == header_brand { - return true; - } - } - - false + Some(if heic_brands.contains(&&header_brand) { + Heif::Heic + } else if avif_brands.contains(&&header_brand) { + Heif::Avif + } else { + Heif::Unknown + }) } fn skip_to_tag(reader: &mut R, tag: &[u8]) -> ImageResult { diff --git a/src/container/mod.rs b/src/container/mod.rs new file mode 100644 index 0000000..8aef9bd --- /dev/null +++ b/src/container/mod.rs @@ -0,0 +1 @@ +pub mod heif; diff --git a/src/formats/avif.rs b/src/formats/avif.rs deleted file mode 100644 index 2d31c7c..0000000 --- a/src/formats/avif.rs +++ /dev/null @@ -1,25 +0,0 @@ -// AVIF is a special case of HEIF. Image size methods are defined in there and should work for both. -// Only difference is that we want to specify the image type as AVIF instead of wrapping it into HEIF. -pub fn matches(header: &[u8]) -> bool { - if header.len() < 12 || &header[4..8] != b"ftyp" { - return false; - } - - let header_brand = &header[8..12]; - - // Since other non-AVIF files may contain ftype in the header - // we try to use brands to distinguish image files specifically. - // List of brands from here: https://mp4ra.org/#/brands - let valid_brands = [ - b"avif", b"avio", b"avis", b"MA1A", - b"MA1B", - ]; - - for brand in valid_brands { - if brand == header_brand { - return true; - } - } - - false -} diff --git a/src/formats/mod.rs b/src/formats/mod.rs index 2f1050e..c6687ad 100644 --- a/src/formats/mod.rs +++ b/src/formats/mod.rs @@ -1,12 +1,10 @@ pub mod aesprite; -pub mod avif; pub mod bmp; pub mod dds; pub mod exr; pub mod farbfeld; pub mod gif; pub mod hdr; -pub mod heif; pub mod ico; pub mod jpeg; pub mod jxl; @@ -20,7 +18,7 @@ pub mod tiff; pub mod vtf; pub mod webp; -use crate::{ImageError, ImageResult, ImageType}; +use crate::{container, ImageError, ImageResult, ImageType}; use std::io::{BufRead, Seek}; pub fn image_type(reader: &mut R) -> ImageResult { @@ -56,12 +54,15 @@ pub fn image_type(reader: &mut R) -> ImageResult { return Ok(ImageType::Webp); } - if heif::matches(&header) { - return Ok(ImageType::Heif); - } + if let Some(ty) = container::heif::matches(&header) { + use container::heif::Heif; - if avif::matches(&header) { - return Ok(ImageType::Avif); + return Ok(match ty { + Heif::Avif => ImageType::Avif, + Heif::Heic => ImageType::Heic, + // Unknown format in HEIF. + _ => ImageType::Heif, + }); } if jxl::matches(&header) { diff --git a/src/lib.rs b/src/lib.rs index 58cecc5..89a2d78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,11 @@ use std::fs::File; use std::io::{BufRead, BufReader, Cursor, Seek}; use std::path::Path; +mod container; +mod formats; mod util; -mod formats; -use formats::*; +use {container::*, formats::*}; /// An Error type used in failure cases. #[derive(Debug)] @@ -63,6 +64,8 @@ pub enum ImageType { /// Radiance HDR Hdr, /// High Efficiency Image File Format + Heic, + /// Image Container Format Heif, /// Icon file Ico, @@ -248,14 +251,12 @@ pub fn reader_size(mut reader: R) -> ImageResult { fn dispatch_header(reader: &mut R) -> ImageResult { match formats::image_type(reader)? { ImageType::Aseprite => aesprite::size(reader), - ImageType::Avif => heif::size(reader), // AVIF uses HEIF size on purpose ImageType::Bmp => bmp::size(reader), ImageType::Dds => dds::size(reader), ImageType::Exr => exr::size(reader), ImageType::Farbfeld => farbfeld::size(reader), ImageType::Gif => gif::size(reader), ImageType::Hdr => hdr::size(reader), - ImageType::Heif => heif::size(reader), ImageType::Ico => ico::size(reader), ImageType::Jpeg => jpeg::size(reader), ImageType::Jxl => jxl::size(reader), @@ -268,5 +269,8 @@ fn dispatch_header(reader: &mut R) -> ImageResult ImageType::Tiff => tiff::size(reader), ImageType::Vtf => vtf::size(reader), ImageType::Webp => webp::size(reader), + + // AVIF and HEIC uses HEIF size on purpose + ImageType::Heif | ImageType::Heic | ImageType::Avif => heif::size(reader), } } diff --git a/tests/avif.rs b/tests/avif.rs index 9af83df..de382f8 100644 --- a/tests/avif.rs +++ b/tests/avif.rs @@ -1,14 +1,38 @@ #[cfg(test)] -use imagesize::{size, ImageSize}; +use imagesize::{image_type, size, ImageSize, ImageType}; #[test] fn avif_test() { let dim = size("tests/images/avif/test.avif").unwrap(); - assert_eq!(dim, ImageSize { width: 1204, height: 800 }); + assert_eq!( + dim, + ImageSize { + width: 1204, + height: 800 + } + ); } #[test] fn avif_multi_picks_largest() { let dim = size("tests/images/avif/test.avifs").unwrap(); - assert_eq!(dim, ImageSize { width: 159, height: 159 }); + assert_eq!( + dim, + ImageSize { + width: 159, + height: 159 + } + ); +} + +#[test] +fn avif_type() { + use std::{fs::File, io::Read}; + + let mut f = File::open("tests/images/avif/test.avif").unwrap(); + let mut buf = vec![]; + f.read_to_end(&mut buf).unwrap(); + + let ty = image_type(&buf).unwrap(); + assert_eq!(ty, ImageType::Avif); } diff --git a/tests/heic.rs b/tests/heic.rs index e3d9ac7..65967b1 100644 --- a/tests/heic.rs +++ b/tests/heic.rs @@ -1,14 +1,38 @@ #[cfg(test)] -use imagesize::{size, ImageSize}; +use imagesize::{image_type, size, ImageSize, ImageType}; #[test] -fn heif_test() { +fn heic_test() { let dim = size("tests/images/heic/test.heic").unwrap(); - assert_eq!(dim, ImageSize { width: 1280, height: 720 }); + assert_eq!( + dim, + ImageSize { + width: 1280, + height: 720 + } + ); } #[test] -fn heif_multi_picks_largest() { +fn heic_multi_picks_largest() { let dim = size("tests/images/heic/IMG_0007.heic").unwrap(); - assert_eq!(dim, ImageSize { width: 2448, height: 3264 }); + assert_eq!( + dim, + ImageSize { + width: 2448, + height: 3264 + } + ); +} + +#[test] +fn heic_type() { + use std::{fs::File, io::Read}; + + let mut f = File::open("tests/images/heic/test.heic").unwrap(); + let mut buf = vec![]; + f.read_to_end(&mut buf).unwrap(); + + let ty = image_type(&buf).unwrap(); + assert_eq!(ty, ImageType::Heic); } From 281b3ba35f9271e2f607c3ef1ef5fb1e8edbc8f7 Mon Sep 17 00:00:00 2001 From: RSUU Date: Sat, 8 Jun 2024 10:49:10 +0800 Subject: [PATCH 2/4] Rename field --- src/container/heif.rs | 99 ++++++++++++++---- src/formats/mod.rs | 10 +- src/formats/pnm.rs | 4 +- src/lib.rs | 3 + tests/avif.rs | 12 +++ tests/heic.rs | 22 +++- .../images/heic/{IMG_0007.heic => heic.heic} | Bin .../images/heic/{test.heic => heic_msf1.heic} | Bin 8 files changed, 115 insertions(+), 35 deletions(-) rename tests/images/heic/{IMG_0007.heic => heic.heic} (100%) rename tests/images/heic/{test.heic => heic_msf1.heic} (100%) diff --git a/src/container/heif.rs b/src/container/heif.rs index e3aa81b..b6a574d 100644 --- a/src/container/heif.rs +++ b/src/container/heif.rs @@ -4,10 +4,16 @@ use crate::{ImageError, ImageResult, ImageSize}; use std::convert::TryInto; use std::io::{BufRead, Seek, SeekFrom}; +// REFS: https://github.com/strukturag/libheif/blob/f0c1a863cabbccb2d280515b7ecc73e6717702dc/libheif/heif.h#L600 pub enum Heif { - Avif, - Heic, + Av1, + Hevc, + Jpeg, Unknown, + // unused(reuse in the future?) + // Avc, + // Vvc, + // Evc, } pub fn size(reader: &mut R) -> ImageResult { @@ -82,38 +88,85 @@ pub fn size(reader: &mut R) -> ImageResult { }) } -pub fn matches(header: &[u8]) -> Option { +pub fn matches(header: &[u8], reader: &mut R) -> Option { if header.len() < 12 || &header[4..8] != b"ftyp" { return None; } - let header_brand: [u8; 4] = header[8..12].try_into().unwrap(); + let brand: [u8; 4] = header[8..12].try_into().unwrap(); + // case 1: { heic, ... } + if let Some(v) = inner_matches(&brand) { + Some(v) + + // case 2: { msf1, version, heic, msf1, ... } + // brand brand2 brand3 + // case 3: { msf1, version, msf1, heic, ... } + // brand brand2 brand3 + } else { + // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/reader/heifreaderimpl.cpp#L738 + let m_brands = [b"mif1", b"msf1", b"mif2", b"miaf"]; + + if m_brands.contains(&&brand) { + let mut buf = [0; 12]; + + if reader.read_exact(&mut buf).is_err() { + return Some(Heif::Unknown); + } + + let brand2: [u8; 4] = buf[4..8].try_into().unwrap(); + let brand3: [u8; 4] = buf[8..12].try_into().unwrap(); + + // case 2 + if let Some(v) = inner_matches(&brand2) { + return Some(v); + + // case 3 + } else if m_brands.contains(&&brand2) { + if let Some(v) = inner_matches(&brand3) { + return Some(v); + } + } + } + + Some(Heif::Unknown) + } +} + +fn inner_matches(brand: &[u8; 4]) -> Option { // Since other non-heif files may contain ftype in the header // we try to use brands to distinguish image files specifically. // List of brands from here: https://mp4ra.org/#/brands - #[rustfmt::skip] - // HEIC specific - let heic_brands = [ - b"avci", b"avcs", b"heic", b"heim", - b"heis", b"heix", b"hevc", b"hevm", - b"hevs", b"hevx", b"jpeg", b"jpgs", - b"mif1", b"msf1", b"mif2", b"pred", + let hevc_brands = [ + b"heic", b"heix", b"heis", b"hevs", b"heim", b"hevm", b"hevc", b"hevx", ]; - - #[rustfmt::skip] - // AVIF specific - let avif_brands = [ - b"avif", b"avio", b"avis", b"MA1A", - b"MA1B", + let av1_brands = [ + b"avif", b"avio", b"avis", + // AVIF only + // REFS: https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html#advanced-profile + b"MA1A", b"MA1B", ]; - - Some(if heic_brands.contains(&&header_brand) { - Heif::Heic - } else if avif_brands.contains(&&header_brand) { - Heif::Avif + let jpeg_brands = [b"jpeg", b"jpgs"]; + + // unused + // REFS: https://github.com/MPEGGroup/FileFormatConformance/blob/6eef4e4c8bc70e2af9aeb1d62e764a6235f9d6a6/data/standard_features/23008-12/brands.json + // let avc_brands = [b"avci", b"avcs"]; + // let vvc_brands = [b"vvic", b"vvis"]; + // let evc_brands = [b"evbi", b"evbs", b"evmi", b"evms"]; + + // Maybe unnecessary + // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/reader/heifreaderimpl.cpp#L1415 + // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/api-cpp/ImageItem.h#L37 + // let feature_brands = [b"pred", b"auxl", b"thmb", b"base", b"dimg"]; + + Some(if hevc_brands.contains(&brand) { + Heif::Hevc + } else if av1_brands.contains(&brand) { + Heif::Av1 + } else if jpeg_brands.contains(&brand) { + Heif::Jpeg } else { - Heif::Unknown + return None; }) } diff --git a/src/formats/mod.rs b/src/formats/mod.rs index c6687ad..646ec65 100644 --- a/src/formats/mod.rs +++ b/src/formats/mod.rs @@ -54,14 +54,14 @@ pub fn image_type(reader: &mut R) -> ImageResult { return Ok(ImageType::Webp); } - if let Some(ty) = container::heif::matches(&header) { + if let Some(ty) = container::heif::matches(&header, reader) { use container::heif::Heif; return Ok(match ty { - Heif::Avif => ImageType::Avif, - Heif::Heic => ImageType::Heic, - // Unknown format in HEIF. - _ => ImageType::Heif, + Heif::Hevc => ImageType::Heic, + Heif::Av1 => ImageType::Avif, + Heif::Jpeg => ImageType::Jpeg, + Heif::Unknown => ImageType::Heif, }); } diff --git a/src/formats/pnm.rs b/src/formats/pnm.rs index dc8a28b..b6a0914 100644 --- a/src/formats/pnm.rs +++ b/src/formats/pnm.rs @@ -18,7 +18,7 @@ pub fn size(reader: &mut R) -> ImageResult { // If it's a comment, skip until newline if trimmed_line.starts_with('#') { read_until_capped(reader, b'\n', 1024)?; - continue + continue; } // If it's just empty skip @@ -56,7 +56,7 @@ pub fn matches(header: &[u8]) -> bool { } // We only support P1 to P6. Currently ignoring P7, PF, PFM - if header[1] < b'1' && header[1] > b'6' { + if header[1] < b'1' || header[1] > b'6' { return false; } diff --git a/src/lib.rs b/src/lib.rs index 89a2d78..5883de0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,9 @@ pub enum ImageType { /// High Efficiency Image File Format Heic, /// Image Container Format + /// + /// This means there is a `Unknown Compression Type` in `HEIF` file. But you don't need to care + /// about this in normal. Heif, /// Icon file Ico, diff --git a/tests/avif.rs b/tests/avif.rs index de382f8..70f524c 100644 --- a/tests/avif.rs +++ b/tests/avif.rs @@ -36,3 +36,15 @@ fn avif_type() { let ty = image_type(&buf).unwrap(); assert_eq!(ty, ImageType::Avif); } + +#[test] +fn avif_seq_type() { + use std::{fs::File, io::Read}; + + let mut f = File::open("tests/images/avif/test.avifs").unwrap(); + let mut buf = vec![]; + f.read_to_end(&mut buf).unwrap(); + + let ty = image_type(&buf).unwrap(); + assert_eq!(ty, ImageType::Avif); +} diff --git a/tests/heic.rs b/tests/heic.rs index 65967b1..0b451bb 100644 --- a/tests/heic.rs +++ b/tests/heic.rs @@ -3,19 +3,19 @@ use imagesize::{image_type, size, ImageSize, ImageType}; #[test] fn heic_test() { - let dim = size("tests/images/heic/test.heic").unwrap(); + let dim = size("tests/images/heic/heic.heic").unwrap(); assert_eq!( dim, ImageSize { - width: 1280, - height: 720 + width: 2448, + height: 3264 } ); } #[test] fn heic_multi_picks_largest() { - let dim = size("tests/images/heic/IMG_0007.heic").unwrap(); + let dim = size("tests/images/heic/heic.heic").unwrap(); assert_eq!( dim, ImageSize { @@ -29,7 +29,19 @@ fn heic_multi_picks_largest() { fn heic_type() { use std::{fs::File, io::Read}; - let mut f = File::open("tests/images/heic/test.heic").unwrap(); + let mut f = File::open("tests/images/heic/heic.heic").unwrap(); + let mut buf = vec![]; + f.read_to_end(&mut buf).unwrap(); + + let ty = image_type(&buf).unwrap(); + assert_eq!(ty, ImageType::Heic); +} + +#[test] +fn heic_msf1_type() { + use std::{fs::File, io::Read}; + + let mut f = File::open("tests/images/heic/heic_msf1.heic").unwrap(); let mut buf = vec![]; f.read_to_end(&mut buf).unwrap(); diff --git a/tests/images/heic/IMG_0007.heic b/tests/images/heic/heic.heic similarity index 100% rename from tests/images/heic/IMG_0007.heic rename to tests/images/heic/heic.heic diff --git a/tests/images/heic/test.heic b/tests/images/heic/heic_msf1.heic similarity index 100% rename from tests/images/heic/test.heic rename to tests/images/heic/heic_msf1.heic From 36fca5ce95ac4b287779674043bfa1501bb80482 Mon Sep 17 00:00:00 2001 From: RSUU Date: Sat, 8 Jun 2024 11:32:43 +0800 Subject: [PATCH 3/4] Rename enum Signed-off-by: RSUU --- src/container/heif.rs | 17 +++++++++-------- src/formats/mod.rs | 11 ++--------- src/lib.rs | 15 +++++++-------- tests/avif.rs | 6 +++--- tests/heic.rs | 6 +++--- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/container/heif.rs b/src/container/heif.rs index b6a574d..aa84df7 100644 --- a/src/container/heif.rs +++ b/src/container/heif.rs @@ -5,7 +5,8 @@ use std::convert::TryInto; use std::io::{BufRead, Seek, SeekFrom}; // REFS: https://github.com/strukturag/libheif/blob/f0c1a863cabbccb2d280515b7ecc73e6717702dc/libheif/heif.h#L600 -pub enum Heif { +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Compression { Av1, Hevc, Jpeg, @@ -88,7 +89,7 @@ pub fn size(reader: &mut R) -> ImageResult { }) } -pub fn matches(header: &[u8], reader: &mut R) -> Option { +pub fn matches(header: &[u8], reader: &mut R) -> Option { if header.len() < 12 || &header[4..8] != b"ftyp" { return None; } @@ -111,7 +112,7 @@ pub fn matches(header: &[u8], reader: &mut R) -> Option let mut buf = [0; 12]; if reader.read_exact(&mut buf).is_err() { - return Some(Heif::Unknown); + return Some(Compression::Unknown); } let brand2: [u8; 4] = buf[4..8].try_into().unwrap(); @@ -129,11 +130,11 @@ pub fn matches(header: &[u8], reader: &mut R) -> Option } } - Some(Heif::Unknown) + Some(Compression::Unknown) } } -fn inner_matches(brand: &[u8; 4]) -> Option { +fn inner_matches(brand: &[u8; 4]) -> Option { // Since other non-heif files may contain ftype in the header // we try to use brands to distinguish image files specifically. // List of brands from here: https://mp4ra.org/#/brands @@ -160,11 +161,11 @@ fn inner_matches(brand: &[u8; 4]) -> Option { // let feature_brands = [b"pred", b"auxl", b"thmb", b"base", b"dimg"]; Some(if hevc_brands.contains(&brand) { - Heif::Hevc + Compression::Hevc } else if av1_brands.contains(&brand) { - Heif::Av1 + Compression::Av1 } else if jpeg_brands.contains(&brand) { - Heif::Jpeg + Compression::Jpeg } else { return None; }) diff --git a/src/formats/mod.rs b/src/formats/mod.rs index 646ec65..6a6e5c6 100644 --- a/src/formats/mod.rs +++ b/src/formats/mod.rs @@ -54,15 +54,8 @@ pub fn image_type(reader: &mut R) -> ImageResult { return Ok(ImageType::Webp); } - if let Some(ty) = container::heif::matches(&header, reader) { - use container::heif::Heif; - - return Ok(match ty { - Heif::Hevc => ImageType::Heic, - Heif::Av1 => ImageType::Avif, - Heif::Jpeg => ImageType::Jpeg, - Heif::Unknown => ImageType::Heif, - }); + if let Some(c) = container::heif::matches(&header, reader) { + return Ok(ImageType::Heif(c)); } if jxl::matches(&header) { diff --git a/src/lib.rs b/src/lib.rs index 5883de0..0c42c9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,11 @@ mod container; mod formats; mod util; -use {container::*, formats::*}; +pub use container::heif::Compression; +use { + container::heif::{self}, + formats::*, +}; /// An Error type used in failure cases. #[derive(Debug)] @@ -48,8 +52,6 @@ pub enum ImageType { /// Animated sprite image format /// Aseprite, - /// AV1 Image File Format - Avif, /// Standard Bitmap Bmp, /// DirectDraw Surface @@ -63,13 +65,11 @@ pub enum ImageType { Gif, /// Radiance HDR Hdr, - /// High Efficiency Image File Format - Heic, /// Image Container Format /// /// This means there is a `Unknown Compression Type` in `HEIF` file. But you don't need to care /// about this in normal. - Heif, + Heif(Compression), /// Icon file Ico, /// Standard JPEG @@ -273,7 +273,6 @@ fn dispatch_header(reader: &mut R) -> ImageResult ImageType::Vtf => vtf::size(reader), ImageType::Webp => webp::size(reader), - // AVIF and HEIC uses HEIF size on purpose - ImageType::Heif | ImageType::Heic | ImageType::Avif => heif::size(reader), + ImageType::Heif(..) => heif::size(reader), } } diff --git a/tests/avif.rs b/tests/avif.rs index 70f524c..783cc46 100644 --- a/tests/avif.rs +++ b/tests/avif.rs @@ -1,5 +1,5 @@ #[cfg(test)] -use imagesize::{image_type, size, ImageSize, ImageType}; +use imagesize::{image_type, size, Compression, ImageSize, ImageType}; #[test] fn avif_test() { @@ -34,7 +34,7 @@ fn avif_type() { f.read_to_end(&mut buf).unwrap(); let ty = image_type(&buf).unwrap(); - assert_eq!(ty, ImageType::Avif); + assert_eq!(ty, ImageType::Heif(Compression::Av1)); } #[test] @@ -46,5 +46,5 @@ fn avif_seq_type() { f.read_to_end(&mut buf).unwrap(); let ty = image_type(&buf).unwrap(); - assert_eq!(ty, ImageType::Avif); + assert_eq!(ty, ImageType::Heif(Compression::Av1)); } diff --git a/tests/heic.rs b/tests/heic.rs index 0b451bb..bddf279 100644 --- a/tests/heic.rs +++ b/tests/heic.rs @@ -1,5 +1,5 @@ #[cfg(test)] -use imagesize::{image_type, size, ImageSize, ImageType}; +use imagesize::{image_type, size, Compression, ImageSize, ImageType}; #[test] fn heic_test() { @@ -34,7 +34,7 @@ fn heic_type() { f.read_to_end(&mut buf).unwrap(); let ty = image_type(&buf).unwrap(); - assert_eq!(ty, ImageType::Heic); + assert_eq!(ty, ImageType::Heif(Compression::Hevc)); } #[test] @@ -46,5 +46,5 @@ fn heic_msf1_type() { f.read_to_end(&mut buf).unwrap(); let ty = image_type(&buf).unwrap(); - assert_eq!(ty, ImageType::Heic); + assert_eq!(ty, ImageType::Heif(Compression::Hevc)); } From 5195b9d3e70f36f222c67b50137c927f4c41e421 Mon Sep 17 00:00:00 2001 From: RSUU Date: Sat, 8 Jun 2024 13:05:34 +0800 Subject: [PATCH 4/4] Chore Signed-off-by: RSUU --- src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0c42c9f..3f78f71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,9 +66,6 @@ pub enum ImageType { /// Radiance HDR Hdr, /// Image Container Format - /// - /// This means there is a `Unknown Compression Type` in `HEIF` file. But you don't need to care - /// about this in normal. Heif(Compression), /// Icon file Ico,