6 * Support for Exif file format, originally written by Eric Swalens.
7 * Modified by Quy Tonthat
9 * Reimplemented with generic data storage by John Ellis (Nov 2003)
11 * The tags were added with information from the FREE document:
12 * http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
14 * For the official Exif Format, please refer to:
16 * http://www.exif.org/specifications.html (PDF spec sheets)
19 * Additional tag formats should be added to the proper
20 * location in ExifKnownMarkersList[].
22 * Human readable ouput (that needs additional processing of data to
23 * be useable) can be defined by adding a key to ExifFormattedList[],
24 * then handling that tag in the function exif_get_formatted_by_key().
25 * The human readable formatted keys must begin with the character 'f'.
27 * Unsupported at this time:
33 * Convert data to useable form in the ??_as_text function for:
34 * ComponentsConfiguration
35 * UserComment (convert this to UTF-8?)
38 This program is free software; you can redistribute it and/or modify
39 it under the terms of the GNU General Public License as published by
40 the Free Software Foundation; either version 2 of the License, or
41 (at your option) any later version.
43 This program is distributed in the hope that it will be useful,
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU General Public License for more details.
48 You should have received a copy of the GNU General Public License
49 along with this program; if not, write to the Free Software
50 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
58 #include <inttypes.h> /* stdint.h is not available on all systems... */
62 #include <sys/types.h>
73 #include "format_raw.h"
74 #include "ui_fileops.h"
76 /* makernote parsers */
77 #include "format_canon.h"
80 *-----------------------------------------------------------------------------
82 *-----------------------------------------------------------------------------
85 ExifFormatAttrib ExifFormatList[] = {
86 { EXIF_FORMAT_UNKNOWN, 1, "unknown", "unknown" },
87 { EXIF_FORMAT_BYTE_UNSIGNED, 1, "ubyte", "unsigned byte" },
88 { EXIF_FORMAT_STRING, 1, "string", "string" },
89 { EXIF_FORMAT_SHORT_UNSIGNED, 2, "ushort", "unsigned short" },
90 { EXIF_FORMAT_LONG_UNSIGNED, 4, "ulong", "unsigned long" },
91 { EXIF_FORMAT_RATIONAL_UNSIGNED,8, "urational", "unsigned rational" },
92 { EXIF_FORMAT_BYTE, 1, "byte", "byte" },
93 { EXIF_FORMAT_UNDEFINED, 1, "undefined", "undefined" },
94 { EXIF_FORMAT_SHORT, 2, "sshort", "signed short" },
95 { EXIF_FORMAT_LONG, 4, "slong", "signed long" },
96 { EXIF_FORMAT_RATIONAL, 8, "srational", "signed rational" },
97 { EXIF_FORMAT_FLOAT, 4, "float", "float" },
98 { EXIF_FORMAT_DOUBLE, 8, "double", "double" },
102 /* tags that are special, or need special treatment */
103 #define TAG_EXIFOFFSET 0x8769
104 #define TAG_EXIFMAKERNOTE 0x927c
108 *-----------------------------------------------------------------------------
110 *-----------------------------------------------------------------------------
113 static ExifTextList ExifOrientationList[] = {
114 { EXIF_ORIENTATION_UNKNOWN, N_("unknown") },
115 { EXIF_ORIENTATION_TOP_LEFT, N_("top left") },
116 { EXIF_ORIENTATION_TOP_RIGHT, N_("top right") },
117 { EXIF_ORIENTATION_BOTTOM_RIGHT,N_("bottom right") },
118 { EXIF_ORIENTATION_BOTTOM_LEFT, N_("bottom left") },
119 { EXIF_ORIENTATION_LEFT_TOP, N_("left top") },
120 { EXIF_ORIENTATION_RIGHT_TOP, N_("right top") },
121 { EXIF_ORIENTATION_RIGHT_BOTTOM,N_("right bottom") },
122 { EXIF_ORIENTATION_LEFT_BOTTOM, N_("left bottom") },
126 static ExifTextList ExifUnitList[] = {
127 { EXIF_UNIT_UNKNOWN, N_("unknown") },
128 { EXIF_UNIT_NOUNIT, "" },
129 { EXIF_UNIT_INCH, N_("inch") },
130 { EXIF_UNIT_CENTIMETER, N_("centimeter") },
134 static ExifTextList ExifYCbCrPosList[] = {
140 static ExifTextList ExifMeteringModeList[] = {
141 { 0, N_("unknown") },
142 { 1, N_("average") },
143 { 2, N_("center weighted") },
145 { 4, N_("multi-spot") },
146 { 5, N_("multi-segment") },
147 { 6, N_("partial") },
148 { 255, N_("other") },
152 static ExifTextList ExifExposureProgramList[] = {
153 { 0, N_("not defined") },
156 { 3, N_("aperture") },
157 { 4, N_("shutter") },
158 { 5, N_("creative") },
160 { 7, N_("portrait") },
161 { 8, N_("landscape") },
165 static ExifTextList ExifLightSourceList[] = {
166 { 0, N_("unknown") },
167 { 1, N_("daylight") },
168 { 2, N_("fluorescent") },
169 { 3, N_("tungsten (incandescent)") },
171 { 9, "fine weather" },
172 { 10, "cloudy weather" },
174 { 12, "daylight fluorescent" },
175 { 13, "day white fluorescent" },
176 { 14, "cool white fluorescent" },
177 { 15, "while fluorescent" },
178 { 17, "standard light A" },
179 { 18, "standard light B" },
180 { 19, "standard light C" },
185 { 24, "ISO studio tungsten" },
186 { 255, N_("other") },
190 static ExifTextList ExifFlashList[] = {
193 { 5, N_("yes, not detected by strobe") },
194 { 7, N_("yes, detected by strobe") },
198 static ExifTextList ExifColorSpaceList[] = {
200 { 65535,"uncalibrated" },
204 static ExifTextList ExifSensorList[] = {
205 { 1, "not defined" },
206 { 2, "1 chip color area" },
207 { 2, "2 chip color area" },
208 { 4, "3 chip color area" },
209 { 5, "color sequential area" },
211 { 8, "color sequential linear" },
215 static ExifTextList ExifSourceList[] = {
216 { 3, "digital still camera" },
220 static ExifTextList ExifSceneList[] = {
221 { 1, "direct photo" },
225 static ExifTextList ExifCustRenderList[] = {
231 static ExifTextList ExifExposureModeList[] = {
234 { 2, "auto bracket" },
238 static ExifTextList ExifWhiteBalanceList[] = {
244 static ExifTextList ExifSceneCaptureList[] = {
248 { 3, "night scene" },
252 static ExifTextList ExifGainControlList[] = {
254 { 1, "low gain up" },
255 { 2, "high gain up" },
256 { 3, "low gain down" },
257 { 4, "high gain down" },
261 static ExifTextList ExifContrastList[] = {
268 static ExifTextList ExifSaturationList[] = {
275 static ExifTextList ExifSharpnessList[] = {
282 static ExifTextList ExifSubjectRangeList[] = {
290 ExifMarker ExifKnownMarkersList[] = {
291 { 0x010e, EXIF_FORMAT_STRING, -1, "ImageDescription", N_("Image description"), NULL },
292 { 0x010f, EXIF_FORMAT_STRING, -1, "Make", "Camera make", NULL },
293 { 0x0110, EXIF_FORMAT_STRING, -1, "Model", "Camera model", NULL },
294 { 0x0112, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Orientation", N_("Orientation"), ExifOrientationList },
295 { 0x011a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "XResolution", "X resolution", NULL },
296 { 0x011b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "YResolution", "Y Resolution", NULL },
297 { 0x0128, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ResolutionUnit", "Resolution units", ExifUnitList },
298 { 0x0131, EXIF_FORMAT_STRING, -1, "Software", "Firmware", NULL },
299 { 0x0132, EXIF_FORMAT_STRING, 20, "DateTime", N_("Date"), NULL },
300 { 0x013e, EXIF_FORMAT_RATIONAL_UNSIGNED, 2, "WhitePoint", "White point", NULL },
301 { 0x013f, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "PrimaryChromaticities","Primary chromaticities", NULL },
302 { 0x0211, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "YCbCrCoefficients", "YCbCy coefficients", NULL },
303 { 0x0213, EXIF_FORMAT_SHORT_UNSIGNED, 1, "YCbCrPositioning", "YCbCr positioning", ExifYCbCrPosList },
304 { 0x0214, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "ReferenceBlackWhite", "Black white reference", NULL },
305 { 0x8298, EXIF_FORMAT_STRING, -1, "Copyright", N_("Copyright"), NULL },
306 { 0x8769, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifOffset", "SubIFD Exif offset", NULL },
308 { 0x829a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureTime", "Exposure time (seconds)", NULL },
309 { 0x829d, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FNumber", "FNumber", NULL },
310 { 0x8822, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureProgram", N_("Exposure program"), ExifExposureProgramList },
311 { 0x8824, EXIF_FORMAT_STRING, -1, "SpectralSensitivity", "Spectral Sensitivity", NULL },
312 { 0x8827, EXIF_FORMAT_SHORT_UNSIGNED, -1, "ISOSpeedRatings", N_("ISO sensitivity"), NULL },
313 { 0x8828, EXIF_FORMAT_UNDEFINED, -1, "OECF", "Optoelectric conversion factor", NULL },
314 { 0x9000, EXIF_FORMAT_UNDEFINED, 4, "ExifVersion", "Exif version", NULL },
315 { 0x9003, EXIF_FORMAT_STRING, 20, "DateTimeOriginal", N_("Date original"), NULL },
316 { 0x9004, EXIF_FORMAT_STRING, 20, "DateTimeDigitized", N_("Date digitized"), NULL },
317 { 0x9101, EXIF_FORMAT_UNDEFINED, -1, "ComponentsConfiguration","Pixel format", NULL },
318 { 0x9102, EXIF_FORMAT_RATIONAL_UNSIGNED,1, "CompressedBitsPerPixel","Compression ratio", NULL },
319 { 0x9201, EXIF_FORMAT_RATIONAL, 1, "ShutterSpeedValue", N_("Shutter speed"), NULL },
320 { 0x9202, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ApertureValue", N_("Aperture"), NULL },
321 { 0x9203, EXIF_FORMAT_RATIONAL, 1, "BrightnessValue", "Brightness", NULL },
322 { 0x9204, EXIF_FORMAT_RATIONAL, 1, "ExposureBiasValue", N_("Exposure bias"), NULL },
323 { 0x9205, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "MaxApertureValue", "Maximum aperture", NULL },
324 { 0x9206, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "SubjectDistance", N_("Subject distance"), NULL },
325 { 0x9207, EXIF_FORMAT_SHORT_UNSIGNED, 1, "MeteringMode", N_("Metering mode"), ExifMeteringModeList },
326 { 0x9208, EXIF_FORMAT_SHORT_UNSIGNED, 1, "LightSource", N_("Light source"), ExifLightSourceList },
327 { 0x9209, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Flash", N_("Flash"), ExifFlashList },
328 { 0x920a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalLength", N_("Focal length"), NULL },
329 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SubjectArea", "Subject area", NULL },
330 { 0x927c, EXIF_FORMAT_UNDEFINED, -1, "MakerNote", "MakerNote", NULL },
331 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, "UserComment", "UserComment", NULL },
332 { 0x9290, EXIF_FORMAT_STRING, -1, "SubsecTime", "Subsecond time", NULL },
333 { 0x9291, EXIF_FORMAT_STRING, -1, "SubsecTimeOriginal", "Subsecond time original", NULL },
334 { 0x9292, EXIF_FORMAT_STRING, -1, "SubsecTimeDigitized", "Subsecond time digitized", NULL },
335 { 0xa000, EXIF_FORMAT_UNDEFINED, 4, "FlashPixVersion", "FlashPix version", NULL },
336 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ColorSpace", "Colorspace", ExifColorSpaceList },
337 /* ExifImageWidth, ExifImageHeight can also be unsigned short */
338 { 0xa002, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageWidth", N_("Width"), NULL },
339 { 0xa003, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageHeight", N_("Height"), NULL },
340 { 0xa004, EXIF_FORMAT_STRING, -1, "RelatedSoundFile", "Audio data", NULL },
341 { 0xa005, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifInteroperabilityOffset", "ExifR98 extension", NULL },
342 { 0xa20b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", "Flash strength", NULL },
343 { 0xa20c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SpatialFrequencyResponse","Spatial frequency response", NULL },
344 { 0xa20e, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneXResolution", "X Pixel density", NULL },
345 { 0xa20f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneYResolution", "Y Pixel density", NULL },
346 { 0xa210, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalPlaneResolutionUnit", "Pixel density units", ExifUnitList },
347 { 0x0214, EXIF_FORMAT_SHORT_UNSIGNED, 2, "SubjectLocation", "Subject location", NULL },
348 { 0xa215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", N_("ISO sensitivity"), NULL },
349 { 0xa217, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SensingMethod", "Sensor type", ExifSensorList },
350 { 0xa300, EXIF_FORMAT_UNDEFINED, 1, "FileSource", "Source type", ExifSourceList },
351 { 0xa301, EXIF_FORMAT_UNDEFINED, 1, "SceneType", "Scene type", ExifSceneList },
352 { 0xa302, EXIF_FORMAT_UNDEFINED, -1, "CFAPattern", "Color filter array pattern", NULL },
353 /* tags a4xx were added for Exif 2.2 (not just these - some above, as well) */
354 { 0xa401, EXIF_FORMAT_SHORT_UNSIGNED, 1, "CustomRendered", "Render process", ExifCustRenderList },
355 { 0xa402, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureMode", "Exposure mode", ExifExposureModeList },
356 { 0xa403, EXIF_FORMAT_SHORT_UNSIGNED, 1, "WhiteBalance", "White balance", ExifWhiteBalanceList },
357 { 0xa404, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "DigitalZoomRatio", "Digital zoom ratio", NULL },
358 { 0xa405, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalLength35mmFilm", "Focal length (35mm)", NULL },
359 { 0xa406, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SceneCapturetype", "Scene capture type", ExifSceneCaptureList },
360 { 0xa407, EXIF_FORMAT_SHORT_UNSIGNED, 1, "GainControl", "Gain control", ExifGainControlList },
361 { 0xa408, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Contrast", "Contrast", ExifContrastList },
362 { 0xa409, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Saturation", "Saturation", ExifSaturationList },
363 { 0xa40a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Sharpness", "Sharpness", ExifSharpnessList },
364 { 0xa40b, EXIF_FORMAT_UNDEFINED, -1, "DeviceSettingDescription","Device setting", NULL },
365 { 0xa40c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubjectDistanceRange", "Subject range", ExifSubjectRangeList },
366 { 0xa420, EXIF_FORMAT_STRING, -1, "ImageUniqueID", "Image serial number", NULL },
367 /* place known, but undocumented or lesser used tags here */
368 { 0x00fe, EXIF_FORMAT_LONG_UNSIGNED, 1, "NewSubfileType", NULL, NULL },
369 { 0x00ff, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubfileType", NULL, NULL },
370 { 0x012d, EXIF_FORMAT_SHORT_UNSIGNED, 3, "TransferFunction", NULL, NULL },
371 { 0x013b, EXIF_FORMAT_STRING, -1, "Artist", "Artist", NULL },
372 { 0x013d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Predictor", NULL, NULL },
373 { 0x0142, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileWidth", NULL, NULL },
374 { 0x0143, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileLength", NULL, NULL },
375 { 0x0144, EXIF_FORMAT_LONG_UNSIGNED, -1, "TileOffsets", NULL, NULL },
376 { 0x0145, EXIF_FORMAT_SHORT_UNSIGNED, -1, "TileByteCounts", NULL, NULL },
377 { 0x014a, EXIF_FORMAT_LONG_UNSIGNED, -1, "SubIFDs", NULL, NULL },
378 { 0x015b, EXIF_FORMAT_UNDEFINED, -1, "JPEGTables", NULL, NULL },
379 { 0x828d, EXIF_FORMAT_SHORT_UNSIGNED, 2, "CFARepeatPatternDim", NULL, NULL },
380 { 0x828e, EXIF_FORMAT_BYTE_UNSIGNED, -1, "CFAPattern", NULL, NULL },
381 { 0x828f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "BatteryLevel", NULL, NULL },
382 { 0x83bb, EXIF_FORMAT_LONG_UNSIGNED, -1, "IPTC/NAA", NULL, NULL },
383 { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "InterColorProfile", NULL, NULL },
384 { 0x8825, EXIF_FORMAT_LONG_UNSIGNED, 1, "GPSInfo", "SubIFD GPS offset", NULL },
385 { 0x8829, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Interlace", NULL, NULL },
386 { 0x882a, EXIF_FORMAT_SHORT, 1, "TimeZoneOffset", NULL, NULL },
387 { 0x882b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SelfTimerMode", NULL, NULL },
388 { 0x920b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", NULL, NULL },
389 { 0x920c, EXIF_FORMAT_UNDEFINED, -1, "SpatialFrequencyResponse", NULL, NULL },
390 { 0x920d, EXIF_FORMAT_UNDEFINED, -1, "Noise", NULL, NULL },
391 { 0x9211, EXIF_FORMAT_LONG_UNSIGNED, 1, "ImageNumber", NULL, NULL },
392 { 0x9212, EXIF_FORMAT_STRING, 1, "SecurityClassification", NULL, NULL },
393 { 0x9213, EXIF_FORMAT_STRING, -1, "ImageHistory", NULL, NULL },
394 { 0x9215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", NULL, NULL },
395 { 0x9216, EXIF_FORMAT_BYTE_UNSIGNED, 4, "TIFF/EPStandardID", NULL, NULL },
400 ExifMarker ExifUnknownMarkersList[] = {
401 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL },
402 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL },
403 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL },
404 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL },
405 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL },
406 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL },
407 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL },
408 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL },
409 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL },
410 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL },
411 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL },
412 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL },
413 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL },
416 /* human readable key list */
418 ExifFormattedText ExifFormattedList[] = {
419 { "fCamera", N_("Camera") },
420 { "fDateTime", N_("Date") },
421 { "fShutterSpeed", N_("Shutter speed") },
422 { "fAperture", N_("Aperture") },
423 { "fExposureBias", N_("Exposure bias") },
424 { "fISOSpeedRating", N_("ISO sensitivity") },
425 { "fFocalLength", N_("Focal length") },
426 { "fSubjectDistance", N_("Subject distance") },
427 { "fFlash", N_("Flash") },
428 { "fResolution", N_("Resolution") },
434 *-----------------------------------------------------------------------------
436 *-----------------------------------------------------------------------------
439 #define BYTE_ORDER_INTEL 1
440 #define BYTE_ORDER_MOTOROLA 2
443 #define MARKER_UNKNOWN 0x00
444 #define MARKER_SOI 0xD8
445 #define MARKER_APP1 0xE1
447 /* These data structs are packed to make sure the
448 * byte alignment matches the on-disk data format.
450 typedef struct __attribute__((packed)) {
456 typedef struct __attribute__((packed)) {
464 static const ExifMarker *exif_marker_from_tag(uint16_t tag, const ExifMarker *list);
467 *-----------------------------------------------------------------------------
469 *-----------------------------------------------------------------------------
472 ExifItem *exif_item_new(ExifFormatType format, unsigned int tag,
473 unsigned int elements, const ExifMarker *marker)
477 item = g_new0(ExifItem, 1);
478 item->format = format;
480 item->marker = marker;
481 item->elements = elements;
487 case EXIF_FORMAT_UNKNOWN:
488 /* unknown, data is NULL */
491 case EXIF_FORMAT_BYTE_UNSIGNED:
492 item->data_len = sizeof(char) * elements;
494 case EXIF_FORMAT_STRING:
495 item->data_len = sizeof(char) * elements;
497 case EXIF_FORMAT_SHORT_UNSIGNED:
498 item->data_len = sizeof(unsigned short int) * elements;
500 case EXIF_FORMAT_LONG_UNSIGNED:
501 item->data_len = sizeof(unsigned long int) * elements;
503 case EXIF_FORMAT_RATIONAL_UNSIGNED:
504 item->data_len = sizeof(ExifRational) * elements;
506 case EXIF_FORMAT_BYTE:
507 item->data_len = sizeof(char) * elements;
509 case EXIF_FORMAT_UNDEFINED:
510 item->data_len = sizeof(char) * elements;
512 case EXIF_FORMAT_SHORT:
513 item->data_len = sizeof(short int) * elements;
515 case EXIF_FORMAT_LONG:
516 item->data_len = sizeof(long int) * elements;
518 case EXIF_FORMAT_RATIONAL:
519 item->data_len = sizeof(ExifRational) * elements;
521 case EXIF_FORMAT_FLOAT:
522 item->data_len = sizeof(float) * elements;
524 case EXIF_FORMAT_DOUBLE:
525 item->data_len = sizeof(double) * elements;
529 item->data = g_malloc0(item->data_len);
534 static void exif_item_free(ExifItem *item)
542 const char *exif_item_get_tag_name(ExifItem *item)
544 if (!item || !item->marker) return NULL;
545 return item->marker->key;
548 const char *exif_item_get_description(ExifItem *item)
550 if (!item || !item->marker) return NULL;
551 return _(item->marker->description);
554 const char *exif_item_get_format_name(ExifItem *item, gint brief)
556 if (!item || !item->marker) return NULL;
557 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description;
561 #define UNDEFINED_TEXT_BYTE_COUNT 16
563 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne)
567 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
569 unsigned char c = ((char *)data)[i];
570 if (c < 32 || c > 127) c = '.';
571 g_string_append_printf(string, "%c", c);
573 string = g_string_append(string, " : ");
574 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
592 g_string_append_printf(string, "%s%02x", spacer, ((char *)data)[i]);
594 if (i >= UNDEFINED_TEXT_BYTE_COUNT) g_string_append_printf(string, " (%d bytes)", ne);
599 static gchar *text_list_find_value(ExifTextList *list, gint value)
601 gchar *result = NULL;
605 while (!result && list[i].value >= 0)
607 if (value == list[i].value) result = g_strdup(_(list[i].description));
610 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown"));
616 *-------------------------------------------------------------------
618 *-------------------------------------------------------------------
621 static uint16_t get_int16(unsigned char *f, int bo)
623 if (bo == BYTE_ORDER_INTEL)
624 return *f + (*(f+1)<<8);
626 return ((*f)<<8) + *(f+1);
631 static uint32_t get_int32(unsigned char *f, int bo)
633 if (bo == BYTE_ORDER_INTEL)
634 return get_int16(f, BYTE_ORDER_INTEL) + (get_int16(f+2, BYTE_ORDER_INTEL)<<16);
636 return (get_int16(f, BYTE_ORDER_MOTOROLA)<<16) + get_int16(f+2, BYTE_ORDER_MOTOROLA);
640 static uint16_t swab_int16(uint16_t n, int bo)
642 #if BYTE_ORDER == LITTLE_ENDIAN
643 if (bo == BYTE_ORDER_MOTOROLA)
645 if (bo == BYTE_ORDER_INTEL)
652 static uint32_t swab_int32(uint32_t n, int bo)
654 #if BYTE_ORDER == LITTLE_ENDIAN
655 if (bo == BYTE_ORDER_MOTOROLA)
657 if (bo == BYTE_ORDER_INTEL)
659 return n<<24 | n>>24 | (n & 0xFF0000)>>8 | (n & 0xFF00)<<8;
665 *-------------------------------------------------------------------
667 *-------------------------------------------------------------------
670 static int get_marker_size(unsigned char *f)
672 /* Size is always in Motorola byte order */
673 return get_int16(f+2, BYTE_ORDER_MOTOROLA);
676 static int goto_next_marker(unsigned char **f, int *size, int *marker)
680 *marker = MARKER_UNKNOWN;
682 /* It is safe to access the marker and its size since we have checked
683 * the SOI and this function guaranties the whole next marker is
686 if (*(*f+1) != MARKER_SOI)
688 marker_size += get_marker_size(*f);
691 *size -= marker_size;
693 /* size should be at least 4, so we can read the marker and its size
694 * and check data are actually available
696 if (*size < 4) return -1;
698 /* Jump to the next marker and be sure it begins with 0xFF
701 if (**f != 0xFF) return -1;
703 if (get_marker_size(*f)+2 > *size) return -1;
711 *-------------------------------------------------------------------
713 *-------------------------------------------------------------------
716 static const ExifMarker *exif_marker_from_tag(uint16_t tag, const ExifMarker *list)
720 if (!list) return NULL;
722 while (list[i].tag != 0 && list[i].tag != tag)
727 return (list[i].tag == 0 ? NULL : &list[i]);
730 static void rational_from_data(ExifRational *r, void *src, int byte_order)
732 r->num = swab_int32(*(uint32_t*)src, byte_order);
733 r->den = swab_int32(*(uint32_t*)(src + sizeof(uint32_t)), byte_order);
736 void exif_item_copy_data(ExifItem *item, void *src, int len, ExifFormatType src_format, int byte_order)
743 bs = ExifFormatList[item->format].size;
747 if (!dest || len > item->data_len)
749 printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
753 switch (item->format)
755 case EXIF_FORMAT_UNKNOWN:
757 case EXIF_FORMAT_BYTE_UNSIGNED:
758 case EXIF_FORMAT_BYTE:
759 case EXIF_FORMAT_UNDEFINED:
760 memcpy(dest, src, len);
762 case EXIF_FORMAT_STRING:
763 memcpy(dest, src, len);
764 /* string is NULL terminated, make sure this is true */
765 if (((char *)dest)[len - 1] != '\0') ((char *)dest)[len - 1] = '\0';
767 case EXIF_FORMAT_SHORT_UNSIGNED:
768 case EXIF_FORMAT_SHORT:
769 for (i = 0; i < ne; i++)
771 ((short *)dest)[i] = swab_int16(*(uint16_t*)(src + i * bs), byte_order);
774 case EXIF_FORMAT_LONG_UNSIGNED:
775 case EXIF_FORMAT_LONG:
776 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED ||
777 src_format == EXIF_FORMAT_SHORT)
779 /* a short fits into a long, so allow it */
782 ss = ExifFormatList[src_format].size;
783 for (i = 0; i < ne; i++)
785 ((long *)dest)[i] = (long)swab_int16(*(uint16_t*)(src + i * ss), byte_order);
790 for (i = 0; i < ne; i++)
792 ((long *)dest)[i] = swab_int32(*(uint32_t*)(src + i * bs), byte_order);
796 case EXIF_FORMAT_RATIONAL_UNSIGNED:
797 case EXIF_FORMAT_RATIONAL:
798 for (i = 0; i < ne; i++)
800 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, byte_order);
803 case EXIF_FORMAT_FLOAT:
804 for (i = 0; i < ne; i++)
806 ((float *)dest)[i] = swab_int32(*(uint32_t*)(src + i * bs), byte_order);
809 case EXIF_FORMAT_DOUBLE:
810 for (i = 0; i < ne; i++)
814 rational_from_data(&r, src + i * bs, byte_order);
815 if (r.den) ((double *)dest)[i] = (double)r.num / r.den;
821 static int exif_parse_IFD_entry(ExifData *exif, unsigned char *tiff, int offset,
822 int size, int byte_order,
823 const ExifMarker *list)
825 IFDEntry *ent = (IFDEntry*)(tiff+offset);
826 uint32_t swabed_data;
829 const ExifMarker *marker;
832 ent->tag = swab_int16(ent->tag, byte_order);
833 ent->format = swab_int16(ent->format, byte_order);
834 ent->nb = swab_int32(ent->nb, byte_order);
835 swabed_data = swab_int32(ent->data, byte_order);
837 /* Check tag type. If it does not match, either the format is wrong,
838 * either it is a unknown tag; so it is not really an error.
840 marker = exif_marker_from_tag(ent->tag, list);
843 if (ent->format > EXIF_FORMAT_DOUBLE)
845 printf("warning: exif tag 0x%4x has invalid format %d\n", ent->tag, ent->format);
848 /* allow non recognized tags to be displayed */
849 marker = &ExifUnknownMarkersList[ent->format];
851 if (marker->format != ent->format)
853 /* Some cameras got mixed up signed/unsigned_rational
854 * eg KODAK DC4800 on object_distance tag
856 * FIXME: what exactly is this test trying to do?
857 * ok, so this test is to allow the case of swapped signed/unsigned mismatch to leak through?
859 if ( !(marker->format == EXIF_FORMAT_RATIONAL_UNSIGNED && ent->format == EXIF_FORMAT_RATIONAL) &&
860 !(marker->format == EXIF_FORMAT_RATIONAL && ent->format == EXIF_FORMAT_RATIONAL_UNSIGNED) &&
861 /* short fits into a long so allow this mismatch
862 * as well (some tags allowed to be unsigned short _or_ unsigned long)
864 !(marker->format == EXIF_FORMAT_LONG_UNSIGNED && ent->format == EXIF_FORMAT_SHORT_UNSIGNED) )
866 if (ent->format <= EXIF_FORMAT_DOUBLE)
868 printf("warning: exif tag %s format mismatch, found %s exif spec requests %s\n",
869 marker->key, ExifFormatList[ent->format].short_name, ExifFormatList[marker->format].short_name);
873 printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n",
874 marker->key, ent->format, marker->format, ExifFormatList[marker->format].short_name);
880 /* Where is the data, is it available?
882 if (marker->components > 0 && marker->components != ent->nb)
884 printf("warning: exif tag %s has %d elements, exif spec requests %d\n", marker->key, ent->nb, marker->components);
886 data_len = ExifFormatList[marker->format].size * ent->nb;
887 if (data_len > sizeof(ent->data))
889 if (size < swabed_data+data_len)
891 printf("warning: exif tag %s will overrun IFD segment, ignored.\n", marker->key);
894 data = (void*)tiff + swabed_data;
898 data = (void*)(&(ent->data));
901 item = exif_item_new(marker->format, ent->tag, ent->nb, marker);
902 exif_item_copy_data(item, data, data_len, ent->format, byte_order);
903 exif->items = g_list_prepend(exif->items, item);
905 if (list == ExifKnownMarkersList)
910 exif_parse_IFD_table(exif, tiff, swabed_data, size, byte_order, list);
912 case TAG_EXIFMAKERNOTE:
913 format_exif_makernote_canon_parse(exif, tiff, swabed_data, size, byte_order);
921 int exif_parse_IFD_table(ExifData *exif,
922 unsigned char *tiff, int offset,
923 int size, int byte_order,
924 const ExifMarker *list)
928 /* We should be able to read number of entries in IFD0) */
929 if (size < offset+2) return -1;
931 nb_entries = get_int16(tiff+offset, byte_order);
933 /* Entries and next IFD offset must be readable */
934 if (size < offset+nb_entries*12+4) return -1;
936 for (i=0; i<nb_entries; ++i)
938 exif_parse_IFD_entry(exif, tiff, offset+2+i*sizeof(IFDEntry), size, byte_order, list);
945 *-------------------------------------------------------------------
947 *-------------------------------------------------------------------
950 static int parse_TIFF(ExifData *exif, unsigned char *tiff, int size)
952 int byte_order, offset=0;
954 if (size < sizeof(TIFFHeader))
959 if (strncmp(((TIFFHeader*)tiff)->byte_order, "II", 2) == 0)
961 byte_order = BYTE_ORDER_INTEL;
963 else if (strncmp(((TIFFHeader*)tiff)->byte_order, "MM", 2) == 0)
965 byte_order = BYTE_ORDER_MOTOROLA;
972 if (swab_int16(((TIFFHeader*)tiff)->magic, byte_order) != 0x002A)
977 offset = swab_int32(((TIFFHeader*)tiff)->IFD_offset, byte_order);
979 return exif_parse_IFD_table(exif, tiff, offset, size, byte_order, ExifKnownMarkersList);
982 static int parse_JPEG(ExifData *exif, unsigned char *f, int size)
984 int marker, marker_size;
986 if (size<2 || *f!=0xFF || *(f+1)!=MARKER_SOI)
992 if (goto_next_marker(&f, &size, &marker) == -1)
996 } while (marker != MARKER_APP1);
998 if (marker != MARKER_APP1)
1003 marker_size = get_marker_size(f)-2;
1005 if (marker_size<6 || strncmp((char*)f+4, "Exif\0\0", 6)!=0)
1010 return parse_TIFF(exif, f+10, marker_size-6);
1013 static gint map_file(const gchar *path, void **mapping, int *size)
1018 if ((fd = open(path, O_RDONLY)) == -1)
1024 if (fstat(fd, &fs) == -1)
1033 if ((*mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
1044 static gint unmap_file(void *mapping, int size)
1046 if (munmap(mapping, size) == -1)
1055 void exif_free(ExifData *exif)
1064 ExifItem *item = work->data;
1066 exif_item_free(item);
1069 g_list_free(exif->items);
1073 ExifData *exif_read(const gchar *path)
1080 if (!path) return NULL;
1082 pathl = path_from_utf8(path);
1083 if (map_file(pathl, &f, &size) == -1)
1090 exif = g_new0(ExifData, 1);
1093 if ((res = parse_JPEG(exif, (unsigned char *)f, size)) == -2)
1095 res = parse_TIFF(exif, (unsigned char *)f, size);
1102 if (format_raw_img_exif_offsets(f, size, NULL, &offset))
1104 res = parse_TIFF(exif, (unsigned char*)f + offset, size - offset);
1114 unmap_file(f, size);
1116 if (exif) exif->items = g_list_reverse(exif->items);
1119 exif_write_data_list(exif, stdout, TRUE);
1120 exif_write_data_list(exif, stdout, FALSE);
1126 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
1130 if (!key) return NULL;
1139 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item;
1144 gchar *exif_item_get_data_as_text(ExifItem *item)
1146 const ExifMarker *marker;
1153 if (!item) return NULL;
1155 marker = item->marker;
1156 if (!marker) return NULL;
1159 ne = item->elements;
1160 string = g_string_new("");
1161 switch (item->format)
1163 case EXIF_FORMAT_UNKNOWN:
1165 case EXIF_FORMAT_BYTE_UNSIGNED:
1166 case EXIF_FORMAT_BYTE:
1167 case EXIF_FORMAT_UNDEFINED:
1168 if (ne == 1 && marker->list)
1173 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED ||
1174 item->format == EXIF_FORMAT_UNDEFINED)
1176 val = ((unsigned char *)data)[0];
1180 val = (unsigned char)(((signed char *)data)[0]);
1183 result = text_list_find_value(marker->list, (unsigned short)val);
1184 string = g_string_append(string, result);
1189 string = string_append_raw_bytes(string, data, ne);
1192 case EXIF_FORMAT_STRING:
1193 string = g_string_append(string, (gchar *)(item->data));
1195 case EXIF_FORMAT_SHORT_UNSIGNED:
1196 if (ne == 1 && marker->list)
1200 result = text_list_find_value(marker->list, ((unsigned short *)data)[0]);
1201 string = g_string_append(string, result);
1204 else for (i = 0; i < ne; i++)
1206 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1207 ((unsigned short *)data)[i]);
1210 case EXIF_FORMAT_LONG_UNSIGNED:
1211 for (i = 0; i < ne; i++)
1213 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1214 ((unsigned long *)data)[i]);
1217 case EXIF_FORMAT_RATIONAL_UNSIGNED:
1218 for (i = 0; i < ne; i++)
1222 r = &((ExifRational *)data)[i];
1223 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1224 (unsigned long)r->num, (unsigned long)r->den);
1227 case EXIF_FORMAT_SHORT:
1228 for (i = 0; i < ne; i++)
1230 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1231 ((short *)data)[i]);
1234 case EXIF_FORMAT_LONG:
1235 for (i = 0; i < ne; i++)
1237 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1241 case EXIF_FORMAT_RATIONAL:
1242 for (i = 0; i < ne; i++)
1246 r = &((ExifRational *)data)[i];
1247 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1248 (long)r->num, (long)r->den);
1251 case EXIF_FORMAT_FLOAT:
1252 for (i = 0; i < ne; i++)
1254 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1255 ((float *)data)[i]);
1258 case EXIF_FORMAT_DOUBLE:
1259 for (i = 0; i < ne; i++)
1261 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1262 ((double *)data)[i]);
1267 text = g_strdup(string->str);
1268 g_string_free(string, TRUE);
1273 gint exif_item_get_integer(ExifItem *item, gint *value)
1275 if (!item) return FALSE;
1277 switch (item->format)
1279 case EXIF_FORMAT_SHORT:
1280 *value = (gint)(((short *)(item->data))[0]);
1283 case EXIF_FORMAT_SHORT_UNSIGNED:
1284 *value = (gint)(((unsigned short *)(item->data))[0]);
1287 case EXIF_FORMAT_LONG:
1288 *value = (gint)(((long *)(item->data))[0]);
1291 case EXIF_FORMAT_LONG_UNSIGNED:
1292 /* FIXME: overflow possible */
1293 *value = (gint)(((unsigned long *)(item->data))[0]);
1296 /* all other type return FALSE */
1302 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
1306 item = exif_get_item(exif, key);
1307 return exif_item_get_integer(item, value);
1310 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
1312 if (!item) return NULL;
1314 if (item->format == EXIF_FORMAT_RATIONAL ||
1315 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED)
1317 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL);
1318 return &((ExifRational *)(item->data))[0];
1324 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
1328 item = exif_get_item(exif, key);
1329 return exif_item_get_rational(item, sign);
1332 double exif_rational_to_double(ExifRational *r, gint sign)
1334 if (!r || r->den == 0.0) return 0.0;
1336 if (sign) return (double)((int)r->num) / (double)((int)r->den);
1337 return (double)r->num / r->den;
1340 static double exif_get_rational_as_double(ExifData *exif, const gchar *key)
1345 r = exif_get_rational(exif, key, &sign);
1346 return exif_rational_to_double(r, sign);
1349 static GString *append_comma_text(GString *string, const gchar *text)
1351 string = g_string_append(string, ", ");
1352 string = g_string_append(string, text);
1357 static gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
1359 /* must begin with f, else not formatted */
1362 if (key_valid) *key_valid = FALSE;
1366 if (key_valid) *key_valid = TRUE;
1368 if (strcmp(key, "fCamera") == 0)
1371 gchar *make = exif_get_data_as_text(exif, "Make");
1372 gchar *model = exif_get_data_as_text(exif, "Model");
1373 gchar *software = exif_get_data_as_text(exif, "Software");
1375 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
1376 (model) ? model : "",
1377 (software) ? " (" : "",
1378 (software) ? software : "",
1379 (software) ? ")" : "");
1386 if (strcmp(key, "fDateTime") == 0)
1388 gchar *text = exif_get_data_as_text(exif, "DateTimeOriginal");
1389 gchar *subsec = NULL;
1390 if (text) subsec = exif_get_data_as_text(exif, "SubsecTimeOriginal");
1393 text = exif_get_data_as_text(exif, "DateTime");
1394 if (text) subsec = exif_get_data_as_text(exif, "SubsecTime");
1399 text = g_strconcat(tmp, ".", subsec, NULL);
1405 if (strcmp(key, "fShutterSpeed") == 0)
1409 r = exif_get_rational(exif, "ExposureTime", NULL);
1410 if (r && r->num && r->den)
1412 double n = (double)r->den / (double)r->num;
1413 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1414 n > 1.0 ? n : 1.0 / n);
1416 r = exif_get_rational(exif, "ShutterSpeedValue", NULL);
1417 if (r && r->num && r->den)
1419 double n = pow(2.0, exif_rational_to_double(r, TRUE));
1421 /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
1422 if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
1424 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1425 n > 1.0 ? floor(n) : 1.0 / n);
1429 if (strcmp(key, "fAperture") == 0)
1433 n = exif_get_rational_as_double(exif, "FNumber");
1434 if (n == 0.0) n = exif_get_rational_as_double(exif, "ApertureValue");
1435 if (n == 0.0) return NULL;
1437 return g_strdup_printf("f/%.1f", n);
1439 if (strcmp(key, "fExposureBias") == 0)
1445 r = exif_get_rational(exif, "ExposureBiasValue", &sign);
1446 if (!r) return NULL;
1448 n = exif_rational_to_double(r, sign);
1449 return g_strdup_printf("%+.1f", n);
1451 if (strcmp(key, "fFocalLength") == 0)
1455 n = exif_get_rational_as_double(exif, "FocalLength");
1456 if (n == 0.0) return NULL;
1457 return g_strdup_printf("%.2f mm", n);
1459 if (strcmp(key, "fISOSpeedRating") == 0)
1463 text = exif_get_data_as_text(exif, "ISOSpeedRatings");
1464 /* kodak may set this instead */
1465 if (!text) text = exif_get_data_as_text(exif, "ExposureIndex");
1468 if (strcmp(key, "fSubjectDistance") == 0)
1474 r = exif_get_rational(exif, "SubjectDistance", &sign);
1475 if (!r) return NULL;
1477 if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
1478 if ((long)r->num == 0) return g_strdup(_("unknown"));
1480 n = exif_rational_to_double(r, sign);
1481 if (n == 0.0) return _("unknown");
1482 return g_strdup_printf("%.3f m", n);
1484 if (strcmp(key, "fFlash") == 0)
1486 /* grr, flash is a bitmask... */
1492 if (!exif_get_integer(exif, "Flash", &n)) return NULL;
1494 /* Exif 2.1 only defines first 3 bits */
1495 if (n <= 0x07) return g_strdup(text_list_find_value(ExifFlashList, n));
1497 /* must be Exif 2.2 */
1498 string = g_string_new("");
1500 /* flash fired (bit 0) */
1501 string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
1503 /* flash mode (bits 3, 4) */
1504 v = (n >> 3) & 0x03;
1505 if (v) string = append_comma_text(string, _("mode:"));
1509 string = g_string_append(string, _("on"));
1512 string = g_string_append(string, _("off"));
1515 string = g_string_append(string, _("auto"));
1519 /* return light (bits 1, 2) */
1520 v = (n >> 1) & 0x03;
1521 if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
1522 if (v == 3) string = append_comma_text(string, _("detected by strobe"));
1524 /* we ignore flash function (bit 5) */
1526 /* red-eye (bit 6) */
1527 if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
1530 g_string_free(string, FALSE);
1533 if (strcmp(key, "fResolution") == 0)
1535 ExifRational *rx, *ry;
1539 rx = exif_get_rational(exif, "XResolution", NULL);
1540 ry = exif_get_rational(exif, "YResolution", NULL);
1541 if (!rx || !ry) return NULL;
1543 units = exif_get_data_as_text(exif, "ResolutionUnit");
1544 text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
1545 ry->den ? (double)ry->num / ry->den : 1.0,
1546 _("dot"), (units) ? units : _("unknown"));
1552 if (key_valid) *key_valid = FALSE;
1556 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
1562 if (!key) return NULL;
1564 text = exif_get_formatted_by_key(exif, key, &key_valid);
1565 if (key_valid) return text;
1567 item = exif_get_item(exif, key);
1568 if (item) return exif_item_get_data_as_text(item);
1573 const gchar *exif_get_description_by_key(const gchar *key)
1577 if (!key) return NULL;
1580 while (ExifFormattedList[i].key != NULL)
1582 if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
1587 while (ExifKnownMarkersList[i].tag > 0)
1589 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
1596 static void exif_write_item(FILE *f, ExifItem *item)
1600 text = exif_item_get_data_as_text(item);
1603 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
1604 exif_item_get_tag_name(item), text);
1609 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list)
1611 if (!f || !exif) return;
1613 fprintf(f, " tag format key value\n");
1614 fprintf(f, "----------------------------------------------------\n");
1616 if (human_readable_list)
1621 while (ExifFormattedList[i].key)
1625 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL);
1628 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text);
1645 exif_write_item(f, item);
1648 fprintf(f, "----------------------------------------------------\n");