MCPcopy
hub / github.com/pythongosssss/ComfyUI-Custom-Scripts / readExif

Method readExif

web/js/workflowImage.js:326–357  ·  view source on GitHub ↗

* @param {ArrayBuffer} buffer

(buffer)

Source from the content-addressed store, hash-verified

324 * @param {ArrayBuffer} buffer
325 */
326 readExif(buffer) {
327 const JPEG_MARKER = 0xffd8;
328 const EXIF_SIG = 0x45786966;
329
330 this.#reader = new DataReader(new DataView(buffer));
331 if (!this.#reader.read(2) === JPEG_MARKER) {
332 throw new Error("Invalid JPEG: SOI not found.");
333 }
334
335 const app0 = this.#readAppMarkerId();
336 if (app0 !== 0) {
337 throw new Error(`Invalid JPEG: APP0 not found [found: ${app0}].`);
338 }
339
340 this.#consumeAppSegment();
341 const app1 = this.#readAppMarkerId();
342 if (app1 !== 1) {
343 throw new Error(`No EXIF: APP1 not found [found: ${app0}].`);
344 }
345
346 // Skip size
347 this.#reader.seek(2);
348
349 if (this.#reader.read(4) !== EXIF_SIG) {
350 throw new Error(`No EXIF: Invalid EXIF header signature.`);
351 }
352 if (this.#reader.read(2) !== 0) {
353 throw new Error(`No EXIF: Invalid EXIF header.`);
354 }
355
356 return new Tiff().readExif(this.#reader);
357 }
358
359 #readAppMarkerId() {
360 const APP0_MARKER = 0xffe0;

Callers

nothing calls this directly

Calls 5

#readAppMarkerIdMethod · 0.95
#consumeAppSegmentMethod · 0.95
readMethod · 0.80
seekMethod · 0.80
readExifMethod · 0.45

Tested by

no test coverage detected