Update exif.cpp from upstream

Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
Robert C. Helling 2017-02-19 10:27:27 +01:00 committed by Dirk Hohndel
parent 4a550e4d7d
commit dc55ee4a23
3 changed files with 911 additions and 584 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,34 +1,16 @@
/************************************************************************** /**************************************************************************
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. information from a JPEG file.
Based on the description of the EXIF file format at: Based on the description of the EXIF file format at:
-- http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html -- http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
-- http://www.media.mit.edu/pia/Research/deepview/exif.html -- http://www.media.mit.edu/pia/Research/deepview/exif.html
-- http://www.exif.org/Exif2-2.PDF -- http://www.exif.org/Exif2-2.PDF
Copyright (c) 2010-2013 Mayank Lahiri Copyright (c) 2010-2016 Mayank Lahiri
mlahiri@gmail.com mlahiri@gmail.com
All rights reserved. All rights reserved.
VERSION HISTORY:
================
2.1: Released July 2013
-- fixed a bug where JPEGs without an EXIF SubIFD would not be parsed
-- fixed a bug in parsing GPS coordinate seconds
-- fixed makefile bug
-- added two pathological test images from Matt Galloway
http://www.galloway.me.uk/2012/01/uiimageorientation-exif-orientation-sample-images/
-- split main parsing routine for easier integration into Firefox
2.0: Released February 2013
-- complete rewrite
-- no new/delete
-- 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: modification, are permitted provided that the following conditions are met:
@ -49,99 +31,113 @@
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef EXIF_H #ifndef __EXIF_H
#define EXIF_H #define __EXIF_H
#include <string> #include <string>
namespace easyexif {
// //
// Class responsible for storing and parsing EXIF information from a JPEG blob // Class responsible for storing and parsing EXIF information from a JPEG blob
// //
class EXIFInfo { class EXIFInfo {
public: public:
// Parsing function for an entire JPEG image buffer. // Parsing function for an entire JPEG image buffer.
// //
// PARAM 'data': A pointer to a JPEG image. // PARAM 'data': A pointer to a JPEG image.
// PARAM 'length': The length of the JPEG image. // PARAM 'length': The length of the JPEG image.
// RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out // RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out
// error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros // error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros
int parseFrom(const unsigned char *data, unsigned length); int parseFrom(const unsigned char *data, unsigned length);
int parseFrom(const std::string &data); int parseFrom(const std::string &data);
// Parsing function for an EXIF segment. This is used internally by parseFrom() // 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"). // available (i.e., a blob starting with the bytes "Exif\0\0").
int parseFromEXIFSegment(const unsigned char *buf, unsigned len); int parseFromEXIFSegment(const unsigned char *buf, unsigned len);
// Set all data members to default values. // Set all data members to default values.
void clear(); void clear();
// Data fields filled out by parseFrom() // 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 ImageDescription; // Image description
std::string Make; // Camera manufacturer's name std::string Make; // Camera manufacturer's name
std::string Model; // Camera model std::string Model; // Camera model
unsigned short Orientation; // Image orientation, start of data corresponds to unsigned short Orientation; // Image orientation, start of data corresponds to
// 0: unspecified in EXIF data // 0: unspecified in EXIF data
// 1: upper left of image // 1: upper left of image
// 3: lower right of image // 3: lower right of image
// 6: upper right of image // 6: upper right of image
// 8: lower left of image // 8: lower left of image
// 9: undefined // 9: undefined
unsigned short BitsPerSample; // Number of bits per component unsigned short BitsPerSample; // Number of bits per component
std::string Software; // Software used std::string Software; // Software used
std::string DateTime; // File change date and time std::string DateTime; // File change date and time
std::string DateTimeOriginal; // Original file date and time (may not exist) std::string DateTimeOriginal; // Original file date and time (may not exist)
std::string DateTimeDigitized; // Digitization date and time (may not exist) std::string DateTimeDigitized; // Digitization date and time (may not exist)
std::string SubSecTimeOriginal; // Sub-second time that original picture was taken std::string SubSecTimeOriginal; // Sub-second time that original picture was taken
std::string Copyright; // File copyright information std::string Copyright; // File copyright information
double ExposureTime; // Exposure time in seconds double ExposureTime; // Exposure time in seconds
double FNumber; // F/stop double FNumber; // F/stop
unsigned short ISOSpeedRatings; // ISO speed unsigned short ISOSpeedRatings; // ISO speed
double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time) double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time)
double ExposureBiasValue; // Exposure bias value in EV double ExposureBiasValue; // Exposure bias value in EV
double SubjectDistance; // Distance to focus point in meters double SubjectDistance; // Distance to focus point in meters
double FocalLength; // Focal length of lens in millimeters double FocalLength; // Focal length of lens in millimeters
unsigned short FocalLengthIn35mm; // Focal length in 35mm film unsigned short FocalLengthIn35mm; // Focal length in 35mm film
char Flash; // 0 = no flash, 1 = flash used char Flash; // 0 = no flash, 1 = flash used
unsigned short MeteringMode; // Metering mode unsigned short MeteringMode; // Metering mode
// 1: average // 1: average
// 2: center weighted average // 2: center weighted average
// 3: spot // 3: spot
// 4: multi-spot // 4: multi-spot
// 5: multi-segment // 5: multi-segment
unsigned ImageWidth; // Image width reported in EXIF data unsigned ImageWidth; // Image width reported in EXIF data
unsigned ImageHeight; // Image height reported in EXIF data unsigned ImageHeight; // Image height reported in EXIF data
struct Geolocation_t struct Geolocation_t { // GPS information embedded in file
{ // GPS information embedded in file double Latitude; // Image latitude expressed as decimal
double Latitude; // Image latitude expressed as decimal double Longitude; // Image longitude expressed as decimal
double Longitude; // Image longitude expressed as decimal double Altitude; // Altitude in meters, relative to sea level
double Altitude; // Altitude in meters, relative to sea level char AltitudeRef; // 0 = above sea level, -1 = below sea level
char AltitudeRef; // 0 = above sea level, -1 = below sea level double DOP; // GPS degree of precision (DOP)
struct Coord_t { struct Coord_t {
double degrees; double degrees;
double minutes; double minutes;
double seconds; double seconds;
char direction; char direction;
} LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec } LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
} GeoLocation; } GeoLocation;
EXIFInfo() struct LensInfo_t { // Lens information
{ double FStopMin; // Min aperture (f-stop)
clear(); 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;
time_t epoch();
EXIFInfo() {
clear();
}
time_t epoch();
}; };
// Parse was successful }
#define PARSE_EXIF_SUCCESS 0
// No JPEG markers found in buffer, possibly invalid JPEG file
#define PARSE_EXIF_ERROR_NO_JPEG 1982
// No EXIF header found in JPEG file.
#define PARSE_EXIF_ERROR_NO_EXIF 1983
// Byte alignment specified in EXIF file was unknown (not Motorola or Intel).
#define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984
// EXIF header was found, but data was corrupted.
#define PARSE_EXIF_ERROR_CORRUPT 1985
#endif // EXIF_H // Parse was successful
#define PARSE_EXIF_SUCCESS 0
// No JPEG markers found in buffer, possibly invalid JPEG file
#define PARSE_EXIF_ERROR_NO_JPEG 1982
// No EXIF header found in JPEG file.
#define PARSE_EXIF_ERROR_NO_EXIF 1983
// Byte alignment specified in EXIF file was unknown (not Motorola or Intel).
#define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984
// EXIF header was found, but data was corrupted.
#define PARSE_EXIF_ERROR_CORRUPT 1985
#endif

View file

@ -354,7 +354,7 @@ extern "C" xsltStylesheetPtr get_stylesheet(const char *name)
extern "C" timestamp_t picture_get_timestamp(char *filename) extern "C" timestamp_t picture_get_timestamp(char *filename)
{ {
EXIFInfo exif; easyexif::EXIFInfo exif;
memblock mem; memblock mem;
int retval; int retval;
@ -1211,7 +1211,7 @@ extern "C" void savePictureLocal(struct picture *picture, const char *data, int
extern "C" void picture_load_exif_data(struct picture *p) extern "C" void picture_load_exif_data(struct picture *p)
{ {
EXIFInfo exif; easyexif::EXIFInfo exif;
memblock mem; memblock mem;
if (readfile(localFilePath(QString(p->filename)).toUtf8().data(), &mem) <= 0) if (readfile(localFilePath(QString(p->filename)).toUtf8().data(), &mem) <= 0)