1 /* 2 * Copyright (c) 2001-2007, Eric M. Johnston <emj@postal.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Eric M. Johnston. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Id: exifint.h,v 1.32 2007/12/16 00:48:22 ejohnst Exp $ 33 */ 34 35 /* 36 * Exchangeable image file format (Exif) parser. 37 * 38 * Developed using the TIFF 6.0 specification 39 * (http://partners.adobe.com/asn/developer/pdfs/tn/TIFF6.pdf) 40 * and the EXIF 2.21 standard: (http://tsc.jeita.or.jp/avs/data/cp3451_1.pdf). 41 * 42 * Definitions internal to the Exif parsing library. 43 * 44 */ 45 46 #ifndef _EXIFINT_H 47 #define _EXIFINT_H 48 49 #include "exif.h" 50 51 52 /* Exif IFD tags. */ 53 54 #define EXIF_T_EXIFIFD 0x8769 55 #define EXIF_T_GPSIFD 0x8825 56 #define EXIF_T_MAKERNOTE 0x927c 57 #define EXIF_T_INTEROP 0xa005 58 59 60 /* IFD field types. */ 61 62 struct fieldtype { 63 u_int16_t type; 64 const char *name; 65 size_t size; 66 }; 67 68 69 /* A raw Image File Directory (IFD) entry (12 bytes). */ 70 71 struct field { 72 unsigned char tag[2]; 73 unsigned char type[2]; 74 unsigned char count[4]; 75 unsigned char value[4]; 76 }; 77 78 79 /* IFD entry. */ 80 81 struct ifd { 82 u_int16_t num; /* Number of fields. */ 83 struct field *fields; /* Array of fields. */ 84 struct exifprop *par; /* Parent property association. */ 85 struct exiftag *tagset; /* Tag definitions. */ 86 struct tiffmeta md; /* Metadata. */ 87 struct ifd *next; 88 }; 89 90 91 /* List of IFD offsets, to detect loops. */ 92 93 struct ifdoff { 94 unsigned char *offset; /* Offset to IFD. */ 95 struct ifdoff *next; /* Next IFD in list. */ 96 }; 97 98 99 /* Macro for making sense of a fraction. */ 100 101 #define fixfract(str, n, d, t) { \ 102 if ((t)) { (n) /= (t); (d) /= (t); } \ 103 if (!(n)) sprintf((str), "0"); \ 104 else if (!(d)) sprintf((str), "Infinite"); \ 105 else if (abs((n)) == abs((d))) sprintf((str), "%d", (n) / (d)); \ 106 else if (abs((d)) == 1) snprintf((str), 31, "%d", (n) / (d)); \ 107 else if (abs((n)) > abs((d))) snprintf((str), 31, "%.1f", \ 108 (double)(n) / (double)(d)); \ 109 else if (abs((d)) > 2 && abs((n)) > 1 && \ 110 (fabs((double)(n) / (double)(d))) >= 0.1) \ 111 snprintf((str), 31, "%.1f", (double)(n) / (double)(d)); \ 112 else snprintf((str), 31, "%d/%d", (n), (d)); \ 113 } 114 115 116 /* The tables from tagdefs.c. */ 117 118 extern struct fieldtype ftypes[]; 119 extern struct descrip ucomment[]; 120 extern struct descrip flash_fire[]; 121 extern struct descrip flash_return[]; 122 extern struct descrip flash_mode[]; 123 extern struct descrip flash_func[]; 124 extern struct descrip flash_redeye[]; 125 extern struct descrip filesrcs[]; 126 127 128 /* Utility functions from exifutil.c. */ 129 130 extern int offsanity(struct exifprop *prop, u_int16_t size, struct ifd *dir); 131 extern u_int16_t exif2byte(unsigned char *b, enum byteorder o); 132 extern int16_t exif2sbyte(unsigned char *b, enum byteorder o); 133 extern u_int32_t exif4byte(unsigned char *b, enum byteorder o); 134 extern void byte4exif(u_int32_t n, unsigned char *b, enum byteorder o); 135 extern int32_t exif4sbyte(unsigned char *b, enum byteorder o); 136 extern char *finddescr(struct descrip *table, u_int16_t val); 137 extern int catdescr(char *c, struct descrip *table, u_int16_t val, int len); 138 extern struct exifprop *newprop(void); 139 extern struct exifprop *childprop(struct exifprop *parent); 140 extern void exifstralloc(char **str, int len); 141 extern void hexprint(unsigned char *b, int len); 142 extern void dumpprop(struct exifprop *prop, struct field *afield); 143 extern struct ifd *readifds(u_int32_t offset, struct exiftag *tagset, 144 struct tiffmeta *md); 145 extern u_int32_t readifd(u_int32_t offset, struct ifd **dir, 146 struct exiftag *tagset, struct tiffmeta *md); 147 extern u_int32_t gcd(u_int32_t a, u_int32_t b); 148 149 /* Interface to exifgps.c. */ 150 151 extern struct exiftag gpstags[]; 152 extern void gpsprop(struct exifprop *prop, struct exiftags *t); 153 154 #endif 155