Skip to content

Commit

Permalink
Decode content in XP tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasw committed Dec 25, 2024
1 parent 172ebb2 commit 9792907
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/exif-reader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/exif-reader.js.map

Large diffs are not rendered by default.

34 changes: 29 additions & 5 deletions src/tag-names-0th-ifd.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,26 @@ export default {
0x87b0: 'GeoTiffDoubleParams',
0x87b1: 'GeoTiffAsciiParams',
0x8825: 'GPS Info IFD Pointer',
0x9c9b: 'XPTitle',
0x9c9c: 'XPComment',
0x9c9d: 'XPAuthor',
0x9c9e: 'XPKeywords',
0x9c9f: 'XPSubject',
0x9c9b: {
name: 'XPTitle',
description: decodeXPValue,
},
0x9c9c: {
name: 'XPComment',
description: decodeXPValue
},
0x9c9d: {
name: 'XPAuthor',
description: decodeXPValue,
},
0x9c9e: {
name: 'XPKeywords',
description: decodeXPValue,
},
0x9c9f: {
name: 'XPSubject',
description: decodeXPValue,
},
0xa480: 'GDALMetadata',
0xa481: 'GDALNoData',
0xc4a5: 'PrintIM',
Expand Down Expand Up @@ -355,3 +370,12 @@ export default {
0xc7a7: 'NewRawImageDigest',
0xc7a8: 'RawToPreviewGain'
};

function decodeXPValue(value) {
// The XP tags are encoded as UCS-2 which uses two bytes per character but
// it's close to UTF-16 so we can use that to decode them.
// https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
const decodedValue = new TextDecoder('utf-16').decode(new Uint8Array(value));
// Some softwares pad the string with null characters so we remove them.
return decodedValue.replace(/\u0000+$/, ''); // eslint-disable-line no-control-regex
}
15 changes: 10 additions & 5 deletions test/unit/tag-names-0th-ifd-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,23 +359,28 @@ describe('tag-names-0th-ifd', () => {
});

it('should have tag XPTitle', () => {
expect(TagNames0thIfd[0x9c9b]).to.equal('XPTitle');
expect(TagNames0thIfd[0x9c9b].name).to.equal('XPTitle');
expect(TagNames0thIfd[0x9c9b].description([116, 0, 105, 0, 116, 0, 108, 0, 101, 0])).to.equal('title');
});

it('should have tag XPComment', () => {
expect(TagNames0thIfd[0x9c9c]).to.equal('XPComment');
expect(TagNames0thIfd[0x9c9c].name).to.equal('XPComment');
expect(TagNames0thIfd[0x9c9c].description([99, 0, 111, 0, 109, 0, 109, 0, 101, 0, 110, 0, 116, 0])).to.equal('comment');
});

it('should have tag XPAuthor', () => {
expect(TagNames0thIfd[0x9c9d]).to.equal('XPAuthor');
expect(TagNames0thIfd[0x9c9d].name).to.equal('XPAuthor');
expect(TagNames0thIfd[0x9c9d].description([97, 0, 117, 0, 116, 0, 104, 0, 111, 0, 114, 0])).to.equal('author');
});

it('should have tag XPKeywords', () => {
expect(TagNames0thIfd[0x9c9e]).to.equal('XPKeywords');
expect(TagNames0thIfd[0x9c9e].name).to.equal('XPKeywords');
expect(TagNames0thIfd[0x9c9e].description([107, 0, 101, 0, 121, 0, 119, 0, 111, 0, 114, 0, 100, 0, 115, 0])).to.equal('keywords');
});

it('should have tag XPSubject', () => {
expect(TagNames0thIfd[0x9c9f]).to.equal('XPSubject');
expect(TagNames0thIfd[0x9c9f].name).to.equal('XPSubject');
expect(TagNames0thIfd[0x9c9f].description([115, 0, 117, 0, 98, 0, 106, 0, 101, 0, 99, 0, 116, 0])).to.equal('subject');
});

it('should have tag GDALMetadata', () => {
Expand Down

0 comments on commit 9792907

Please sign in to comment.