file-type icon indicating copy to clipboard operation
file-type copied to clipboard

Detect SOF55 marker to distinguish JPEG-LS from baseline JPEG

Open hackermd opened this issue 3 years ago • 3 comments

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

https://github.com/sindresorhus/file-type/blob/bb4f8225672b9392ae9e959fc2eb56c7579e5574/core.js#L154-L159

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 avatar Dec 13 '21 16:12 hackermd

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

hackermd avatar Dec 13 '21 16:12 hackermd

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

Borewit avatar Dec 14 '21 18:12 Borewit

Small reminder @hackermd

Borewit avatar Jul 29 '22 07:07 Borewit

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

somebody1234 avatar Oct 20 '22 18:10 somebody1234

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:

  • http://fileformats.archiveteam.org/wiki/JPEG-LS
  • https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS

Borewit avatar Jan 05 '23 17:01 Borewit

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 avatar Jan 05 '23 17:01 Borewit

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.

Borewit avatar Jan 06 '23 12:01 Borewit