EXIF library (libexif) Internals  0.6.24
exif-data.c
Go to the documentation of this file.
1 /* exif-data.c
2  *
3  * Copyright (c) 2001 Lutz Mueller <lutz@users.sourceforge.net>
4  *
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.
9  *
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.
14  *
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., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA.
19  */
20 
21 #include <config.h>
22 
24 #include <libexif/exif-data.h>
25 #include <libexif/exif-ifd.h>
27 #include <libexif/exif-utils.h>
28 #include <libexif/exif-loader.h>
29 #include <libexif/exif-log.h>
30 #include <libexif/i18n.h>
31 #include <libexif/exif-system.h>
32 
38 
39 #include <math.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 
44 #undef JPEG_MARKER_SOI
45 #define JPEG_MARKER_SOI 0xd8
46 #undef JPEG_MARKER_APP0
47 #define JPEG_MARKER_APP0 0xe0
48 #undef JPEG_MARKER_APP1
49 #define JPEG_MARKER_APP1 0xe1
50 
51 #define CHECKOVERFLOW(offset,datasize,structsize) (( offset >= datasize) || (structsize > datasize) || (offset > datasize - structsize ))
52 
53 static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
54 
56 {
58 
60 
63 
64  unsigned int ref_count;
65 
66  /* Temporarily used while loading data */
67  unsigned int offset_mnote;
68 
71 };
72 
73 static void *
74 exif_data_alloc (ExifData *data, unsigned int i)
75 {
76  void *d;
77 
78  if (!data || !i)
79  return NULL;
80 
81  d = exif_mem_alloc (data->priv->mem, i);
82  if (d)
83  return d;
84 
85  EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", i);
86  return NULL;
87 }
88 
91 {
92  return (d && d->priv) ? d->priv->md : NULL;
93 }
94 
95 ExifData *
97 {
98  ExifMem *mem = exif_mem_new_default ();
99  ExifData *d = exif_data_new_mem (mem);
100 
101  exif_mem_unref (mem);
102 
103  return d;
104 }
105 
106 ExifData *
108 {
109  ExifData *data;
110  unsigned int i;
111 
112  if (!mem)
113  return NULL;
114 
115  data = exif_mem_alloc (mem, sizeof (ExifData));
116  if (!data)
117  return (NULL);
118  data->priv = exif_mem_alloc (mem, sizeof (ExifDataPrivate));
119  if (!data->priv) {
120  exif_mem_free (mem, data);
121  return (NULL);
122  }
123  data->priv->ref_count = 1;
124 
125  data->priv->mem = mem;
126  exif_mem_ref (mem);
127 
128  for (i = 0; i < EXIF_IFD_COUNT; i++) {
129  data->ifd[i] = exif_content_new_mem (data->priv->mem);
130  if (!data->ifd[i]) {
131  exif_data_free (data);
132  return (NULL);
133  }
134  data->ifd[i]->parent = data;
135  }
136 
137  /* Default options */
138 #ifndef NO_VERBOSE_TAG_STRINGS
139  /*
140  * When the tag list is compiled away, setting this option prevents
141  * any tags from being loaded
142  */
144 #endif
146 
147  /* Default data type: none */
149 
150  return (data);
151 }
152 
153 ExifData *
154 exif_data_new_from_data (const unsigned char *data, unsigned int size)
155 {
156  ExifData *edata;
157 
158  edata = exif_data_new ();
159  exif_data_load_data (edata, data, size);
160  return (edata);
161 }
162 
163 static int
165  const unsigned char *d,
166  unsigned int size, unsigned int offset)
167 {
168  unsigned int s, doff;
169 
170  entry->tag = exif_get_short (d + offset + 0, data->priv->order);
171  entry->format = exif_get_short (d + offset + 2, data->priv->order);
172  entry->components = exif_get_long (d + offset + 4, data->priv->order);
173 
174  /* FIXME: should use exif_tag_get_name_in_ifd here but entry->parent
175  * has not been set yet
176  */
177  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
178  "Loading entry 0x%x ('%s')...", entry->tag,
179  exif_tag_get_name (entry->tag));
180 
181  /* {0,1,2,4,8} x { 0x00000000 .. 0xffffffff }
182  * -> { 0x000000000 .. 0x7fffffff8 } */
183  s = exif_format_get_size(entry->format) * entry->components;
184  if ((s < entry->components) || (s == 0)){
185  return 0;
186  }
187 
188  /*
189  * Size? If bigger than 4 bytes, the actual data is not
190  * in the entry but somewhere else (offset).
191  */
192  if (s > 4)
193  doff = exif_get_long (d + offset + 8, data->priv->order);
194  else
195  doff = offset + 8;
196 
197  /* Sanity checks */
198  if (doff >= size) {
199  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
200  "Tag starts past end of buffer (%u > %u)", doff, size);
201  return 0;
202  }
203 
204  if (s > size - doff) {
205  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
206  "Tag data goes past end of buffer (%u > %u)", doff+s, size);
207  return 0;
208  }
209 
210  entry->data = exif_data_alloc (data, s);
211  if (entry->data) {
212  entry->size = s;
213  memcpy (entry->data, d + doff, s);
214  } else {
215  EXIF_LOG_NO_MEMORY(data->priv->log, "ExifData", s);
216  return 0;
217  }
218 
219  /* If this is the MakerNote, remember the offset */
220  if (entry->tag == EXIF_TAG_MAKER_NOTE) {
221  if (!entry->data) {
222  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
223  "MakerNote found with empty data");
224  } else if (entry->size > 6) {
225  exif_log (data->priv->log,
226  EXIF_LOG_CODE_DEBUG, "ExifData",
227  "MakerNote found (%02x %02x %02x %02x "
228  "%02x %02x %02x...).",
229  entry->data[0], entry->data[1], entry->data[2],
230  entry->data[3], entry->data[4], entry->data[5],
231  entry->data[6]);
232  }
233  data->priv->offset_mnote = doff;
234  }
235  return 1;
236 }
237 
238 static void
240  unsigned char **d, unsigned int *ds,
241  unsigned int offset)
242 {
243  unsigned int doff, s;
244  unsigned int ts;
245 
246  if (!data || !data->priv)
247  return;
248 
249  /*
250  * Each entry is 12 bytes long. The memory for the entry has
251  * already been allocated.
252  */
253  exif_set_short (*d + 6 + offset + 0,
254  data->priv->order, (ExifShort) e->tag);
255  exif_set_short (*d + 6 + offset + 2,
256  data->priv->order, (ExifShort) e->format);
257 
259  /* If this is the maker note tag, update it. */
260  if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) {
261  /* TODO: this is using the wrong ExifMem to free e->data */
262  exif_mem_free (data->priv->mem, e->data);
263  e->data = NULL;
264  e->size = 0;
265  exif_mnote_data_set_offset (data->priv->md, *ds - 6);
266  exif_mnote_data_save (data->priv->md, &e->data, &e->size);
267  e->components = e->size;
268  if (exif_format_get_size (e->format) != 1) {
269  /* e->format is taken from input code,
270  * but we need to make sure it is a 1 byte
271  * entity due to the multiplication below. */
273  }
274  }
275  }
276 
277  exif_set_long (*d + 6 + offset + 4,
278  data->priv->order, e->components);
279 
280  /*
281  * Size? If bigger than 4 bytes, the actual data is not in
282  * the entry but somewhere else.
283  */
284  s = exif_format_get_size (e->format) * e->components;
285  if (s > 4) {
286  unsigned char *t;
287  doff = *ds - 6;
288  ts = *ds + s;
289 
290  /*
291  * According to the TIFF specification,
292  * the offset must be an even number. If we need to introduce
293  * a padding byte, we set it to 0.
294  */
295  if (s & 1)
296  ts++;
297  t = exif_mem_realloc (data->priv->mem, *d, ts);
298  if (!t) {
299  EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", ts);
300  return;
301  }
302  *d = t;
303  *ds = ts;
304  exif_set_long (*d + 6 + offset + 8, data->priv->order, doff);
305  if (s & 1)
306  *(*d + *ds - 1) = '\0';
307 
308  } else
309  doff = offset + 8;
310 
311  /* Write the data. Fill unneeded bytes with 0. Do not crash with
312  * e->data is NULL */
313  if (e->data) {
314  unsigned int len = s;
315  if (e->size < s) len = e->size;
316  memcpy (*d + 6 + doff, e->data, len);
317  } else {
318  memset (*d + 6 + doff, 0, s);
319  }
320  if (s < 4)
321  memset (*d + 6 + doff + s, 0, (4 - s));
322 }
323 
324 static void
325 exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d,
326  unsigned int ds, ExifLong o, ExifLong s)
327 {
328  /* Sanity checks */
329  if (o >= ds) {
330  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail offset (%u).", o);
331  return;
332  }
333  if (CHECKOVERFLOW(o,ds,s)) {
334  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail size (%u), max would be %u.", s, ds-o);
335  return;
336  }
337  if (data->data)
338  exif_mem_free (data->priv->mem, data->data);
339  if (!(data->data = exif_data_alloc (data, s))) {
340  EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", s);
341  data->size = 0;
342  return;
343  }
344  data->size = s;
345  memcpy (data->data, d + o, s);
346 }
347 
348 #undef CHECK_REC
349 #define CHECK_REC(i) \
350 if ((i) == ifd) { \
351  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
352  "ExifData", "Recursive entry in IFD " \
353  "'%s' detected. Skipping...", \
354  exif_ifd_get_name (i)); \
355  break; \
356 } \
357 if (data->ifd[(i)]->count) { \
358  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
359  "ExifData", "Attempt to load IFD " \
360  "'%s' multiple times detected. " \
361  "Skipping...", \
362  exif_ifd_get_name (i)); \
363  break; \
364 }
365 
371 static unsigned int
372 level_cost(unsigned int n)
373 {
374  static const double log_1_1 = 0.09531017980432493;
375 
376  /* Adding 0.1 protects against the case where n==1 */
377  return ceil(log(n + 0.1)/log_1_1);
378 }
379 
390 static void
392  const unsigned char *d,
393  unsigned int ds, unsigned int offset, unsigned int recursion_cost)
394 {
395  ExifLong o, thumbnail_offset = 0, thumbnail_length = 0;
396  ExifShort n;
397  ExifEntry *entry;
398  unsigned int i;
399  ExifTag tag;
400 
401  if (!data || !data->priv)
402  return;
403 
404  /* check for valid ExifIfd enum range */
405  if ((((int)ifd) < 0) || ( ((int)ifd) >= EXIF_IFD_COUNT))
406  return;
407 
408  if (recursion_cost > 170) {
409  /*
410  * recursion_cost is a logarithmic-scale indicator of how expensive this
411  * recursive call might end up being. It is an indicator of the depth of
412  * recursion as well as the potential for worst-case future recursive
413  * calls. Since it's difficult to tell ahead of time how often recursion
414  * will occur, this assumes the worst by assuming every tag could end up
415  * causing recursion.
416  * The value of 170 was chosen to limit typical EXIF structures to a
417  * recursive depth of about 6, but pathological ones (those with very
418  * many tags) to only 2.
419  */
420  exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData",
421  "Deep/expensive recursion detected!");
422  return;
423  }
424 
425  /* Read the number of entries */
426  if (CHECKOVERFLOW(offset, ds, 2)) {
427  exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData",
428  "Tag data past end of buffer (%u+2 > %u)", offset, ds);
429  return;
430  }
431  n = exif_get_short (d + offset, data->priv->order);
432  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
433  "Loading %hu entries...", n);
434  offset += 2;
435 
436  /* Check if we have enough data. */
437  if (CHECKOVERFLOW(offset, ds, 12*n)) {
438  n = (ds - offset) / 12;
439  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
440  "Short data; only loading %hu entries...", n);
441  }
442 
443  for (i = 0; i < n; i++) {
444 
445  tag = exif_get_short (d + offset + 12 * i, data->priv->order);
446  switch (tag) {
452  o = exif_get_long (d + offset + 12 * i + 8,
453  data->priv->order);
454  if (o >= ds) {
455  exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData",
456  "Tag data past end of buffer (%u > %u)", offset+2, ds);
457  return;
458  }
459  /* FIXME: IFD_POINTER tags aren't marked as being in a
460  * specific IFD, so exif_tag_get_name_in_ifd won't work
461  */
462  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
463  "Sub-IFD entry 0x%x ('%s') at %u.", tag,
464  exif_tag_get_name(tag), o);
465  switch (tag) {
469  recursion_cost + level_cost(n));
470  break;
473  exif_data_load_data_content (data, EXIF_IFD_GPS, d, ds, o,
474  recursion_cost + level_cost(n));
475  break;
479  recursion_cost + level_cost(n));
480  break;
482  thumbnail_offset = o;
483  if (thumbnail_offset && thumbnail_length)
485  ds, thumbnail_offset,
486  thumbnail_length);
487  break;
489  thumbnail_length = o;
490  if (thumbnail_offset && thumbnail_length)
492  ds, thumbnail_offset,
493  thumbnail_length);
494  break;
495  default:
496  return;
497  }
498  break;
499  default:
500 
501  /*
502  * If we don't know the tag, don't fail. It could be that new
503  * versions of the standard have defined additional tags. Note that
504  * 0 is a valid tag in the GPS IFD.
505  */
506  if (!exif_tag_get_name_in_ifd (tag, ifd)) {
507 
508  /*
509  * Special case: Tag and format 0. That's against specification
510  * (at least up to 2.2). But Photoshop writes it anyways.
511  */
512  if (!memcmp (d + offset + 12 * i, "\0\0\0\0", 4)) {
513  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
514  "Skipping empty entry at position %u in '%s'.", i,
516  break;
517  }
518  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
519  "Unknown tag 0x%04x (entry %u in '%s'). Please report this tag "
520  "to <libexif-devel@lists.sourceforge.net>.", tag, i,
523  break;
524  }
525  entry = exif_entry_new_mem (data->priv->mem);
526  if (!entry) {
527  exif_log (data->priv->log, EXIF_LOG_CODE_NO_MEMORY, "ExifData",
528  "Could not allocate memory");
529  return;
530  }
531  if (exif_data_load_data_entry (data, entry, d, ds,
532  offset + 12 * i))
533  exif_content_add_entry (data->ifd[ifd], entry);
534  exif_entry_unref (entry);
535  break;
536  }
537  }
538 }
539 
540 static int
541 cmp_func (const unsigned char *p1, const unsigned char *p2, ExifByteOrder o)
542 {
543  ExifShort tag1 = exif_get_short (p1, o);
544  ExifShort tag2 = exif_get_short (p2, o);
545 
546  return (tag1 < tag2) ? -1 : (tag1 > tag2) ? 1 : 0;
547 }
548 
549 static int
550 cmp_func_intel (const void *elem1, const void *elem2)
551 {
552  return cmp_func ((const unsigned char *) elem1,
553  (const unsigned char *) elem2, EXIF_BYTE_ORDER_INTEL);
554 }
555 
556 static int
557 cmp_func_motorola (const void *elem1, const void *elem2)
558 {
559  return cmp_func ((const unsigned char *) elem1,
560  (const unsigned char *) elem2, EXIF_BYTE_ORDER_MOTOROLA);
561 }
562 
563 static void
565  unsigned char **d, unsigned int *ds,
566  unsigned int offset)
567 {
568  unsigned int j, n_ptr = 0, n_thumb = 0;
569  ExifIfd i;
570  unsigned char *t;
571  unsigned int ts;
572 
573  if (!data || !data->priv || !ifd || !d || !ds)
574  return;
575 
576  for (i = 0; i < EXIF_IFD_COUNT; i++)
577  if (ifd == data->ifd[i])
578  break;
579  if (i == EXIF_IFD_COUNT)
580  return; /* error */
581 
582  /*
583  * Check if we need some extra entries for pointers or the thumbnail.
584  */
585  switch (i) {
586  case EXIF_IFD_0:
587 
588  /*
589  * The pointer to IFD_EXIF is in IFD_0. The pointer to
590  * IFD_INTEROPERABILITY is in IFD_EXIF.
591  */
592  if (data->ifd[EXIF_IFD_EXIF]->count ||
594  n_ptr++;
595 
596  /* The pointer to IFD_GPS is in IFD_0. */
597  if (data->ifd[EXIF_IFD_GPS]->count)
598  n_ptr++;
599 
600  break;
601  case EXIF_IFD_1:
602  if (data->size)
603  n_thumb = 2;
604  break;
605  case EXIF_IFD_EXIF:
606  if (data->ifd[EXIF_IFD_INTEROPERABILITY]->count)
607  n_ptr++;
608  default:
609  break;
610  }
611 
612  /*
613  * Allocate enough memory for all entries
614  * and the number of entries.
615  */
616  ts = *ds + (2 + (ifd->count + n_ptr + n_thumb) * 12 + 4);
617  t = exif_mem_realloc (data->priv->mem, *d, ts);
618  if (!t) {
619  EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", ts);
620  return;
621  }
622  *d = t;
623  *ds = ts;
624 
625  /* Save the number of entries */
626  exif_set_short (*d + 6 + offset, data->priv->order,
627  (ExifShort) (ifd->count + n_ptr + n_thumb));
628  offset += 2;
629 
630  /*
631  * Save each entry. Make sure that no memcpys from NULL pointers are
632  * performed
633  */
634  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
635  "Saving %i entries (IFD '%s', offset: %i)...",
636  ifd->count, exif_ifd_get_name (i), offset);
637  for (j = 0; j < ifd->count; j++) {
638  if (ifd->entries[j]) {
639  exif_data_save_data_entry (data, ifd->entries[j], d, ds,
640  offset + 12 * j);
641  }
642  }
643 
644  offset += 12 * ifd->count;
645 
646  /* Now save special entries. */
647  switch (i) {
648  case EXIF_IFD_0:
649 
650  /*
651  * The pointer to IFD_EXIF is in IFD_0.
652  * However, the pointer to IFD_INTEROPERABILITY is in IFD_EXIF,
653  * therefore, if IFD_INTEROPERABILITY is not empty, we need
654  * IFD_EXIF even if latter is empty.
655  */
656  if (data->ifd[EXIF_IFD_EXIF]->count ||
658  exif_set_short (*d + 6 + offset + 0, data->priv->order,
660  exif_set_short (*d + 6 + offset + 2, data->priv->order,
662  exif_set_long (*d + 6 + offset + 4, data->priv->order,
663  1);
664  exif_set_long (*d + 6 + offset + 8, data->priv->order,
665  *ds - 6);
667  data->ifd[EXIF_IFD_EXIF], d, ds, *ds - 6);
668  offset += 12;
669  }
670 
671  /* The pointer to IFD_GPS is in IFD_0, too. */
672  if (data->ifd[EXIF_IFD_GPS]->count) {
673  exif_set_short (*d + 6 + offset + 0, data->priv->order,
675  exif_set_short (*d + 6 + offset + 2, data->priv->order,
677  exif_set_long (*d + 6 + offset + 4, data->priv->order,
678  1);
679  exif_set_long (*d + 6 + offset + 8, data->priv->order,
680  *ds - 6);
682  data->ifd[EXIF_IFD_GPS], d, ds, *ds - 6);
683  offset += 12;
684  }
685 
686  break;
687  case EXIF_IFD_EXIF:
688 
689  /*
690  * The pointer to IFD_INTEROPERABILITY is in IFD_EXIF.
691  * See note above.
692  */
693  if (data->ifd[EXIF_IFD_INTEROPERABILITY]->count) {
694  exif_set_short (*d + 6 + offset + 0, data->priv->order,
696  exif_set_short (*d + 6 + offset + 2, data->priv->order,
698  exif_set_long (*d + 6 + offset + 4, data->priv->order,
699  1);
700  exif_set_long (*d + 6 + offset + 8, data->priv->order,
701  *ds - 6);
703  data->ifd[EXIF_IFD_INTEROPERABILITY], d, ds,
704  *ds - 6);
705  offset += 12;
706  }
707 
708  break;
709  case EXIF_IFD_1:
710 
711  /*
712  * Information about the thumbnail (if any) is saved in
713  * IFD_1.
714  */
715  if (data->size) {
716 
717  /* EXIF_TAG_JPEG_INTERCHANGE_FORMAT */
718  exif_set_short (*d + 6 + offset + 0, data->priv->order,
720  exif_set_short (*d + 6 + offset + 2, data->priv->order,
722  exif_set_long (*d + 6 + offset + 4, data->priv->order,
723  1);
724  exif_set_long (*d + 6 + offset + 8, data->priv->order,
725  *ds - 6);
726  ts = *ds + data->size;
727  t = exif_mem_realloc (data->priv->mem, *d, ts);
728  if (!t) {
729  EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData",
730  ts);
731  return;
732  }
733  *d = t;
734  *ds = ts;
735  memcpy (*d + *ds - data->size, data->data, data->size);
736  offset += 12;
737 
738  /* EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH */
739  exif_set_short (*d + 6 + offset + 0, data->priv->order,
741  exif_set_short (*d + 6 + offset + 2, data->priv->order,
743  exif_set_long (*d + 6 + offset + 4, data->priv->order,
744  1);
745  exif_set_long (*d + 6 + offset + 8, data->priv->order,
746  data->size);
747  offset += 12;
748  }
749 
750  break;
751  default:
752  break;
753  }
754 
755  /* Sort the directory according to TIFF specification */
756  qsort (*d + 6 + offset - (ifd->count + n_ptr + n_thumb) * 12,
757  (ifd->count + n_ptr + n_thumb), 12,
759 
760  /* Correctly terminate the directory */
761  if (i == EXIF_IFD_0 && (data->ifd[EXIF_IFD_1]->count ||
762  data->size)) {
763 
764  /*
765  * We are saving IFD 0. Tell where IFD 1 starts and save
766  * IFD 1.
767  */
768  exif_set_long (*d + 6 + offset, data->priv->order, *ds - 6);
769  exif_data_save_data_content (data, data->ifd[EXIF_IFD_1], d, ds,
770  *ds - 6);
771  } else
772  exif_set_long (*d + 6 + offset, data->priv->order, 0);
773 }
774 
775 typedef enum {
784 
791 static void
792 interpret_maker_note(ExifData *data, const unsigned char *d, unsigned int ds)
793 {
794  int mnoteid;
796  if (!e)
797  return;
798 
799  if ((mnoteid = exif_mnote_data_olympus_identify (data, e)) != 0) {
801  "ExifData", "Olympus MakerNote variant type %d", mnoteid);
802  data->priv->md = exif_mnote_data_olympus_new (data->priv->mem);
803 
804  } else if ((mnoteid = exif_mnote_data_canon_identify (data, e)) != 0) {
806  "ExifData", "Canon MakerNote variant type %d", mnoteid);
807  data->priv->md = exif_mnote_data_canon_new (data->priv->mem, data->priv->options);
808 
809  } else if ((mnoteid = exif_mnote_data_fuji_identify (data, e)) != 0) {
811  "ExifData", "Fuji MakerNote variant type %d", mnoteid);
812  data->priv->md = exif_mnote_data_fuji_new (data->priv->mem);
813 
814  /* NOTE: Must do Pentax detection last because some of the
815  * heuristics are pretty general. */
816  } else if ((mnoteid = exif_mnote_data_pentax_identify (data, e)) != 0) {
818  "ExifData", "Pentax MakerNote variant type %d", mnoteid);
819  data->priv->md = exif_mnote_data_pentax_new (data->priv->mem);
820  } else if ((mnoteid = exif_mnote_data_apple_identify (data, e)) != 0) {
822  "ExifData", "Apple MakerNote variant type %d", mnoteid);
823  data->priv->md = exif_mnote_data_apple_new (data->priv->mem);
824  }
825 
826  /*
827  * If we are able to interpret the maker note, do so.
828  */
829  if (data->priv->md) {
830  exif_mnote_data_log (data->priv->md, data->priv->log);
832  data->priv->order);
834  data->priv->offset_mnote);
835  exif_mnote_data_load (data->priv->md, d, ds);
836  }
837 }
838 
839 #define LOG_TOO_SMALL \
840 exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData", \
841  _("Size of data too small to allow for EXIF data."));
842 
843 void
844 exif_data_load_data (ExifData *data, const unsigned char *d_orig,
845  unsigned int ds)
846 {
847  unsigned int l;
848  ExifLong offset;
849  ExifShort n;
850  const unsigned char *d = d_orig;
851  unsigned int len, fullds;
852 
853  if (!data || !data->priv || !d || !ds)
854  return;
855 
856  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
857  "Parsing %i byte(s) EXIF data...\n", ds);
858 
859  /*
860  * It can be that the data starts with the EXIF header. If it does
861  * not, search the EXIF marker.
862  */
863  if (ds < 6) {
865  return;
866  }
867  if (!memcmp (d, ExifHeader, 6)) {
868  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
869  "Found EXIF header at start.");
870  } else {
871  while (ds >= 3) {
872  while (ds && (d[0] == 0xff)) {
873  d++;
874  ds--;
875  }
876 
877  /* JPEG_MARKER_SOI */
878  if (ds && d[0] == JPEG_MARKER_SOI) {
879  d++;
880  ds--;
881  continue;
882  }
883 
884  /* JPEG_MARKER_APP1 */
885  if (ds && d[0] == JPEG_MARKER_APP1) {
886  /*
887  * Verify the exif header
888  * (offset 3, length 6).
889  * FF E1 NN NN EXIFHEADER
890  * ^^ d points here currently
891  */
892  if ((ds >= 9) && !memcmp (d+3, ExifHeader, 6))
893  break;
894  /* fallthrough */
895  }
896  /* Skip irrelevant APP markers. The branch for APP1 must come before this,
897  otherwise this code block will cause APP1 to be skipped. This code path
898  is only relevant for files that are nonconformant to the EXIF
899  specification. For conformant files, the APP1 code path above will be
900  taken. */
901  if (ds >= 3 && d[0] >= 0xe0 && d[0] <= 0xef) { /* JPEG_MARKER_APPn */
902  d++;
903  ds--;
904  l = (((unsigned int)d[0]) << 8) | d[1];
905  if (l > ds)
906  return;
907  d += l;
908  ds -= l;
909  continue;
910  }
911 
912  /* Unknown marker or data. Give up. */
914  "ExifData", _("EXIF marker not found."));
915  return;
916  }
917  if (ds < 3) {
919  return;
920  }
921  d++;
922  ds--;
923  len = (((unsigned int)d[0]) << 8) | d[1];
924  if (len > ds) {
926  "ExifData", _("Read length %d is longer than data length %d."), len, ds);
927  return;
928  }
929  if (len < 2) {
931  "ExifData", _("APP Tag too short."));
932  return;
933  }
934  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
935  "We have to deal with %i byte(s) of EXIF data.",
936  len);
937  d += 2;
938  ds = len - 2; /* we do not want the full rest size, but only the size of the tag */
939  }
940 
941  /*
942  * Verify the exif header
943  * (offset 2, length 6).
944  */
945  if (ds < 6) {
947  return;
948  }
949  if (memcmp (d, ExifHeader, 6)) {
951  "ExifData", _("EXIF header not found."));
952  return;
953  }
954 
955  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
956  "Found EXIF header.");
957 
958  /* Sanity check the data length */
959  if (ds < 14)
960  return;
961 
962  /* The JPEG APP1 section can be no longer than 64 KiB (including a
963  16-bit length), so cap the data length to protect against overflow
964  in future offset calculations */
965  fullds = ds;
966  if (ds > 0xfffe)
967  ds = 0xfffe;
968 
969  /* Byte order (offset 6, length 2) */
970  if (!memcmp (d + 6, "II", 2))
972  else if (!memcmp (d + 6, "MM", 2))
974  else {
976  "ExifData", _("Unknown encoding."));
977  return;
978  }
979 
980  /* Fixed value */
981  if (exif_get_short (d + 8, data->priv->order) != 0x002a)
982  return;
983 
984  /* IFD 0 offset */
985  offset = exif_get_long (d + 10, data->priv->order);
986  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
987  "IFD 0 at %i.", (int) offset);
988 
989  /* ds is restricted to 16 bit above, so offset is restricted too, and offset+8 should not overflow. */
990  if (offset > ds || offset + 6 + 2 > ds)
991  return;
992 
993  /* Parse the actual exif data (usually offset 14 from start) */
994  exif_data_load_data_content (data, EXIF_IFD_0, d + 6, ds - 6, offset, 0);
995 
996  /* IFD 1 offset */
997  n = exif_get_short (d + 6 + offset, data->priv->order);
998  /* offset < 2<<16, n is 16 bit at most, so this op will not overflow */
999  if (offset + 6 + 2 + 12 * n + 4 > ds)
1000  return;
1001 
1002  offset = exif_get_long (d + 6 + offset + 2 + 12 * n, data->priv->order);
1003  if (offset) {
1004  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
1005  "IFD 1 at %i.", (int) offset);
1006 
1007  /* Sanity check. ds is ensured to be above 6 above, offset is 16bit */
1008  if (offset > ds - 6) {
1010  "ExifData", "Bogus offset of IFD1.");
1011  } else {
1012  exif_data_load_data_content (data, EXIF_IFD_1, d + 6, ds - 6, offset, 0);
1013  }
1014  }
1015 
1016  /*
1017  * If we got an EXIF_TAG_MAKER_NOTE, try to interpret it. Some
1018  * cameras use pointers in the maker note tag that point to the
1019  * space between IFDs. Here is the only place where we have access
1020  * to that data.
1021  */
1022  interpret_maker_note(data, d, fullds);
1023 
1024  /* Fixup tags if requested */
1026  exif_data_fix (data);
1027 }
1028 
1029 void
1030 exif_data_save_data (ExifData *data, unsigned char **d, unsigned int *ds)
1031 {
1032  if (ds)
1033  *ds = 0; /* This means something went wrong */
1034 
1035  if (!data || !d || !ds)
1036  return;
1037 
1038  /* Header */
1039  *ds = 14;
1040  *d = exif_data_alloc (data, *ds);
1041  if (!*d) {
1042  *ds = 0;
1043  return;
1044  }
1045  memcpy (*d, ExifHeader, 6);
1046 
1047  /* Order (offset 6) */
1048  if (data->priv->order == EXIF_BYTE_ORDER_INTEL) {
1049  memcpy (*d + 6, "II", 2);
1050  } else {
1051  memcpy (*d + 6, "MM", 2);
1052  }
1053 
1054  /* Fixed value (2 bytes, offset 8) */
1055  exif_set_short (*d + 8, data->priv->order, 0x002a);
1056 
1057  /*
1058  * IFD 0 offset (4 bytes, offset 10).
1059  * We will start 8 bytes after the
1060  * EXIF header (2 bytes for order, another 2 for the test, and
1061  * 4 bytes for the IFD 0 offset make 8 bytes together).
1062  */
1063  exif_set_long (*d + 10, data->priv->order, 8);
1064 
1065  /* Now save IFD 0. IFD 1 will be saved automatically. */
1066  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
1067  "Saving IFDs...");
1068  exif_data_save_data_content (data, data->ifd[EXIF_IFD_0], d, ds,
1069  *ds - 6);
1070  exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
1071  "Saved %i byte(s) EXIF data.", *ds);
1072 }
1073 
1074 ExifData *
1075 exif_data_new_from_file (const char *path)
1076 {
1077  ExifData *edata;
1078  ExifLoader *loader;
1079 
1080  loader = exif_loader_new ();
1081  exif_loader_write_file (loader, path);
1082  edata = exif_loader_get_data (loader);
1083  exif_loader_unref (loader);
1084 
1085  return (edata);
1086 }
1087 
1088 void
1090 {
1091  if (!data)
1092  return;
1093 
1094  data->priv->ref_count++;
1095 }
1096 
1097 void
1099 {
1100  if (!data)
1101  return;
1102 
1103  data->priv->ref_count--;
1104  if (!data->priv->ref_count)
1105  exif_data_free (data);
1106 }
1107 
1108 void
1110 {
1111  unsigned int i;
1112  ExifMem *mem = (data && data->priv) ? data->priv->mem : NULL;
1113 
1114  if (!data)
1115  return;
1116 
1117  for (i = 0; i < EXIF_IFD_COUNT; i++) {
1118  if (data->ifd[i]) {
1119  exif_content_unref (data->ifd[i]);
1120  data->ifd[i] = NULL;
1121  }
1122  }
1123 
1124  if (data->data) {
1125  exif_mem_free (mem, data->data);
1126  data->data = NULL;
1127  }
1128 
1129  if (data->priv) {
1130  if (data->priv->log) {
1131  exif_log_unref (data->priv->log);
1132  data->priv->log = NULL;
1133  }
1134  if (data->priv->md) {
1135  exif_mnote_data_unref (data->priv->md);
1136  data->priv->md = NULL;
1137  }
1138  exif_mem_free (mem, data->priv);
1139  exif_mem_free (mem, data);
1140  }
1141 
1142  exif_mem_unref (mem);
1143 }
1144 
1145 void
1147 {
1148  unsigned int i;
1149 
1150  if (!data)
1151  return;
1152 
1153  for (i = 0; i < EXIF_IFD_COUNT; i++) {
1154  if (data->ifd[i] && data->ifd[i]->count) {
1155  printf ("Dumping IFD '%s'...\n",
1156  exif_ifd_get_name (i));
1157  exif_content_dump (data->ifd[i], 0);
1158  }
1159  }
1160 
1161  if (data->data) {
1162  printf ("%i byte(s) thumbnail data available: ", data->size);
1163  if (data->size >= 4) {
1164  printf ("0x%02x 0x%02x ... 0x%02x 0x%02x\n",
1165  data->data[0], data->data[1],
1166  data->data[data->size - 2],
1167  data->data[data->size - 1]);
1168  }
1169  }
1170 }
1171 
1174 {
1175  if (!data)
1176  return (0);
1177 
1178  return (data->priv->order);
1179 }
1180 
1181 void
1183  void *user_data)
1184 {
1185  unsigned int i;
1186 
1187  if (!data || !func)
1188  return;
1189 
1190  for (i = 0; i < EXIF_IFD_COUNT; i++)
1191  func (data->ifd[i], user_data);
1192 }
1193 
1197 };
1198 
1199 static void
1201 {
1202  ByteOrderChangeData *d = data;
1203 
1204  if (!e)
1205  return;
1206 
1207  exif_array_set_byte_order (e->format, e->data, e->components, d->old, d->new);
1208 }
1209 
1210 static void
1211 content_set_byte_order (ExifContent *content, void *data)
1212 {
1214 }
1215 
1216 void
1218 {
1220 
1221  if (!data || (order == data->priv->order))
1222  return;
1223 
1224  d.old = data->priv->order;
1225  d.new = order;
1227  data->priv->order = order;
1228  if (data->priv->md)
1229  exif_mnote_data_set_byte_order (data->priv->md, order);
1230 }
1231 
1232 void
1234 {
1235  unsigned int i;
1236 
1237  if (!data || !data->priv)
1238  return;
1239  exif_log_unref (data->priv->log);
1240  data->priv->log = log;
1241  exif_log_ref (log);
1242 
1243  for (i = 0; i < EXIF_IFD_COUNT; i++)
1244  exif_content_log (data->ifd[i], log);
1245 }
1246 
1247 /* Used internally within libexif */
1249 ExifLog *
1251 {
1252  if (!data || !data->priv)
1253  return NULL;
1254  return data->priv->log;
1255 }
1256 
1257 static const struct {
1259  const char *name;
1260  const char *description;
1261 } exif_data_option[] = {
1262  {EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS, N_("Ignore unknown tags"),
1263  N_("Ignore unknown tags when loading EXIF data.")},
1264  {EXIF_DATA_OPTION_FOLLOW_SPECIFICATION, N_("Follow specification"),
1265  N_("Add, correct and remove entries to get EXIF data that follows "
1266  "the specification.")},
1267  {EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE, N_("Do not change maker note"),
1268  N_("When loading and resaving Exif data, save the maker note unmodified."
1269  " Be aware that the maker note can get corrupted.")},
1270  {0, NULL, NULL}
1271 };
1272 
1273 const char *
1275 {
1276  unsigned int i;
1277 
1278  for (i = 0; exif_data_option[i].name; i++)
1279  if (exif_data_option[i].option == o)
1280  break;
1281  return _(exif_data_option[i].name);
1282 }
1283 
1284 const char *
1286 {
1287  unsigned int i;
1288 
1289  for (i = 0; exif_data_option[i].description; i++)
1290  if (exif_data_option[i].option == o)
1291  break;
1292  return _(exif_data_option[i].description);
1293 }
1294 
1295 void
1297 {
1298  if (!d)
1299  return;
1300 
1301  d->priv->options |= o;
1302 }
1303 
1304 void
1306 {
1307  if (!d)
1308  return;
1309 
1310  d->priv->options &= ~o;
1311 }
1312 
1313 static void
1314 fix_func (ExifContent *c, void *UNUSED(data))
1315 {
1316  switch (exif_content_get_ifd (c)) {
1317  case EXIF_IFD_1:
1318  if (c->parent->data)
1319  exif_content_fix (c);
1320  else if (c->count) {
1321  exif_log (c->parent->priv->log, EXIF_LOG_CODE_DEBUG, "exif-data",
1322  "No thumbnail but entries on thumbnail. These entries have been "
1323  "removed.");
1324  while (c->count) {
1325  unsigned int cnt = c->count;
1326  exif_content_remove_entry (c, c->entries[c->count - 1]);
1327  if (cnt == c->count) {
1328  /* safety net */
1329  exif_log (c->parent->priv->log, EXIF_LOG_CODE_DEBUG, "exif-data",
1330  "failed to remove last entry from entries.");
1331  c->count--;
1332  }
1333  }
1334  }
1335  break;
1336  default:
1337  exif_content_fix (c);
1338  }
1339 }
1340 
1341 void
1343 {
1345 }
1346 
1347 void
1349 {
1350  if (!d || !d->priv)
1351  return;
1352 
1353  d->priv->data_type = dt;
1354 }
1355 
1358 {
1359  return (d && d->priv) ? d->priv->data_type : EXIF_DATA_TYPE_UNKNOWN;
1360 }
ExifByteOrder
Which byte order to use.
@ EXIF_BYTE_ORDER_INTEL
Little-endian byte order.
@ EXIF_BYTE_ORDER_MOTOROLA
Big-endian byte order.
void exif_content_remove_entry(ExifContent *c, ExifEntry *e)
Remove an EXIF tag from an IFD.
Definition: exif-content.c:163
ExifIfd exif_content_get_ifd(ExifContent *c)
Return the IFD number in which the given ExifContent is found.
Definition: exif-content.c:240
void exif_content_fix(ExifContent *c)
Fix the IFD to bring it into specification.
Definition: exif-content.c:284
void exif_content_unref(ExifContent *content)
Decrease reference counter for ExifContent.
Definition: exif-content.c:88
void exif_content_add_entry(ExifContent *c, ExifEntry *entry)
Add an EXIF tag to an IFD.
Definition: exif-content.c:139
ExifContent * exif_content_new_mem(ExifMem *mem)
Reserve memory for and initialize new ExifContent using the specified memory allocator.
Definition: exif-content.c:54
void exif_content_dump(ExifContent *content, unsigned int indent)
Dump contents of the IFD to stdout.
Definition: exif-content.c:120
void exif_content_log(ExifContent *content, ExifLog *log)
Set the log message object for this IFD.
Definition: exif-content.c:229
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
Definition: exif-content.c:216
ExifDataType
Represents the type of image data to which the EXIF data applies.
@ EXIF_DATA_TYPE_UNKNOWN
@ EXIF_DATA_TYPE_COUNT
#define JPEG_MARKER_APP1
Definition: exif-data.c:49
static void exif_data_load_data_thumbnail(ExifData *data, const unsigned char *d, unsigned int ds, ExifLong o, ExifLong s)
Definition: exif-data.c:325
static unsigned int level_cost(unsigned int n)
Calculate the recursion cost added by one level of IFD loading.
Definition: exif-data.c:372
static int cmp_func(const unsigned char *p1, const unsigned char *p2, ExifByteOrder o)
Definition: exif-data.c:541
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition: exif-data.c:1217
#define LOG_TOO_SMALL
Definition: exif-data.c:839
ExifData * exif_data_new(void)
Allocate a new ExifData.
Definition: exif-data.c:96
static void fix_func(ExifContent *c, void *UNUSED(data))
Definition: exif-data.c:1314
void exif_data_unref(ExifData *data)
Definition: exif-data.c:1098
void exif_data_free(ExifData *data)
Definition: exif-data.c:1109
const char * exif_data_option_get_name(ExifDataOption o)
Return a short textual description of the given ExifDataOption.
Definition: exif-data.c:1274
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition: exif-data.c:1173
#define CHECK_REC(i)
Definition: exif-data.c:349
ExifDataTypeMakerNote
Definition: exif-data.c:775
@ EXIF_DATA_TYPE_MAKER_NOTE_CANON
Definition: exif-data.c:777
@ EXIF_DATA_TYPE_MAKER_NOTE_CASIO
Definition: exif-data.c:781
@ EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS
Definition: exif-data.c:778
@ EXIF_DATA_TYPE_MAKER_NOTE_NONE
Definition: exif-data.c:776
@ EXIF_DATA_TYPE_MAKER_NOTE_FUJI
Definition: exif-data.c:782
@ EXIF_DATA_TYPE_MAKER_NOTE_NIKON
Definition: exif-data.c:780
@ EXIF_DATA_TYPE_MAKER_NOTE_PENTAX
Definition: exif-data.c:779
void exif_data_ref(ExifData *data)
Definition: exif-data.c:1089
const char * exif_data_option_get_description(ExifDataOption o)
Return a verbose textual description of the given ExifDataOption.
Definition: exif-data.c:1285
void exif_data_load_data(ExifData *data, const unsigned char *d_orig, unsigned int ds)
Load the ExifData structure from the raw JPEG or EXIF data in the given memory buffer.
Definition: exif-data.c:844
ExifDataType exif_data_get_data_type(ExifData *d)
Return the data type for the given ExifData.
Definition: exif-data.c:1357
static void content_set_byte_order(ExifContent *content, void *data)
Definition: exif-data.c:1211
ExifData * exif_data_new_from_data(const unsigned char *data, unsigned int size)
Allocate a new ExifData and load EXIF data from a memory buffer.
Definition: exif-data.c:154
const char * description
Definition: exif-data.c:1260
#define JPEG_MARKER_SOI
Definition: exif-data.c:45
static const unsigned char ExifHeader[]
Definition: exif-data.c:53
static void * exif_data_alloc(ExifData *data, unsigned int i)
Definition: exif-data.c:74
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition: exif-data.c:90
static void exif_data_save_data_entry(ExifData *data, ExifEntry *e, unsigned char **d, unsigned int *ds, unsigned int offset)
Definition: exif-data.c:239
const char * name
Definition: exif-data.c:1259
void exif_data_fix(ExifData *d)
Fix the EXIF data to bring it into specification.
Definition: exif-data.c:1342
ExifLog * exif_data_get_log(ExifData *)
Definition: exif-data.c:1250
static void entry_set_byte_order(ExifEntry *e, void *data)
Definition: exif-data.c:1200
static void interpret_maker_note(ExifData *data, const unsigned char *d, unsigned int ds)
If MakerNote is recognized, load it.
Definition: exif-data.c:792
static const struct @3 exif_data_option[]
void exif_data_dump(ExifData *data)
Dump all EXIF data to stdout.
Definition: exif-data.c:1146
ExifData * exif_data_new_mem(ExifMem *mem)
Allocate a new ExifData using the given memory allocator.
Definition: exif-data.c:107
void exif_data_unset_option(ExifData *d, ExifDataOption o)
Clear the given option on the given ExifData.
Definition: exif-data.c:1305
void exif_data_set_data_type(ExifData *d, ExifDataType dt)
Set the data type for the given ExifData.
Definition: exif-data.c:1348
static int cmp_func_intel(const void *elem1, const void *elem2)
Definition: exif-data.c:550
static int exif_data_load_data_entry(ExifData *data, ExifEntry *entry, const unsigned char *d, unsigned int size, unsigned int offset)
Definition: exif-data.c:164
ExifData * exif_data_new_from_file(const char *path)
Allocate a new ExifData and load EXIF data from a JPEG file.
Definition: exif-data.c:1075
void exif_data_save_data(ExifData *data, unsigned char **d, unsigned int *ds)
Store raw EXIF data representing the ExifData structure into a memory buffer.
Definition: exif-data.c:1030
static void exif_data_save_data_content(ExifData *data, ExifContent *ifd, unsigned char **d, unsigned int *ds, unsigned int offset)
Definition: exif-data.c:564
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition: exif-data.c:1182
#define CHECKOVERFLOW(offset, datasize, structsize)
Definition: exif-data.c:51
ExifDataOption option
Definition: exif-data.c:1258
static int cmp_func_motorola(const void *elem1, const void *elem2)
Definition: exif-data.c:557
static void exif_data_load_data_content(ExifData *data, ExifIfd ifd, const unsigned char *d, unsigned int ds, unsigned int offset, unsigned int recursion_cost)
Load data for an IFD.
Definition: exif-data.c:391
void exif_data_log(ExifData *data, ExifLog *log)
Set the log message object for all IFDs.
Definition: exif-data.c:1233
void exif_data_set_option(ExifData *d, ExifDataOption o)
Set the given option on the given ExifData.
Definition: exif-data.c:1296
Defines the ExifData type and the associated functions.
ExifDataOption
Options to configure the behaviour of ExifData.
Definition: exif-data.h:174
@ EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE
Leave the MakerNote alone, which could cause it to be corrupted.
Definition: exif-data.h:182
@ EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS
Act as though unknown tags are not present.
Definition: exif-data.h:176
@ EXIF_DATA_OPTION_FOLLOW_SPECIFICATION
Fix the EXIF tags to follow the spec.
Definition: exif-data.h:179
#define exif_data_get_entry(d, t)
Return an ExifEntry for the given tag if found in any IFD.
Definition: exif-data.h:251
void(* ExifDataForeachContentFunc)(ExifContent *, void *user_data)
Definition: exif-data.h:161
ExifEntry * exif_entry_new_mem(ExifMem *mem)
Reserve memory for and initialize new ExifEntry using the specified memory allocator.
Definition: exif-entry.c:122
void exif_entry_unref(ExifEntry *e)
Decrease reference counter for ExifEntry.
Definition: exif-entry.c:147
unsigned char exif_format_get_size(ExifFormat format)
Return the raw size of the given EXIF data type.
Definition: exif-format.c:66
unsigned char size
Definition: exif-format.c:35
@ EXIF_FORMAT_LONG
Definition: exif-format.h:36
@ EXIF_FORMAT_UNDEFINED
Definition: exif-format.h:39
ExifIfd ifd
Definition: exif-ifd.c:28
const char * exif_ifd_get_name(ExifIfd ifd)
Return a textual name of the given IFD.
Definition: exif-ifd.c:40
ExifIfd
Possible EXIF Image File Directories.
Definition: exif-ifd.h:29
@ EXIF_IFD_GPS
Definition: exif-ifd.h:33
@ EXIF_IFD_INTEROPERABILITY
Definition: exif-ifd.h:34
@ EXIF_IFD_EXIF
Definition: exif-ifd.h:32
@ EXIF_IFD_1
Definition: exif-ifd.h:31
@ EXIF_IFD_COUNT
Not a real value, just (max_value + 1).
Definition: exif-ifd.h:35
@ EXIF_IFD_0
Definition: exif-ifd.h:30
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
Definition: exif-loader.c:352
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
Definition: exif-loader.c:404
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
Definition: exif-loader.c:426
void exif_loader_write_file(ExifLoader *l, const char *path)
Load a file into the given ExifLoader from the filesystem.
Definition: exif-loader.c:117
Defines the ExifLoader type.
void exif_log(ExifLog *log, ExifLogCode code, const char *domain, const char *format,...)
Definition: exif-log.c:135
void exif_log_unref(ExifLog *log)
Definition: exif-log.c:104
void exif_log_ref(ExifLog *log)
Definition: exif-log.c:97
Log message infrastructure.
@ EXIF_LOG_CODE_NO_MEMORY
Definition: exif-log.h:57
@ EXIF_LOG_CODE_CORRUPT_DATA
Definition: exif-log.h:58
@ EXIF_LOG_CODE_DEBUG
Definition: exif-log.h:56
#define EXIF_LOG_NO_MEMORY(l, d, s)
Definition: exif-log.h:110
void * exif_mem_realloc(ExifMem *mem, void *d, ExifLong ds)
Definition: exif-mem.c:89
void exif_mem_free(ExifMem *mem, void *d)
Definition: exif-mem.c:69
void exif_mem_unref(ExifMem *mem)
Unrefcount an ExifMem.
Definition: exif-mem.c:61
ExifMem * exif_mem_new_default(void)
Create a new ExifMem with default values for your convenience.
Definition: exif-mem.c:95
void * exif_mem_alloc(ExifMem *mem, ExifLong ds)
Definition: exif-mem.c:79
void exif_mem_ref(ExifMem *mem)
Refcount an ExifMem.
Definition: exif-mem.c:54
int exif_mnote_data_apple_identify(const ExifData *ed, const ExifEntry *e)
ExifMnoteData * exif_mnote_data_apple_new(ExifMem *mem)
ExifMnoteData * exif_mnote_data_canon_new(ExifMem *mem, ExifDataOption o)
int exif_mnote_data_canon_identify(const ExifData *ed, const ExifEntry *e)
Detect if MakerNote is recognized as one handled by the Canon module.
ExifMnoteData * exif_mnote_data_fuji_new(ExifMem *mem)
int exif_mnote_data_fuji_identify(const ExifData *ed, const ExifEntry *e)
Detect if MakerNote is recognized as one handled by the Fuji module.
ExifMnoteData * exif_mnote_data_olympus_new(ExifMem *mem)
int exif_mnote_data_olympus_identify(const ExifData *ed, const ExifEntry *e)
Detect if MakerNote is recognized as one handled by the Olympus module.
ExifMnoteData * exif_mnote_data_pentax_new(ExifMem *mem)
int exif_mnote_data_pentax_identify(const ExifData *ed, const ExifEntry *e)
Detect if MakerNote is recognized as one handled by the Pentax module.
void exif_mnote_data_set_offset(ExifMnoteData *, unsigned int)
void exif_mnote_data_set_byte_order(ExifMnoteData *, ExifByteOrder)
void exif_mnote_data_load(ExifMnoteData *d, const unsigned char *buf, unsigned int buf_size)
Load the MakerNote data from a memory buffer.
void exif_mnote_data_save(ExifMnoteData *d, unsigned char **buf, unsigned int *buf_size)
Save the raw MakerNote data into a memory buffer.
void exif_mnote_data_log(ExifMnoteData *d, ExifLog *log)
void exif_mnote_data_unref(ExifMnoteData *d)
Handling EXIF MakerNote tags.
System specific definitions, not for installation!
#define UNUSED(param)
Definition: exif-system.h:29
const char * exif_tag_get_name(ExifTag tag)
Definition: exif-tag.c:1147
const char * exif_tag_get_name_in_ifd(ExifTag tag, ExifIfd ifd)
Return a textual name of the given tag when found in the given IFD.
Definition: exif-tag.c:1038
ExifTag
EXIF tags.
Definition: exif-tag.h:34
@ EXIF_TAG_EXIF_IFD_POINTER
Definition: exif-tag.h:85
@ EXIF_TAG_GPS_INFO_IFD_POINTER
Definition: exif-tag.h:89
@ EXIF_TAG_INTEROPERABILITY_IFD_POINTER
Definition: exif-tag.h:134
@ EXIF_TAG_JPEG_INTERCHANGE_FORMAT
Definition: exif-tag.h:66
@ EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH
Definition: exif-tag.h:67
@ EXIF_TAG_MAKER_NOTE
Definition: exif-tag.h:119
ExifLong exif_get_long(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifLong value from memory.
Definition: exif-utils.c:165
ExifShort exif_get_short(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifShort value from memory.
Definition: exif-utils.c:102
void exif_array_set_byte_order(ExifFormat f, unsigned char *b, unsigned int n, ExifByteOrder o_orig, ExifByteOrder o_new)
Definition: exif-utils.c:26
void exif_set_long(unsigned char *b, ExifByteOrder order, ExifLong value)
Store an ExifLong value into memory in EXIF format.
Definition: exif-utils.c:171
void exif_set_short(unsigned char *b, ExifByteOrder order, ExifShort value)
Store an ExifShort value into memory in EXIF format.
Definition: exif-utils.c:124
EXIF data manipulation functions and types.
uint32_t ExifLong
EXIF Unsigned Long data type.
Definition: exif-utils.h:54
uint16_t ExifShort
EXIF Unsigned Short data type.
Definition: exif-utils.h:48
#define _(String)
Definition: i18n.h:48
#define N_(String)
Definition: i18n.h:49
MnoteAppleTag tag
ExifByteOrder old
Definition: exif-data.c:1196
ExifByteOrder new
Definition: exif-data.c:1196
unsigned int count
Definition: exif-content.h:43
ExifData * parent
Data containing this content.
Definition: exif-content.h:46
ExifEntry ** entries
Definition: exif-content.h:42
ExifDataType data_type
Definition: exif-data.c:70
ExifDataOption options
Definition: exif-data.c:69
unsigned int offset_mnote
Definition: exif-data.c:67
ExifMem * mem
Definition: exif-data.c:62
ExifLog * log
Definition: exif-data.c:61
ExifMnoteData * md
Definition: exif-data.c:59
ExifByteOrder order
Definition: exif-data.c:57
unsigned int ref_count
Definition: exif-data.c:64
Represents the entire EXIF data found in an image.
Definition: exif-data.h:47
unsigned char * data
Pointer to thumbnail image, or NULL if not available.
Definition: exif-data.h:52
unsigned int size
Number of bytes in thumbnail image at data.
Definition: exif-data.h:55
ExifContent * ifd[EXIF_IFD_COUNT]
Data for each IFD.
Definition: exif-data.h:49
ExifDataPrivate * priv
Definition: exif-data.h:57
Data found in one EXIF tag.
Definition: exif-entry.h:43
unsigned long components
Number of elements in the array, if this is an array entry.
Definition: exif-entry.h:52
ExifFormat format
Type of data in this entry.
Definition: exif-entry.h:48
unsigned char * data
Pointer to the raw EXIF data for this entry.
Definition: exif-entry.h:57
ExifTag tag
EXIF tag for this entry.
Definition: exif-entry.h:45
unsigned int size
Number of bytes in the buffer at data.
Definition: exif-entry.h:61

libexif Generated by doxygen