3 * Copyright (c) 2001 Lutz Mueller <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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA.
23 #include <libexif/exif-entry.h>
24 #include <libexif/exif-ifd.h>
25 #include <libexif/exif-utils.h>
26 #include <libexif/i18n.h>
36 #define M_PI 3.14159265358979323846
39 struct _ExifEntryPrivate
41 unsigned int ref_count;
46 /* This function is hidden in exif-data.c */
47 ExifLog *exif_data_get_log (ExifData *);
49 #ifndef NO_VERBOSE_TAG_STRINGS
51 exif_entry_log (ExifEntry *e, ExifLogCode code, const char *format, ...)
56 if (e && e->parent && e->parent->parent)
57 l = exif_data_get_log (e->parent->parent);
58 va_start (args, format);
59 exif_logv (l, code, "ExifEntry", format, args);
63 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
64 #define exif_entry_log(...) do { } while (0)
65 #elif defined(__GNUC__)
66 #define exif_entry_log(x...) do { } while (0)
68 #define exif_entry_log (void)
73 exif_entry_alloc (ExifEntry *e, unsigned int i)
78 if (!e || !e->priv || !i) return NULL;
80 d = exif_mem_alloc (e->priv->mem, i);
83 if (e->parent && e->parent->parent)
84 l = exif_data_get_log (e->parent->parent);
85 EXIF_LOG_NO_MEMORY (l, "ExifEntry", i);
90 exif_entry_realloc (ExifEntry *e, void *d_orig, unsigned int i)
95 if (!e || !e->priv) return NULL;
97 if (!i) { exif_mem_free (e->priv->mem, d_orig); return NULL; }
99 d = exif_mem_realloc (e->priv->mem, d_orig, i);
102 if (e->parent && e->parent->parent)
103 l = exif_data_get_log (e->parent->parent);
104 EXIF_LOG_NO_MEMORY (l, "ExifEntry", i);
109 exif_entry_new (void)
111 ExifMem *mem = exif_mem_new_default ();
112 ExifEntry *e = exif_entry_new_mem (mem);
114 exif_mem_unref (mem);
120 exif_entry_new_mem (ExifMem *mem)
124 e = exif_mem_alloc (mem, sizeof (ExifEntry));
126 e->priv = exif_mem_alloc (mem, sizeof (ExifEntryPrivate));
127 if (!e->priv) { exif_mem_free (mem, e); return NULL; }
128 e->priv->ref_count = 1;
137 exif_entry_ref (ExifEntry *e)
141 e->priv->ref_count++;
145 exif_entry_unref (ExifEntry *e)
149 e->priv->ref_count--;
150 if (!e->priv->ref_count)
155 exif_entry_free (ExifEntry *e)
160 ExifMem *mem = e->priv->mem;
162 exif_mem_free (mem, e->data);
163 exif_mem_free (mem, e->priv);
164 exif_mem_free (mem, e);
165 exif_mem_unref (mem);
170 clear_entry (ExifEntry *e)
176 /*! Get a value and convert it to an ExifShort.
177 * \bug Not all types are converted that could be converted and no indication
178 * is made when that occurs
180 static inline ExifShort
181 exif_get_short_convert (const unsigned char *buf, ExifFormat format,
185 case EXIF_FORMAT_LONG:
186 return (ExifShort) exif_get_long (buf, order);
187 case EXIF_FORMAT_SLONG:
188 return (ExifShort) exif_get_slong (buf, order);
189 case EXIF_FORMAT_SHORT:
190 return (ExifShort) exif_get_short (buf, order);
191 case EXIF_FORMAT_SSHORT:
192 return (ExifShort) exif_get_sshort (buf, order);
193 case EXIF_FORMAT_BYTE:
194 case EXIF_FORMAT_SBYTE:
195 return (ExifShort) buf[0];
197 /* Unsupported type */
198 return (ExifShort) 0;
203 exif_entry_fix (ExifEntry *e)
205 unsigned int i, newsize;
206 unsigned char *newdata;
211 if (!e || !e->priv) return;
215 /* These tags all need to be of format SHORT. */
216 case EXIF_TAG_YCBCR_SUB_SAMPLING:
217 case EXIF_TAG_SUBJECT_AREA:
218 case EXIF_TAG_COLOR_SPACE:
219 case EXIF_TAG_PLANAR_CONFIGURATION:
220 case EXIF_TAG_SENSING_METHOD:
221 case EXIF_TAG_ORIENTATION:
222 case EXIF_TAG_YCBCR_POSITIONING:
223 case EXIF_TAG_PHOTOMETRIC_INTERPRETATION:
224 case EXIF_TAG_CUSTOM_RENDERED:
225 case EXIF_TAG_EXPOSURE_MODE:
226 case EXIF_TAG_WHITE_BALANCE:
227 case EXIF_TAG_SCENE_CAPTURE_TYPE:
228 case EXIF_TAG_GAIN_CONTROL:
229 case EXIF_TAG_SATURATION:
230 case EXIF_TAG_CONTRAST:
231 case EXIF_TAG_SHARPNESS:
232 case EXIF_TAG_ISO_SPEED_RATINGS:
234 case EXIF_FORMAT_LONG:
235 case EXIF_FORMAT_SLONG:
236 case EXIF_FORMAT_BYTE:
237 case EXIF_FORMAT_SBYTE:
238 case EXIF_FORMAT_SSHORT:
239 if (!e->parent || !e->parent->parent) break;
240 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
241 _("Tag '%s' was of format '%s' (which is "
242 "against specification) and has been "
243 "changed to format '%s'."),
244 exif_tag_get_name_in_ifd(e->tag,
245 exif_entry_get_ifd(e)),
246 exif_format_get_name (e->format),
247 exif_format_get_name (EXIF_FORMAT_SHORT));
249 o = exif_data_get_byte_order (e->parent->parent);
250 newsize = e->components * exif_format_get_size (EXIF_FORMAT_SHORT);
251 newdata = exif_entry_alloc (e, newsize);
253 exif_entry_log (e, EXIF_LOG_CODE_NO_MEMORY,
254 "Could not allocate %lu byte(s).", (unsigned long)newsize);
258 for (i = 0; i < e->components; i++)
261 exif_format_get_size (
262 EXIF_FORMAT_SHORT), o,
263 exif_get_short_convert (
265 exif_format_get_size (e->format),
268 exif_mem_free (e->priv->mem, e->data);
271 e->format = EXIF_FORMAT_SHORT;
273 case EXIF_FORMAT_SHORT:
274 /* No conversion necessary */
277 exif_entry_log (e, EXIF_LOG_CODE_CORRUPT_DATA,
278 _("Tag '%s' is of format '%s' (which is "
279 "against specification) but cannot be changed "
281 exif_tag_get_name_in_ifd(e->tag,
282 exif_entry_get_ifd(e)),
283 exif_format_get_name (e->format),
284 exif_format_get_name (EXIF_FORMAT_SHORT));
289 /* All these tags need to be of format 'Rational'. */
290 case EXIF_TAG_FNUMBER:
291 case EXIF_TAG_APERTURE_VALUE:
292 case EXIF_TAG_EXPOSURE_TIME:
293 case EXIF_TAG_FOCAL_LENGTH:
295 case EXIF_FORMAT_SRATIONAL:
296 if (!e->parent || !e->parent->parent) break;
297 o = exif_data_get_byte_order (e->parent->parent);
298 for (i = 0; i < e->components; i++) {
299 sr = exif_get_srational (e->data + i *
300 exif_format_get_size (
301 EXIF_FORMAT_SRATIONAL), o);
302 r.numerator = (ExifLong) sr.numerator;
303 r.denominator = (ExifLong) sr.denominator;
304 exif_set_rational (e->data + i *
305 exif_format_get_size (
306 EXIF_FORMAT_RATIONAL), o, r);
308 e->format = EXIF_FORMAT_RATIONAL;
309 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
310 _("Tag '%s' was of format '%s' (which is "
311 "against specification) and has been "
312 "changed to format '%s'."),
313 exif_tag_get_name_in_ifd(e->tag,
314 exif_entry_get_ifd(e)),
315 exif_format_get_name (EXIF_FORMAT_SRATIONAL),
316 exif_format_get_name (EXIF_FORMAT_RATIONAL));
323 /* All these tags need to be of format 'SRational'. */
324 case EXIF_TAG_EXPOSURE_BIAS_VALUE:
325 case EXIF_TAG_BRIGHTNESS_VALUE:
326 case EXIF_TAG_SHUTTER_SPEED_VALUE:
328 case EXIF_FORMAT_RATIONAL:
329 if (!e->parent || !e->parent->parent) break;
330 o = exif_data_get_byte_order (e->parent->parent);
331 for (i = 0; i < e->components; i++) {
332 r = exif_get_rational (e->data + i *
333 exif_format_get_size (
334 EXIF_FORMAT_RATIONAL), o);
335 sr.numerator = (ExifLong) r.numerator;
336 sr.denominator = (ExifLong) r.denominator;
337 exif_set_srational (e->data + i *
338 exif_format_get_size (
339 EXIF_FORMAT_SRATIONAL), o, sr);
341 e->format = EXIF_FORMAT_SRATIONAL;
342 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
343 _("Tag '%s' was of format '%s' (which is "
344 "against specification) and has been "
345 "changed to format '%s'."),
346 exif_tag_get_name_in_ifd(e->tag,
347 exif_entry_get_ifd(e)),
348 exif_format_get_name (EXIF_FORMAT_RATIONAL),
349 exif_format_get_name (EXIF_FORMAT_SRATIONAL));
356 case EXIF_TAG_USER_COMMENT:
358 /* Format needs to be UNDEFINED. */
359 if (e->format != EXIF_FORMAT_UNDEFINED) {
360 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
361 _("Tag 'UserComment' had invalid format '%s'. "
362 "Format has been set to 'undefined'."),
363 exif_format_get_name (e->format));
364 e->format = EXIF_FORMAT_UNDEFINED;
367 /* Some packages like Canon ZoomBrowser EX 4.5 store
368 only one zero byte followed by 7 bytes of rubbish */
369 if ((e->size >= 8) && (e->data[0] == 0)) {
370 memcpy(e->data, "\0\0\0\0\0\0\0\0", 8);
373 /* There need to be at least 8 bytes. */
375 e->data = exif_entry_realloc (e, e->data, 8 + e->size);
382 memmove (e->data + 8, e->data, e->size);
383 memcpy (e->data, "ASCII\0\0\0", 8);
386 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
387 _("Tag 'UserComment' has been expanded to at "
388 "least 8 bytes in order to follow the "
394 * If the first 8 bytes are empty and real data starts
395 * afterwards, let's assume ASCII and claim the 8 first
396 * bytes for the format specifyer.
398 for (i = 0; (i < e->size) && !e->data[i]; i++);
399 if (!i) for ( ; (i < e->size) && (e->data[i] == ' '); i++);
400 if ((i >= 8) && (i < e->size)) {
401 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
402 _("Tag 'UserComment' is not empty but does not "
403 "start with a format identifier. "
404 "This has been fixed."));
405 memcpy (e->data, "ASCII\0\0\0", 8);
410 * First 8 bytes need to follow the specification. If they don't,
413 if (memcmp (e->data, "ASCII\0\0\0" , 8) &&
414 memcmp (e->data, "UNICODE\0" , 8) &&
415 memcmp (e->data, "JIS\0\0\0\0\0" , 8) &&
416 memcmp (e->data, "\0\0\0\0\0\0\0\0", 8)) {
417 e->data = exif_entry_realloc (e, e->data, 8 + e->size);
424 memmove (e->data + 8, e->data, e->size);
425 memcpy (e->data, "ASCII\0\0\0", 8);
428 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
429 _("Tag 'UserComment' did not start with a "
430 "format identifier. This has been fixed."));
440 /*! Format the value of an ExifEntry for human display in a generic way.
441 * The output is localized. The formatting is independent of the tag number
442 * and is based entirely on the data type.
443 * \pre The ExifEntry is already a member of an ExifData.
444 * \param[in] e EXIF entry
445 * \param[out] val buffer in which to store value
446 * \param[in] maxlen the length of the buffer val
449 exif_entry_format_value(ExifEntry *e, char *val, size_t maxlen)
456 ExifSRational v_srat;
460 const ExifByteOrder o = exif_data_get_byte_order (e->parent->parent);
462 if (!e->size || !maxlen)
465 case EXIF_FORMAT_UNDEFINED:
466 snprintf (val, maxlen, _("%i bytes undefined data"), e->size);
468 case EXIF_FORMAT_BYTE:
469 case EXIF_FORMAT_SBYTE:
471 snprintf (val, maxlen, "0x%02x", v_byte);
473 for (i = 1; i < e->components; i++) {
475 snprintf (val+len, maxlen-len, ", 0x%02x", v_byte);
476 len += strlen (val+len);
477 if (len >= maxlen-1) break;
480 case EXIF_FORMAT_SHORT:
481 v_short = exif_get_short (e->data, o);
482 snprintf (val, maxlen, "%u", v_short);
484 for (i = 1; i < e->components; i++) {
485 v_short = exif_get_short (e->data +
486 exif_format_get_size (e->format) * i, o);
487 snprintf (val+len, maxlen-len, ", %u", v_short);
488 len += strlen (val+len);
489 if (len >= maxlen-1) break;
492 case EXIF_FORMAT_SSHORT:
493 v_sshort = exif_get_sshort (e->data, o);
494 snprintf (val, maxlen, "%i", v_sshort);
496 for (i = 1; i < e->components; i++) {
497 v_sshort = exif_get_short (e->data +
498 exif_format_get_size (e->format) *
500 snprintf (val+len, maxlen-len, ", %i", v_sshort);
501 len += strlen (val+len);
502 if (len >= maxlen-1) break;
505 case EXIF_FORMAT_LONG:
506 v_long = exif_get_long (e->data, o);
507 snprintf (val, maxlen, "%lu", (unsigned long) v_long);
509 for (i = 1; i < e->components; i++) {
510 v_long = exif_get_long (e->data +
511 exif_format_get_size (e->format) *
513 snprintf (val+len, maxlen-len, ", %lu", (unsigned long) v_long);
514 len += strlen (val+len);
515 if (len >= maxlen-1) break;
518 case EXIF_FORMAT_SLONG:
519 v_slong = exif_get_slong (e->data, o);
520 snprintf (val, maxlen, "%li", (long) v_slong);
522 for (i = 1; i < e->components; i++) {
523 v_slong = exif_get_slong (e->data +
524 exif_format_get_size (e->format) * i, o);
525 snprintf (val+len, maxlen-len, ", %li", (long) v_slong);
526 len += strlen (val+len);
527 if (len >= maxlen-1) break;
530 case EXIF_FORMAT_ASCII:
531 strncpy (val, (char *) e->data, MIN (maxlen-1, e->size));
532 val[MIN (maxlen-1, e->size)] = 0;
534 case EXIF_FORMAT_RATIONAL:
536 for (i = 0; i < e->components; i++) {
538 snprintf (val+len, maxlen-len, ", ");
539 len += strlen (val+len);
541 v_rat = exif_get_rational (
543 if (v_rat.denominator) {
545 * Choose the number of significant digits to
546 * display based on the size of the denominator.
547 * It is scaled so that denominators within the
548 * range 13..120 will show 2 decimal points.
550 int decimals = (int)(log10(v_rat.denominator)-0.08+1.0);
551 snprintf (val+len, maxlen-len, "%2.*f",
553 (double) v_rat.numerator /
554 (double) v_rat.denominator);
556 snprintf (val+len, maxlen-len, "%lu/%lu",
557 (unsigned long) v_rat.numerator,
558 (unsigned long) v_rat.denominator);
559 len += strlen (val+len);
560 if (len >= maxlen-1) break;
563 case EXIF_FORMAT_SRATIONAL:
565 for (i = 0; i < e->components; i++) {
567 snprintf (val+len, maxlen-len, ", ");
568 len += strlen (val+len);
570 v_srat = exif_get_srational (
572 if (v_srat.denominator) {
573 int decimals = (int)(log10(abs(v_srat.denominator))-0.08+1.0);
574 snprintf (val+len, maxlen-len, "%2.*f",
576 (double) v_srat.numerator /
577 (double) v_srat.denominator);
579 snprintf (val+len, maxlen-len, "%li/%li",
580 (long) v_srat.numerator,
581 (long) v_srat.denominator);
582 len += strlen (val+len);
583 if (len >= maxlen-1) break;
586 case EXIF_FORMAT_DOUBLE:
587 case EXIF_FORMAT_FLOAT:
589 snprintf (val, maxlen, _("%i bytes unsupported data type"),
596 exif_entry_dump (ExifEntry *e, unsigned int indent)
605 l = MIN(sizeof(buf)-1, 2*indent);
609 printf ("%sTag: 0x%x ('%s')\n", buf, e->tag,
610 exif_tag_get_name_in_ifd (e->tag, exif_entry_get_ifd(e)));
611 printf ("%s Format: %i ('%s')\n", buf, e->format,
612 exif_format_get_name (e->format));
613 printf ("%s Components: %i\n", buf, (int) e->components);
614 printf ("%s Size: %i\n", buf, e->size);
615 printf ("%s Value: %s\n", buf, exif_entry_get_value (e, value, sizeof(value)));
618 /*! Check if a string consists entirely of a single, repeated character.
619 * Up to first n bytes are checked.
621 * \param[in] data pointer of string to check
622 * \param[in] ch character to match
623 * \param[in] n maximum number of characters to match
625 * \return 0 if the string matches or is of zero length, nonzero otherwise
628 match_repeated_char(const unsigned char *data, unsigned char ch, size_t n)
631 for (i=n; i; --i, ++data) {
633 i = 0; /* all bytes before NUL matched */
642 #define CF(entry,target,v,maxlen) \
644 if (entry->format != target) { \
645 exif_entry_log (entry, EXIF_LOG_CODE_CORRUPT_DATA, \
646 _("The tag '%s' contains data of an invalid " \
647 "format ('%s', expected '%s')."), \
648 exif_tag_get_name (entry->tag), \
649 exif_format_get_name (entry->format), \
650 exif_format_get_name (target)); \
655 #define CC(entry,target,v,maxlen) \
657 if (entry->components != target) { \
658 exif_entry_log (entry, EXIF_LOG_CODE_CORRUPT_DATA, \
659 _("The tag '%s' contains an invalid number of " \
660 "components (%i, expected %i)."), \
661 exif_tag_get_name (entry->tag), \
662 (int) entry->components, (int) target); \
667 static const struct {
669 const char *strings[10];
671 #ifndef NO_VERBOSE_TAG_DATA
672 { EXIF_TAG_PLANAR_CONFIGURATION,
673 { N_("Chunky format"), N_("Planar format"), NULL}},
674 { EXIF_TAG_SENSING_METHOD,
675 { "", N_("Not defined"), N_("One-chip color area sensor"),
676 N_("Two-chip color area sensor"), N_("Three-chip color area sensor"),
677 N_("Color sequential area sensor"), "", N_("Trilinear sensor"),
678 N_("Color sequential linear sensor"), NULL}},
679 { EXIF_TAG_ORIENTATION,
680 { "", N_("Top-left"), N_("Top-right"), N_("Bottom-right"),
681 N_("Bottom-left"), N_("Left-top"), N_("Right-top"),
682 N_("Right-bottom"), N_("Left-bottom"), NULL}},
683 { EXIF_TAG_YCBCR_POSITIONING,
684 { "", N_("Centered"), N_("Co-sited"), NULL}},
685 { EXIF_TAG_PHOTOMETRIC_INTERPRETATION,
686 { N_("Reversed mono"), N_("Normal mono"), N_("RGB"), N_("Palette"), "",
687 N_("CMYK"), N_("YCbCr"), "", N_("CieLAB"), NULL}},
688 { EXIF_TAG_CUSTOM_RENDERED,
689 { N_("Normal process"), N_("Custom process"), NULL}},
690 { EXIF_TAG_EXPOSURE_MODE,
691 { N_("Auto exposure"), N_("Manual exposure"), N_("Auto bracket"), NULL}},
692 { EXIF_TAG_WHITE_BALANCE,
693 { N_("Auto white balance"), N_("Manual white balance"), NULL}},
694 { EXIF_TAG_SCENE_CAPTURE_TYPE,
695 { N_("Standard"), N_("Landscape"), N_("Portrait"),
696 N_("Night scene"), NULL}},
697 { EXIF_TAG_GAIN_CONTROL,
698 { N_("Normal"), N_("Low gain up"), N_("High gain up"),
699 N_("Low gain down"), N_("High gain down"), NULL}},
700 { EXIF_TAG_SATURATION,
701 { N_("Normal"), N_("Low saturation"), N_("High saturation"), NULL}},
702 { EXIF_TAG_CONTRAST , {N_("Normal"), N_("Soft"), N_("Hard"), NULL}},
703 { EXIF_TAG_SHARPNESS, {N_("Normal"), N_("Soft"), N_("Hard"), NULL}},
708 static const struct {
712 const char *values[4]; /*!< list of progressively shorter string
713 descriptions; the longest one that fits will be
717 #ifndef NO_VERBOSE_TAG_DATA
718 { EXIF_TAG_METERING_MODE,
719 { { 0, {N_("Unknown"), NULL}},
720 { 1, {N_("Average"), N_("Avg"), NULL}},
721 { 2, {N_("Center-weighted average"), N_("Center-weight"), NULL}},
722 { 3, {N_("Spot"), NULL}},
723 { 4, {N_("Multi spot"), NULL}},
724 { 5, {N_("Pattern"), NULL}},
725 { 6, {N_("Partial"), NULL}},
726 {255, {N_("Other"), NULL}},
728 { EXIF_TAG_COMPRESSION,
729 { {1, {N_("Uncompressed"), NULL}},
730 {5, {N_("LZW compression"), NULL}},
731 {6, {N_("JPEG compression"), NULL}},
732 {7, {N_("JPEG compression"), NULL}},
733 {8, {N_("Deflate/ZIP compression"), NULL}},
734 {32773, {N_("PackBits compression"), NULL}},
736 { EXIF_TAG_LIGHT_SOURCE,
737 { { 0, {N_("Unknown"), NULL}},
738 { 1, {N_("Daylight"), NULL}},
739 { 2, {N_("Fluorescent"), NULL}},
740 { 3, {N_("Tungsten incandescent light"), N_("Tungsten"), NULL}},
741 { 4, {N_("Flash"), NULL}},
742 { 9, {N_("Fine weather"), NULL}},
743 { 10, {N_("Cloudy weather"), N_("Cloudy"), NULL}},
744 { 11, {N_("Shade"), NULL}},
745 { 12, {N_("Daylight fluorescent"), NULL}},
746 { 13, {N_("Day white fluorescent"), NULL}},
747 { 14, {N_("Cool white fluorescent"), NULL}},
748 { 15, {N_("White fluorescent"), NULL}},
749 { 17, {N_("Standard light A"), NULL}},
750 { 18, {N_("Standard light B"), NULL}},
751 { 19, {N_("Standard light C"), NULL}},
752 { 20, {N_("D55"), NULL}},
753 { 21, {N_("D65"), NULL}},
754 { 22, {N_("D75"), NULL}},
755 { 24, {N_("ISO studio tungsten"),NULL}},
756 {255, {N_("Other"), NULL}},
758 { EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT,
759 { {2, {N_("Inch"), N_("in"), NULL}},
760 {3, {N_("Centimeter"), N_("cm"), NULL}},
762 { EXIF_TAG_RESOLUTION_UNIT,
763 { {2, {N_("Inch"), N_("in"), NULL}},
764 {3, {N_("Centimeter"), N_("cm"), NULL}},
766 { EXIF_TAG_EXPOSURE_PROGRAM,
767 { {0, {N_("Not defined"), NULL}},
768 {1, {N_("Manual"), NULL}},
769 {2, {N_("Normal program"), N_("Normal"), NULL}},
770 {3, {N_("Aperture priority"), N_("Aperture"), NULL}},
771 {4, {N_("Shutter priority"),N_("Shutter"), NULL}},
772 {5, {N_("Creative program (biased toward depth of field)"),
773 N_("Creative"), NULL}},
774 {6, {N_("Creative program (biased toward fast shutter speed)"),
775 N_("Action"), NULL}},
776 {7, {N_("Portrait mode (for closeup photos with the background out "
777 "of focus)"), N_("Portrait"), NULL}},
778 {8, {N_("Landscape mode (for landscape photos with the background "
779 "in focus)"), N_("Landscape"), NULL}},
782 { {0x0000, {N_("Flash did not fire"), N_("No flash"), NULL}},
783 {0x0001, {N_("Flash fired"), N_("Flash"), N_("Yes"), NULL}},
784 {0x0005, {N_("Strobe return light not detected"), N_("Without strobe"),
786 {0x0007, {N_("Strobe return light detected"), N_("With strobe"), NULL}},
787 {0x0008, {N_("Flash did not fire"), NULL}}, /* Olympus E-330 */
788 {0x0009, {N_("Flash fired, compulsory flash mode"), NULL}},
789 {0x000d, {N_("Flash fired, compulsory flash mode, return light "
790 "not detected"), NULL}},
791 {0x000f, {N_("Flash fired, compulsory flash mode, return light "
793 {0x0010, {N_("Flash did not fire, compulsory flash mode"), NULL}},
794 {0x0018, {N_("Flash did not fire, auto mode"), NULL}},
795 {0x0019, {N_("Flash fired, auto mode"), NULL}},
796 {0x001d, {N_("Flash fired, auto mode, return light not detected"),
798 {0x001f, {N_("Flash fired, auto mode, return light detected"), NULL}},
799 {0x0020, {N_("No flash function"),NULL}},
800 {0x0041, {N_("Flash fired, red-eye reduction mode"), NULL}},
801 {0x0045, {N_("Flash fired, red-eye reduction mode, return light "
802 "not detected"), NULL}},
803 {0x0047, {N_("Flash fired, red-eye reduction mode, return light "
805 {0x0049, {N_("Flash fired, compulsory flash mode, red-eye reduction "
807 {0x004d, {N_("Flash fired, compulsory flash mode, red-eye reduction "
808 "mode, return light not detected"), NULL}},
809 {0x004f, {N_("Flash fired, compulsory flash mode, red-eye reduction mode, "
810 "return light detected"), NULL}},
811 {0x0058, {N_("Flash did not fire, auto mode, red-eye reduction mode"), NULL}},
812 {0x0059, {N_("Flash fired, auto mode, red-eye reduction mode"), NULL}},
813 {0x005d, {N_("Flash fired, auto mode, return light not detected, "
814 "red-eye reduction mode"), NULL}},
815 {0x005f, {N_("Flash fired, auto mode, return light detected, "
816 "red-eye reduction mode"), NULL}},
818 { EXIF_TAG_SUBJECT_DISTANCE_RANGE,
819 { {0, {N_("Unknown"), N_("?"), NULL}},
820 {1, {N_("Macro"), NULL}},
821 {2, {N_("Close view"), N_("Close"), NULL}},
822 {3, {N_("Distant view"), N_("Distant"), NULL}},
824 { EXIF_TAG_COLOR_SPACE,
825 { {1, {N_("sRGB"), NULL}},
826 {2, {N_("Adobe RGB"), NULL}},
827 {0xffff, {N_("Uncalibrated"), NULL}},
830 {0, { { 0, {NULL}}} }
834 exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen)
836 unsigned int i, j, k;
837 ExifShort v_short, v_short2, v_short3, v_short4;
840 ExifSRational v_srat;
846 static const struct {
860 (void) bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
862 if (!e || !e->parent || !e->parent->parent || !maxlen || !val)
865 /* make sure the returned string is zero terminated */
866 /* FIXME: this is inefficient in the case of long buffers and should
867 * instead be taken care of on each write instead. */
868 memset (val, 0, maxlen);
870 /* We need the byte order */
871 o = exif_data_get_byte_order (e->parent->parent);
874 if (e->size != e->components * exif_format_get_size (e->format)) {
875 snprintf (val, maxlen, _("Invalid size of entry (%i, "
876 "expected %li x %i)."), e->size, e->components,
877 exif_format_get_size (e->format));
882 case EXIF_TAG_USER_COMMENT:
885 * The specification says UNDEFINED, but some
886 * manufacturers don't care and use ASCII. If this is the
887 * case here, only refuse to read it if there is no chance
888 * of finding readable data.
890 if ((e->format != EXIF_FORMAT_ASCII) ||
892 ( memcmp (e->data, "ASCII\0\0\0" , 8) &&
893 memcmp (e->data, "UNICODE\0" , 8) &&
894 memcmp (e->data, "JIS\0\0\0\0\0", 8) &&
895 memcmp (e->data, "\0\0\0\0\0\0\0\0", 8)))
896 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
899 * Note that, according to the specification (V2.1, p 40),
900 * the user comment field does not have to be
903 if ((e->size >= 8) && !memcmp (e->data, "ASCII\0\0\0", 8)) {
904 strncpy (val, (char *) e->data + 8, MIN (e->size - 8, maxlen-1));
907 if ((e->size >= 8) && !memcmp (e->data, "UNICODE\0", 8)) {
908 strncpy (val, _("Unsupported UNICODE string"), maxlen-1);
909 /* FIXME: use iconv to convert into the locale encoding.
910 * EXIF 2.2 implies (but does not say) that this encoding is
915 if ((e->size >= 8) && !memcmp (e->data, "JIS\0\0\0\0\0", 8)) {
916 strncpy (val, _("Unsupported JIS string"), maxlen-1);
917 /* FIXME: use iconv to convert into the locale encoding */
921 /* Check if there is really some information in the tag. */
922 for (i = 0; (i < e->size) &&
923 (!e->data[i] || (e->data[i] == ' ')); i++);
924 if (i == e->size) break;
927 * If we reach this point, the tag does not
928 * comply with the standard but seems to contain data.
929 * Print as much as possible.
930 * Note: make sure we do not overwrite the final \0 at maxlen-1
932 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
933 _("Tag UserComment contains data but is "
934 "against specification."));
935 for (j = 0; (i < e->size) && (j < maxlen-1); i++, j++) {
936 exif_entry_log (e, EXIF_LOG_CODE_DEBUG,
937 _("Byte at position %i: 0x%02x"), i, e->data[i]);
938 val[j] = isprint (e->data[i]) ? e->data[i] : '.';
942 case EXIF_TAG_EXIF_VERSION:
943 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
944 CC (e, 4, val, maxlen);
945 strncpy (val, _("Unknown Exif Version"), maxlen-1);
946 for (i = 0; *versions[i].label; i++) {
947 if (!memcmp (e->data, versions[i].label, 4)) {
948 snprintf (val, maxlen,
949 _("Exif Version %d.%d"),
956 case EXIF_TAG_FLASH_PIX_VERSION:
957 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
958 CC (e, 4, val, maxlen);
959 if (!memcmp (e->data, "0100", 4))
960 strncpy (val, _("FlashPix Version 1.0"), maxlen-1);
961 else if (!memcmp (e->data, "0101", 4))
962 strncpy (val, _("FlashPix Version 1.01"), maxlen-1);
964 strncpy (val, _("Unknown FlashPix Version"), maxlen-1);
966 case EXIF_TAG_COPYRIGHT:
967 CF (e, EXIF_FORMAT_ASCII, val, maxlen);
970 * First part: Photographer.
971 * Some cameras store a string like " " here. Ignore it.
972 * Remember that a corrupted tag might not be NUL-terminated
974 if (e->size && e->data && match_repeated_char(e->data, ' ', e->size))
975 strncpy (val, (char *) e->data, MIN (maxlen-1, e->size));
977 strncpy (val, _("[None]"), maxlen-1);
978 strncat (val, " ", maxlen-1 - strlen (val));
979 strncat (val, _("(Photographer)"), maxlen-1 - strlen (val));
981 /* Second part: Editor. */
982 strncat (val, " - ", maxlen-1 - strlen (val));
984 if (e->size && e->data) {
985 const unsigned char *tagdata = memchr(e->data, 0, e->size);
987 unsigned int editor_ofs = tagdata - e->data;
988 unsigned int remaining = e->size - editor_ofs;
989 if (match_repeated_char(tagdata, ' ', remaining)) {
990 strncat (val, (const char*)tagdata, MIN (maxlen-1 - strlen (val), remaining));
996 strncat (val, _("[None]"), maxlen-1 - strlen (val));
997 strncat (val, " ", maxlen-1 - strlen (val));
998 strncat (val, _("(Editor)"), maxlen-1 - strlen (val));
1001 case EXIF_TAG_FNUMBER:
1002 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1003 CC (e, 1, val, maxlen);
1004 v_rat = exif_get_rational (e->data, o);
1005 if (!v_rat.denominator) {
1006 exif_entry_format_value(e, val, maxlen);
1009 d = (double) v_rat.numerator / (double) v_rat.denominator;
1010 snprintf (val, maxlen, "f/%.01f", d);
1012 case EXIF_TAG_APERTURE_VALUE:
1013 case EXIF_TAG_MAX_APERTURE_VALUE:
1014 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1015 CC (e, 1, val, maxlen);
1016 v_rat = exif_get_rational (e->data, o);
1017 if (!v_rat.denominator || (0x80000000 == v_rat.numerator)) {
1018 exif_entry_format_value(e, val, maxlen);
1021 d = (double) v_rat.numerator / (double) v_rat.denominator;
1022 snprintf (val, maxlen, _("%.02f EV"), d);
1023 snprintf (b, sizeof (b), _(" (f/%.01f)"), pow (2, d / 2.));
1024 strncat (val, b, maxlen-1 - strlen (val));
1026 case EXIF_TAG_FOCAL_LENGTH:
1027 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1028 CC (e, 1, val, maxlen);
1029 v_rat = exif_get_rational (e->data, o);
1030 if (!v_rat.denominator) {
1031 exif_entry_format_value(e, val, maxlen);
1036 * For calculation of the 35mm equivalent,
1037 * Minolta cameras need a multiplier that depends on the
1041 entry = exif_content_get_entry (
1042 e->parent->parent->ifd[EXIF_IFD_0], EXIF_TAG_MAKE);
1043 if (entry && entry->data && entry->size >= 7 &&
1044 !strncmp ((char *)entry->data, "Minolta", 7)) {
1045 entry = exif_content_get_entry (
1046 e->parent->parent->ifd[EXIF_IFD_0],
1048 if (entry && entry->data && entry->size >= 8) {
1049 if (!strncmp ((char *)entry->data, "DiMAGE 7", 8))
1051 else if (!strncmp ((char *)entry->data, "DiMAGE 5", 8))
1056 snprintf (b, sizeof (b), _(" (35 equivalent: %.0f mm)"),
1057 (d * (double) v_rat.numerator /
1058 (double) v_rat.denominator));
1062 d = (double) v_rat.numerator / (double) v_rat.denominator;
1063 snprintf (val, maxlen, "%.1f mm", d);
1064 strncat (val, b, maxlen-1 - strlen (val));
1066 case EXIF_TAG_SUBJECT_DISTANCE:
1067 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1068 CC (e, 1, val, maxlen);
1069 v_rat = exif_get_rational (e->data, o);
1070 if (!v_rat.denominator) {
1071 exif_entry_format_value(e, val, maxlen);
1074 d = (double) v_rat.numerator / (double) v_rat.denominator;
1075 snprintf (val, maxlen, "%.1f m", d);
1077 case EXIF_TAG_EXPOSURE_TIME:
1078 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1079 CC (e, 1, val, maxlen);
1080 v_rat = exif_get_rational (e->data, o);
1081 if (!v_rat.denominator) {
1082 exif_entry_format_value(e, val, maxlen);
1085 d = (double) v_rat.numerator / (double) v_rat.denominator;
1087 snprintf (val, maxlen, _("1/%.0f"), 1. / d);
1089 snprintf (val, maxlen, "%.0f", d);
1090 strncat (val, _(" sec."), maxlen-1 - strlen (val));
1092 case EXIF_TAG_SHUTTER_SPEED_VALUE:
1093 CF (e, EXIF_FORMAT_SRATIONAL, val, maxlen);
1094 CC (e, 1, val, maxlen);
1095 v_srat = exif_get_srational (e->data, o);
1096 if (!v_srat.denominator) {
1097 exif_entry_format_value(e, val, maxlen);
1100 d = (double) v_srat.numerator / (double) v_srat.denominator;
1101 snprintf (val, maxlen, _("%.02f EV"), d);
1103 d = 1. / pow (2, d);
1105 snprintf (b, sizeof (b), _(" (1/%.0f sec.)"), 1. / d);
1107 snprintf (b, sizeof (b), _(" (%.0f sec.)"), d);
1108 strncat (val, b, maxlen-1 - strlen (val));
1110 case EXIF_TAG_BRIGHTNESS_VALUE:
1111 CF (e, EXIF_FORMAT_SRATIONAL, val, maxlen);
1112 CC (e, 1, val, maxlen);
1113 v_srat = exif_get_srational (e->data, o);
1114 if (!v_srat.denominator) {
1115 exif_entry_format_value(e, val, maxlen);
1118 d = (double) v_srat.numerator / (double) v_srat.denominator;
1119 snprintf (val, maxlen, _("%.02f EV"), d);
1120 snprintf (b, sizeof (b), _(" (%.02f cd/m^2)"),
1121 1. / (M_PI * 0.3048 * 0.3048) * pow (2, d));
1122 strncat (val, b, maxlen-1 - strlen (val));
1124 case EXIF_TAG_FILE_SOURCE:
1125 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
1126 CC (e, 1, val, maxlen);
1127 v_byte = e->data[0];
1129 strncpy (val, _("DSC"), maxlen-1);
1131 snprintf (val, maxlen, _("Internal error (unknown "
1132 "value %i)"), v_byte);
1134 case EXIF_TAG_COMPONENTS_CONFIGURATION:
1135 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
1136 CC (e, 4, val, maxlen);
1137 for (i = 0; i < 4; i++) {
1138 switch (e->data[i]) {
1139 case 0: c = _("-"); break;
1140 case 1: c = _("Y"); break;
1141 case 2: c = _("Cb"); break;
1142 case 3: c = _("Cr"); break;
1143 case 4: c = _("R"); break;
1144 case 5: c = _("G"); break;
1145 case 6: c = _("B"); break;
1146 default: c = _("Reserved"); break;
1148 strncat (val, c, maxlen-1 - strlen (val));
1150 strncat (val, " ", maxlen-1 - strlen (val));
1153 case EXIF_TAG_EXPOSURE_BIAS_VALUE:
1154 CF (e, EXIF_FORMAT_SRATIONAL, val, maxlen);
1155 CC (e, 1, val, maxlen);
1156 v_srat = exif_get_srational (e->data, o);
1157 if (!v_srat.denominator) {
1158 exif_entry_format_value(e, val, maxlen);
1161 d = (double) v_srat.numerator / (double) v_srat.denominator;
1162 snprintf (val, maxlen, _("%.02f EV"), d);
1164 case EXIF_TAG_SCENE_TYPE:
1165 CF (e, EXIF_FORMAT_UNDEFINED, val, maxlen);
1166 CC (e, 1, val, maxlen);
1167 v_byte = e->data[0];
1169 strncpy (val, _("Directly photographed"), maxlen-1);
1171 snprintf (val, maxlen, _("Internal error (unknown "
1172 "value %i)"), v_byte);
1174 case EXIF_TAG_YCBCR_SUB_SAMPLING:
1175 CF (e, EXIF_FORMAT_SHORT, val, maxlen);
1176 CC (e, 2, val, maxlen);
1177 v_short = exif_get_short (e->data, o);
1178 v_short2 = exif_get_short (
1179 e->data + exif_format_get_size (e->format),
1181 if ((v_short == 2) && (v_short2 == 1))
1182 strncpy (val, _("YCbCr4:2:2"), maxlen-1);
1183 else if ((v_short == 2) && (v_short2 == 2))
1184 strncpy (val, _("YCbCr4:2:0"), maxlen-1);
1186 snprintf (val, maxlen, "%u, %u", v_short, v_short2);
1188 case EXIF_TAG_SUBJECT_AREA:
1189 CF (e, EXIF_FORMAT_SHORT, val, maxlen);
1190 switch (e->components) {
1192 v_short = exif_get_short (e->data, o);
1193 v_short2 = exif_get_short (e->data + 2, o);
1194 snprintf (val, maxlen, "(x,y) = (%i,%i)",
1198 v_short = exif_get_short (e->data, o);
1199 v_short2 = exif_get_short (e->data + 2, o);
1200 v_short3 = exif_get_short (e->data + 4, o);
1201 snprintf (val, maxlen, _("Within distance %i of "
1202 "(x,y) = (%i,%i)"), v_short3, v_short,
1206 v_short = exif_get_short (e->data, o);
1207 v_short2 = exif_get_short (e->data + 2, o);
1208 v_short3 = exif_get_short (e->data + 4, o);
1209 v_short4 = exif_get_short (e->data + 6, o);
1210 snprintf (val, maxlen, _("Within rectangle "
1211 "(width %i, height %i) around "
1212 "(x,y) = (%i,%i)"), v_short3, v_short4,
1216 snprintf (val, maxlen, _("Unexpected number "
1217 "of components (%li, expected 2, 3, or 4)."),
1221 case EXIF_TAG_GPS_VERSION_ID:
1222 /* This is only valid in the GPS IFD */
1223 CF (e, EXIF_FORMAT_BYTE, val, maxlen);
1224 CC (e, 4, val, maxlen);
1225 v_byte = e->data[0];
1226 snprintf (val, maxlen, "%u", v_byte);
1227 for (i = 1; i < e->components; i++) {
1228 v_byte = e->data[i];
1229 snprintf (b, sizeof (b), ".%u", v_byte);
1230 strncat (val, b, maxlen-1 - strlen (val));
1233 case EXIF_TAG_INTEROPERABILITY_VERSION:
1234 /* a.k.a. case EXIF_TAG_GPS_LATITUDE: */
1235 /* This tag occurs in EXIF_IFD_INTEROPERABILITY */
1236 if (e->format == EXIF_FORMAT_UNDEFINED) {
1237 strncpy (val, (char *) e->data, MIN (maxlen-1, e->size));
1240 /* EXIF_TAG_GPS_LATITUDE is the same numerically as
1241 * EXIF_TAG_INTEROPERABILITY_VERSION but in EXIF_IFD_GPS
1243 exif_entry_format_value(e, val, maxlen);
1245 case EXIF_TAG_GPS_ALTITUDE_REF:
1246 /* This is only valid in the GPS IFD */
1247 CF (e, EXIF_FORMAT_BYTE, val, maxlen);
1248 CC (e, 1, val, maxlen);
1249 v_byte = e->data[0];
1251 strncpy (val, _("Sea level"), maxlen-1);
1252 else if (v_byte == 1)
1253 strncpy (val, _("Sea level reference"), maxlen-1);
1255 snprintf (val, maxlen, _("Internal error (unknown "
1256 "value %i)"), v_byte);
1258 case EXIF_TAG_GPS_TIME_STAMP:
1259 /* This is only valid in the GPS IFD */
1260 CF (e, EXIF_FORMAT_RATIONAL, val, maxlen);
1261 CC (e, 3, val, maxlen);
1263 v_rat = exif_get_rational (e->data, o);
1264 if (!v_rat.denominator) {
1265 exif_entry_format_value(e, val, maxlen);
1268 i = v_rat.numerator / v_rat.denominator;
1270 v_rat = exif_get_rational (e->data +
1271 exif_format_get_size (e->format),
1273 if (!v_rat.denominator) {
1274 exif_entry_format_value(e, val, maxlen);
1277 j = v_rat.numerator / v_rat.denominator;
1279 v_rat = exif_get_rational (e->data +
1280 2*exif_format_get_size (e->format),
1282 if (!v_rat.denominator) {
1283 exif_entry_format_value(e, val, maxlen);
1286 d = (double) v_rat.numerator / (double) v_rat.denominator;
1287 snprintf (val, maxlen, "%02u:%02u:%05.2f", i, j, d);
1290 case EXIF_TAG_METERING_MODE:
1291 case EXIF_TAG_COMPRESSION:
1292 case EXIF_TAG_LIGHT_SOURCE:
1293 case EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT:
1294 case EXIF_TAG_RESOLUTION_UNIT:
1295 case EXIF_TAG_EXPOSURE_PROGRAM:
1296 case EXIF_TAG_FLASH:
1297 case EXIF_TAG_SUBJECT_DISTANCE_RANGE:
1298 case EXIF_TAG_COLOR_SPACE:
1299 CF (e,EXIF_FORMAT_SHORT, val, maxlen);
1300 CC (e, 1, val, maxlen);
1301 v_short = exif_get_short (e->data, o);
1303 /* Search the tag */
1304 for (i = 0; list2[i].tag && (list2[i].tag != e->tag); i++);
1305 if (!list2[i].tag) {
1306 snprintf (val, maxlen, _("Internal error (unknown "
1307 "value %i)"), v_short);
1311 /* Find the value */
1312 for (j = 0; list2[i].elem[j].values[0] &&
1313 (list2[i].elem[j].index < v_short); j++);
1314 if (list2[i].elem[j].index != v_short) {
1315 snprintf (val, maxlen, _("Internal error (unknown "
1316 "value %i)"), v_short);
1320 /* Find a short enough value */
1321 memset (val, 0, maxlen);
1322 for (k = 0; list2[i].elem[j].values[k]; k++) {
1323 size_t l = strlen (_(list2[i].elem[j].values[k]));
1324 if ((maxlen > l) && (strlen (val) < l))
1325 strncpy (val, _(list2[i].elem[j].values[k]), maxlen-1);
1327 if (!val[0]) snprintf (val, maxlen, "%i", v_short);
1331 case EXIF_TAG_PLANAR_CONFIGURATION:
1332 case EXIF_TAG_SENSING_METHOD:
1333 case EXIF_TAG_ORIENTATION:
1334 case EXIF_TAG_YCBCR_POSITIONING:
1335 case EXIF_TAG_PHOTOMETRIC_INTERPRETATION:
1336 case EXIF_TAG_CUSTOM_RENDERED:
1337 case EXIF_TAG_EXPOSURE_MODE:
1338 case EXIF_TAG_WHITE_BALANCE:
1339 case EXIF_TAG_SCENE_CAPTURE_TYPE:
1340 case EXIF_TAG_GAIN_CONTROL:
1341 case EXIF_TAG_SATURATION:
1342 case EXIF_TAG_CONTRAST:
1343 case EXIF_TAG_SHARPNESS:
1344 CF (e, EXIF_FORMAT_SHORT, val, maxlen);
1345 CC (e, 1, val, maxlen);
1346 v_short = exif_get_short (e->data, o);
1348 /* Search the tag */
1349 for (i = 0; list[i].tag && (list[i].tag != e->tag); i++);
1351 snprintf (val, maxlen, _("Internal error (unknown "
1352 "value %i)"), v_short);
1356 /* Find the value */
1357 for (j = 0; list[i].strings[j] && (j < v_short); j++);
1358 if (!list[i].strings[j])
1359 snprintf (val, maxlen, "%i", v_short);
1360 else if (!*list[i].strings[j])
1361 snprintf (val, maxlen, _("Unknown value %i"), v_short);
1363 strncpy (val, _(list[i].strings[j]), maxlen-1);
1366 case EXIF_TAG_XP_TITLE:
1367 case EXIF_TAG_XP_COMMENT:
1368 case EXIF_TAG_XP_AUTHOR:
1369 case EXIF_TAG_XP_KEYWORDS:
1370 case EXIF_TAG_XP_SUBJECT:
1372 unsigned char *utf16;
1374 /* Sanity check the size to prevent overflow */
1375 if (e->size+sizeof(uint16_t)+1 < e->size) break;
1377 /* The tag may not be U+0000-terminated , so make a local
1378 U+0000-terminated copy before converting it */
1379 utf16 = exif_mem_alloc (e->priv->mem, e->size+sizeof(uint16_t)+1);
1381 memcpy(utf16, e->data, e->size);
1383 /* NUL terminate the string. If the size is odd (which isn't possible
1384 * for a valid UTF16 string), then this will overwrite the high byte of
1385 * the final half word, plus add a full zero NUL word at the end.
1388 utf16[e->size+1] = 0;
1389 utf16[e->size+2] = 0;
1391 /* Warning! The texts are converted from UTF16 to UTF8 */
1392 /* FIXME: use iconv to convert into the locale encoding */
1393 exif_convert_utf16_to_utf8(val, utf16, maxlen);
1394 exif_mem_free(e->priv->mem, utf16);
1399 /* Use a generic value formatting */
1400 exif_entry_format_value(e, val, maxlen);
1408 * \bug Log and report failed exif_mem_malloc() calls.
1411 exif_entry_initialize (ExifEntry *e, ExifTag tag)
1416 /* We need the byte order */
1417 if (!e || !e->parent || e->data || !e->parent->parent)
1419 o = exif_data_get_byte_order (e->parent->parent);
1424 /* LONG, 1 component, no default */
1425 case EXIF_TAG_PIXEL_X_DIMENSION:
1426 case EXIF_TAG_PIXEL_Y_DIMENSION:
1427 case EXIF_TAG_EXIF_IFD_POINTER:
1428 case EXIF_TAG_GPS_INFO_IFD_POINTER:
1429 case EXIF_TAG_INTEROPERABILITY_IFD_POINTER:
1430 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH:
1431 case EXIF_TAG_JPEG_INTERCHANGE_FORMAT:
1433 e->format = EXIF_FORMAT_LONG;
1434 e->size = exif_format_get_size (e->format) * e->components;
1435 e->data = exif_entry_alloc (e, e->size);
1436 if (!e->data) { clear_entry(e); break; }
1439 /* SHORT, 1 component, no default */
1440 case EXIF_TAG_SUBJECT_LOCATION:
1441 case EXIF_TAG_SENSING_METHOD:
1442 case EXIF_TAG_PHOTOMETRIC_INTERPRETATION:
1443 case EXIF_TAG_COMPRESSION:
1444 case EXIF_TAG_EXPOSURE_MODE:
1445 case EXIF_TAG_WHITE_BALANCE:
1446 case EXIF_TAG_FOCAL_LENGTH_IN_35MM_FILM:
1447 case EXIF_TAG_GAIN_CONTROL:
1448 case EXIF_TAG_SUBJECT_DISTANCE_RANGE:
1449 case EXIF_TAG_FLASH:
1450 case EXIF_TAG_ISO_SPEED_RATINGS:
1452 /* SHORT, 1 component, default 0 */
1453 case EXIF_TAG_IMAGE_WIDTH:
1454 case EXIF_TAG_IMAGE_LENGTH:
1455 case EXIF_TAG_EXPOSURE_PROGRAM:
1456 case EXIF_TAG_LIGHT_SOURCE:
1457 case EXIF_TAG_METERING_MODE:
1458 case EXIF_TAG_CUSTOM_RENDERED:
1459 case EXIF_TAG_SCENE_CAPTURE_TYPE:
1460 case EXIF_TAG_CONTRAST:
1461 case EXIF_TAG_SATURATION:
1462 case EXIF_TAG_SHARPNESS:
1464 e->format = EXIF_FORMAT_SHORT;
1465 e->size = exif_format_get_size (e->format) * e->components;
1466 e->data = exif_entry_alloc (e, e->size);
1467 if (!e->data) { clear_entry(e); break; }
1468 exif_set_short (e->data, o, 0);
1471 /* SHORT, 1 component, default 1 */
1472 case EXIF_TAG_ORIENTATION:
1473 case EXIF_TAG_PLANAR_CONFIGURATION:
1474 case EXIF_TAG_YCBCR_POSITIONING:
1476 e->format = EXIF_FORMAT_SHORT;
1477 e->size = exif_format_get_size (e->format) * e->components;
1478 e->data = exif_entry_alloc (e, e->size);
1479 if (!e->data) { clear_entry(e); break; }
1480 exif_set_short (e->data, o, 1);
1483 /* SHORT, 1 component, default 2 */
1484 case EXIF_TAG_RESOLUTION_UNIT:
1485 case EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT:
1487 e->format = EXIF_FORMAT_SHORT;
1488 e->size = exif_format_get_size (e->format) * e->components;
1489 e->data = exif_entry_alloc (e, e->size);
1490 if (!e->data) { clear_entry(e); break; }
1491 exif_set_short (e->data, o, 2);
1494 /* SHORT, 1 component, default 3 */
1495 case EXIF_TAG_SAMPLES_PER_PIXEL:
1497 e->format = EXIF_FORMAT_SHORT;
1498 e->size = exif_format_get_size (e->format) * e->components;
1499 e->data = exif_entry_alloc (e, e->size);
1500 if (!e->data) { clear_entry(e); break; }
1501 exif_set_short (e->data, o, 3);
1504 /* SHORT, 1 component, default 0xffff */
1505 case EXIF_TAG_COLOR_SPACE:
1507 e->format = EXIF_FORMAT_SHORT;
1508 e->size = exif_format_get_size (e->format) * e->components;
1509 e->data = exif_entry_alloc (e, e->size);
1510 if (!e->data) { clear_entry(e); break; }
1511 exif_set_short (e->data, o, 0xffff);
1514 /* SHORT, 3 components, default 8 8 8 */
1515 case EXIF_TAG_BITS_PER_SAMPLE:
1517 e->format = EXIF_FORMAT_SHORT;
1518 e->size = exif_format_get_size (e->format) * e->components;
1519 e->data = exif_entry_alloc (e, e->size);
1520 if (!e->data) { clear_entry(e); break; }
1521 exif_set_short (e->data, o, 8);
1523 e->data + exif_format_get_size (e->format),
1526 e->data + 2 * exif_format_get_size (e->format),
1530 /* SHORT, 2 components, default 2 1 */
1531 case EXIF_TAG_YCBCR_SUB_SAMPLING:
1533 e->format = EXIF_FORMAT_SHORT;
1534 e->size = exif_format_get_size (e->format) * e->components;
1535 e->data = exif_entry_alloc (e, e->size);
1536 if (!e->data) { clear_entry(e); break; }
1537 exif_set_short (e->data, o, 2);
1539 e->data + exif_format_get_size (e->format),
1543 /* SRATIONAL, 1 component, no default */
1544 case EXIF_TAG_EXPOSURE_BIAS_VALUE:
1545 case EXIF_TAG_BRIGHTNESS_VALUE:
1546 case EXIF_TAG_SHUTTER_SPEED_VALUE:
1548 e->format = EXIF_FORMAT_SRATIONAL;
1549 e->size = exif_format_get_size (e->format) * e->components;
1550 e->data = exif_entry_alloc (e, e->size);
1551 if (!e->data) { clear_entry(e); break; }
1554 /* RATIONAL, 1 component, no default */
1555 case EXIF_TAG_EXPOSURE_TIME:
1556 case EXIF_TAG_FOCAL_PLANE_X_RESOLUTION:
1557 case EXIF_TAG_FOCAL_PLANE_Y_RESOLUTION:
1558 case EXIF_TAG_EXPOSURE_INDEX:
1559 case EXIF_TAG_FLASH_ENERGY:
1560 case EXIF_TAG_FNUMBER:
1561 case EXIF_TAG_FOCAL_LENGTH:
1562 case EXIF_TAG_SUBJECT_DISTANCE:
1563 case EXIF_TAG_MAX_APERTURE_VALUE:
1564 case EXIF_TAG_APERTURE_VALUE:
1565 case EXIF_TAG_COMPRESSED_BITS_PER_PIXEL:
1566 case EXIF_TAG_PRIMARY_CHROMATICITIES:
1567 case EXIF_TAG_DIGITAL_ZOOM_RATIO:
1569 e->format = EXIF_FORMAT_RATIONAL;
1570 e->size = exif_format_get_size (e->format) * e->components;
1571 e->data = exif_entry_alloc (e, e->size);
1572 if (!e->data) { clear_entry(e); break; }
1575 /* RATIONAL, 1 component, default 72/1 */
1576 case EXIF_TAG_X_RESOLUTION:
1577 case EXIF_TAG_Y_RESOLUTION:
1579 e->format = EXIF_FORMAT_RATIONAL;
1580 e->size = exif_format_get_size (e->format) * e->components;
1581 e->data = exif_entry_alloc (e, e->size);
1582 if (!e->data) { clear_entry(e); break; }
1585 exif_set_rational (e->data, o, r);
1588 /* RATIONAL, 2 components, no default */
1589 case EXIF_TAG_WHITE_POINT:
1591 e->format = EXIF_FORMAT_RATIONAL;
1592 e->size = exif_format_get_size (e->format) * e->components;
1593 e->data = exif_entry_alloc (e, e->size);
1594 if (!e->data) { clear_entry(e); break; }
1597 /* RATIONAL, 6 components */
1598 case EXIF_TAG_REFERENCE_BLACK_WHITE:
1600 e->format = EXIF_FORMAT_RATIONAL;
1601 e->size = exif_format_get_size (e->format) * e->components;
1602 e->data = exif_entry_alloc (e, e->size);
1603 if (!e->data) { clear_entry(e); break; }
1606 exif_set_rational (e->data, o, r);
1609 e->data + exif_format_get_size (e->format), o, r);
1612 e->data + 2 * exif_format_get_size (e->format), o, r);
1615 e->data + 3 * exif_format_get_size (e->format), o, r);
1618 e->data + 4 * exif_format_get_size (e->format), o, r);
1621 e->data + 5 * exif_format_get_size (e->format), o, r);
1624 /* ASCII, 20 components */
1625 case EXIF_TAG_DATE_TIME:
1626 case EXIF_TAG_DATE_TIME_ORIGINAL:
1627 case EXIF_TAG_DATE_TIME_DIGITIZED:
1630 #ifdef HAVE_LOCALTIME_R
1636 #ifdef HAVE_LOCALTIME_R
1637 tm = localtime_r (&t, &tms);
1639 tm = localtime (&t);
1642 e->format = EXIF_FORMAT_ASCII;
1643 e->size = exif_format_get_size (e->format) * e->components;
1644 e->data = exif_entry_alloc (e, e->size);
1645 if (!e->data) { clear_entry(e); break; }
1646 snprintf ((char *) e->data, e->size,
1647 "%04i:%02i:%02i %02i:%02i:%02i",
1648 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1649 tm->tm_hour, tm->tm_min, tm->tm_sec);
1653 /* ASCII, no default */
1654 case EXIF_TAG_SUB_SEC_TIME:
1655 case EXIF_TAG_SUB_SEC_TIME_ORIGINAL:
1656 case EXIF_TAG_SUB_SEC_TIME_DIGITIZED:
1658 e->format = EXIF_FORMAT_ASCII;
1663 /* ASCII, default "[None]" */
1664 case EXIF_TAG_IMAGE_DESCRIPTION:
1666 case EXIF_TAG_MODEL:
1667 case EXIF_TAG_SOFTWARE:
1668 case EXIF_TAG_ARTIST:
1669 e->components = strlen (_("[None]")) + 1;
1670 e->format = EXIF_FORMAT_ASCII;
1671 e->size = exif_format_get_size (e->format) * e->components;
1672 e->data = exif_entry_alloc (e, e->size);
1673 if (!e->data) { clear_entry(e); break; }
1674 strncpy ((char *)e->data, _("[None]"), e->size);
1676 /* ASCII, default "[None]\0[None]\0" */
1677 case EXIF_TAG_COPYRIGHT:
1678 e->components = (strlen (_("[None]")) + 1) * 2;
1679 e->format = EXIF_FORMAT_ASCII;
1680 e->size = exif_format_get_size (e->format) * e->components;
1681 e->data = exif_entry_alloc (e, e->size);
1682 if (!e->data) { clear_entry(e); break; }
1683 strcpy (((char *)e->data) + 0, _("[None]"));
1684 strcpy (((char *)e->data) + strlen (_("[None]")) + 1, _("[None]"));
1687 /* UNDEFINED, 1 component, default 1 */
1688 case EXIF_TAG_SCENE_TYPE:
1690 e->format = EXIF_FORMAT_UNDEFINED;
1691 e->size = exif_format_get_size (e->format) * e->components;
1692 e->data = exif_entry_alloc (e, e->size);
1693 if (!e->data) { clear_entry(e); break; }
1697 /* UNDEFINED, 1 component, default 3 */
1698 case EXIF_TAG_FILE_SOURCE:
1700 e->format = EXIF_FORMAT_UNDEFINED;
1701 e->size = exif_format_get_size (e->format) * e->components;
1702 e->data = exif_entry_alloc (e, e->size);
1703 if (!e->data) { clear_entry(e); break; }
1707 /* UNDEFINED, 4 components, default 48 49 48 48 */
1708 case EXIF_TAG_FLASH_PIX_VERSION:
1710 e->format = EXIF_FORMAT_UNDEFINED;
1711 e->size = exif_format_get_size (e->format) * e->components;
1712 e->data = exif_entry_alloc (e, e->size);
1713 if (!e->data) { clear_entry(e); break; }
1714 memcpy (e->data, "0100", 4);
1717 /* UNDEFINED, 4 components, default 48 50 49 48 */
1718 case EXIF_TAG_EXIF_VERSION:
1720 e->format = EXIF_FORMAT_UNDEFINED;
1721 e->size = exif_format_get_size (e->format) * e->components;
1722 e->data = exif_entry_alloc (e, e->size);
1723 if (!e->data) { clear_entry(e); break; }
1724 memcpy (e->data, "0210", 4);
1727 /* UNDEFINED, 4 components, default 1 2 3 0 */
1728 case EXIF_TAG_COMPONENTS_CONFIGURATION:
1730 e->format = EXIF_FORMAT_UNDEFINED;
1731 e->size = exif_format_get_size (e->format) * e->components;
1732 e->data = exif_entry_alloc (e, e->size);
1733 if (!e->data) { clear_entry(e); break; }
1740 /* UNDEFINED, no components, no default */
1741 /* Use this if the tag is otherwise unsupported */
1742 case EXIF_TAG_MAKER_NOTE:
1743 case EXIF_TAG_USER_COMMENT:
1746 e->format = EXIF_FORMAT_UNDEFINED;