2 * \brief Defines the ExifData type and the associated functions.
5 * \author Lutz Mueller <lutz@users.sourceforge.net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
24 #ifndef __EXIF_DATA_H__
25 #define __EXIF_DATA_H__
29 #endif /* __cplusplus */
31 #include <libexif/exif-byte-order.h>
32 #include <libexif/exif-data-type.h>
33 #include <libexif/exif-ifd.h>
34 #include <libexif/exif-log.h>
35 #include <libexif/exif-tag.h>
37 /*! Represents the entire EXIF data found in an image */
38 typedef struct _ExifData ExifData;
39 typedef struct _ExifDataPrivate ExifDataPrivate;
41 #include <libexif/exif-content.h>
42 #include <libexif/exif-mnote-data.h>
43 #include <libexif/exif-mem.h>
55 /*! Represents the entire EXIF data found in an image */
58 /*! Data for each IFD */
59 ExifContent *ifd[EXIF_IFD_COUNT];
61 /*! Pointer to thumbnail image, or NULL if not available */
64 /*! Number of bytes in thumbnail image at \c data */
67 ExifDataPrivate *priv;
70 /*! Allocate a new #ExifData. The #ExifData contains an empty
71 * #ExifContent for each IFD and the default set of options,
72 * which has #EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS
73 * and #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.
75 * \return allocated #ExifData, or NULL on error
77 ExifData *exif_data_new (void);
79 /*! Allocate a new #ExifData using the given memory allocator.
80 * The #ExifData contains an empty #ExifContent for each IFD and the default
81 * set of options, which has #EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS and
82 * #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.
84 * \return allocated #ExifData, or NULL on error
86 ExifData *exif_data_new_mem (ExifMem *);
88 /*! Allocate a new #ExifData and load EXIF data from a JPEG file.
89 * Uses an #ExifLoader internally to do the loading.
91 * \param[in] path filename including path
92 * \return allocated #ExifData, or NULL on error
94 ExifData *exif_data_new_from_file (const char *path);
96 /*! Allocate a new #ExifData and load EXIF data from a memory buffer.
98 * \param[in] data pointer to raw JPEG or EXIF data
99 * \param[in] size number of bytes of data at data
100 * \return allocated #ExifData, or NULL on error
102 ExifData *exif_data_new_from_data (const unsigned char *data,
105 /*! Load the #ExifData structure from the raw JPEG or EXIF data in the given
106 * memory buffer. If the EXIF data contains a recognized MakerNote, it is
107 * loaded and stored as well for later retrieval by #exif_data_get_mnote_data.
108 * If the #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION option has been set on this
109 * #ExifData, then the tags are automatically fixed after loading (by calling
112 * \param[in,out] data EXIF data
113 * \param[in] d pointer to raw JPEG or EXIF data
114 * \param[in] size number of bytes of data at d
116 void exif_data_load_data (ExifData *data, const unsigned char *d,
119 /*! Store raw EXIF data representing the #ExifData structure into a memory
120 * buffer. The buffer is allocated by this function and must subsequently be
121 * freed by the caller using the matching free function as used by the #ExifMem
122 * in use by this #ExifData.
124 * \param[in] data EXIF data
125 * \param[out] d pointer to buffer pointer containing raw EXIF data on return
126 * \param[out] ds pointer to variable to hold the number of bytes of
127 * data at d, or set to 0 on error
129 void exif_data_save_data (ExifData *data, unsigned char **d,
132 void exif_data_ref (ExifData *data);
133 void exif_data_unref (ExifData *data);
134 void exif_data_free (ExifData *data);
136 /*! Return the byte order in use by this EXIF structure.
138 * \param[in] data EXIF data
141 ExifByteOrder exif_data_get_byte_order (ExifData *data);
143 /*! Set the byte order to use for this EXIF data. If any tags already exist
144 * (including MakerNote tags) they are are converted to the specified byte
147 * \param[in,out] data EXIF data
148 * \param[in] order byte order
150 void exif_data_set_byte_order (ExifData *data, ExifByteOrder order);
152 /*! Return the MakerNote data out of the EXIF data. Only certain
153 * MakerNote formats that are recognized by libexif are supported.
154 * The pointer references a member of the #ExifData structure and must NOT be
155 * freed by the caller.
157 * \param[in] d EXIF data
158 * \return MakerNote data, or NULL if not found or not supported
160 ExifMnoteData *exif_data_get_mnote_data (ExifData *d);
162 ExifByteOrder exif_data_get_data_order (ExifData *d);
164 /*! Fix the EXIF data to bring it into specification. Call #exif_content_fix
165 * on each IFD to fix existing entries, create any new entries that are
166 * mandatory but do not yet exist, and remove any entries that are not
169 * \param[in,out] d EXIF data
171 void exif_data_fix (ExifData *d);
173 typedef void (* ExifDataForeachContentFunc) (ExifContent *, void *user_data);
175 /*! Execute a function on each IFD in turn.
177 * \param[in] data EXIF data over which to iterate
178 * \param[in] func function to call for each entry
179 * \param[in] user_data data to pass into func on each call
181 void exif_data_foreach_content (ExifData *data,
182 ExifDataForeachContentFunc func,
185 /*! Options to configure the behaviour of #ExifData */
187 /*! Act as though unknown tags are not present */
188 EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS = 1 << 0,
190 /*! Fix the EXIF tags to follow the spec */
191 EXIF_DATA_OPTION_FOLLOW_SPECIFICATION = 1 << 1,
193 /*! Leave the MakerNote alone, which could cause it to be corrupted */
194 EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE = 1 << 2
197 /*! Return a short textual description of the given #ExifDataOption.
199 * \param[in] o option
200 * \return localized textual description of the option
202 const char *exif_data_option_get_name (ExifDataOption o);
204 /*! Return a verbose textual description of the given #ExifDataOption.
206 * \param[in] o option
207 * \return verbose localized textual description of the option
209 const char *exif_data_option_get_description (ExifDataOption o);
211 /*! Set the given option on the given #ExifData.
213 * \param[in] d EXIF data
214 * \param[in] o option
216 void exif_data_set_option (ExifData *d, ExifDataOption o);
218 /*! Clear the given option on the given #ExifData.
220 * \param[in] d EXIF data
221 * \param[in] o option
223 void exif_data_unset_option (ExifData *d, ExifDataOption o);
225 /*! Set the data type for the given #ExifData.
227 * \param[in] d EXIF data
228 * \param[in] dt data type
230 void exif_data_set_data_type (ExifData *d, ExifDataType dt);
232 /*! Return the data type for the given #ExifData.
234 * \param[in] d EXIF data
235 * \return data type, or #EXIF_DATA_TYPE_UNKNOWN on error
237 ExifDataType exif_data_get_data_type (ExifData *d);
239 /*! Dump all EXIF data to stdout.
240 * This is intended for diagnostic purposes only.
242 * \param[in] data EXIF data
244 void exif_data_dump (ExifData *data);
246 /*! Set the log message object for all IFDs.
248 * \param[in] data EXIF data
249 * \param[in] log #ExifLog
251 void exif_data_log (ExifData *data, ExifLog *log);
253 /*! Create new mnote data and set up related function pointers for particular manufacturer.
255 * \param[in,out] d EXIF data
256 * \param[in] maker Manufacturer
257 * \param[in] o option
258 * \return 1 if normal, else 0 if abnormal
260 int exif_data_mnote_data_new(ExifData *d, Manufacturer maker, ExifDataOption o);
262 /*! Allocate makernote entries memory for particular manufacturer.
264 * \param[in,out] d EXIF Makernote data
265 * \param[in] maker Manufacturer
266 * \return 1 if normal, else 0 if abnormal
268 int exif_data_mnote_set_mem_for_adding_entry(ExifMnoteData *md, Manufacturer maker);
270 /*! Add a makernote entry for particular manufacturer.
272 * \param[in,out] d EXIF Makernote data
273 * \param[in] maker Manufacturer
274 * \param[in] tag Manufacturer specified makernote tag
275 * \param[in] fmt Exifformat
276 * \param[in] components The number of components
277 * \param[in] id Index
278 * \return 1 if normal, else 0 if abnormal
280 int exif_data_mnote_set_add_entry(ExifMnoteData *md, Manufacturer maker, int tag, ExifFormat fmt, int components, int id);
282 /*! Add a makernote entry using subtag information for particular manufacturer.
284 * \param[in,out] d EXIF Makernote data
285 * \param[in] maker Manufacturer
286 * \param[in] tag Manufacturer specified makernote tag
287 * \param[in] fmt Exifformat
288 * \param[in] components The number of components
289 * \param[in] subtag1 Manufacturer specified makernote subtag
290 * \param[in] id1 Index for subtag1
291 * \param[in] subtag2 Manufacturer specified makernote subtag
292 * \param[in] id2 Indoex for subtag2
293 * \param[in] val Integer value
294 * \return 1 if normal, else 0 if abnormal
296 int exif_data_mnote_set_add_entry_subtag(ExifMnoteData* md, Manufacturer maker, int tag, ExifFormat fmt, int components, int subtag1, int id1, int subtag2, int id2, int val);
298 /*! Add a makernote entry using string information for particular manufacturer.
300 * \param[in,out] d EXIF Makernote data
301 * \param[in] maker Manufacturer
302 * \param[in] tag Manufacturer specified makernote tag
303 * \param[in] fmt Exifformat
304 * \param[in] components The number of components
305 * \param[in] string String value to be written
306 * \return 1 if normal, else 0 if abnormal
308 int exif_data_mnote_set_add_entry_string(ExifMnoteData* md, Manufacturer maker, int tag, ExifFormat fmt, int components, const char* string);
310 /*! Return an #ExifEntry for the given tag if found in any IFD.
311 * Each IFD is searched in turn and the first containing a tag with
312 * this number is returned.
314 * \param[in] d #ExifData
315 * \param[in] t #ExifTag
316 * \return #ExifEntry* if found, else NULL if not found
318 #define exif_data_get_entry(d,t) \
319 (exif_content_get_entry(d->ifd[EXIF_IFD_0],t) ? \
320 exif_content_get_entry(d->ifd[EXIF_IFD_0],t) : \
321 exif_content_get_entry(d->ifd[EXIF_IFD_1],t) ? \
322 exif_content_get_entry(d->ifd[EXIF_IFD_1],t) : \
323 exif_content_get_entry(d->ifd[EXIF_IFD_EXIF],t) ? \
324 exif_content_get_entry(d->ifd[EXIF_IFD_EXIF],t) : \
325 exif_content_get_entry(d->ifd[EXIF_IFD_GPS],t) ? \
326 exif_content_get_entry(d->ifd[EXIF_IFD_GPS],t) : \
327 exif_content_get_entry(d->ifd[EXIF_IFD_INTEROPERABILITY],t) ? \
328 exif_content_get_entry(d->ifd[EXIF_IFD_INTEROPERABILITY],t) : NULL)
332 #endif /* __cplusplus */
334 #endif /* __EXIF_DATA_H__ */