Skip to content

Commit

Permalink
fix: gps data read (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Mar 25, 2024
1 parent ba19140 commit a7905c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/markers/exif.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as r from "restructure";
import {
readUInt8,
readUInt16BE,
readUInt16LE,
readUInt32BE,
Expand Down Expand Up @@ -168,7 +169,7 @@ class IDFEntries {

switch (dataFormat) {
case 1:
return dataValue.readUInt8(0);
return readUInt8(dataValue, 0)
case 2:
return dataValue.toString("ascii").replace(/\0+$/, "");
case 3:
Expand All @@ -193,7 +194,7 @@ class IDFEntries {
}
}

_decodeIDFEntries(buffer, tags, offset) {
_decodeIDFEntries(buffer, tags, offset, log = false) {
let pos = 2;

const entries = {};
Expand Down Expand Up @@ -242,7 +243,7 @@ class IDFEntries {
}

decode(stream, parent) {
const buffer = stream.buffer.slice(stream.pos);
let buffer = stream.buffer.slice(stream.pos);
const offsetToFirstIFD = parent.offsetToFirstIFD;

if (offsetToFirstIFD > buffer.length) {
Expand All @@ -254,20 +255,20 @@ class IDFEntries {
const { exifIFDPointer, gpsInfoIFDPointer } = entries;

if (exifIFDPointer) {
const subuffer = buffer.slice(exifIFDPointer - offsetToFirstIFD);
buffer = buffer.slice(exifIFDPointer - offsetToFirstIFD);
entries.subExif = this._decodeIDFEntries(
subuffer,
buffer,
tags.ifd,
exifIFDPointer,
);
}

if (gpsInfoIFDPointer) {
const gps = gpsInfoIFDPointer;
const subuffer = buffer.slice(
buffer = buffer.slice(
exifIFDPointer ? gps - exifIFDPointer : gps - offsetToFirstIFD,
);
entries.gpsInfo = IFDHandler(subuffer, tags.gps, gps);
entries.gpsInfo = this._decodeIDFEntries(buffer, tags.gps, gps, true);
}

stream.pos += parent.parent.length - 16;
Expand Down
Binary file modified tests/__snapshots__/index.test.js.snap
Binary file not shown.
Binary file added tests/images/with-gps.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7905c1

Please sign in to comment.