File tree Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ imagesize = "0.12"
23
23
* HDR
24
24
* HEIC / HEIF
25
25
* ICO*
26
+ * ILBM (IFF)
26
27
* JPEG
27
28
* JPEG XL
28
29
* KTX2
Original file line number Diff line number Diff line change
1
+ use crate :: {
2
+ util:: { read_u16, read_u32, Endian } ,
3
+ ImageResult , ImageSize ,
4
+ } ;
5
+ use std:: io:: { BufRead , Seek , SeekFrom } ;
6
+
7
+ pub fn size < R : BufRead + Seek > ( reader : & mut R ) -> ImageResult < ImageSize > {
8
+ // skip the IFF header
9
+ reader. seek ( SeekFrom :: Start ( 12 ) ) ?;
10
+
11
+ let mut chunk_id = [ 0 ; 4 ] ;
12
+
13
+ loop {
14
+ reader. read_exact ( & mut chunk_id) ?;
15
+ let chunk_length = read_u32 ( reader, & Endian :: Big ) ? as i64 ;
16
+
17
+ if & chunk_id == b"BMHD" {
18
+ return Ok ( ImageSize {
19
+ width : read_u16 ( reader, & Endian :: Big ) ? as usize ,
20
+ height : read_u16 ( reader, & Endian :: Big ) ? as usize ,
21
+ } ) ;
22
+ }
23
+
24
+ // the BMHD chunk must occur before the BODY chunk
25
+ if & chunk_id == b"BODY" {
26
+ return Err ( crate :: ImageError :: CorruptedImage ) ;
27
+ }
28
+
29
+ // skip over the chunk; chunks of odd length have a padding byte
30
+ reader. seek ( SeekFrom :: Current ( chunk_length + chunk_length % 2 ) ) ?;
31
+ }
32
+ }
33
+
34
+ pub fn matches ( header : & [ u8 ] ) -> bool {
35
+ header. len ( ) >= 12
36
+ && & header[ 0 ..4 ] == b"FORM"
37
+ && ( & header[ 8 ..12 ] == b"ILBM" || & header[ 8 ..12 ] == b"PBM " )
38
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ pub mod gif;
8
8
pub mod hdr;
9
9
pub mod heif;
10
10
pub mod ico;
11
+ pub mod ilbm;
11
12
pub mod jpeg;
12
13
pub mod jxl;
13
14
pub mod ktx2;
@@ -116,6 +117,10 @@ pub fn image_type<R: BufRead + Seek>(reader: &mut R) -> ImageResult<ImageType> {
116
117
return Ok ( ImageType :: Vtf ) ;
117
118
}
118
119
120
+ if ilbm:: matches ( & header) {
121
+ return Ok ( ImageType :: Ilbm ) ;
122
+ }
123
+
119
124
// Keep TGA last because it has the highest probability of false positives
120
125
if tga:: matches ( & header, reader) {
121
126
return Ok ( ImageType :: Tga ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ pub enum ImageType {
66
66
Heif ,
67
67
/// Icon file
68
68
Ico ,
69
+ /// Interleaved Bitmap
70
+ Ilbm ,
69
71
/// Standard JPEG
70
72
Jpeg ,
71
73
/// JPEG XL
@@ -257,6 +259,7 @@ fn dispatch_header<R: BufRead + Seek>(reader: &mut R) -> ImageResult<ImageSize>
257
259
ImageType :: Hdr => hdr:: size ( reader) ,
258
260
ImageType :: Heif => heif:: size ( reader) ,
259
261
ImageType :: Ico => ico:: size ( reader) ,
262
+ ImageType :: Ilbm => ilbm:: size ( reader) ,
260
263
ImageType :: Jpeg => jpeg:: size ( reader) ,
261
264
ImageType :: Jxl => jxl:: size ( reader) ,
262
265
ImageType :: Ktx2 => ktx2:: size ( reader) ,
Original file line number Diff line number Diff line change
1
+ #[ cfg( test) ]
2
+ use imagesize:: { size, ImageSize } ;
3
+
4
+ #[ test]
5
+ fn ilbm_test ( ) {
6
+ assert_eq ! (
7
+ size( "tests/images/ilbm/test.iff" ) . unwrap( ) ,
8
+ ImageSize {
9
+ width: 640 ,
10
+ height: 512
11
+ }
12
+ ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments