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 23 #ifndef LIBEXIF_EXIF_ENTRY_H 24 #define LIBEXIF_EXIF_ENTRY_H 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 30 /*! Data found in one EXIF tag. 31 * The #exif_entry_get_value function can provide access to the 32 * formatted contents, or the struct members can be used directly to 33 * access the raw contents. 34 */ 35 typedef struct _ExifEntry ExifEntry; 36 typedef struct _ExifEntryPrivate ExifEntryPrivate; 37 38 #include <libexif/exif-content.h> 39 #include <libexif/exif-format.h> 40 #include <libexif/exif-mem.h> 41 42 /*! Data found in one EXIF tag */ 43 struct _ExifEntry { 44 /*! EXIF tag for this entry */ 45 ExifTag tag; 46 47 /*! Type of data in this entry */ 48 ExifFormat format; 49 50 /*! Number of elements in the array, if this is an array entry. 51 * Contains 1 for non-array data types. */ 52 unsigned long components; 53 54 /*! Pointer to the raw EXIF data for this entry. It is allocated 55 * by #exif_entry_initialize and is NULL beforehand. Data contained 56 * here may be manipulated using the functions in exif-utils.h */ 57 unsigned char *data; 58 59 /*! Number of bytes in the buffer at \c data. This must be no less 60 * than exif_format_get_size(format)*components */ 61 unsigned int size; 62 63 unsigned long offset; 64 65 /*! #ExifContent containing this entry. 66 * \see exif_entry_get_ifd */ 67 ExifContent *parent; 68 69 /*! Internal data to be used by libexif itself */ 70 ExifEntryPrivate *priv; 71 }; 72 73 /* Lifecycle */ 74 75 /*! Reserve memory for and initialize a new #ExifEntry. 76 * No memory is allocated for the \c data element of the returned #ExifEntry. 77 * 78 * \return new allocated #ExifEntry, or NULL on error 79 * 80 * \see exif_entry_new_mem, exif_entry_unref 81 */ 82 ExifEntry *exif_entry_new (void); 83 84 /*! Reserve memory for and initialize new #ExifEntry using the specified 85 * memory allocator. 86 * No memory is allocated for the \c data element of the returned #ExifEntry. 87 * 88 * \return new allocated #ExifEntry, or NULL on error 89 * 90 * \see exif_entry_new, exif_entry_unref 91 */ 92 ExifEntry *exif_entry_new_mem (ExifMem *); 93 94 /*! Increase reference counter for #ExifEntry. 95 * 96 * \param[in] entry #ExifEntry 97 * 98 * \see exif_entry_unref 99 */ 100 void exif_entry_ref (ExifEntry *entry); 101 102 /*! Decrease reference counter for #ExifEntry. 103 * When the reference count drops to zero, free the entry. 104 * 105 * \param[in] entry #ExifEntry 106 */ 107 void exif_entry_unref (ExifEntry *entry); 108 109 /*! Actually free the #ExifEntry. 110 * 111 * \deprecated Should not be called directly. Use #exif_entry_ref and 112 * #exif_entry_unref instead. 113 * 114 * \param[in] entry EXIF entry 115 */ 116 void exif_entry_free (ExifEntry *entry); 117 118 /*! Initialize an empty #ExifEntry with default data in the correct format 119 * for the given tag. If the entry is already initialized, this function 120 * does nothing. 121 * This call allocates memory for the \c data element of the given #ExifEntry. 122 * That memory is freed at the same time as the #ExifEntry. 123 * 124 * \param[out] e entry to initialize 125 * \param[in] tag tag number to initialize as 126 */ 127 void exif_entry_initialize (ExifEntry *e, ExifTag tag); 128 129 /*! Fix the type or format of the given EXIF entry to bring it into spec. 130 * If the data for this EXIF tag is in of the wrong type or is in an invalid 131 * format according to the EXIF specification, then it is converted to make it 132 * valid. This may involve, for example, converting an EXIF_FORMAT_LONG into a 133 * EXIF_FORMAT_SHORT. If the tag is unknown, its value is untouched. 134 * 135 * \note Unfortunately, some conversions are to a type with a more restricted 136 * range, which could have the side effect that the converted data becomes 137 * invalid. This is unlikely as the range of each tag in the standard is 138 * designed to encompass all likely data. 139 * 140 * \param[in,out] entry EXIF entry 141 */ 142 void exif_entry_fix (ExifEntry *entry); 143 144 145 /* For your convenience */ 146 147 /*! Return a localized textual representation of the value of the EXIF entry. 148 * This is meant for display to the user. The format of each tag is subject 149 * to change between locales and in newer versions of libexif. Users who 150 * require the tag data in an unambiguous form should access the data members 151 * of the #ExifEntry structure directly. 152 * 153 * \warning The character set of the returned string may be in 154 * the encoding of the current locale or the native encoding 155 * of the camera. 156 * \bug The EXIF_TAG_XP_* tags are currently always returned in UTF-8, 157 * regardless of locale, and code points above U+FFFF are not 158 * supported. 159 * 160 * \param[in] entry EXIF entry 161 * \param[out] val buffer in which to store value; if entry is valid and 162 * maxlen > 0 then this string will be NUL-terminated 163 * \param[in] maxlen length of the buffer val 164 * \return val pointer 165 */ 166 const char *exif_entry_get_value (ExifEntry *entry, char *val, 167 unsigned int maxlen); 168 169 /*! Dump text representation of #ExifEntry to stdout. 170 * This is intended for diagnostic purposes only. 171 * 172 * \param[in] entry EXIF tag data 173 * \param[in] indent how many levels deep to indent the data 174 */ 175 void exif_entry_dump (ExifEntry *entry, unsigned int indent); 176 177 /*! Return the IFD number of the given #ExifEntry 178 * 179 * \param[in] e an #ExifEntry* 180 * \return #ExifIfd, or #EXIF_IFD_COUNT on error 181 */ 182 #define exif_entry_get_ifd(e) ((e)?exif_content_get_ifd((e)->parent):EXIF_IFD_COUNT) 183 184 #ifdef __cplusplus 185 } 186 #endif /* __cplusplus */ 187 188 #endif /* !defined(LIBEXIF_EXIF_ENTRY_H) */ 189