|
shun-iwasawa |
fdbab5 |
/*-------------------------------------------------------------
|
|
shun-iwasawa |
fdbab5 |
tiio_jpg_exif.h
|
|
shun-iwasawa |
fdbab5 |
Based on source code of a public domain software "Exif Jpeg header manipulation
|
|
shun-iwasawa |
fdbab5 |
tool (jhead)" by Matthias Wandel.
|
|
shun-iwasawa |
fdbab5 |
For now it is used only for obtaining resolution values.
|
|
shun-iwasawa |
fdbab5 |
http://www.sentex.net/~mwandel/jhead/
|
|
shun-iwasawa |
fdbab5 |
-------------------------------------------------------------*/
|
|
shun-iwasawa |
fdbab5 |
#pragma once
|
|
shun-iwasawa |
fdbab5 |
#ifndef TIIO_JPG_EXIF_H
|
|
shun-iwasawa |
fdbab5 |
#define TIIO_JPG_EXIF_H
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
#include <stdlib.h></stdlib.h>
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
// undefining ReadAllTags will load only resolution infomation
|
|
shun-iwasawa |
fdbab5 |
#define ReadAllTags
|
|
shun-iwasawa |
fdbab5 |
#undef ReadAllTags
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
#define MAX_COMMENT_SIZE 16000
|
|
shun-iwasawa |
fdbab5 |
#define MAX_DATE_COPIES 10
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
#ifdef _WIN32
|
|
shun-iwasawa |
fdbab5 |
#define PATH_MAX _MAX_PATH
|
|
shun-iwasawa |
fdbab5 |
#define SLASH '\\'
|
|
shun-iwasawa |
fdbab5 |
#else
|
|
shun-iwasawa |
fdbab5 |
#ifndef PATH_MAX
|
|
shun-iwasawa |
fdbab5 |
#define PATH_MAX 1024
|
|
shun-iwasawa |
fdbab5 |
#endif
|
|
shun-iwasawa |
fdbab5 |
#define SLASH '/'
|
|
shun-iwasawa |
fdbab5 |
#endif
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
class JpgExifReader {
|
|
shun-iwasawa |
fdbab5 |
enum FORMATS {
|
|
shun-iwasawa |
fdbab5 |
FMT_BYTE = 1,
|
|
shun-iwasawa |
fdbab5 |
FMT_STRING,
|
|
shun-iwasawa |
fdbab5 |
FMT_USHORT,
|
|
shun-iwasawa |
fdbab5 |
FMT_ULONG,
|
|
shun-iwasawa |
fdbab5 |
FMT_URATIONAL,
|
|
shun-iwasawa |
fdbab5 |
FMT_SBYTE,
|
|
shun-iwasawa |
fdbab5 |
FMT_UNDEFINED,
|
|
shun-iwasawa |
fdbab5 |
FMT_SSHORT,
|
|
shun-iwasawa |
fdbab5 |
FMT_SLONG,
|
|
shun-iwasawa |
fdbab5 |
FMT_SRATIONAL,
|
|
shun-iwasawa |
fdbab5 |
FMT_SINGLE,
|
|
shun-iwasawa |
fdbab5 |
FMT_DOUBLE
|
|
shun-iwasawa |
fdbab5 |
};
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int NUM_FORMATS = FMT_DOUBLE;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
struct ExifImageInfo {
|
|
shun-iwasawa |
fdbab5 |
float xResolution = 0.0;
|
|
shun-iwasawa |
fdbab5 |
float yResolution = 0.0;
|
|
shun-iwasawa |
fdbab5 |
int ResolutionUnit;
|
|
shun-iwasawa |
fdbab5 |
#ifdef ReadAllTags
|
|
shun-iwasawa |
fdbab5 |
char FileName[PATH_MAX + 1];
|
|
shun-iwasawa |
fdbab5 |
time_t FileDateTime;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
unsigned FileSize;
|
|
shun-iwasawa |
fdbab5 |
char CameraMake[32];
|
|
shun-iwasawa |
fdbab5 |
char CameraModel[40];
|
|
shun-iwasawa |
fdbab5 |
char DateTime[20];
|
|
shun-iwasawa |
fdbab5 |
unsigned Height, Width;
|
|
shun-iwasawa |
fdbab5 |
int Orientation;
|
|
shun-iwasawa |
fdbab5 |
int IsColor;
|
|
shun-iwasawa |
fdbab5 |
int Process;
|
|
shun-iwasawa |
fdbab5 |
int FlashUsed;
|
|
shun-iwasawa |
fdbab5 |
float FocalLength;
|
|
shun-iwasawa |
fdbab5 |
float ExposureTime;
|
|
shun-iwasawa |
fdbab5 |
float ApertureFNumber;
|
|
shun-iwasawa |
fdbab5 |
float Distance;
|
|
shun-iwasawa |
fdbab5 |
float CCDWidth;
|
|
shun-iwasawa |
fdbab5 |
float ExposureBias;
|
|
shun-iwasawa |
fdbab5 |
float DigitalZoomRatio;
|
|
shun-iwasawa |
fdbab5 |
int FocalLength35mmEquiv; // Exif 2.2 tag - usually not present.
|
|
shun-iwasawa |
fdbab5 |
int Whitebalance;
|
|
shun-iwasawa |
fdbab5 |
int MeteringMode;
|
|
shun-iwasawa |
fdbab5 |
int ExposureProgram;
|
|
shun-iwasawa |
fdbab5 |
int ExposureMode;
|
|
shun-iwasawa |
fdbab5 |
int ISOequivalent;
|
|
shun-iwasawa |
fdbab5 |
int LightSource;
|
|
shun-iwasawa |
fdbab5 |
int DistanceRange;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
char Comments[MAX_COMMENT_SIZE];
|
|
shun-iwasawa |
fdbab5 |
int CommentWidthchars; // If nonzero, widechar comment, indicates number of
|
|
shun-iwasawa |
fdbab5 |
// chars.
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
unsigned ThumbnailOffset; // Exif offset to thumbnail
|
|
shun-iwasawa |
fdbab5 |
unsigned ThumbnailSize; // Size of thumbnail.
|
|
shun-iwasawa |
fdbab5 |
unsigned LargestExifOffset; // Last exif data referenced (to check if
|
|
shun-iwasawa |
fdbab5 |
// thumbnail is at end)
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
char ThumbnailAtEnd; // Exif header ends with the thumbnail
|
|
shun-iwasawa |
fdbab5 |
// (we can only modify the thumbnail if its at the end)
|
|
shun-iwasawa |
fdbab5 |
int ThumbnailSizeOffset;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int DateTimeOffsets[MAX_DATE_COPIES];
|
|
shun-iwasawa |
fdbab5 |
int numDateTimeTags = 0;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int GpsInfoPresent;
|
|
shun-iwasawa |
fdbab5 |
char GpsLat[31];
|
|
shun-iwasawa |
fdbab5 |
char GpsLong[31];
|
|
shun-iwasawa |
fdbab5 |
char GpsAlt[20];
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int QualityGuess;
|
|
shun-iwasawa |
fdbab5 |
#endif
|
|
shun-iwasawa |
fdbab5 |
} ImageInfo;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
#ifdef ReadAllTags
|
|
shun-iwasawa |
fdbab5 |
unsigned char* DirWithThumbnailPtrs;
|
|
shun-iwasawa |
fdbab5 |
double FocalplaneXRes;
|
|
shun-iwasawa |
fdbab5 |
double FocalplaneUnits;
|
|
shun-iwasawa |
fdbab5 |
int ExifImageWidth;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
// for fixing the rotation.
|
|
shun-iwasawa |
fdbab5 |
void* OrientationPtr[2];
|
|
shun-iwasawa |
fdbab5 |
int OrientationNumFormat[2];
|
|
shun-iwasawa |
fdbab5 |
int NumOrientations = 0;
|
|
shun-iwasawa |
fdbab5 |
#endif
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int MotorolaOrder = 0;
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
int Get16u(void* Short);
|
|
shun-iwasawa |
fdbab5 |
unsigned Get32u(void* Long);
|
|
shun-iwasawa |
fdbab5 |
int Get32s(void* Long);
|
|
shun-iwasawa |
fdbab5 |
void PrintFormatNumber(void* ValuePtr, int Format, int ByteCount);
|
|
shun-iwasawa |
fdbab5 |
double ConvertAnyFormat(void* ValuePtr, int Format);
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
public:
|
|
shun-iwasawa |
fdbab5 |
void process_EXIF(unsigned char* ExifSection, unsigned int length);
|
|
shun-iwasawa |
fdbab5 |
void ProcessExifDir(unsigned char* DirStart, unsigned char* OffsetBase,
|
|
shun-iwasawa |
fdbab5 |
unsigned ExifLength, int NestingLevel);
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
// obtaining resolution info
|
|
shun-iwasawa |
fdbab5 |
bool containsResolution() { return ImageInfo.xResolution != 0.0; }
|
|
shun-iwasawa |
fdbab5 |
float getXResolution() { return ImageInfo.xResolution; }
|
|
shun-iwasawa |
fdbab5 |
float getYResolution() { return ImageInfo.yResolution; }
|
|
shun-iwasawa |
fdbab5 |
int getResolutionUnit() { return ImageInfo.ResolutionUnit; }
|
|
shun-iwasawa |
fdbab5 |
};
|
|
shun-iwasawa |
fdbab5 |
|
|
shun-iwasawa |
fdbab5 |
#endif
|