26 lines
726 B
Plaintext
26 lines
726 B
Plaintext
|
import { readUInt32BE, findBox } from "./utils.js";
|
||
|
const JP2 = {
|
||
|
validate(input) {
|
||
|
if (readUInt32BE(input, 4) !== 1783636e3 || readUInt32BE(input, 0) < 1)
|
||
|
return false;
|
||
|
const ftypBox = findBox(input, "ftyp", 0);
|
||
|
if (!ftypBox)
|
||
|
return false;
|
||
|
return readUInt32BE(input, ftypBox.offset + 4) === 1718909296;
|
||
|
},
|
||
|
calculate(input) {
|
||
|
const jp2hBox = findBox(input, "jp2h", 0);
|
||
|
const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8);
|
||
|
if (ihdrBox) {
|
||
|
return {
|
||
|
height: readUInt32BE(input, ihdrBox.offset + 8),
|
||
|
width: readUInt32BE(input, ihdrBox.offset + 12)
|
||
|
};
|
||
|
}
|
||
|
throw new TypeError("Unsupported JPEG 2000 format");
|
||
|
}
|
||
|
};
|
||
|
export {
|
||
|
JP2
|
||
|
};
|