Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect SOF55 marker to distinguish JPEG-LS from baseline JPEG #506

Closed
hackermd opened this issue Dec 13, 2021 · 7 comments · Fixed by #568
Closed

Detect SOF55 marker to distinguish JPEG-LS from baseline JPEG #506

hackermd opened this issue Dec 13, 2021 · 7 comments · Fixed by #568
Assignees
Labels
enhancement Add new functionality

Comments

@hackermd
Copy link

The library currently checks the first three bytes of the file (0xFF, 0xD8, and 0xFF) to determine whether it is a JPEG file:

file-type/core.js

Lines 154 to 159 in bb4f822

if (this.check([0xFF, 0xD8, 0xFF])) {
return {
ext: 'jpg',
mime: 'image/jpeg',
};
}

However, to distinguish between baseline JPEG and JPEG-LS the forth byte should also be checked. It it is 0xF7 ("SOF55" or "JPG7" segment), then the file is a JPEG-LS rather than JPEG file and image/jls should be returned instead of image/jpeg.

@hackermd
Copy link
Author

It may also be a good idea to check for 0xE8 ("APP8" segment) to further distinguish SPIFF from baseline JPEG.

@Borewit Borewit added the enhancement Add new functionality label Dec 14, 2021
@Borewit
Copy link
Collaborator

Borewit commented Dec 14, 2021

Sounds good to me, why don't you create a PR?
Can you link to some supporting documentation or reference material?

@Borewit
Copy link
Collaborator

Borewit commented Jul 29, 2022

Small reminder @hackermd

@somebody1234
Copy link
Contributor

not sure this is required, afaict neither jpeg-ls nor spiff have a different file extension (or even mimetype)

@Borewit
Copy link
Collaborator

Borewit commented Jan 5, 2023

not sure this is required, afaict neither jpeg-ls nor spiff have a different file extension (or even mimetype)

It seems to me that they do have a dedicated registered MIME-type: https://www.iana.org/assignments/media-types/image/jls

Other references:

@Borewit
Copy link
Collaborator

Borewit commented Jan 5, 2023

Looking to some jls fixtures found here, some of them have a string J1U6G at offset 0xF7 (247), some others not, none of them have the SOF55 or JPG7 marker.

So I am not entirely sure how to detect JPEG-LS yet.

@Borewit
Copy link
Collaborator

Borewit commented Jan 6, 2023

I found this information: JPEG Lossless Compression (ISO/IEC 14495), File type signifiers and format identifiers.

Which describes the SOF55 maker, which is actually encoded as JPG7 at 0xF7. But the way I read it, more conventional to use the 0xFFF7 at offset 2, which is a marker to indicate the improved lossless baseline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Add new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants