|
18 | 18 | #[cfg(feature = "pcx")] |
19 | 19 | pub mod pcx; |
20 | 20 |
|
| 21 | +#[cfg(feature = "sgi")] |
| 22 | +pub mod sgi; |
| 23 | + |
21 | 24 | /// Register all enabled extra formats with the image crate. |
22 | 25 | pub fn register() { |
23 | | - let just_registered = image::hooks::register_decoding_hook( |
| 26 | + let just_registered_pcx = image::hooks::register_decoding_hook( |
24 | 27 | "pcx".into(), |
25 | 28 | Box::new(|r| Ok(Box::new(pcx::PCXDecoder::new(r)?))), |
26 | 29 | ); |
27 | | - if just_registered { |
| 30 | + if just_registered_pcx { |
28 | 31 | image::hooks::register_format_detection_hook("pcx".into(), &[0x0a, 0x0], Some(b"\xFF\xF8")); |
29 | 32 | } |
| 33 | + |
| 34 | + // SGI RGB images generally show up with a .rgb ending (whether or not they |
| 35 | + // have 3 channels), and sometimes .bw (when grayscale) and .rgba. The |
| 36 | + // extensions .sgi and .iris, while unambiguous, do not seem to have been |
| 37 | + // used much. The extension .rgb is also used for a variety of other files, |
| 38 | + // including bare image data, so to be sure it would be best to check both |
| 39 | + // extension and leading bytes |
| 40 | + let hook: for<'a> fn( |
| 41 | + image::hooks::GenericReader<'a>, |
| 42 | + ) -> image::ImageResult<Box<dyn image::ImageDecoder + 'a>> = |
| 43 | + |r| Ok(Box::new(sgi::SgiDecoder::new(r)?)); |
| 44 | + image::hooks::register_decoding_hook("bw".into(), Box::new(hook)); |
| 45 | + image::hooks::register_decoding_hook("rgb".into(), Box::new(hook)); |
| 46 | + image::hooks::register_decoding_hook("rgba".into(), Box::new(hook)); |
| 47 | + image::hooks::register_decoding_hook("iris".into(), Box::new(hook)); |
| 48 | + let just_registered_sgi = image::hooks::register_decoding_hook("sgi".into(), Box::new(hook)); |
| 49 | + if just_registered_sgi { |
| 50 | + // The main signature bytes are technically just 01 da, but this is short |
| 51 | + // and the following storage and bpc fields are constrained well enough to |
| 52 | + // efficiently match them as well |
| 53 | + image::hooks::register_format_detection_hook("sgi".into(), b"\x01\xda\x00\x01", None); |
| 54 | + image::hooks::register_format_detection_hook("sgi".into(), b"\x01\xda\x01\x01", None); |
| 55 | + image::hooks::register_format_detection_hook("sgi".into(), b"\x01\xda\x00\x02", None); |
| 56 | + image::hooks::register_format_detection_hook("sgi".into(), b"\x01\xda\x01\x02", None); |
| 57 | + } |
30 | 58 | } |
0 commit comments