Skip to content

Commit 976ed4b

Browse files
authored
Add support for JPEG-LS (.jls) (#568)
1 parent e8bc341 commit 976ed4b

File tree

10 files changed

+30
-10
lines changed

10 files changed

+30
-10
lines changed

core.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export type FileExtension =
140140
| '3mf'
141141
| 'zst'
142142
| 'jxl'
143-
| 'vcf';
143+
| 'vcf'
144+
| 'jls';
144145

145146
export type MimeType =
146147
| 'image/jpeg'
@@ -276,7 +277,8 @@ export type MimeType =
276277
| 'application/vnd.ms-htmlhelp'
277278
| 'model/3mf'
278279
| 'image/jxl'
279-
| 'application/zstd';
280+
| 'application/zstd'
281+
| 'image/jls';
280282

281283
export type FileTypeResult = {
282284
/**

core.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ class FileTypeParser {
159159
};
160160
}
161161

162-
if (this.check([0xFF, 0xD8, 0xFF])) {
163-
return {
164-
ext: 'jpg',
165-
mime: 'image/jpeg',
166-
};
167-
}
168-
169162
if (this.check([0x49, 0x49, 0xBC])) {
170163
return {
171164
ext: 'jxr',
@@ -222,6 +215,21 @@ class FileTypeParser {
222215

223216
// -- 4-byte signatures --
224217

218+
// Requires a sample size of 4 bytes
219+
if (this.check([0xFF, 0xD8, 0xFF])) {
220+
if (this.check([0xF7], {offset: 3})) { // JPG7/SOF55, indicating a ISO/IEC 14495 / JPEG-LS file
221+
return {
222+
ext: 'jls',
223+
mime: 'image/jls',
224+
};
225+
}
226+
227+
return {
228+
ext: 'jpg',
229+
mime: 'image/jpeg',
230+
};
231+
}
232+
225233
if (this.checkString('FLIF')) {
226234
return {
227235
ext: 'flif',

fixture/fixture-hp1.jls

53.9 KB
Binary file not shown.

fixture/fixture-hp2.jls

54.8 KB
Binary file not shown.

fixture/fixture-hp3.jls

53.8 KB
Binary file not shown.

fixture/fixture-normal.jls

70.1 KB
Binary file not shown.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@
193193
"3mf",
194194
"zst",
195195
"jxl",
196-
"vcf"
196+
"vcf",
197+
"jls"
197198
],
198199
"dependencies": {
199200
"readable-web-to-node-stream": "^3.0.2",

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ Returns a `Set<string>` of supported MIME types.
397397
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
398398
- [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document
399399
- [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker
400+
- [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
400401
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
401402
- [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image
402403
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000

supported.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const extensions = [
138138
'zst',
139139
'jxl',
140140
'vcf',
141+
'jls',
141142
];
142143

143144
export const mimeTypes = [
@@ -275,4 +276,5 @@ export const mimeTypes = [
275276
'model/3mf',
276277
'image/jxl',
277278
'application/zstd',
279+
'image/jls',
278280
];

test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ const names = {
229229
'fixture-utf16-be-bom', // UTF-16 little endian encoded XML, with BOM
230230
'fixture-utf16-le-bom', // UTF-16 big endian encoded XML, with BOM
231231
],
232+
jls: [
233+
'fixture-normal',
234+
'fixture-hp1',
235+
'fixture-hp2',
236+
'fixture-hp3',
237+
],
232238
};
233239

234240
// Define an entry here only if the file type has potential

0 commit comments

Comments
 (0)