Permalink
Browse files

extractExifEntry now takes endianness as a parameter

  • Loading branch information...
gomfunkel committed May 23, 2011
1 parent f54a475 commit 0b6519ba3926130b321d267bd8c62948fdb4c3d4
Showing with 28 additions and 28 deletions.
  1. +25 −25 lib/exif/ExifImage.js
  2. +1 −1 lib/exif/makernotes/agfa.js
  3. +1 −1 lib/exif/makernotes/epson.js
  4. +1 −1 lib/exif/makernotes/olympus.js
View
@@ -149,7 +149,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Each IFD entry consists of 12 bytes which we loop through and extract
// the data from
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, ExifImage.TAGS.tiff);
+ var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.tiff);
if (exifEntry) this.exifData.image.push(exifEntry);
}
@@ -164,7 +164,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Each IFD entry consists of 12 bytes which we loop through and extract
// the data from
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, ExifImage.TAGS.tiff);
+ var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.tiff);
if (exifEntry) this.exifData.thumbnail.push(exifEntry);
}
}
@@ -181,7 +181,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Each IFD entry consists of 12 bytes which we loop through and extract
// the data from
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, ExifImage.TAGS.exif);
+ var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif);
if (exifEntry) this.exifData.exif.push(exifEntry);
}
@@ -201,7 +201,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Each IFD entry consists of 12 bytes which we loop through and extract
// the data from
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, ExifImage.TAGS.gps);
+ var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.gps);
if (exifEntry) this.exifData.gps.push(exifEntry);
}
@@ -221,7 +221,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Each IFD entry consists of 12 bytes which we loop through and extract
// the data from
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset);
+ var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian);
if (exifEntry) this.exifData.interoperability.push(exifEntry);
}
@@ -261,78 +261,78 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
}
-ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset, tags) {
+ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset, isBigEndian, tags) {
var entry = {
tag : data.slice(entryOffset, entryOffset + 2),
- format : data.getShort(entryOffset + 2, this.isBigEndian),
- components : data.getLong(entryOffset + 4, this.isBigEndian),
+ format : data.getShort(entryOffset + 2, isBigEndian),
+ components : data.getLong(entryOffset + 4, isBigEndian),
valueOffset: null,
value : []
}
- entry.tagName = (tags && tags[entry.tag.getShort(0, this.isBigEndian)]) ? tags[entry.tag.getShort(0, this.isBigEndian)] : null;
+ entry.tagName = (tags && tags[entry.tag.getShort(0, isBigEndian)]) ? tags[entry.tag.getShort(0, isBigEndian)] : null;
switch (entry.format) {
case 0x0001: // unsigned byte, 1 byte per component
- entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
entry.value.push(data.getByte(entry.valueOffset + i));
break;
case 0x0002: // ascii strings, 1 byte per component
- entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
entry.value = data.getString(entry.valueOffset, entry.components);
if (entry.value[entry.value.length - 1] === "\u0000") // Trim null terminated strings
entry.value = entry.value.substring(0, entry.value.length - 1);
break;
case 0x0003: // unsigned short, 2 byte per component
- entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getShort(entry.valueOffset + i * 2, this.isBigEndian));
+ entry.value.push(data.getShort(entry.valueOffset + i * 2, isBigEndian));
break;
case 0x0004: // unsigned long, 4 byte per component
- entry.valueOffset = (entry.components == 1) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components == 1) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getLong(entry.valueOffset + i * 4, this.isBigEndian));
+ entry.value.push(data.getLong(entry.valueOffset + i * 4, isBigEndian));
break;
case 0x0005: // unsigned rational, 8 byte per component (4 byte numerator and 4 byte denominator)
- entry.valueOffset = data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getLong(entry.valueOffset, this.isBigEndian) / data.getLong(entry.valueOffset + 4, this.isBigEndian));
+ entry.value.push(data.getLong(entry.valueOffset, isBigEndian) / data.getLong(entry.valueOffset + 4, isBigEndian));
break;
case 0x0006: // signed byte, 1 byte per component
- entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
entry.value.push(data.getSignedByte(entry.valueOffset + i));
break;
case 0x0007: // undefined, 1 byte per component
- entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 4) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
entry.value.push(data.slice(entry.valueOffset, entry.valueOffset + entry.components));
break;
case 0x0008: // signed short, 2 byte per component
- entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getSignedShort(entry.valueOffset + i * 2, this.isBigEndian));
+ entry.value.push(data.getSignedShort(entry.valueOffset + i * 2, isBigEndian));
break;
case 0x0009: // signed long, 4 byte per component
- entry.valueOffset = (entry.components == 1) ? entryOffset + 8 : data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = (entry.components == 1) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getSignedLong(entry.valueOffset + i * 4, this.isBigEndian));
+ entry.value.push(data.getSignedLong(entry.valueOffset + i * 4, isBigEndian));
break;
case 0x000A: // signed rational, 8 byte per component (4 byte numerator and 4 byte denominator)
- entry.valueOffset = data.getLong(entryOffset + 8, this.isBigEndian) + tiffOffset;
+ entry.valueOffset = data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
- entry.value.push(data.getSignedLong(entry.valueOffset, this.isBigEndian) / data.getSignedLong(entry.valueOffset + 4, this.isBigEndian));
+ entry.value.push(data.getSignedLong(entry.valueOffset, isBigEndian) / data.getSignedLong(entry.valueOffset + 4, isBigEndian));
break;
default:
@@ -62,7 +62,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
var numberOfEntries = data.getShort(ifdOffset, this.isBigEndian, tiffOffset);
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, tags);
+ var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags);
if (exifEntry) makernoteData.push(exifEntry);
}
@@ -62,7 +62,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
var numberOfEntries = data.getShort(ifdOffset, this.isBigEndian, tiffOffset);
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, tags);
+ var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags);
if (exifEntry) makernoteData.push(exifEntry);
}
@@ -62,7 +62,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
var numberOfEntries = data.getShort(ifdOffset, this.isBigEndian, tiffOffset);
for (var i = 0; i < numberOfEntries; i++) {
- var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, tags);
+ var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags);
if (exifEntry) makernoteData.push(exifEntry);
}

0 comments on commit 0b6519b

Please sign in to comment.