Skip to content

Commit

Permalink
Add Focal Plane X/Y resolution + GPS degree of precision.
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
Mayank Lahiri committed Nov 14, 2015
1 parent 2315ffe commit 7e60481
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 22 deletions.
3 changes: 3 additions & 0 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ int main(int argc, char *argv[]) {
result.GeoLocation.LonComponents.seconds,
result.GeoLocation.LonComponents.direction);
printf("GPS Altitude : %f m\n", result.GeoLocation.Altitude);
printf("GPS Precision (DOP) : %f\n", result.GeoLocation.DOP);
printf("Lens min focal length: %f mm\n", result.LensInfo.FocalLengthMin);
printf("Lens max focal length: %f mm\n", result.LensInfo.FocalLengthMax);
printf("Lens f-stop min : f/%.1f\n", result.LensInfo.FStopMin);
printf("Lens f-stop max : f/%.1f\n", result.LensInfo.FStopMax);
printf("Lens make : %s\n", result.LensInfo.Make.c_str());
printf("Lens model : %s\n", result.LensInfo.Model.c_str());
printf("Focal plane XRes : %f\n", result.LensInfo.FocalPlaneXResolution);
printf("Focal plane YRes : %f\n", result.LensInfo.FocalPlaneYResolution);

return 0;
}
36 changes: 34 additions & 2 deletions exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,25 +682,45 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
this->ImageHeight = result.val_short().front();
break;

case 0xa20e:
// EXIF Focal plane X-resolution
if (result.format() == 5) {
this->LensInfo.FocalPlaneXResolution = result.val_rational()[0];
}
break;

case 0xa20f:
// EXIF Focal plane Y-resolution
if (result.format() == 5) {
this->LensInfo.FocalPlaneYResolution = result.val_rational()[0];
}
break;

case 0xa405:
// Focal length in 35mm film
if (result.format() == 3)
this->FocalLengthIn35mm = result.val_short().front();
break;

case 0xa432:
// Focal length and FStop.
if (result.format() == 5) {
this->LensInfo.FocalLengthMin = result.val_rational()[0];
this->LensInfo.FocalLengthMax = result.val_rational()[1];
this->LensInfo.FStopMin = result.val_rational()[2];
this->LensInfo.FStopMax = result.val_rational()[3];
}
break;

case 0xa433:
// Lens make.
if (result.format() == 2) {
this->LensInfo.Make = result.val_string();
}
break;

case 0xa434:
// Lens model.
if (result.format() == 2) {
this->LensInfo.Model = result.val_string();
}
Expand Down Expand Up @@ -784,12 +804,13 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
case 5:
// GPS altitude reference (below or above sea level)
this->GeoLocation.AltitudeRef = *(buf + offs + 8);
if (1 == this->GeoLocation.AltitudeRef)
if (1 == this->GeoLocation.AltitudeRef) {
this->GeoLocation.Altitude = -this->GeoLocation.Altitude;
}
break;

case 6:
// GPS altitude reference
// GPS altitude
if (format == 5) {
this->GeoLocation.Altitude = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);
Expand All @@ -798,6 +819,14 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
}
}
break;

case 11:
// GPS degree of precision (DOP)
if (format == 5) {
this->GeoLocation.DOP = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);
}
break;
}
offs += 12;
}
Expand Down Expand Up @@ -841,6 +870,7 @@ void easyexif::EXIFInfo::clear() {
GeoLocation.Longitude = 0;
GeoLocation.Altitude = 0;
GeoLocation.AltitudeRef = 0;
GeoLocation.DOP = 0;
GeoLocation.LatComponents.degrees = 0;
GeoLocation.LatComponents.minutes = 0;
GeoLocation.LatComponents.seconds = 0;
Expand All @@ -855,6 +885,8 @@ void easyexif::EXIFInfo::clear() {
LensInfo.FocalLengthMin = 0;
LensInfo.FStopMax = 0;
LensInfo.FStopMin = 0;
LensInfo.FocalPlaneYResolution = 0;
LensInfo.FocalPlaneXResolution = 0;
LensInfo.Make = "";
LensInfo.Model = "";
}
43 changes: 23 additions & 20 deletions exif.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************
exif.h -- A simple ISO C++ library to parse basic EXIF
exif.h -- A simple ISO C++ library to parse basic EXIF
information from a JPEG file.
Based on the description of the EXIF file format at:
Expand All @@ -15,7 +15,7 @@
================
2.2: Release December 2014
--
--
2.1: Released July 2013
-- fixed a bug where JPEGs without an EXIF SubIFD would not be parsed
Expand All @@ -31,25 +31,25 @@
-- added GPS support
1.0: Released 2010
Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
-- Redistributions of source code must retain the above copyright notice,
-- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
-- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __EXIF_H
Expand All @@ -59,7 +59,7 @@

namespace easyexif {

//
//
// Class responsible for storing and parsing EXIF information from a JPEG blob
//
class EXIFInfo {
Expand All @@ -74,15 +74,15 @@ class EXIFInfo {
int parseFrom(const std::string &data);

// Parsing function for an EXIF segment. This is used internally by parseFrom()
// but can be called for special cases where only the EXIF section is
// but can be called for special cases where only the EXIF section is
// available (i.e., a blob starting with the bytes "Exif\0\0").
int parseFromEXIFSegment(const unsigned char *buf, unsigned len);

// Set all data members to default values.
void clear();

// Data fields filled out by parseFrom()
char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
std::string ImageDescription; // Image description
std::string Make; // Camera manufacturer's name
std::string Model; // Camera model
Expand Down Expand Up @@ -122,18 +122,21 @@ class EXIFInfo {
double Longitude; // Image longitude expressed as decimal
double Altitude; // Altitude in meters, relative to sea level
char AltitudeRef; // 0 = above sea level, -1 = below sea level
double DOP; // GPS degree of precision (DOP)
struct Coord_t {
double degrees;
double minutes;
double seconds;
char direction;
} LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
} LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
} GeoLocation;
struct LensInfo_t { // Lens information
double FStopMin; // Min aperture (f-stop)
double FStopMax; // Max aperture (f-stop)
double FocalLengthMin; // Min focal length (mm)
double FocalLengthMax; // Max focal length (mm)
double FocalPlaneXResolution; // Focal plane X-resolution
double FocalPlaneYResolution; // Focal plane Y-resolution
std::string Make; // Lens manufacturer
std::string Model; // Lens model
} LensInfo;
Expand Down
3 changes: 3 additions & 0 deletions test-images/down-mirrored.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 0.000000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
Binary file added test-images/evil1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test-images/evil1.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make : Canon
Camera model : Canon PowerShot S400
Software : Adobe Photoshop 7.0
Bits per sample : 0
Image width : 400
Image height : 300
Image description :
Image orientation : 1
Image copyright :
Image date/time : 2003:05:25 11:11:41
Original date/time : 2003:05:24 16:40:33
Digitize date/time : 2003:05:24 16:40:33
Subsecond time :
Exposure time : 1/8 s
F-stop : f/2.8
ISO speed : 0
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 1
Metering mode : 5
Lens focal length : 7.406250 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 8114.285714
Focal plane YRes : 8114.285714
3 changes: 3 additions & 0 deletions test-images/lens_info.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 0.000000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 10.000000 mm
Lens max focal length: 400.000000 mm
Lens f-stop min : f/1.1
Lens f-stop max : f/1.2
Lens make : Lens Maker Inc.
Lens model : Lens Model mk I
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/right.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 0.000000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/short-ascii-II.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 3.510000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/short-ascii-MM.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 21.300000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 8114.285714
Focal plane YRes : 8114.285714
3 changes: 3 additions & 0 deletions test-images/sony-alpha-6000.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 22.000000 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 16.000000 mm
Lens max focal length: 50.000000 mm
Lens f-stop min : f/3.5
Lens f-stop max : f/5.6
Lens make :
Lens model : E PZ 16-50mm F3.5-5.6 OSS
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/test1.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 4.280000 mm
GPS Latitude : 37.885000 deg (37.000000 deg, 53.100000 min, 0.000000 sec N)
GPS Longitude : -122.622500 deg (122.000000 deg, 37.350000 min, 0.000000 sec W)
GPS Altitude : 122.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/test2.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 4.280000 mm
GPS Latitude : 37.814667 deg (37.000000 deg, 48.880000 min, 0.000000 sec N)
GPS Longitude : -122.264167 deg (122.000000 deg, 15.850000 min, 0.000000 sec W)
GPS Altitude : 2.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
3 changes: 3 additions & 0 deletions test-images/test3.jpg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Lens focal length : 4.280000 mm
GPS Latitude : 37.776333 deg (37.000000 deg, 46.580000 min, 0.000000 sec N)
GPS Longitude : -122.419667 deg (122.000000 deg, 25.180000 min, 0.000000 sec W)
GPS Altitude : 15.833345 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000

0 comments on commit 7e60481

Please sign in to comment.