Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
[geeqie.git] / src / exif.h
1 /*
2  *  GQView
3  *  (C) 2004 John Ellis
4  *
5  *  Authors:
6  *    Support for Exif file format, originally written by Eric Swalens.    
7  *    Modified by Quy Tonthat
8  *    Reimplemented with generic data storage by John Ellis
9  *
10
11     This program is free software; you can redistribute it and/or modify
12     it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20
21     You should have received a copy of the GNU General Public License
22     along with this program; if not, write to the Free Software
23     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #ifndef __EXIF_H
27 #define __EXIF_H
28
29
30 /*
31  *-----------------------------------------------------------------------------
32  * Tag formats
33  *-----------------------------------------------------------------------------
34  */
35
36 typedef enum {
37         EXIF_FORMAT_UNKNOWN             = 0,
38         EXIF_FORMAT_BYTE_UNSIGNED       = 1,
39         EXIF_FORMAT_STRING              = 2,
40         EXIF_FORMAT_SHORT_UNSIGNED      = 3,
41         EXIF_FORMAT_LONG_UNSIGNED       = 4,
42         EXIF_FORMAT_RATIONAL_UNSIGNED   = 5,
43         EXIF_FORMAT_BYTE                = 6,
44         EXIF_FORMAT_UNDEFINED           = 7,
45         EXIF_FORMAT_SHORT               = 8,
46         EXIF_FORMAT_LONG                = 9,
47         EXIF_FORMAT_RATIONAL            = 10,
48         EXIF_FORMAT_FLOAT               = 11,
49         EXIF_FORMAT_DOUBLE              = 12
50 } ExifFormatType;
51
52 typedef enum {
53         EXIF_BYTE_ORDER_INTEL,
54         EXIF_BYTE_ORDER_MOTOROLA
55 } ExifByteOrder;
56
57 typedef struct _ExifFormatAttrib ExifFormatAttrib;
58 struct _ExifFormatAttrib
59 {
60         ExifFormatType type;
61         guint size;
62         const gchar *short_name;
63         const gchar *description;
64 };
65
66 /* the list of known tag data formats */
67 extern ExifFormatAttrib ExifFormatList[];
68
69
70 /*
71  *-----------------------------------------------------------------------------
72  * Data storage
73  *-----------------------------------------------------------------------------
74  */
75
76 typedef struct _ExifData ExifData;
77 struct _ExifData
78 {
79         GList *items;   /* list of (ExifItem *) */
80 };
81
82 typedef struct _ExifRational ExifRational;
83 struct _ExifRational
84 {
85         guint32 num;
86         guint32 den;
87 };
88
89
90 typedef struct _ExifItem ExifItem;
91 typedef struct _ExifMarker ExifMarker;
92 typedef struct _ExifTextList ExifTextList;
93
94 struct _ExifItem
95 {
96         ExifFormatType format;
97         guint tag;
98         const ExifMarker *marker;
99         guint elements;
100         gpointer data;
101         guint data_len;
102 };
103
104 struct _ExifMarker
105 {
106         guint           tag;
107         ExifFormatType  format;
108         gint            components;
109         gchar           *key;
110         gchar           *description;
111         ExifTextList    *list;
112 };
113
114 #define EXIF_MARKER_LIST_END { 0x0000, EXIF_FORMAT_UNKNOWN, 0, NULL, NULL, NULL }
115
116 struct _ExifTextList
117 {
118         gint value;
119         const gchar* description;
120 };
121
122 #define EXIF_TEXT_LIST_END { -1, NULL }
123
124
125 typedef struct _ExifFormattedText ExifFormattedText;
126 struct _ExifFormattedText
127 {
128         const gchar *key;
129         const gchar *description;
130 };
131
132
133 /*
134  *-----------------------------------------------------------------------------
135  * Data
136  *-----------------------------------------------------------------------------
137  */
138
139 /* enums useful for image manipulation */
140
141 typedef enum {
142         EXIF_ORIENTATION_UNKNOWN        = 0,
143         EXIF_ORIENTATION_TOP_LEFT       = 1,
144         EXIF_ORIENTATION_TOP_RIGHT      = 2,
145         EXIF_ORIENTATION_BOTTOM_RIGHT   = 3,
146         EXIF_ORIENTATION_BOTTOM_LEFT    = 4,
147         EXIF_ORIENTATION_LEFT_TOP       = 5,
148         EXIF_ORIENTATION_RIGHT_TOP      = 6,
149         EXIF_ORIENTATION_RIGHT_BOTTOM   = 7,
150         EXIF_ORIENTATION_LEFT_BOTTOM    = 8
151 } ExifOrientationType;
152
153 typedef enum {
154         EXIF_UNIT_UNKNOWN       = 0,
155         EXIF_UNIT_NOUNIT        = 1,
156         EXIF_UNIT_INCH          = 2,
157         EXIF_UNIT_CENTIMETER    = 3
158 } ExifUnitType;
159
160
161 /* the known exif tags list */
162 extern ExifMarker ExifKnownMarkersList[];
163
164 /* the unknown tags utilize this generic list */
165 extern ExifMarker ExifUnknownMarkersList[];
166
167 /* the list of specially formatted keys, for human readable output */
168 extern ExifFormattedText ExifFormattedList[];
169
170
171 /*
172  *-----------------------------------------------------------------------------
173  * functions
174  *-----------------------------------------------------------------------------
175  */
176
177 ExifData *exif_read(const gchar *path);
178 void exif_free(ExifData *exif);
179
180 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key);
181 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value);
182 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
183 double exif_rational_to_double(ExifRational *r, gint sign);
184
185 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
186
187 const char *exif_item_get_tag_name(ExifItem *item);
188 const char *exif_item_get_description(ExifItem *item);
189 const char *exif_item_get_format_name(ExifItem *item, gint brief);
190 gchar *exif_item_get_data_as_text(ExifItem *item);
191 gint exif_item_get_integer(ExifItem *item, gint *value);
192 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign);
193
194 const gchar *exif_get_description_by_key(const gchar *key);
195
196 /* usually for debugging to stdout */
197 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list);
198
199
200
201 /* These funcs for use by makernote parsers only */
202
203
204 guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo);
205 guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo);
206 guint16 exif_byte_swab_int16(guint16 n, ExifByteOrder bo);
207 guint32 exif_byte_swab_int32(guint32 n, ExifByteOrder bo);
208
209 ExifItem *exif_item_new(ExifFormatType format, guint tag,
210                         guint elements, const ExifMarker *marker);
211 void exif_item_copy_data(ExifItem *item, void *src, guint len,
212                          ExifFormatType src_format, ExifByteOrder byte_order);
213
214 gint exif_parse_IFD_table(ExifData *exif,
215                           unsigned char *tiff, guint offset,
216                           guint size, ExifByteOrder byte_order,
217                           const ExifMarker *list);
218
219 gint exif_parse_TIFF(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list);
220
221
222 #endif
223