3 * Copyright © 2001 Lutz Müller <lutz@users.sourceforge.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include <libexif/exif-mnote-data.h>
24 #include <libexif/exif-data.h>
25 #include <libexif/exif-ifd.h>
26 #include <libexif/exif-mnote-data-priv.h>
27 #include <libexif/exif-utils.h>
28 #include <libexif/exif-loader.h>
29 #include <libexif/exif-log.h>
31 #include <libjpeg/jpeg-marker.h>
33 #include <libexif/olympus/exif-mnote-data-olympus.h>
34 #include <libexif/canon/exif-mnote-data-canon.h>
35 #include <libexif/pentax/exif-mnote-data-pentax.h>
42 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
44 #if defined(__WATCOMC__) || defined(_MSC_VER)
45 # define strncasecmp strnicmp
48 static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
50 struct _ExifDataPrivate
59 unsigned int ref_count;
61 /* Temporarily used while loading data */
62 unsigned int offset_mnote;
66 exif_data_alloc (ExifData *data, unsigned int i)
70 if (!data || !i) return NULL;
72 d = exif_mem_alloc (data->priv->mem, i);
75 EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", i);
80 exif_data_get_mnote_data (ExifData *d)
82 return (d && d->priv) ? d->priv->md : NULL;
88 ExifMem *mem = exif_mem_new_default ();
89 ExifData *d = exif_data_new_mem (mem);
97 exif_data_new_mem (ExifMem *mem)
102 if (!mem) return NULL;
104 data = exif_mem_alloc (mem, sizeof (ExifData));
105 if (!data) return (NULL);
106 data->priv = exif_mem_alloc (mem, sizeof (ExifDataPrivate));
107 if (!data->priv) { exif_mem_free (mem, data); return (NULL); }
108 data->priv->ref_count = 1;
110 data->priv->mem = mem;
113 for (i = 0; i < EXIF_IFD_COUNT; i++) {
114 data->ifd[i] = exif_content_new_mem (data->priv->mem);
116 exif_data_free (data);
119 data->ifd[i]->parent = data;
126 exif_data_new_from_data (const unsigned char *data, unsigned int size)
130 edata = exif_data_new ();
131 exif_data_load_data (edata, data, size);
136 exif_data_load_data_entry (ExifData *data, ExifEntry *entry,
137 const unsigned char *d,
138 unsigned int size, unsigned int offset)
140 unsigned int s, doff;
142 entry->tag = exif_get_short (d + offset + 0, data->priv->order);
143 entry->format = exif_get_short (d + offset + 2, data->priv->order);
144 entry->components = exif_get_long (d + offset + 4, data->priv->order);
146 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
147 "Loading entry 0x%x ('%s')...", entry->tag,
148 exif_tag_get_name (entry->tag));
151 * Size? If bigger than 4 bytes, the actual data is not
152 * in the entry but somewhere else (offset).
154 s = exif_format_get_size (entry->format) * entry->components;
158 doff = exif_get_long (d + offset + 8, data->priv->order);
166 entry->data = exif_data_alloc (data, s);
169 memcpy (entry->data, d + doff, s);
172 /* If this is the MakerNote, remember the offset */
173 if (entry->tag == EXIF_TAG_MAKER_NOTE) {
174 if (entry->size > 6) exif_log (data->priv->log,
175 EXIF_LOG_CODE_DEBUG, "ExifData",
176 "MakerNote found (%02x %02x %02x %02x "
177 "%02x %02x %02x...).",
178 entry->data[0], entry->data[1], entry->data[2],
179 entry->data[3], entry->data[4], entry->data[5],
181 data->priv->offset_mnote = doff;
184 exif_entry_fix (entry);
188 exif_data_save_data_entry (ExifData *data, ExifEntry *e,
189 unsigned char **d, unsigned int *ds,
192 unsigned int doff, s;
194 if (!data || !data->priv) return;
197 * Each entry is 12 bytes long. The memory for the entry has
198 * already been allocated.
200 exif_set_short (*d + 6 + offset + 0,
201 data->priv->order, (ExifShort) e->tag);
202 exif_set_short (*d + 6 + offset + 2,
203 data->priv->order, (ExifShort) e->format);
205 #ifndef EXIF_DONT_CHANGE_MAKER_NOTE
206 /* If this is the maker note tag, update it. */
207 if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) {
208 exif_mem_free (data->priv->mem, e->data);
211 exif_mnote_data_set_offset (data->priv->md, *ds - 6);
212 exif_mnote_data_save (data->priv->md, &e->data, &e->size);
213 e->components = e->size;
217 exif_set_long (*d + 6 + offset + 4,
218 data->priv->order, e->components);
221 * Size? If bigger than 4 bytes, the actual data is not in
222 * the entry but somewhere else.
224 s = exif_format_get_size (e->format) * e->components;
228 *d = exif_mem_realloc (data->priv->mem, *d, *ds);
230 EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds);
233 exif_set_long (*d + 6 + offset + 8,
234 data->priv->order, doff);
238 /* Write the data. Fill unneeded bytes with 0. */
239 memcpy (*d + 6 + doff, e->data, s);
240 if (s < 4) memset (*d + 6 + doff + s, 0, (4 - s));
244 exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d,
245 unsigned int ds, ExifLong offset, ExifLong size)
247 if (ds < offset + size) {
248 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
249 "Bogus thumbnail offset and size: %i < %i + %i.",
250 (int) ds, (int) offset, (int) size);
253 if (data->data) exif_mem_free (data->priv->mem, data->data);
255 data->data = exif_data_alloc (data, data->size);
256 if (!data->data) return;
257 memcpy (data->data, d + offset, data->size);
261 #define CHECK_REC(i) \
262 if (data->ifd[(i)] == ifd) { \
263 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
264 "ExifData", "Recursive entry in IFD " \
265 "'%s' detected. Skipping...", \
266 exif_ifd_get_name (i)); \
269 if (data->ifd[(i)]->count) { \
270 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
271 "ExifData", "Attemt to load IFD " \
272 "'%s' multiple times detected. " \
274 exif_ifd_get_name (i)); \
279 exif_data_load_data_content (ExifData *data, ExifContent *ifd,
280 const unsigned char *d,
281 unsigned int ds, unsigned int offset)
283 ExifLong o, thumbnail_offset = 0, thumbnail_length = 0;
289 if (!data || !data->priv) return;
291 /* Read the number of entries */
292 if (offset >= ds - 1) return;
293 n = exif_get_short (d + offset, data->priv->order);
294 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
295 "Loading %i entries...", n);
298 /* Check if we have enough data. */
299 if (offset + 12 * n > ds) n = (ds - offset) / 12;
301 for (i = 0; i < n; i++) {
303 tag = exif_get_short (d + offset + 12 * i, data->priv->order);
305 case EXIF_TAG_EXIF_IFD_POINTER:
306 case EXIF_TAG_GPS_INFO_IFD_POINTER:
307 case EXIF_TAG_INTEROPERABILITY_IFD_POINTER:
308 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH:
309 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT:
310 o = exif_get_long (d + offset + 12 * i + 8,
313 case EXIF_TAG_EXIF_IFD_POINTER:
314 CHECK_REC (EXIF_IFD_EXIF);
315 exif_data_load_data_content (data,
316 data->ifd[EXIF_IFD_EXIF], d, ds, o);
318 case EXIF_TAG_GPS_INFO_IFD_POINTER:
319 CHECK_REC (EXIF_IFD_GPS);
320 exif_data_load_data_content (data,
321 data->ifd[EXIF_IFD_GPS], d, ds, o);
323 case EXIF_TAG_INTEROPERABILITY_IFD_POINTER:
324 CHECK_REC (EXIF_IFD_INTEROPERABILITY);
325 exif_data_load_data_content (data,
326 data->ifd[EXIF_IFD_INTEROPERABILITY], d, ds, o);
328 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT:
329 thumbnail_offset = o;
330 if (thumbnail_offset && thumbnail_length)
331 exif_data_load_data_thumbnail (data, d,
332 ds, thumbnail_offset,
335 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH:
336 thumbnail_length = o;
337 if (thumbnail_offset && thumbnail_length)
338 exif_data_load_data_thumbnail (data, d,
339 ds, thumbnail_offset,
349 * If we don't know the tag, changes are high
350 * that the EXIF data does not follow the standard.
352 if (!exif_tag_get_name (tag)) {
353 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
354 "Unknown tag %x (entry %i)", tag, i);
357 entry = exif_entry_new_mem (data->priv->mem);
358 exif_content_add_entry (ifd, entry);
359 exif_data_load_data_entry (data, entry, d, ds,
361 exif_entry_unref (entry);
368 exif_data_save_data_content (ExifData *data, ExifContent *ifd,
369 unsigned char **d, unsigned int *ds,
372 unsigned int j, n_ptr = 0, n_thumb = 0;
375 if (!data || !data->priv || !ifd || !d || !ds) return;
377 for (i = 0; i < EXIF_IFD_COUNT; i++)
378 if (ifd == data->ifd[i])
380 if (i == EXIF_IFD_COUNT)
384 * Check if we need some extra entries for pointers or the thumbnail.
390 * The pointer to IFD_EXIF is in IFD_0. The pointer to
391 * IFD_INTEROPERABILITY is in IFD_EXIF.
393 if (data->ifd[EXIF_IFD_EXIF]->count ||
394 data->ifd[EXIF_IFD_INTEROPERABILITY]->count)
397 /* The pointer to IFD_GPS is in IFD_0. */
398 if (data->ifd[EXIF_IFD_GPS]->count)
407 if (data->ifd[EXIF_IFD_INTEROPERABILITY]->count)
414 * Allocate enough memory for all entries
415 * and the number of entries.
417 *ds += (2 + (ifd->count + n_ptr + n_thumb) * 12 + 4);
418 *d = exif_mem_realloc (data->priv->mem, *d, *ds);
420 EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds);
424 /* Save the number of entries */
425 exif_set_short (*d + 6 + offset, data->priv->order,
426 (ExifShort) (ifd->count + n_ptr + n_thumb));
429 /* Save each entry */
430 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
431 "Saving %i entries (IFD '%s', offset: %i)...",
432 ifd->count, exif_ifd_get_name (i), offset);
433 for (j = 0; j < ifd->count; j++)
434 exif_data_save_data_entry (data, ifd->entries[j],
435 d, ds, offset + 12 * j);
436 offset += 12 * ifd->count;
438 /* Now save special entries. */
443 * The pointer to IFD_EXIF is in IFD_0.
444 * However, the pointer to IFD_INTEROPERABILITY is in IFD_EXIF,
445 * therefore, if IFD_INTEROPERABILITY is not empty, we need
446 * IFD_EXIF even if latter is empty.
448 if (data->ifd[EXIF_IFD_EXIF]->count ||
449 data->ifd[EXIF_IFD_INTEROPERABILITY]->count) {
450 exif_set_short (*d + 6 + offset + 0, data->priv->order,
451 EXIF_TAG_EXIF_IFD_POINTER);
452 exif_set_short (*d + 6 + offset + 2, data->priv->order,
454 exif_set_long (*d + 6 + offset + 4, data->priv->order,
456 exif_set_long (*d + 6 + offset + 8, data->priv->order,
458 exif_data_save_data_content (data,
459 data->ifd[EXIF_IFD_EXIF], d, ds, *ds - 6);
463 /* The pointer to IFD_GPS is in IFD_0, too. */
464 if (data->ifd[EXIF_IFD_GPS]->count) {
465 exif_set_short (*d + 6 + offset + 0, data->priv->order,
466 EXIF_TAG_GPS_INFO_IFD_POINTER);
467 exif_set_short (*d + 6 + offset + 2, data->priv->order,
469 exif_set_long (*d + 6 + offset + 4, data->priv->order,
471 exif_set_long (*d + 6 + offset + 8, data->priv->order,
473 exif_data_save_data_content (data,
474 data->ifd[EXIF_IFD_GPS], d, ds, *ds - 6);
482 * The pointer to IFD_INTEROPERABILITY is in IFD_EXIF.
485 if (data->ifd[EXIF_IFD_INTEROPERABILITY]->count) {
486 exif_set_short (*d + 6 + offset + 0, data->priv->order,
487 EXIF_TAG_INTEROPERABILITY_IFD_POINTER);
488 exif_set_short (*d + 6 + offset + 2, data->priv->order,
490 exif_set_long (*d + 6 + offset + 4, data->priv->order,
492 exif_set_long (*d + 6 + offset + 8, data->priv->order,
494 exif_data_save_data_content (data,
495 data->ifd[EXIF_IFD_INTEROPERABILITY], d, ds,
504 * Information about the thumbnail (if any) is saved in
509 /* EXIF_TAG_JPEG_INTERCHANGE_FORMAT */
510 exif_set_short (*d + 6 + offset + 0, data->priv->order,
511 EXIF_TAG_JPEG_INTERCHANGE_FORMAT);
512 exif_set_short (*d + 6 + offset + 2, data->priv->order,
514 exif_set_long (*d + 6 + offset + 4, data->priv->order,
516 exif_set_long (*d + 6 + offset + 8, data->priv->order,
519 *d = exif_mem_realloc (data->priv->mem, *d, *ds);
521 EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData",
525 memcpy (*d + *ds - data->size, data->data, data->size);
528 /* EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH */
529 exif_set_short (*d + 6 + offset + 0, data->priv->order,
530 EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
531 exif_set_short (*d + 6 + offset + 2, data->priv->order,
533 exif_set_long (*d + 6 + offset + 4, data->priv->order,
535 exif_set_long (*d + 6 + offset + 8, data->priv->order,
545 /* Correctly terminate the directory */
546 if (i == EXIF_IFD_0 && (data->ifd[EXIF_IFD_1]->count ||
550 * We are saving IFD 0. Tell where IFD 1 starts and save
553 exif_set_long (*d + 6 + offset, data->priv->order, *ds - 6);
554 exif_data_save_data_content (data, data->ifd[EXIF_IFD_1], d, ds,
557 exif_set_long (*d + 6 + offset, data->priv->order, 0);
561 EXIF_DATA_TYPE_MAKER_NOTE_NONE = 0,
562 EXIF_DATA_TYPE_MAKER_NOTE_CANON = 1,
563 EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS = 2,
564 EXIF_DATA_TYPE_MAKER_NOTE_PENTAX = 3
565 } ExifDataTypeMakerNote;
567 static ExifDataTypeMakerNote
568 exif_data_get_type_maker_note (ExifData *d)
573 if (!d) return EXIF_DATA_TYPE_MAKER_NOTE_NONE;
575 e = exif_data_get_entry (d, EXIF_TAG_MAKER_NOTE);
576 if (!e) return EXIF_DATA_TYPE_MAKER_NOTE_NONE;
578 /* Olympus & Nikon */
579 if ((e->size >= 5) && (!memcmp (e->data, "OLYMP", 5) ||
580 !memcmp (e->data, "Nikon", 5)))
581 return EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS;
583 em = exif_data_get_entry (d, EXIF_TAG_MAKE);
584 if (!em) return EXIF_DATA_TYPE_MAKER_NOTE_NONE;
587 if (!strcmp (exif_entry_get_value (em, value, sizeof(value)), "Canon"))
588 return EXIF_DATA_TYPE_MAKER_NOTE_CANON;
590 /* Pentax & some variant of Nikon */
591 if ((e->size >= 2) && (e->data[0] == 0x00) && (e->data[1] == 0x1b)) {
593 exif_entry_get_value (em, value, sizeof(value)),
595 return EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS;
597 return EXIF_DATA_TYPE_MAKER_NOTE_PENTAX;
600 return EXIF_DATA_TYPE_MAKER_NOTE_NONE;
604 exif_data_load_data (ExifData *data, const unsigned char *d_orig,
605 unsigned int ds_orig)
610 const unsigned char *d = d_orig;
611 unsigned int ds = ds_orig, len;
613 if (!data || !data->priv || !d || !ds) return;
615 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
616 "Parsing %i byte(s) EXIF data...\n", ds);
619 * It can be that the data starts with the EXIF header. If it does
620 * not, search the EXIF marker.
623 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
627 if (!memcmp (d, ExifHeader, 6)) {
628 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
629 "Found EXIF header.");
632 while ((d[0] == 0xff) && ds) {
637 /* JPEG_MARKER_SOI */
638 if (d[0] == JPEG_MARKER_SOI) {
644 /* JPEG_MARKER_APP0 */
645 if (d[0] == JPEG_MARKER_APP0) {
648 l = (d[0] << 8) | d[1];
656 /* JPEG_MARKER_APP1 */
657 if (d[0] == JPEG_MARKER_APP1)
660 /* Unknown marker or data. Give up. */
661 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
662 "ExifData", "EXIF marker not found.");
668 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
669 "ExifData", "Size too small.");
672 len = (d[0] << 8) | d[1];
673 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
674 "We have to deal with %i byte(s) of EXIF data.",
681 * Verify the exif header
682 * (offset 2, length 6).
685 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
689 if (memcmp (d, ExifHeader, 6)) {
690 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
691 "EXIF header not found.");
695 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
696 "Found EXIF header.");
698 /* Byte order (offset 6, length 2) */
701 if (!memcmp (d + 6, "II", 2))
702 data->priv->order = EXIF_BYTE_ORDER_INTEL;
703 else if (!memcmp (d + 6, "MM", 2))
704 data->priv->order = EXIF_BYTE_ORDER_MOTOROLA;
709 if (exif_get_short (d + 8, data->priv->order) != 0x002a)
713 offset = exif_get_long (d + 10, data->priv->order);
714 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
715 "IFD 0 at %i.", (int) offset);
717 /* Parse the actual exif data (offset 14) */
718 exif_data_load_data_content (data, data->ifd[EXIF_IFD_0], d + 6,
722 n = exif_get_short (d + 6 + offset, data->priv->order);
723 offset = exif_get_long (d + 6 + offset + 2 + 12 * n, data->priv->order);
725 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
726 "IFD 1 at %i.", (int) offset);
729 if (offset > ds - 6) {
730 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
731 "ExifData", "Bogus offset!");
735 exif_data_load_data_content (data, data->ifd[EXIF_IFD_1], d + 6,
740 * If we got an EXIF_TAG_MAKER_NOTE, try to interpret it. Some
741 * cameras use pointers in the maker note tag that point to the
742 * space between IFDs. Here is the only place where we have access
745 switch (exif_data_get_type_maker_note (data)) {
746 case EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS:
747 data->priv->md = exif_mnote_data_olympus_new (data->priv->mem);
749 case EXIF_DATA_TYPE_MAKER_NOTE_PENTAX:
750 data->priv->md = exif_mnote_data_pentax_new (data->priv->mem);
752 case EXIF_DATA_TYPE_MAKER_NOTE_CANON:
753 data->priv->md = exif_mnote_data_canon_new (data->priv->mem);
760 * If we are able to interpret the maker note, do so.
762 if (data->priv->md) {
763 exif_mnote_data_log (data->priv->md, data->priv->log);
764 exif_mnote_data_set_byte_order (data->priv->md,
766 exif_mnote_data_set_offset (data->priv->md,
767 data->priv->offset_mnote);
768 exif_mnote_data_load (data->priv->md, d, ds);
773 exif_data_save_data (ExifData *data, unsigned char **d, unsigned int *ds)
775 if (!data || !d || !ds)
780 *d = exif_data_alloc (data, *ds);
782 memcpy (*d, ExifHeader, 6);
784 /* Order (offset 6) */
785 if (data->priv->order == EXIF_BYTE_ORDER_INTEL) {
786 memcpy (*d + 6, "II", 2);
788 memcpy (*d + 6, "MM", 2);
791 /* Fixed value (2 bytes, offset 8) */
792 exif_set_short (*d + 8, data->priv->order, 0x002a);
795 * IFD 0 offset (4 bytes, offset 10).
796 * We will start 8 bytes after the
797 * EXIF header (2 bytes for order, another 2 for the test, and
798 * 4 bytes for the IFD 0 offset make 8 bytes together).
800 exif_set_long (*d + 10, data->priv->order, 8);
802 /* Now save IFD 0. IFD 1 will be saved automatically. */
803 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
805 exif_data_save_data_content (data, data->ifd[EXIF_IFD_0], d, ds,
807 exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
808 "Saved %i byte(s) EXIF data.", *ds);
812 exif_data_new_from_file (const char *path)
817 loader = exif_loader_new ();
818 exif_loader_write_file (loader, path);
819 edata = exif_loader_get_data (loader);
820 exif_loader_unref (loader);
826 exif_data_ref (ExifData *data)
831 data->priv->ref_count++;
835 exif_data_unref (ExifData *data)
839 data->priv->ref_count--;
840 if (!data->priv->ref_count) exif_data_free (data);
844 exif_data_free (ExifData *data)
847 ExifMem *mem = (data && data->priv) ? data->priv->mem : NULL;
851 for (i = 0; i < EXIF_IFD_COUNT; i++) {
853 exif_content_unref (data->ifd[i]);
859 exif_mem_free (mem, data->data);
864 if (data->priv->log) {
865 exif_log_unref (data->priv->log);
866 data->priv->log = NULL;
868 if (data->priv->md) {
869 exif_mnote_data_unref (data->priv->md);
870 data->priv->md = NULL;
872 exif_mem_free (mem, data->priv);
873 exif_mem_free (mem, data);
876 exif_mem_unref (mem);
880 exif_data_dump (ExifData *data)
887 for (i = 0; i < EXIF_IFD_COUNT; i++) {
888 if (data->ifd[i] && data->ifd[i]->count) {
889 printf ("Dumping IFD '%s'...\n",
890 exif_ifd_get_name (i));
891 exif_content_dump (data->ifd[i], 0);
896 printf ("%i byte(s) thumbnail data available.", data->size);
897 if (data->size >= 4) {
898 printf ("0x%02x 0x%02x ... 0x%02x 0x%02x\n",
899 data->data[0], data->data[1],
900 data->data[data->size - 2],
901 data->data[data->size - 1]);
907 exif_data_get_byte_order (ExifData *data)
912 return (data->priv->order);
916 exif_data_foreach_content (ExifData *data, ExifDataForeachContentFunc func,
924 for (i = 0; i < EXIF_IFD_COUNT; i++)
925 func (data->ifd[i], user_data);
928 typedef struct _ByteOrderChangeData ByteOrderChangeData;
929 struct _ByteOrderChangeData {
930 ExifByteOrder old, new;
934 entry_set_byte_order (ExifEntry *e, void *data)
936 ByteOrderChangeData *d = data;
948 case EXIF_FORMAT_SHORT:
949 for (i = 0; i < e->components; i++) {
950 s = exif_get_short (e->data +
951 (i * exif_format_get_size (e->format)),
953 exif_set_short (e->data +
954 (i * exif_format_get_size (e->format)),
958 case EXIF_FORMAT_LONG:
959 for (i = 0; i < e->components; i++) {
960 l = exif_get_long (e->data +
961 (i * exif_format_get_size (e->format)),
963 exif_set_long (e->data +
964 (i * exif_format_get_size (e->format)),
968 case EXIF_FORMAT_RATIONAL:
969 for (i = 0; i < e->components; i++) {
970 r = exif_get_rational (e->data +
971 (i * exif_format_get_size (e->format)),
973 exif_set_rational (e->data +
974 (i * exif_format_get_size (e->format)),
978 case EXIF_FORMAT_SLONG:
979 for (i = 0; i < e->components; i++) {
980 sl = exif_get_slong (e->data +
981 (i * exif_format_get_size (e->format)),
983 exif_set_slong (e->data +
984 (i * exif_format_get_size (e->format)),
988 case EXIF_FORMAT_SRATIONAL:
989 for (i = 0; i < e->components; i++) {
990 sr = exif_get_srational (e->data +
991 (i * exif_format_get_size (e->format)),
993 exif_set_srational (e->data +
994 (i * exif_format_get_size (e->format)),
998 case EXIF_FORMAT_UNDEFINED:
999 case EXIF_FORMAT_BYTE:
1000 case EXIF_FORMAT_SBYTE:
1001 case EXIF_FORMAT_ASCII:
1009 content_set_byte_order (ExifContent *content, void *data)
1011 exif_content_foreach_entry (content, entry_set_byte_order, data);
1015 exif_data_set_byte_order (ExifData *data, ExifByteOrder order)
1017 ByteOrderChangeData d;
1019 if (!data || (order == data->priv->order))
1022 d.old = data->priv->order;
1024 exif_data_foreach_content (data, content_set_byte_order, &d);
1025 data->priv->order = order;
1027 exif_mnote_data_set_byte_order (data->priv->md, order);
1031 exif_data_log (ExifData *data, ExifLog *log)
1033 if (!data || !data->priv) return;
1034 exif_log_unref (data->priv->log);
1035 data->priv->log = log;
1039 /* Used internally within libexif */
1040 ExifLog *exif_data_get_log (ExifData *);
1042 exif_data_get_log (ExifData *data)
1044 if (!data || !data->priv) return NULL;
1045 return data->priv->log;