exif-data.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*! \file exif-data.h
  2. * \brief Defines the ExifData type and the associated functions.
  3. */
  4. /*
  5. * \author Lutz Mueller <lutz@users.sourceforge.net>
  6. * \date 2001-2005
  7. *
  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.
  12. *
  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.
  17. *
  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.
  22. */
  23. #ifndef __EXIF_DATA_H__
  24. #define __EXIF_DATA_H__
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif /* __cplusplus */
  28. #include <libexif/exif-byte-order.h>
  29. #include <libexif/exif-data-type.h>
  30. #include <libexif/exif-ifd.h>
  31. #include <libexif/exif-log.h>
  32. #include <libexif/exif-tag.h>
  33. /*! Represents the entire EXIF data found in an image */
  34. typedef struct _ExifData ExifData;
  35. typedef struct _ExifDataPrivate ExifDataPrivate;
  36. #include <libexif/exif-content.h>
  37. #include <libexif/exif-mnote-data.h>
  38. #include <libexif/exif-mem.h>
  39. /*! Represents the entire EXIF data found in an image */
  40. struct _ExifData
  41. {
  42. /*! Data for each IFD */
  43. ExifContent *ifd[EXIF_IFD_COUNT];
  44. /*! Pointer to thumbnail image, or NULL if not available */
  45. unsigned char *data;
  46. /*! Number of bytes in thumbnail image at \c data */
  47. unsigned int size;
  48. ExifDataPrivate *priv;
  49. };
  50. /*! Allocate a new #ExifData. The #ExifData contains an empty
  51. * #ExifContent for each IFD and the default set of options,
  52. * which has #EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS
  53. * and #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.
  54. *
  55. * \return allocated #ExifData, or NULL on error
  56. */
  57. ExifData *exif_data_new (void);
  58. /*! Allocate a new #ExifData using the given memory allocator.
  59. * The #ExifData contains an empty #ExifContent for each IFD and the default
  60. * set of options, which has #EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS and
  61. * #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.
  62. *
  63. * \return allocated #ExifData, or NULL on error
  64. */
  65. ExifData *exif_data_new_mem (ExifMem *);
  66. /*! Allocate a new #ExifData and load EXIF data from a JPEG file.
  67. * Uses an #ExifLoader internally to do the loading.
  68. *
  69. * \param[in] path filename including path
  70. * \return allocated #ExifData, or NULL on error
  71. */
  72. ExifData *exif_data_new_from_file (const char *path);
  73. /*! Allocate a new #ExifData and load EXIF data from a memory buffer.
  74. *
  75. * \param[in] data pointer to raw JPEG or EXIF data
  76. * \param[in] size number of bytes of data at data
  77. * \return allocated #ExifData, or NULL on error
  78. */
  79. ExifData *exif_data_new_from_data (const unsigned char *data,
  80. unsigned int size);
  81. /*! Load the #ExifData structure from the raw JPEG or EXIF data in the given
  82. * memory buffer. If the EXIF data contains a recognized MakerNote, it is
  83. * loaded and stored as well for later retrieval by #exif_data_get_mnote_data.
  84. * If the #EXIF_DATA_OPTION_FOLLOW_SPECIFICATION option has been set on this
  85. * #ExifData, then the tags are automatically fixed after loading (by calling
  86. * #exif_data_fix).
  87. *
  88. * \param[in,out] data EXIF data
  89. * \param[in] d pointer to raw JPEG or EXIF data
  90. * \param[in] size number of bytes of data at d
  91. */
  92. void exif_data_load_data (ExifData *data, const unsigned char *d,
  93. unsigned int size);
  94. /*! Store raw EXIF data representing the #ExifData structure into a memory
  95. * buffer. The buffer is allocated by this function and must subsequently be
  96. * freed by the caller using the matching free function as used by the #ExifMem
  97. * in use by this #ExifData.
  98. *
  99. * \param[in] data EXIF data
  100. * \param[out] d pointer to buffer pointer containing raw EXIF data on return
  101. * \param[out] ds pointer to variable to hold the number of bytes of
  102. * data at d, or set to 0 on error
  103. */
  104. void exif_data_save_data (ExifData *data, unsigned char **d,
  105. unsigned int *ds);
  106. void exif_data_ref (ExifData *data);
  107. void exif_data_unref (ExifData *data);
  108. void exif_data_free (ExifData *data);
  109. /*! Return the byte order in use by this EXIF structure.
  110. *
  111. * \param[in] data EXIF data
  112. * \return byte order
  113. */
  114. ExifByteOrder exif_data_get_byte_order (ExifData *data);
  115. /*! Set the byte order to use for this EXIF data. If any tags already exist
  116. * (including MakerNote tags) they are are converted to the specified byte
  117. * order.
  118. *
  119. * \param[in,out] data EXIF data
  120. * \param[in] order byte order
  121. */
  122. void exif_data_set_byte_order (ExifData *data, ExifByteOrder order);
  123. /*! Return the MakerNote data out of the EXIF data. Only certain
  124. * MakerNote formats that are recognized by libexif are supported.
  125. * The pointer references a member of the #ExifData structure and must NOT be
  126. * freed by the caller.
  127. *
  128. * \param[in] d EXIF data
  129. * \return MakerNote data, or NULL if not found or not supported
  130. */
  131. ExifMnoteData *exif_data_get_mnote_data (ExifData *d);
  132. /*! Fix the EXIF data to bring it into specification. Call #exif_content_fix
  133. * on each IFD to fix existing entries, create any new entries that are
  134. * mandatory but do not yet exist, and remove any entries that are not
  135. * allowed.
  136. *
  137. * \param[in,out] d EXIF data
  138. */
  139. void exif_data_fix (ExifData *d);
  140. typedef void (* ExifDataForeachContentFunc) (ExifContent *, void *user_data);
  141. /*! Execute a function on each IFD in turn.
  142. *
  143. * \param[in] data EXIF data over which to iterate
  144. * \param[in] func function to call for each entry
  145. * \param[in] user_data data to pass into func on each call
  146. */
  147. void exif_data_foreach_content (ExifData *data,
  148. ExifDataForeachContentFunc func,
  149. void *user_data);
  150. /*! Options to configure the behaviour of #ExifData */
  151. typedef enum {
  152. /*! Act as though unknown tags are not present */
  153. EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS = 1 << 0,
  154. /*! Fix the EXIF tags to follow the spec */
  155. EXIF_DATA_OPTION_FOLLOW_SPECIFICATION = 1 << 1,
  156. /*! Leave the MakerNote alone, which could cause it to be corrupted */
  157. EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE = 1 << 2
  158. } ExifDataOption;
  159. /*! Return a short textual description of the given #ExifDataOption.
  160. *
  161. * \param[in] o option
  162. * \return localized textual description of the option
  163. */
  164. const char *exif_data_option_get_name (ExifDataOption o);
  165. /*! Return a verbose textual description of the given #ExifDataOption.
  166. *
  167. * \param[in] o option
  168. * \return verbose localized textual description of the option
  169. */
  170. const char *exif_data_option_get_description (ExifDataOption o);
  171. /*! Set the given option on the given #ExifData.
  172. *
  173. * \param[in] d EXIF data
  174. * \param[in] o option
  175. */
  176. void exif_data_set_option (ExifData *d, ExifDataOption o);
  177. /*! Clear the given option on the given #ExifData.
  178. *
  179. * \param[in] d EXIF data
  180. * \param[in] o option
  181. */
  182. void exif_data_unset_option (ExifData *d, ExifDataOption o);
  183. /*! Set the data type for the given #ExifData.
  184. *
  185. * \param[in] d EXIF data
  186. * \param[in] dt data type
  187. */
  188. void exif_data_set_data_type (ExifData *d, ExifDataType dt);
  189. /*! Return the data type for the given #ExifData.
  190. *
  191. * \param[in] d EXIF data
  192. * \return data type, or #EXIF_DATA_TYPE_UNKNOWN on error
  193. */
  194. ExifDataType exif_data_get_data_type (ExifData *d);
  195. /*! Dump all EXIF data to stdout.
  196. * This is intended for diagnostic purposes only.
  197. *
  198. * \param[in] data EXIF data
  199. */
  200. void exif_data_dump (ExifData *data);
  201. /*! Set the log message object for all IFDs.
  202. *
  203. * \param[in] data EXIF data
  204. * \param[in] log #ExifLog
  205. */
  206. void exif_data_log (ExifData *data, ExifLog *log);
  207. /*! Return an #ExifEntry for the given tag if found in any IFD.
  208. * Each IFD is searched in turn and the first containing a tag with
  209. * this number is returned.
  210. *
  211. * \param[in] d #ExifData
  212. * \param[in] t #ExifTag
  213. * \return #ExifEntry* if found, else NULL if not found
  214. */
  215. #define exif_data_get_entry(d,t) \
  216. (exif_content_get_entry(d->ifd[EXIF_IFD_0],t) ? \
  217. exif_content_get_entry(d->ifd[EXIF_IFD_0],t) : \
  218. exif_content_get_entry(d->ifd[EXIF_IFD_1],t) ? \
  219. exif_content_get_entry(d->ifd[EXIF_IFD_1],t) : \
  220. exif_content_get_entry(d->ifd[EXIF_IFD_EXIF],t) ? \
  221. exif_content_get_entry(d->ifd[EXIF_IFD_EXIF],t) : \
  222. exif_content_get_entry(d->ifd[EXIF_IFD_GPS],t) ? \
  223. exif_content_get_entry(d->ifd[EXIF_IFD_GPS],t) : \
  224. exif_content_get_entry(d->ifd[EXIF_IFD_INTEROPERABILITY],t) ? \
  225. exif_content_get_entry(d->ifd[EXIF_IFD_INTEROPERABILITY],t) : NULL)
  226. #ifdef __cplusplus
  227. }
  228. #endif /* __cplusplus */
  229. #endif /* __EXIF_DATA_H__ */