Skip to content

Commit

Permalink
feat: add support for JPEG XL (JXL) format. fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Oct 29, 2022
1 parent e83741f commit 4dc54fe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ matcher_map!(
"avif",
matchers::image::is_avif
),
(
MatcherType::Image,
"image/jxl",
"jxl",
matchers::image::is_jxl
),
// Video
(
MatcherType::Video,
Expand Down
18 changes: 18 additions & 0 deletions src/matchers/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ pub fn is_ico(buf: &[u8]) -> bool {
buf.len() > 3 && buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x01 && buf[3] == 0x00
}

/// Returns whether a buffer is JPEG XL (JXL) image data.
pub fn is_jxl(buf: &[u8]) -> bool {
(buf.len() > 2 && buf[0] == 0xFF && buf[1] == 0x0A)
|| (buf.len() > 12
&& buf[0] == 0x0
&& buf[1] == 0x0
&& buf[2] == 0x0
&& buf[3] == 0x0C
&& buf[4] == 0x4A
&& buf[5] == 0x58
&& buf[6] == 0x4C
&& buf[7] == 0x20
&& buf[8] == 0x0D
&& buf[9] == 0x0A
&& buf[10] == 0x87
&& buf[11] == 0x0A)
}

/// Returns whether a buffer is HEIF image data.
pub fn is_heif(buf: &[u8]) -> bool {
if buf.is_empty() {
Expand Down
Binary file added testdata/spline_on_first_frame.jxl
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ test_format!(Image, "image/vnd.microsoft.icon", "ico", ico, "sample.ico");
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");

0 comments on commit 4dc54fe

Please sign in to comment.