Skip to content

Commit

Permalink
Source cleanup to make more future-proof.
Browse files Browse the repository at this point in the history
  • Loading branch information
DougReeder committed Jan 31, 2012
1 parent 0b6519b commit d12b820
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
30 changes: 15 additions & 15 deletions lib/exif/Buffer.js
Expand Up @@ -4,35 +4,35 @@

Buffer.prototype.getByte = function (offset) {
return this[offset];
}
};

Buffer.prototype.getSignedByte = function (offset) {
return (this[offset] > 127) ? this[offset] - 256 : this[offset];
}
};

Buffer.prototype.getShort = function (offset, bigEndian) {
var short = (bigEndian) ? (this[offset] << 8) + this[offset + 1] : (this[offset + 1] << 8) + this[offset];
return (short < 0) ? short + 65536 : short;
}
var shortVal = (bigEndian) ? (this[offset] << 8) + this[offset + 1] : (this[offset + 1] << 8) + this[offset];
return (shortVal < 0) ? shortVal + 65536 : shortVal;
};

Buffer.prototype.getSignedShort = function (offset, bigEndian) {
var short = (bigEndian) ? (this[offset] << 8) + this[offset + 1] : (this[offset + 1] << 8) + this[offset];
return (short > 32767) ? short - 65536 : short;
}
var shortVal = (bigEndian) ? (this[offset] << 8) + this[offset + 1] : (this[offset + 1] << 8) + this[offset];
return (shortVal > 32767) ? shortVal - 65536 : shortVal;
};

Buffer.prototype.getLong = function (offset, bigEndian) {
var long = (bigEndian) ? (((((this[offset] << 8) + this[offset + 1]) << 8) + this[offset + 2]) << 8) + this[offset + 3] : (((((this[offset + 3] << 8) + this[offset + 2]) << 8) + this[offset + 1]) << 8) + this[offset];
return (long < 0) ? long + 4294967296 : long;
}
var longVal = (bigEndian) ? (((((this[offset] << 8) + this[offset + 1]) << 8) + this[offset + 2]) << 8) + this[offset + 3] : (((((this[offset + 3] << 8) + this[offset + 2]) << 8) + this[offset + 1]) << 8) + this[offset];
return (longVal < 0) ? longVal + 4294967296 : longVal;
};

Buffer.prototype.getSignedLong = function (offset, bigEndian) {
var long = (bigEndian) ? (((((this[offset] << 8) + this[offset + 1]) << 8) + this[offset + 2]) << 8) + this[offset + 3] : (((((this[offset + 3] << 8) + this[offset + 2]) << 8) + this[offset + 1]) << 8) + this[offset];
return (long > 2147483647) ? long - 4294967296 : long;
}
var longVal = (bigEndian) ? (((((this[offset] << 8) + this[offset + 1]) << 8) + this[offset + 2]) << 8) + this[offset + 3] : (((((this[offset + 3] << 8) + this[offset + 2]) << 8) + this[offset + 1]) << 8) + this[offset];
return (longVal > 2147483647) ? longVal - 4294967296 : longVal;
};

Buffer.prototype.getString = function (offset, length) {
var string = [];
for (var i = offset; i < offset + length; i++)
string.push(String.fromCharCode(this[i]));
return string.join('');
}
};
54 changes: 27 additions & 27 deletions lib/exif/ExifImage.js
Expand Up @@ -20,7 +20,7 @@ function ExifImage (options, callback) {
var self = this;

if (!options)
var options = {};
options = {};

this.image;
this.imageType;
Expand Down Expand Up @@ -62,7 +62,7 @@ ExifImage.prototype.loadImage = function (image, callback) {

} else if (image.constructor.name === 'String') {

rawData = fs.readFile(image, function (error, data) {
fs.readFile(image, function (error, data) {
if (error)
callback({ message : 'Encountered the following error while trying to read given image: '+error });
else
Expand All @@ -75,7 +75,7 @@ ExifImage.prototype.loadImage = function (image, callback) {

}

}
};

ExifImage.prototype.processImage = function (data, callback) {

Expand Down Expand Up @@ -107,7 +107,7 @@ ExifImage.prototype.processImage = function (data, callback) {

callback({ message : 'No Exif segment found in the given image' });

}
};

ExifImage.prototype.extractExifData = function (data, start, length, callback) {

Expand Down Expand Up @@ -158,13 +158,13 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {
// Check if there is an offset for IFD1. If so it is always followed by two
// bytes with the amount of entries in this IFD, if not there is no IFD1
ifdOffset = tiffOffset + data.getLong(ifdOffset + 2 + (numberOfEntries * 12), this.isBigEndian);
if (ifdOffset != 0x00000000) {
if (ifdOffset !== 0x00000000) {
numberOfEntries = data.getShort(ifdOffset, this.isBigEndian);

// 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, this.isBigEndian, ExifImage.TAGS.tiff);
for (i = 0; i < numberOfEntries; i++) {
exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.tiff);
if (exifEntry) this.exifData.thumbnail.push(exifEntry);
}
}
Expand All @@ -180,8 +180,8 @@ 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, this.isBigEndian, ExifImage.TAGS.exif);
for (i = 0; i < numberOfEntries; i++) {
exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif);
if (exifEntry) this.exifData.exif.push(exifEntry);
}

Expand All @@ -200,8 +200,8 @@ 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, this.isBigEndian, ExifImage.TAGS.gps);
for (i = 0; i < numberOfEntries; i++) {
exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.gps);
if (exifEntry) this.exifData.gps.push(exifEntry);
}

Expand All @@ -220,8 +220,8 @@ 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, this.isBigEndian);
for (i = 0; i < numberOfEntries; i++) {
exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian);
if (exifEntry) this.exifData.interoperability.push(exifEntry);
}

Expand Down Expand Up @@ -259,7 +259,7 @@ ExifImage.prototype.extractExifData = function (data, start, length, callback) {

callback(false, this.exifData);

}
};

ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset, isBigEndian, tags) {

Expand All @@ -269,7 +269,7 @@ ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset,
components : data.getLong(entryOffset + 4, isBigEndian),
valueOffset: null,
value : []
}
};

entry.tagName = (tags && tags[entry.tag.getShort(0, isBigEndian)]) ? tags[entry.tag.getShort(0, isBigEndian)] : null;

Expand All @@ -290,25 +290,25 @@ ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset,

case 0x0003: // unsigned short, 2 byte per component
entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
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, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
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, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
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, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
entry.value.push(data.getSignedByte(entry.valueOffset + i));
break;

Expand All @@ -319,19 +319,19 @@ ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset,

case 0x0008: // signed short, 2 byte per component
entry.valueOffset = (entry.components <= 2) ? entryOffset + 8 : data.getLong(entryOffset + 8, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
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, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
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, isBigEndian) + tiffOffset;
for (var i = 0; i < entry.components; i++)
for (i = 0; i < entry.components; i++)
entry.value.push(data.getSignedLong(entry.valueOffset, isBigEndian) / data.getSignedLong(entry.valueOffset + 4, isBigEndian));
break;

Expand All @@ -345,7 +345,7 @@ ExifImage.prototype.extractExifEntry = function (data, entryOffset, tiffOffset,

return entry;

}
};

/**
* Comprehensive list of TIFF and Exif tags collected from around the web.
Expand Down Expand Up @@ -411,7 +411,7 @@ ExifImage.TAGS = {
0xA40A : 'Sharpness',
0xA40B : 'DeviceSettingDescription',
0xA40C : 'SubjectDistanceRange',
0xA420 : 'ImageUniqueID',
0xA420 : 'ImageUniqueID'

},

Expand Down Expand Up @@ -590,7 +590,7 @@ ExifImage.TAGS = {
0xC65A : 'CalibrationIlluminant1',
0xC65B : 'CalibrationIlluminant2',
0xC65C : 'BestQualityScale',
0xC660 : 'Alias Layer Metadata',
0xC660 : 'Alias Layer Metadata'

},

Expand Down Expand Up @@ -627,8 +627,8 @@ ExifImage.TAGS = {
0x001B : 'GPSProcessingMethod',
0x001C : 'GPSAreaInformation',
0x001D : 'GPSDateStamp',
0x001E : 'GPSDifferential',
0x001E : 'GPSDifferential'

}

}
};
2 changes: 1 addition & 1 deletion lib/exif/makernotes/agfa.js
Expand Up @@ -51,7 +51,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
0x102D : 'Coring Filter',
0x102E : 'Final Width',
0x102F : 'Final Height',
0x1034 : 'Compression Ratio',
0x1034 : 'Compression Ratio'

};

Expand Down
2 changes: 1 addition & 1 deletion lib/exif/makernotes/epson.js
Expand Up @@ -51,7 +51,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
0x102D : 'Coring Filter',
0x102E : 'Final Width',
0x102F : 'Final Height',
0x1034 : 'Compression Ratio',
0x1034 : 'Compression Ratio'

};

Expand Down
2 changes: 1 addition & 1 deletion lib/exif/makernotes/olympus.js
Expand Up @@ -51,7 +51,7 @@ exports.extractMakernotes = function (data, makernoteOffset, tiffOffset) {
0x102D : 'Coring Filter',
0x102E : 'Final Width',
0x102F : 'Final Height',
0x1034 : 'Compression Ratio',
0x1034 : 'Compression Ratio'

};

Expand Down

0 comments on commit d12b820

Please sign in to comment.