-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from KateMorley/ilbm
Add support for ILBM
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ imagesize = "0.12" | |
* HDR | ||
* HEIC / HEIF | ||
* ICO* | ||
* ILBM (IFF) | ||
* JPEG | ||
* JPEG XL | ||
* KTX2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::{ | ||
util::{read_u16, read_u32, Endian}, | ||
ImageResult, ImageSize, | ||
}; | ||
use std::io::{BufRead, Seek, SeekFrom}; | ||
|
||
pub fn size<R: BufRead + Seek>(reader: &mut R) -> ImageResult<ImageSize> { | ||
// skip the IFF header | ||
reader.seek(SeekFrom::Start(12))?; | ||
|
||
let mut chunk_id = [0; 4]; | ||
|
||
loop { | ||
reader.read_exact(&mut chunk_id)?; | ||
let chunk_length = read_u32(reader, &Endian::Big)? as i64; | ||
|
||
if &chunk_id == b"BMHD" { | ||
return Ok(ImageSize { | ||
width: read_u16(reader, &Endian::Big)? as usize, | ||
height: read_u16(reader, &Endian::Big)? as usize, | ||
}); | ||
} | ||
|
||
// the BMHD chunk must occur before the BODY chunk | ||
if &chunk_id == b"BODY" { | ||
return Err(crate::ImageError::CorruptedImage); | ||
} | ||
|
||
// skip over the chunk; chunks of odd length have a padding byte | ||
reader.seek(SeekFrom::Current(chunk_length + chunk_length % 2))?; | ||
} | ||
} | ||
|
||
pub fn matches(header: &[u8]) -> bool { | ||
header.len() >= 12 | ||
&& &header[0..4] == b"FORM" | ||
&& (&header[8..12] == b"ILBM" || &header[8..12] == b"PBM ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[cfg(test)] | ||
use imagesize::{size, ImageSize}; | ||
|
||
#[test] | ||
fn ilbm_test() { | ||
assert_eq!( | ||
size("tests/images/ilbm/test.iff").unwrap(), | ||
ImageSize { | ||
width: 640, | ||
height: 512 | ||
} | ||
); | ||
} |
Binary file not shown.