fix price and modular
This commit is contained in:
+85
-4
@@ -105,6 +105,89 @@ const GIF = {
|
||||
})
|
||||
};
|
||||
|
||||
const HEIC = {
|
||||
validate: (input) => {
|
||||
const ftypBox = findBox$1(input, "ftyp");
|
||||
if (!ftypBox) return false;
|
||||
const majorBrand = toUTF8String(
|
||||
input,
|
||||
ftypBox.offset + 8,
|
||||
ftypBox.offset + 12
|
||||
);
|
||||
return ["heic", "heix", "hevc", "hevx", "mif1", "msf1"].includes(
|
||||
majorBrand
|
||||
);
|
||||
},
|
||||
calculate: (input) => {
|
||||
const metaBox = findBox$1(input, "meta");
|
||||
if (!metaBox) throw new TypeError("heic: meta box not found");
|
||||
const iprpBox = findBox$1(
|
||||
input,
|
||||
"iprp",
|
||||
metaBox.offset + 12,
|
||||
metaBox.offset + metaBox.size
|
||||
);
|
||||
if (!iprpBox) throw new TypeError("heic: iprp box not found");
|
||||
const ipcoBox = findBox$1(
|
||||
input,
|
||||
"ipco",
|
||||
iprpBox.offset + 8,
|
||||
iprpBox.offset + iprpBox.size
|
||||
);
|
||||
if (!ipcoBox) throw new TypeError("heic: ipco box not found");
|
||||
const dimensions = findAllBoxes(
|
||||
input,
|
||||
"ispe",
|
||||
ipcoBox.offset + 8,
|
||||
ipcoBox.offset + ipcoBox.size
|
||||
).map((box) => ({
|
||||
width: readUInt32BE(input, box.offset + 12),
|
||||
height: readUInt32BE(input, box.offset + 16)
|
||||
}));
|
||||
if (dimensions.length === 0)
|
||||
throw new TypeError("heic: ispe box not found");
|
||||
let largestDimension = dimensions[0];
|
||||
for (let i = 1; i < dimensions.length; i++) {
|
||||
const curr = dimensions[i];
|
||||
if (curr.width * curr.height > largestDimension.width * largestDimension.height) {
|
||||
largestDimension = curr;
|
||||
}
|
||||
}
|
||||
return largestDimension;
|
||||
}
|
||||
};
|
||||
function findBox$1(input, type, startOffset = 0, endOffset = input.length) {
|
||||
let offset = startOffset;
|
||||
while (offset < endOffset) {
|
||||
const size = readUInt32BE(input, offset);
|
||||
const boxType = toUTF8String(input, offset + 4, offset + 8);
|
||||
if (boxType === type) {
|
||||
return { offset, size };
|
||||
}
|
||||
if (size <= 0 || offset + size > endOffset) {
|
||||
break;
|
||||
}
|
||||
offset += size;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
function findAllBoxes(input, type, startOffset = 0, endOffset = input.length) {
|
||||
let offset = startOffset;
|
||||
const boxes = [];
|
||||
while (offset < endOffset) {
|
||||
const size = readUInt32BE(input, offset);
|
||||
const boxType = toUTF8String(input, offset + 4, offset + 8);
|
||||
if (boxType === type) {
|
||||
boxes.push({ offset, size });
|
||||
}
|
||||
if (size <= 0 || offset + size > endOffset) {
|
||||
break;
|
||||
}
|
||||
offset += size;
|
||||
}
|
||||
return boxes;
|
||||
}
|
||||
|
||||
const SIZE_HEADER = 4 + 4;
|
||||
const FILE_LENGTH_OFFSET = 4;
|
||||
const ENTRY_LENGTH_OFFSET = 4;
|
||||
@@ -199,12 +282,9 @@ const J2C = {
|
||||
|
||||
const BoxTypes = {
|
||||
ftyp: "66747970",
|
||||
ihdr: "69686472",
|
||||
jp2h: "6a703268",
|
||||
jp__: "6a502020",
|
||||
rreq: "72726571",
|
||||
xml_: "786d6c20"
|
||||
};
|
||||
rreq: "72726571"};
|
||||
const calculateRREQLength = (box) => {
|
||||
const unit = box[0];
|
||||
let offset = 1 + 2 * unit;
|
||||
@@ -727,6 +807,7 @@ const typeHandlers = {
|
||||
cur: CUR,
|
||||
dds: DDS,
|
||||
gif: GIF,
|
||||
heic: HEIC,
|
||||
icns: ICNS,
|
||||
ico: ICO,
|
||||
j2c: J2C,
|
||||
|
||||
Reference in New Issue
Block a user