|
9 | 9 | */ |
10 | 10 |
|
11 | 11 | import { ByteStream } from '../../io/bytestream.js'; |
12 | | -import { ExifTagNumber, getExifValue } from './exif.js'; |
| 12 | +import { getExifProfile } from './exif.js'; |
13 | 13 |
|
14 | | -/** |
15 | | - * @typedef {import('./exif.js').ExifValue} ExifValue |
16 | | - */ |
| 14 | +/** @typedef {import('./exif.js').ExifValue} ExifValue */ |
17 | 15 |
|
18 | 16 | // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format |
19 | 17 | // https://www.media.mit.edu/pia/Research/deepview/exif.html |
@@ -388,41 +386,7 @@ export class JpegParser extends EventTarget { |
388 | 386 | } |
389 | 387 | if (this.bstream.readNumber(2) !== 0) throw `No null byte termination`; |
390 | 388 |
|
391 | | - const lookAheadStream = this.bstream.tee(); |
392 | | - const tiffByteAlign = this.bstream.readString(2); |
393 | | - if (tiffByteAlign === 'II') { |
394 | | - this.bstream.setLittleEndian(); |
395 | | - lookAheadStream.setLittleEndian(); |
396 | | - } else if (tiffByteAlign === 'MM') { |
397 | | - this.bstream.setBigEndian(); |
398 | | - lookAheadStream.setBigEndian(); |
399 | | - } else { |
400 | | - throw `Invalid TIFF byte align symbol: ${tiffByteAlign}`; |
401 | | - } |
402 | | - |
403 | | - const tiffMarker = this.bstream.readNumber(2); |
404 | | - if (tiffMarker !== 0x002A) { |
405 | | - throw `Invalid marker, not 0x002a: 0x${tiffMarker.toString(16)}`; |
406 | | - } |
407 | | - |
408 | | - /** @type {Map<number, ExifValue} */ |
409 | | - const exifValueMap = new Map(); |
410 | | - |
411 | | - // The offset includes the tiffByteAlign (2), marker (2), and the offset field itself (4). |
412 | | - const ifdOffset = this.bstream.readNumber(4) - 8; |
413 | | - |
414 | | - let ifdStream = this.bstream.tee(); |
415 | | - let nextIfdOffset; |
416 | | - while (true) { |
417 | | - nextIfdOffset = this.readExifIfd(ifdStream, lookAheadStream, exifValueMap); |
418 | | - |
419 | | - // No more IFDs, so stop the loop. |
420 | | - if (nextIfdOffset === 0) break; |
421 | | - |
422 | | - // Else, we have another IFD to read, point the stream at it. |
423 | | - ifdStream = lookAheadStream.tee().skip(nextIfdOffset); |
424 | | - } |
425 | | - |
| 389 | + const exifValueMap = getExifProfile(this.bstream); |
426 | 390 | this.dispatchEvent(new JpegApp1ExifEvent(exifValueMap)); |
427 | 391 |
|
428 | 392 | this.bstream = skipAheadStream; |
@@ -582,31 +546,4 @@ export class JpegParser extends EventTarget { |
582 | 546 | } |
583 | 547 | } while (jpegMarker !== JpegSegmentType.EOI); |
584 | 548 | } |
585 | | - |
586 | | - /** |
587 | | - * Reads an Image File Directory from stream. |
588 | | - * @param {ByteStream} stream The stream to extract the Exif value descriptor. |
589 | | - * @param {ByteStream} lookAheadStream The lookahead stream if the offset is used. |
590 | | - * @param {Map<number, ExifValue} exifValueMap This map to add the Exif values. |
591 | | - * @returns {number} The next IFD offset. |
592 | | - */ |
593 | | - readExifIfd(stream, lookAheadStream, exifValueMap) { |
594 | | - let exifOffsetStream; |
595 | | - const numDirectoryEntries = stream.readNumber(2); |
596 | | - for (let entry = 0; entry < numDirectoryEntries; ++entry) { |
597 | | - const exifValue = getExifValue(stream, lookAheadStream, DEBUG); |
598 | | - const exifTagNumber = exifValue.tagNumber; |
599 | | - exifValueMap.set(exifTagNumber, exifValue); |
600 | | - if (exifValue.tagNumber === ExifTagNumber.EXIF_OFFSET) { |
601 | | - exifOffsetStream = lookAheadStream.tee().skip(exifValue.numericalValue); |
602 | | - } |
603 | | - } // Loop over Directory Entries. |
604 | | - |
605 | | - if (exifOffsetStream) { |
606 | | - this.readExifIfd(exifOffsetStream, lookAheadStream, exifValueMap); |
607 | | - } |
608 | | - |
609 | | - const nextIfdOffset = stream.readNumber(4); |
610 | | - return nextIfdOffset; |
611 | | - } |
612 | 549 | } |
0 commit comments