Skip to content

Commit

Permalink
Merge pull request #81 from chrsmth/feat/ora
Browse files Browse the repository at this point in the history
feat: add support for OpenRaster (ora) format
  • Loading branch information
bojand committed Jan 1, 2023
2 parents ef46e98 + 9f9b90f commit 9b6d0b0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -120,6 +120,7 @@ assert_eq!(kind.extension(), "foo");
- **jxr** - `image/vnd.ms-photo`
- **psd** - `image/vnd.adobe.photoshop`
- **ico** - `image/vnd.microsoft.icon`
- **ora** - `image/openraster`

#### Video

Expand Down
6 changes: 6 additions & 0 deletions src/map.rs
Expand Up @@ -203,6 +203,12 @@ matcher_map!(
"jxl",
matchers::image::is_jxl
),
(
MatcherType::Image,
"image/openraster",
"ora",
matchers::image::is_ora
),
// Video
(
MatcherType::Video,
Expand Down
32 changes: 32 additions & 0 deletions src/matchers/image.rs
Expand Up @@ -162,6 +162,38 @@ fn is_isobmff(buf: &[u8]) -> bool {
buf.len() >= ftyp_length
}

pub fn is_ora(buf: &[u8]) -> bool {
buf.len() > 57
&& buf[0] == 0x50
&& buf[1] == 0x4B
&& buf[2] == 0x3
&& buf[3] == 0x4
&& buf[30] == 0x6D
&& buf[31] == 0x69
&& buf[32] == 0x6D
&& buf[33] == 0x65
&& buf[34] == 0x74
&& buf[35] == 0x79
&& buf[36] == 0x70
&& buf[37] == 0x65
&& buf[38] == 0x69
&& buf[39] == 0x6D
&& buf[40] == 0x61
&& buf[41] == 0x67
&& buf[42] == 0x65
&& buf[43] == 0x2F
&& buf[44] == 0x6F
&& buf[45] == 0x70
&& buf[46] == 0x65
&& buf[47] == 0x6E
&& buf[48] == 0x72
&& buf[49] == 0x61
&& buf[50] == 0x73
&& buf[51] == 0x74
&& buf[52] == 0x65
&& buf[53] == 0x72
}

// GetFtyp returns the major brand, minor version and compatible brands of the ISO-BMFF data
fn get_ftyp(buf: &[u8]) -> Option<(&[u8], &[u8], impl Iterator<Item = &[u8]>)> {
if buf.len() < 16 {
Expand Down
Binary file added testdata/sample.ora
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/image.rs
Expand Up @@ -27,3 +27,5 @@ test_format!(Image, "image/heif", "heif", heif, "sample.heic");
test_format!(Image, "image/avif", "avif", avif, "sample.avif");

test_format!(Image, "image/jxl", "jxl", jxl, "spline_on_first_frame.jxl");

test_format!(Image, "image/openraster", "ora", ora, "sample.ora");

0 comments on commit 9b6d0b0

Please sign in to comment.