@snap/camera-kit
Version:
Camera Kit Web
51 lines • 1.97 kB
JavaScript
const JPEG_ID = 0xffd8;
const APP1_MARKER = 0xffe1;
const EXIF_ID = 0x45786966;
const LITTLE_ENDIAN = 0x4949;
const ORIENTATION_TAG_OFFSET = 0x0112;
export var Orientation;
(function (Orientation) {
Orientation[Orientation["TopLeft"] = 1] = "TopLeft";
Orientation[Orientation["TopRight"] = 2] = "TopRight";
Orientation[Orientation["BottomRight"] = 3] = "BottomRight";
Orientation[Orientation["BottomLeft"] = 4] = "BottomLeft";
Orientation[Orientation["LeftTop"] = 5] = "LeftTop";
Orientation[Orientation["RightTop"] = 6] = "RightTop";
Orientation[Orientation["RightBottom"] = 7] = "RightBottom";
Orientation[Orientation["LeftBottom"] = 8] = "LeftBottom";
})(Orientation || (Orientation = {}));
export function extractJpegOrientationTag(data) {
const view = new DataView(data);
if (view.getUint16(0, false) !== JPEG_ID)
return undefined;
const length = view.byteLength;
let offset = 2;
while (offset < length) {
if (view.getUint16(offset + 2, false) <= 8)
return undefined;
let marker = view.getUint16(offset, false);
offset += 2;
if (marker === APP1_MARKER) {
if (view.getUint32((offset += 2), false) !== EXIF_ID) {
return undefined;
}
let little = view.getUint16((offset += 6), false) === LITTLE_ENDIAN;
offset += view.getUint32(offset + 4, little);
let tags = view.getUint16(offset, little);
offset += 2;
for (let i = 0; i < tags; i++) {
if (view.getUint16(offset + i * 12, little) === ORIENTATION_TAG_OFFSET) {
return view.getUint16(offset + i * 12 + 8, little);
}
}
}
else if ((marker & 0xff00) !== 0xff00) {
break;
}
else {
offset += view.getUint16(offset, false);
}
}
return undefined;
}
//# sourceMappingURL=exif.js.map