exif-entry.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*! \file exif-entry.h
  2. * \brief Handling EXIF entries
  3. */
  4. /*
  5. * Copyright (c) 2001 Lutz Mueller <lutz@users.sourceforge.net>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef __EXIF_ENTRY_H__
  23. #define __EXIF_ENTRY_H__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /* __cplusplus */
  27. /*! Data found in one EXIF tag.
  28. * The #exif_entry_get_value function can provide access to the
  29. * formatted contents, or the struct members can be used directly to
  30. * access the raw contents.
  31. */
  32. typedef struct _ExifEntry ExifEntry;
  33. typedef struct _ExifEntryPrivate ExifEntryPrivate;
  34. #include <libexif/exif-content.h>
  35. #include <libexif/exif-format.h>
  36. #include <libexif/exif-mem.h>
  37. /*! Data found in one EXIF tag */
  38. struct _ExifEntry {
  39. /*! EXIF tag for this entry */
  40. ExifTag tag;
  41. /*! Type of data in this entry */
  42. ExifFormat format;
  43. /*! Number of elements in the array, if this is an array entry.
  44. * Contains 1 for non-array data types. */
  45. unsigned long components;
  46. /*! Pointer to the raw EXIF data for this entry. It is allocated
  47. * by #exif_entry_initialize and is NULL beforehand. Data contained
  48. * here may be manipulated using the functions in exif-utils.h */
  49. unsigned char *data;
  50. /*! Number of bytes in the buffer at \c data. This must be no less
  51. * than exif_format_get_size(format)*components */
  52. unsigned int size;
  53. /*! #ExifContent containing this entry.
  54. * \see exif_entry_get_ifd */
  55. ExifContent *parent;
  56. /*! Internal data to be used by libexif itself */
  57. ExifEntryPrivate *priv;
  58. };
  59. /* Lifecycle */
  60. /*! Reserve memory for and initialize a new #ExifEntry.
  61. * No memory is allocated for the \c data element of the returned #ExifEntry.
  62. *
  63. * \return new allocated #ExifEntry, or NULL on error
  64. *
  65. * \see exif_entry_new_mem, exif_entry_unref
  66. */
  67. ExifEntry *exif_entry_new (void);
  68. /*! Reserve memory for and initialize new #ExifEntry using the specified
  69. * memory allocator.
  70. * No memory is allocated for the \c data element of the returned #ExifEntry.
  71. *
  72. * \return new allocated #ExifEntry, or NULL on error
  73. *
  74. * \see exif_entry_new, exif_entry_unref
  75. */
  76. ExifEntry *exif_entry_new_mem (ExifMem *);
  77. /*! Increase reference counter for #ExifEntry.
  78. *
  79. * \param[in] entry #ExifEntry
  80. *
  81. * \see exif_entry_unref
  82. */
  83. void exif_entry_ref (ExifEntry *entry);
  84. /*! Decrease reference counter for #ExifEntry.
  85. * When the reference count drops to zero, free the entry.
  86. *
  87. * \param[in] entry #ExifEntry
  88. */
  89. void exif_entry_unref (ExifEntry *entry);
  90. /*! Actually free the #ExifEntry.
  91. *
  92. * \deprecated Should not be called directly. Use #exif_entry_ref and
  93. * #exif_entry_unref instead.
  94. *
  95. * \param[in] entry EXIF entry
  96. */
  97. void exif_entry_free (ExifEntry *entry);
  98. /*! Initialize an empty #ExifEntry with default data in the correct format
  99. * for the given tag. If the entry is already initialized, this function
  100. * does nothing.
  101. * This call allocates memory for the \c data element of the given #ExifEntry.
  102. * That memory is freed at the same time as the #ExifEntry.
  103. *
  104. * \param[out] e entry to initialize
  105. * \param[in] tag tag number to initialize as
  106. */
  107. void exif_entry_initialize (ExifEntry *e, ExifTag tag);
  108. /*! Fix the type or format of the given EXIF entry to bring it into spec.
  109. * If the data for this EXIF tag is in of the wrong type or is in an invalid
  110. * format according to the EXIF specification, then it is converted to make it
  111. * valid. This may involve, for example, converting an EXIF_FORMAT_LONG into a
  112. * EXIF_FORMAT_SHORT. If the tag is unknown, its value is untouched.
  113. *
  114. * \note Unfortunately, some conversions are to a type with a more restricted
  115. * range, which could have the side effect that the converted data becomes
  116. * invalid. This is unlikely as the range of each tag in the standard is
  117. * designed to encompass all likely data.
  118. *
  119. * \param[in,out] entry EXIF entry
  120. */
  121. void exif_entry_fix (ExifEntry *entry);
  122. /* For your convenience */
  123. /*! Return a localized textual representation of the value of the EXIF entry.
  124. * This is meant for display to the user. The format of each tag is subject
  125. * to change between locales and in newer versions of libexif. Users who
  126. * require the tag data in an unambiguous form should access the data members
  127. * of the #ExifEntry structure directly.
  128. *
  129. * \warning The character set of the returned string may be in
  130. * the encoding of the current locale or the native encoding
  131. * of the camera.
  132. * \bug The EXIF_TAG_XP_* tags are currently always returned in UTF-8,
  133. * regardless of locale, and code points above U+FFFF are not
  134. * supported.
  135. *
  136. * \param[in] entry EXIF entry
  137. * \param[out] val buffer in which to store value
  138. * \param[in] maxlen length of the buffer val
  139. * \return val pointer
  140. */
  141. const char *exif_entry_get_value (ExifEntry *entry, char *val,
  142. unsigned int maxlen);
  143. /*! Dump text representation of #ExifEntry to stdout.
  144. * This is intended for diagnostic purposes only.
  145. *
  146. * \param[in] entry EXIF tag data
  147. * \param[in] indent how many levels deep to indent the data
  148. */
  149. void exif_entry_dump (ExifEntry *entry, unsigned int indent);
  150. /*! Return the IFD number of the given #ExifEntry
  151. *
  152. * \param[in] e an #ExifEntry*
  153. * \return #ExifIfd, or #EXIF_IFD_COUNT on error
  154. */
  155. #define exif_entry_get_ifd(e) ((e)?exif_content_get_ifd((e)->parent):EXIF_IFD_COUNT)
  156. #ifdef __cplusplus
  157. }
  158. #endif /* __cplusplus */
  159. #endif /* __EXIF_ENTRY_H__ */