Skip to content

Commit 64dda84

Browse files
committed
refactor formats that use a ISO-BMFF container
1 parent e3ea538 commit 64dda84

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/types/heif.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ const brandMap = {
1313

1414
export const HEIF: IImage = {
1515
validate(input) {
16-
const ftype = toUTF8String(input, 4, 8)
17-
const brand = toUTF8String(input, 8, 12)
18-
return 'ftyp' === ftype && brand in brandMap
16+
const boxType = toUTF8String(input, 4, 8)
17+
if (boxType !== 'ftyp') return false
18+
19+
const ftypBox = findBox(input, 'ftyp', 0)
20+
if (!ftypBox) return false
21+
22+
const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12)
23+
return brand in brandMap
1924
},
2025

2126
calculate(input) {

lib/types/jp2.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import type { IImage } from './interface'
2-
import { readUInt32BE, findBox } from './utils'
2+
import { readUInt32BE, findBox, toUTF8String } from './utils'
33

44
export const JP2: IImage = {
55
validate(input) {
6-
if (readUInt32BE(input, 4) !== 0x6a502020 || readUInt32BE(input, 0) < 1) return false
6+
const boxType = toUTF8String(input, 4, 8)
7+
if (boxType !== 'jP ') return false
8+
79
const ftypBox = findBox(input, 'ftyp', 0)
810
if (!ftypBox) return false
9-
return readUInt32BE(input, ftypBox.offset + 4) === 0x66747970
11+
12+
const brand = toUTF8String(input, ftypBox.offset + 8, ftypBox.offset + 12)
13+
return brand === 'jp2 '
1014
},
1115

1216
calculate(input) {

0 commit comments

Comments
 (0)