Skip to content

Commit

Permalink
Move OpenRaster to images
Browse files Browse the repository at this point in the history
  • Loading branch information
chrsmth committed Nov 20, 2022
1 parent 3a989e4 commit 9f9b90f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
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
12 changes: 6 additions & 6 deletions src/map.rs
Original file line number Diff line number Diff line change
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 Expand Up @@ -420,12 +426,6 @@ matcher_map!(
"epub",
matchers::archive::is_epub
),
(
MatcherType::Archive,
"image/openraster",
"ora",
matchers::archive::is_ora
),
(
MatcherType::Archive,
"application/zip",
Expand Down
32 changes: 0 additions & 32 deletions src/matchers/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,6 @@ pub fn is_epub(buf: &[u8]) -> bool {
crate::book::is_epub(buf)
}

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
}

/// Returns whether a buffer is a zip archive.
pub fn is_zip(buf: &[u8]) -> bool {
buf.len() > 3
Expand Down
32 changes: 32 additions & 0 deletions src/matchers/image.rs
Original file line number Diff line number Diff line change
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
2 changes: 0 additions & 2 deletions tests/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ test_format!(
);

test_format!(Archive, "application/zstd", "zst", zst, "sample.tar.zst");

test_format!(Archive, "image/openraster", "ora", ora, "sample.ora");
2 changes: 2 additions & 0 deletions tests/image.rs
Original file line number Diff line number Diff line change
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 9f9b90f

Please sign in to comment.