|
96 | 96 | return |
97 | 97 | } |
98 | 98 |
|
99 | | - // skip over leading (variable) chars, to the always-fixed "8BIM" sequence |
100 | | - offset+=18 |
| 99 | + // Found "8BIM<EOT><EOT>" ? |
| 100 | + var isFieldSegmentStart = function(dataView, offset){ |
| 101 | + return ( |
| 102 | + dataView.getUint32(offset) === 0x3842494d && |
| 103 | + dataView.getUint16(offset+4) === 0x0404 |
| 104 | + ) |
| 105 | + } |
101 | 106 |
|
102 | | - var littleEndian |
103 | | - var dirOffset |
| 107 | + // Hunt forward, looking for the correct Iptc block signature: |
| 108 | + // Reference: https://metacpan.org/pod/distribution/Image-MetaData-JPEG/lib/Image/MetaData/JPEG/Structures.pod#Structure-of-a-Photoshop-style-APP13-segment |
104 | 109 |
|
105 | 110 | // From https://github.com/exif-js/exif-js/blob/master/exif.js ~ line 474 on |
| 111 | + while (offset < offset+length) { |
106 | 112 |
|
107 | | - // Check for the "Iptc" "8BIM<EOT><EOT>" ASCII sequence (0x3842494d 0x0404): |
108 | | - if (dataView.getUint32(offset) !== 0x3842494d && dataView.getUint16(offset + 4) !== 0x0404) { |
109 | | - console.log('no Iptc data at this offset') |
110 | | - // No Iptc data, might be XMP data instead |
111 | | - return |
112 | | - } |
| 113 | + if (isFieldSegmentStart(dataView, offset)) { |
113 | 114 |
|
114 | | - var nameHeaderLength = dataView.getUint8(offset + 7) |
115 | | - if (nameHeaderLength % 2 !== 0) nameHeaderLength += 1 |
116 | | - // Check for pre photoshop 6 format |
117 | | - if (nameHeaderLength === 0) { |
118 | | - // Always 4 |
119 | | - nameHeaderLength = 4 |
120 | | - } |
| 115 | + var nameHeaderLength = dataView.getUint8(offset + 7) |
| 116 | + if (nameHeaderLength % 2 !== 0) nameHeaderLength += 1 |
| 117 | + // Check for pre photoshop 6 format |
| 118 | + if (nameHeaderLength === 0) { |
| 119 | + // Always 4 |
| 120 | + nameHeaderLength = 4 |
| 121 | + } |
| 122 | + |
| 123 | + var startOffset = offset + 8 + nameHeaderLength |
| 124 | + var sectionLength = dataView.getUint16(offset + 6 + nameHeaderLength) |
| 125 | + |
| 126 | + // Create the iptc object to store the tags: |
| 127 | + data.iptc = new loadImage.IptcMap() |
121 | 128 |
|
122 | | - var startOffset = offset + 8 + nameHeaderLength |
123 | | - var sectionLength = dataView.getUint16(offset + 6 + nameHeaderLength) |
| 129 | + // Parse the tags |
| 130 | + return loadImage.parseIptcTags( |
| 131 | + dataView, |
| 132 | + startOffset, |
| 133 | + sectionLength, |
| 134 | + data |
| 135 | + ) |
| 136 | + |
| 137 | + break; |
| 138 | + |
| 139 | + } |
| 140 | + |
| 141 | + offset++ |
| 142 | + |
| 143 | + } |
124 | 144 |
|
125 | | - // Create the iptc object to store the tags: |
126 | | - data.iptc = new loadImage.IptcMap() |
127 | | - window._iptc=data |
| 145 | + console.log('No Iptc data at this offset - could be XMP') |
128 | 146 |
|
129 | | - // Parse the tags |
130 | | - loadImage.parseIptcTags( |
131 | | - dataView, |
132 | | - startOffset, |
133 | | - sectionLength, |
134 | | - data |
135 | | - ) |
136 | 147 | } |
137 | 148 |
|
138 | 149 | // Registers this Iptc parser for the APP13 JPEG meta data segment: |
|
0 commit comments