Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
[geeqie.git] / src / exif.h
1 /*
2  *  GQView
3  *  (C) 2006 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 #define EXIF_FORMAT_COUNT 13
37
38 typedef enum {
39         EXIF_FORMAT_UNKNOWN             = 0,
40         EXIF_FORMAT_BYTE_UNSIGNED       = 1,
41         EXIF_FORMAT_STRING              = 2,
42         EXIF_FORMAT_SHORT_UNSIGNED      = 3,
43         EXIF_FORMAT_LONG_UNSIGNED       = 4,
44         EXIF_FORMAT_RATIONAL_UNSIGNED   = 5,
45         EXIF_FORMAT_BYTE                = 6,
46         EXIF_FORMAT_UNDEFINED           = 7,
47         EXIF_FORMAT_SHORT               = 8,
48         EXIF_FORMAT_LONG                = 9,
49         EXIF_FORMAT_RATIONAL            = 10,
50         EXIF_FORMAT_FLOAT               = 11,
51         EXIF_FORMAT_DOUBLE              = 12
52 } ExifFormatType;
53
54 typedef enum {
55         EXIF_BYTE_ORDER_INTEL,
56         EXIF_BYTE_ORDER_MOTOROLA
57 } ExifByteOrder;
58
59 typedef struct _ExifFormatAttrib ExifFormatAttrib;
60 struct _ExifFormatAttrib
61 {
62         ExifFormatType type;
63         guint size;
64         const gchar *short_name;
65         const gchar *description;
66 };
67
68 /* the list of known tag data formats */
69 extern ExifFormatAttrib ExifFormatList[];
70
71
72 /*
73  *-----------------------------------------------------------------------------
74  * Data storage
75  *-----------------------------------------------------------------------------
76  */
77
78 typedef struct _ExifData ExifData;
79 struct _ExifData
80 {
81         GList *items;   /* list of (ExifItem *) */
82 };
83
84 typedef struct _ExifRational ExifRational;
85 struct _ExifRational
86 {
87         guint32 num;
88         guint32 den;
89 };
90
91
92 typedef struct _ExifItem ExifItem;
93 typedef struct _ExifMarker ExifMarker;
94 typedef struct _ExifTextList ExifTextList;
95
96 struct _ExifItem
97 {
98         ExifFormatType format;
99         guint tag;
100         const ExifMarker *marker;
101         guint elements;
102         gpointer data;
103         guint data_len;
104 };
105
106 struct _ExifMarker
107 {
108         guint           tag;
109         ExifFormatType  format;
110         gint            components;
111         gchar           *key;
112         gchar           *description;
113         ExifTextList    *list;
114 };
115
116 #define EXIF_MARKER_LIST_END { 0x0000, EXIF_FORMAT_UNKNOWN, 0, NULL, NULL, NULL }
117
118 struct _ExifTextList
119 {
120         gint value;
121         const gchar* description;
122 };
123
124 #define EXIF_TEXT_LIST_END { -1, NULL }
125
126
127 typedef struct _ExifFormattedText ExifFormattedText;
128 struct _ExifFormattedText
129 {
130         const gchar *key;
131         const gchar *description;
132 };
133
134
135 /*
136  *-----------------------------------------------------------------------------
137  * Data
138  *-----------------------------------------------------------------------------
139  */
140
141 /* enums useful for image manipulation */
142
143 typedef enum {
144         EXIF_ORIENTATION_UNKNOWN        = 0,
145         EXIF_ORIENTATION_TOP_LEFT       = 1,
146         EXIF_ORIENTATION_TOP_RIGHT      = 2,
147         EXIF_ORIENTATION_BOTTOM_RIGHT   = 3,
148         EXIF_ORIENTATION_BOTTOM_LEFT    = 4,
149         EXIF_ORIENTATION_LEFT_TOP       = 5,
150         EXIF_ORIENTATION_RIGHT_TOP      = 6,
151         EXIF_ORIENTATION_RIGHT_BOTTOM   = 7,
152         EXIF_ORIENTATION_LEFT_BOTTOM    = 8
153 } ExifOrientationType;
154
155 typedef enum {
156         EXIF_UNIT_UNKNOWN       = 0,
157         EXIF_UNIT_NOUNIT        = 1,
158         EXIF_UNIT_INCH          = 2,
159         EXIF_UNIT_CENTIMETER    = 3
160 } ExifUnitType;
161
162
163 /* the known exif tags list */
164 extern ExifMarker ExifKnownMarkersList[];
165
166 /* the unknown tags utilize this generic list */
167 extern ExifMarker ExifUnknownMarkersList[];
168
169 /* the list of specially formatted keys, for human readable output */
170 extern ExifFormattedText ExifFormattedList[];
171
172
173 /*
174  *-----------------------------------------------------------------------------
175  * functions
176  *-----------------------------------------------------------------------------
177  */
178
179 ExifData *exif_read(const gchar *path, gint parse_color_profile);
180 void exif_free(ExifData *exif);
181
182 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key);
183 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value);
184 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
185 double exif_rational_to_double(ExifRational *r, gint sign);
186
187 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
188
189 const char *exif_item_get_tag_name(ExifItem *item);
190 const char *exif_item_get_description(ExifItem *item);
191 const char *exif_item_get_format_name(ExifItem *item, gint brief);
192 gchar *exif_item_get_data_as_text(ExifItem *item);
193 gint exif_item_get_integer(ExifItem *item, gint *value);
194 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign);
195
196 const gchar *exif_get_description_by_key(const gchar *key);
197
198 /* usually for debugging to stdout */
199 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list);
200
201
202
203 /* These funcs for use by makernote/tiff parsers only */
204
205 #define EXIF_TIFF_MAX_LEVELS 4
206
207 #define EXIF_TIFD_OFFSET_TAG 0
208 #define EXIF_TIFD_OFFSET_FORMAT 2
209 #define EXIF_TIFD_OFFSET_COUNT 4
210 #define EXIF_TIFD_OFFSET_DATA 8
211 #define EXIF_TIFD_SIZE 12
212
213
214 guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo);
215 guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo);
216 void exif_byte_put_int16(unsigned char *f, guint16 n, ExifByteOrder bo);
217 void exif_byte_put_int32(unsigned char *f, guint32 n, ExifByteOrder bo);
218
219 ExifItem *exif_item_new(ExifFormatType format, guint tag,
220                         guint elements, const ExifMarker *marker);
221 void exif_item_copy_data(ExifItem *item, void *src, guint len,
222                          ExifFormatType src_format, ExifByteOrder bo);
223
224 gint exif_parse_IFD_table(ExifData *exif,
225                           unsigned char *tiff, guint offset,
226                           guint size, ExifByteOrder bo,
227                           gint level,
228                           const ExifMarker *list);
229
230 gint exif_tiff_directory_offset(unsigned char *data, const guint len,
231                                 guint *offset, ExifByteOrder *bo);
232 gint exif_tiff_parse(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list);
233
234 gchar *exif_text_list_find_value(ExifTextList *list, guint value);
235
236
237 #endif
238