file-type
file-type copied to clipboard
Detect SOF55 marker to distinguish JPEG-LS from baseline JPEG
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
.
It may also be a good idea to check for 0xE8
("APP8" segment) to further distinguish SPIFF from baseline JPEG.
Sounds good to me, why don't you create a PR? Can you link to some supporting documentation or reference material?
Small reminder @hackermd
not sure this is required, afaict neither jpeg-ls nor spiff have a different file extension (or even mimetype)
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
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.
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.