astro-ghostcms/.pnpm-store/v3/files/44/13961f9863bdc3f367383fc7695...

26 lines
726 B
Plaintext
Raw Permalink Normal View History

2024-02-20 00:35:26 +00:00
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
};