/* The interface to exifparse is pretty plain: Get an exif_properties structure by calling exif_get_properties(uint8_t *buf,int giveupafter,exif_properties_t *prop), where buf is the buffer containing the data, the exif marker should be within the first giveupafter bytes, and prop is a handle that is needed for calling all the other functions. This call does some mallocing, and if you don't need the exif info any more, call exif_release_properties(exif_properties_t *prop) to free the memory. After you've done this, you can call exif_get_tagval(uint8_t taghi,uint8_t taglo,exif_properties_t *prop, int32_t *data,int32_t *ncomp,int ifdsel) The macros defined in in this header will fill out both taghi and taglo, ncomp is the number of items field in the directory entry pointed to by tag, and data its data content. ifdsel can be -1 to indicate the exif subifd should be searched, 0 to indicate all known ifds should be searched and the first match returned, or a positive number to indicate the corresponding ifd should be searched. The function returns 0 if the tag was found, -1 otherwise As convenience functions, you can also call exif_get_string(unit8_t taghi,unit8_t taglo,exif_properties_t *prop) The function searches the tag in all ifds, and, if found, interprets its contents as a string pointer. It then allocates a new string, copies the data into it and returns a pointer to it (that memory must be freed when done). If the tag is not found, NULL is returned. exif_get_rational(unit8_t taghi,unit8_t taglo,exif_properties_t *prop) The analog function for rationals. It returns a double or, in case of an error, the special double EXIF_INVALID_RATIONAL (a double too large to be representable by a 64-bit rational (which is about 4e9) msdemlei@tucana.harvard.edu */ #ifndef _EXIF_H #define _EXIF_H #include /* Predefined tags: hi and lo bytes (I have to do it this way since you cannot tell the endianness of the host and the data in advance */ /* These should reside in the primary ifds */ #define TH_IMAGEWIDTH 0x01,0x00 #define TH_IMAGEHEIGHT 0x01,0x01 #define TH_BITSPERSAMPLE 0x01,0x02 #define TH_COMPRESSION 0x01,0x03 #define TH_PHOTOMETRICINTERPOLATION 0x01,0x06 #define TH_IMAGE_DESCRIPTOR 0x01,0x0e #define TH_MAKE 0x01,0x0f #define TH_MODEL 0x01,0x10 #define TH_STRIPOFFSETS 0x01,0x11 #define TH_ORIENTATION 0x01,0x12 #define TH_SAMPLESPERPIXEL 0x01,0x15 #define TH_ROWSPERSTRIP 0x01,0x16 #define TH_STRIPBYTECOUNTS 0x01,0x17 #define TH_XRESOLUTION 0x01,0x1a #define TH_YRESOLUTION 0x01,0x1b #define TH_PLANARCONFIGURATION 0x01,0x1c #define TH_RESOLUTIONUNIT 0x01,0x28 #define TH_SOFTWARE 0x01,0x31 #define TH_DATETIME 0x01,0x32 #define TH_WHITEPOINT 0x01,0x3e #define TH_PRIMARYCHROMATICIES 0x01,0x3f #define TH_JPEGIFOFFSET 0x02,0x01 #define TH_JPEGIFBYTECOUNT 0x02,0x02 #define TH_YBCRCOEFFICIENTS 0x02,0x11 #define TH_YBCRPOSITIONING 0x02,0x13 #define TH_REFERENCEBLACKWHITE 0x02,0x14 #define TH_COPYRIGHT 0x82,0x98 #define TH_EXIF_OFFSET 0x87,0x69 /* These might live in the exif ifd */ #define EXIF_EXPOSURETIME 0x82,0x9a #define EXIF_FNUMBER 0x82,0x9d #define EXIF_EXPOSUREPROGRAM 0x88,0x22 #define EXIF_ISOSPEEDRATINGS 0x88,0x27 #define EXIF_EXIFVERSION 0x90,0x00 #define EXIF_DATETIMEORIGINAL 0x90,0x03 #define EXIF_DATETIMEDIGITIZED 0x90,0x04 #define EXIF_COMPONENTCONFIGURATION 0x91,0x01 #define EXIF_COMPRESSEDBITSPERPIXEL 0x91,0x02 #define EXIF_SHUTTERSPEEDVALUE 0x92,0x01 #define EXIF_APERTUREVALUE 0x92,0x02 #define EXIF_BRIGHTNESSVALUE 0x92,0x03 #define EXIF_EXPOSUREBIASVALUE 0x92,0x04 #define EXIF_MAXAPERTUREVALUE 0x92,0x05 #define EXIF_SUBJECTDISTANCE 0x92,0x06 #define EXIF_METERINGMODE 0x92,0x07 #define EXIF_FLASH 0x92,0x09 #define EXIF_FOCALLENGTH 0x92,0x0a #define EXIF_EXIFIMAGEWIDTH 0xa0,0x02 #define EXIF_EXIFIMAGEHEIGHT 0xa0,0x03 #define EXIF_INVALID_RATIONAL 1e40 typedef unsigned char uint8_t; /* The next two types are actually private */ typedef struct { int16_t tag; int16_t format; int32_t ncomp; int32_t data; } tiffdir_t; typedef struct _ifd { int numentry; tiffdir_t *dir; struct _ifd *next; /* NULL or a pointer to another ifd */ } ifd_t; /* and this one would ideally be opaque, but as it stands now, tiffbase must be available to client programs */ typedef struct { int endian; /* 0=false=big-endian :-) */ int length; uint8_t *start; uint8_t *tiffbase; ifd_t *ifd; ifd_t *exif_ifd; } exif_properties_t; int exif_get_properties(uint8_t *buf,int giveupafter,exif_properties_t *prop); int exif_release_properties(exif_properties_t *prop); int exif_get_tagval(uint8_t taghi,uint8_t taglo,exif_properties_t *prop, int32_t *data,int32_t *ncomp,int ifdsel); char *exif_get_string(uint8_t taghi,uint8_t taglo,exif_properties_t *prop); double exif_get_rational(uint8_t taghi,uint8_t taglo,exif_properties_t *prop); #endif