Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type .ico #1

Merged
merged 2 commits into from May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -37,6 +37,8 @@ pub enum Type {
Rgb,
/// FLIF (Free Lossless Image Format) files
Flif,
/// ICO files
Ico
}


Expand Down
2 changes: 2 additions & 0 deletions src/patterns.rs
Expand Up @@ -16,6 +16,7 @@ const BMP: &'static [u8] = b"BM";
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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are .CUR images still exists, btw? Have not seen them for a decades.

Copy link
Contributor Author

@iwatakeshi iwatakeshi May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen them either. Also, it isn't listed as one of image's supported file types.


#[inline]
fn is_pbm(ref bytes: [u8; 32]) -> bool {
Expand Down Expand Up @@ -51,6 +52,7 @@ pub fn guess(ref bytes: [u8; 32]) -> Option<Type> {
_ if &bytes[..4] == BGP => Some(Type::Bgp),
_ if &bytes[..2] == RGB => Some(Type::Rgb),
_ if &bytes[..4] == FLIF => Some(Type::Flif),
_ if &bytes[..4] == ICO => Some(Type::Ico),
_ if is_pbm(*bytes) => Some(Type::Pbm),
_ if is_pgm(*bytes) => Some(Type::Pgm),
_ if is_ppm(*bytes) => Some(Type::Ppm),
Expand Down
Binary file added tests/images/example.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/mod.rs
Expand Up @@ -99,6 +99,11 @@ fn test_flif() {
assert_result!(Some(imghdr::Type::Flif), "./tests/images/example.flif");
}

#[test]
fn test_ico() {
assert_result!(Some(imghdr::Type::Ico), "./tests/images/example.ico");
}

#[test]
fn test_not_a_image() {
assert_result!(None::<imghdr::Type>, "./tests/images/not-a-image.txt");
Expand Down