Skip to content

Commit

Permalink
Add support for JPEG XL and XR
Browse files Browse the repository at this point in the history
closes #170
  • Loading branch information
netroy committed Nov 13, 2023
1 parent cf1eccb commit 870bc76
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ICO } from './ico'
import { J2C } from './j2c'
import { JP2 } from './jp2'
import { JPG } from './jpg'
import { JXL } from './jxl'
import { JXR } from './jxr'
import { KTX } from './ktx'
import { PNG } from './png'
import { PNM } from './pnm'
Expand All @@ -29,6 +31,8 @@ export const typeHandlers = new Map([
['j2c', J2C],
['jp2', JP2],
['jpg', JPG],
['jxl', JXL],
['jxr', JXR],
['ktx', KTX],
['png', PNG],
['pnm', PNM],
Expand Down
4 changes: 2 additions & 2 deletions lib/types/j2c.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IImage } from './interface'
import { toHexString, readUInt32BE } from './utils'
import { readUInt32BE } from './utils'

export const J2C: IImage = {
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
validate: (input) => toHexString(input, 0, 4) === 'ff4fff51',
validate: (input) => readUInt32BE(input, 0) === 0xff4fff51,

calculate: (input) => ({
height: readUInt32BE(input, 12),
Expand Down
11 changes: 11 additions & 0 deletions lib/types/jxl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { IImage } from './interface'
import { readUInt32BE, readUInt16BE } from './utils'

export const JXL: IImage = {
validate: (input) => readUInt16BE(input, 0) === 0xff0a,

calculate: (input) => ({
height: readUInt32BE(input, 12),
width: readUInt32BE(input, 8),
}),
}
11 changes: 11 additions & 0 deletions lib/types/jxr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { IImage } from './interface'
import { readUInt32BE } from './utils'

export const JXR: IImage = {
validate: (input) => readUInt32BE(input, 0) === 0x4949BC01,

calculate: (input) => ({
height: readUInt32BE(input, 12),
width: readUInt32BE(input, 8),
}),
}
Binary file added specs/images/valid/jxl/sample.jxl
Binary file not shown.
Binary file added specs/images/valid/jxr/sample.jxr
Binary file not shown.

0 comments on commit 870bc76

Please sign in to comment.