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"
78 *-----------------------------------------------------------------------------
80 *-----------------------------------------------------------------------------
83 ExifFormatAttrib ExifFormatList[] = {
84 { EXIF_FORMAT_UNKNOWN, 1, "unknown", "unknown" },
85 { EXIF_FORMAT_BYTE_UNSIGNED, 1, "ubyte", "unsigned byte" },
86 { EXIF_FORMAT_STRING, 1, "string", "string" },
87 { EXIF_FORMAT_SHORT_UNSIGNED, 2, "ushort", "unsigned short" },
88 { EXIF_FORMAT_LONG_UNSIGNED, 4, "ulong", "unsigned long" },
89 { EXIF_FORMAT_RATIONAL_UNSIGNED,8, "urational", "unsigned rational" },
90 { EXIF_FORMAT_BYTE, 1, "byte", "byte" },
91 { EXIF_FORMAT_UNDEFINED, 1, "undefined", "undefined" },
92 { EXIF_FORMAT_SHORT, 2, "sshort", "signed short" },
93 { EXIF_FORMAT_LONG, 4, "slong", "signed long" },
94 { EXIF_FORMAT_RATIONAL, 8, "srational", "signed rational" },
95 { EXIF_FORMAT_FLOAT, 4, "float", "float" },
96 { EXIF_FORMAT_DOUBLE, 8, "double", "double" },
100 /* tags that are special, or need special treatment */
101 #define TAG_EXIFOFFSET 0x8769
102 #define TAG_EXIFMAKERNOTE 0x927c
106 *-----------------------------------------------------------------------------
108 *-----------------------------------------------------------------------------
111 static ExifTextList ExifOrientationList[] = {
112 { EXIF_ORIENTATION_UNKNOWN, N_("unknown") },
113 { EXIF_ORIENTATION_TOP_LEFT, N_("top left") },
114 { EXIF_ORIENTATION_TOP_RIGHT, N_("top right") },
115 { EXIF_ORIENTATION_BOTTOM_RIGHT,N_("bottom right") },
116 { EXIF_ORIENTATION_BOTTOM_LEFT, N_("bottom left") },
117 { EXIF_ORIENTATION_LEFT_TOP, N_("left top") },
118 { EXIF_ORIENTATION_RIGHT_TOP, N_("right top") },
119 { EXIF_ORIENTATION_RIGHT_BOTTOM,N_("right bottom") },
120 { EXIF_ORIENTATION_LEFT_BOTTOM, N_("left bottom") },
124 static ExifTextList ExifUnitList[] = {
125 { EXIF_UNIT_UNKNOWN, N_("unknown") },
126 { EXIF_UNIT_NOUNIT, "" },
127 { EXIF_UNIT_INCH, N_("inch") },
128 { EXIF_UNIT_CENTIMETER, N_("centimeter") },
132 static ExifTextList ExifYCbCrPosList[] = {
138 static ExifTextList ExifMeteringModeList[] = {
139 { 0, N_("unknown") },
140 { 1, N_("average") },
141 { 2, N_("center weighted") },
143 { 4, N_("multi-spot") },
144 { 5, N_("multi-segment") },
145 { 6, N_("partial") },
146 { 255, N_("other") },
150 static ExifTextList ExifExposureProgramList[] = {
151 { 0, N_("not defined") },
154 { 3, N_("aperture") },
155 { 4, N_("shutter") },
156 { 5, N_("creative") },
158 { 7, N_("portrait") },
159 { 8, N_("landscape") },
163 static ExifTextList ExifLightSourceList[] = {
164 { 0, N_("unknown") },
165 { 1, N_("daylight") },
166 { 2, N_("fluorescent") },
167 { 3, N_("tungsten (incandescent)") },
169 { 9, "fine weather" },
170 { 10, "cloudy weather" },
172 { 12, "daylight fluorescent" },
173 { 13, "day white fluorescent" },
174 { 14, "cool white fluorescent" },
175 { 15, "while fluorescent" },
176 { 17, "standard light A" },
177 { 18, "standard light B" },
178 { 19, "standard light C" },
183 { 24, "ISO studio tungsten" },
184 { 255, N_("other") },
188 static ExifTextList ExifFlashList[] = {
191 { 5, N_("yes, not detected by strobe") },
192 { 7, N_("yes, detected by strobe") },
196 static ExifTextList ExifColorSpaceList[] = {
198 { 65535,"uncalibrated" },
202 static ExifTextList ExifSensorList[] = {
203 { 1, "not defined" },
204 { 2, "1 chip color area" },
205 { 2, "2 chip color area" },
206 { 4, "3 chip color area" },
207 { 5, "color sequential area" },
209 { 8, "color sequential linear" },
213 static ExifTextList ExifSourceList[] = {
214 { 3, "digital still camera" },
218 static ExifTextList ExifSceneList[] = {
219 { 1, "direct photo" },
223 static ExifTextList ExifCustRenderList[] = {
229 static ExifTextList ExifExposureModeList[] = {
232 { 2, "auto bracket" },
236 static ExifTextList ExifWhiteBalanceList[] = {
242 static ExifTextList ExifSceneCaptureList[] = {
246 { 3, "night scene" },
250 static ExifTextList ExifGainControlList[] = {
252 { 1, "low gain up" },
253 { 2, "high gain up" },
254 { 3, "low gain down" },
255 { 4, "high gain down" },
259 static ExifTextList ExifContrastList[] = {
266 static ExifTextList ExifSaturationList[] = {
273 static ExifTextList ExifSharpnessList[] = {
280 static ExifTextList ExifSubjectRangeList[] = {
288 ExifMarker ExifKnownMarkersList[] = {
289 { 0x010e, EXIF_FORMAT_STRING, -1, "ImageDescription", N_("Image description"), NULL },
290 { 0x010f, EXIF_FORMAT_STRING, -1, "Make", "Camera make", NULL },
291 { 0x0110, EXIF_FORMAT_STRING, -1, "Model", "Camera model", NULL },
292 { 0x0112, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Orientation", N_("Orientation"), ExifOrientationList },
293 { 0x011a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "XResolution", "X resolution", NULL },
294 { 0x011b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "YResolution", "Y Resolution", NULL },
295 { 0x0128, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ResolutionUnit", "Resolution units", ExifUnitList },
296 { 0x0131, EXIF_FORMAT_STRING, -1, "Software", "Firmware", NULL },
297 { 0x0132, EXIF_FORMAT_STRING, 20, "DateTime", N_("Date"), NULL },
298 { 0x013e, EXIF_FORMAT_RATIONAL_UNSIGNED, 2, "WhitePoint", "White point", NULL },
299 { 0x013f, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "PrimaryChromaticities","Primary chromaticities", NULL },
300 { 0x0211, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "YCbCrCoefficients", "YCbCy coefficients", NULL },
301 { 0x0213, EXIF_FORMAT_SHORT_UNSIGNED, 1, "YCbCrPositioning", "YCbCr positioning", ExifYCbCrPosList },
302 { 0x0214, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "ReferenceBlackWhite", "Black white reference", NULL },
303 { 0x8298, EXIF_FORMAT_STRING, -1, "Copyright", N_("Copyright"), NULL },
304 { 0x8769, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifOffset", "SubIFD Exif offset", NULL },
306 { 0x829a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureTime", "Exposure time (seconds)", NULL },
307 { 0x829d, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FNumber", "FNumber", NULL },
308 { 0x8822, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureProgram", N_("Exposure program"), ExifExposureProgramList },
309 { 0x8824, EXIF_FORMAT_STRING, -1, "SpectralSensitivity", "Spectral Sensitivity", NULL },
310 { 0x8827, EXIF_FORMAT_SHORT_UNSIGNED, -1, "ISOSpeedRatings", N_("ISO sensitivity"), NULL },
311 { 0x8828, EXIF_FORMAT_UNDEFINED, -1, "OECF", "Optoelectric conversion factor", NULL },
312 { 0x9000, EXIF_FORMAT_UNDEFINED, 4, "ExifVersion", "Exif version", NULL },
313 { 0x9003, EXIF_FORMAT_STRING, 20, "DateTimeOriginal", N_("Date original"), NULL },
314 { 0x9004, EXIF_FORMAT_STRING, 20, "DateTimeDigitized", N_("Date digitized"), NULL },
315 { 0x9101, EXIF_FORMAT_UNDEFINED, -1, "ComponentsConfiguration","Pixel format", NULL },
316 { 0x9102, EXIF_FORMAT_RATIONAL_UNSIGNED,1, "CompressedBitsPerPixel","Compression ratio", NULL },
317 { 0x9201, EXIF_FORMAT_RATIONAL, 1, "ShutterSpeedValue", N_("Shutter speed"), NULL },
318 { 0x9202, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ApertureValue", N_("Aperture"), NULL },
319 { 0x9203, EXIF_FORMAT_RATIONAL, 1, "BrightnessValue", "Brightness", NULL },
320 { 0x9204, EXIF_FORMAT_RATIONAL, 1, "ExposureBiasValue", N_("Exposure bias"), NULL },
321 { 0x9205, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "MaxApertureValue", "Maximum aperture", NULL },
322 { 0x9206, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "SubjectDistance", N_("Subject distance"), NULL },
323 { 0x9207, EXIF_FORMAT_SHORT_UNSIGNED, 1, "MeteringMode", N_("Metering mode"), ExifMeteringModeList },
324 { 0x9208, EXIF_FORMAT_SHORT_UNSIGNED, 1, "LightSource", N_("Light source"), ExifLightSourceList },
325 { 0x9209, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Flash", N_("Flash"), ExifFlashList },
326 { 0x920a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalLength", N_("Focal length"), NULL },
327 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SubjectArea", "Subject area", NULL },
328 { 0x927c, EXIF_FORMAT_UNDEFINED, -1, "MakerNote", "MakerNote", NULL },
329 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, "UserComment", "UserComment", NULL },
330 { 0x9290, EXIF_FORMAT_STRING, -1, "SubsecTime", "Subsecond time", NULL },
331 { 0x9291, EXIF_FORMAT_STRING, -1, "SubsecTimeOriginal", "Subsecond time original", NULL },
332 { 0x9292, EXIF_FORMAT_STRING, -1, "SubsecTimeDigitized", "Subsecond time digitized", NULL },
333 { 0xa000, EXIF_FORMAT_UNDEFINED, 4, "FlashPixVersion", "FlashPix version", NULL },
334 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ColorSpace", "Colorspace", ExifColorSpaceList },
335 /* ExifImageWidth, ExifImageHeight can also be unsigned short */
336 { 0xa002, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageWidth", N_("Width"), NULL },
337 { 0xa003, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageHeight", N_("Height"), NULL },
338 { 0xa004, EXIF_FORMAT_STRING, -1, "RelatedSoundFile", "Audio data", NULL },
339 { 0xa005, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifInteroperabilityOffset", "ExifR98 extension", NULL },
340 { 0xa20b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", "Flash strength", NULL },
341 { 0xa20c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SpatialFrequencyResponse","Spatial frequency response", NULL },
342 { 0xa20e, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneXResolution", "X Pixel density", NULL },
343 { 0xa20f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneYResolution", "Y Pixel density", NULL },
344 { 0xa210, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalPlaneResolutionUnit", "Pixel density units", ExifUnitList },
345 { 0x0214, EXIF_FORMAT_SHORT_UNSIGNED, 2, "SubjectLocation", "Subject location", NULL },
346 { 0xa215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", N_("ISO sensitivity"), NULL },
347 { 0xa217, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SensingMethod", "Sensor type", ExifSensorList },
348 { 0xa300, EXIF_FORMAT_UNDEFINED, 1, "FileSource", "Source type", ExifSourceList },
349 { 0xa301, EXIF_FORMAT_UNDEFINED, 1, "SceneType", "Scene type", ExifSceneList },
350 { 0xa302, EXIF_FORMAT_UNDEFINED, -1, "CFAPattern", "Color filter array pattern", NULL },
351 /* tags a4xx were added for Exif 2.2 (not just these - some above, as well) */
352 { 0xa401, EXIF_FORMAT_SHORT_UNSIGNED, 1, "CustomRendered", "Render process", ExifCustRenderList },
353 { 0xa402, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureMode", "Exposure mode", ExifExposureModeList },
354 { 0xa403, EXIF_FORMAT_SHORT_UNSIGNED, 1, "WhiteBalance", "White balance", ExifWhiteBalanceList },
355 { 0xa404, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "DigitalZoomRatio", "Digital zoom ratio", NULL },
356 { 0xa405, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalLength35mmFilm", "Focal length (35mm)", NULL },
357 { 0xa406, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SceneCapturetype", "Scene capture type", ExifSceneCaptureList },
358 { 0xa407, EXIF_FORMAT_SHORT_UNSIGNED, 1, "GainControl", "Gain control", ExifGainControlList },
359 { 0xa408, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Contrast", "Contrast", ExifContrastList },
360 { 0xa409, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Saturation", "Saturation", ExifSaturationList },
361 { 0xa40a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Sharpness", "Sharpness", ExifSharpnessList },
362 { 0xa40b, EXIF_FORMAT_UNDEFINED, -1, "DeviceSettingDescription","Device setting", NULL },
363 { 0xa40c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubjectDistanceRange", "Subject range", ExifSubjectRangeList },
364 { 0xa420, EXIF_FORMAT_STRING, -1, "ImageUniqueID", "Image serial number", NULL },
365 /* place known, but undocumented or lesser used tags here */
366 { 0x00fe, EXIF_FORMAT_LONG_UNSIGNED, 1, "NewSubfileType", NULL, NULL },
367 { 0x00ff, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubfileType", NULL, NULL },
368 { 0x012d, EXIF_FORMAT_SHORT_UNSIGNED, 3, "TransferFunction", NULL, NULL },
369 { 0x013b, EXIF_FORMAT_STRING, -1, "Artist", "Artist", NULL },
370 { 0x013d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Predictor", NULL, NULL },
371 { 0x0142, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileWidth", NULL, NULL },
372 { 0x0143, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileLength", NULL, NULL },
373 { 0x0144, EXIF_FORMAT_LONG_UNSIGNED, -1, "TileOffsets", NULL, NULL },
374 { 0x0145, EXIF_FORMAT_SHORT_UNSIGNED, -1, "TileByteCounts", NULL, NULL },
375 { 0x014a, EXIF_FORMAT_LONG_UNSIGNED, -1, "SubIFDs", NULL, NULL },
376 { 0x015b, EXIF_FORMAT_UNDEFINED, -1, "JPEGTables", NULL, NULL },
377 { 0x828d, EXIF_FORMAT_SHORT_UNSIGNED, 2, "CFARepeatPatternDim", NULL, NULL },
378 { 0x828e, EXIF_FORMAT_BYTE_UNSIGNED, -1, "CFAPattern", NULL, NULL },
379 { 0x828f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "BatteryLevel", NULL, NULL },
380 { 0x83bb, EXIF_FORMAT_LONG_UNSIGNED, -1, "IPTC/NAA", NULL, NULL },
381 { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "InterColorProfile", NULL, NULL },
382 { 0x8825, EXIF_FORMAT_LONG_UNSIGNED, 1, "GPSInfo", "SubIFD GPS offset", NULL },
383 { 0x8829, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Interlace", NULL, NULL },
384 { 0x882a, EXIF_FORMAT_SHORT, 1, "TimeZoneOffset", NULL, NULL },
385 { 0x882b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SelfTimerMode", NULL, NULL },
386 { 0x920b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", NULL, NULL },
387 { 0x920c, EXIF_FORMAT_UNDEFINED, -1, "SpatialFrequencyResponse", NULL, NULL },
388 { 0x920d, EXIF_FORMAT_UNDEFINED, -1, "Noise", NULL, NULL },
389 { 0x9211, EXIF_FORMAT_LONG_UNSIGNED, 1, "ImageNumber", NULL, NULL },
390 { 0x9212, EXIF_FORMAT_STRING, 1, "SecurityClassification", NULL, NULL },
391 { 0x9213, EXIF_FORMAT_STRING, -1, "ImageHistory", NULL, NULL },
392 { 0x9215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", NULL, NULL },
393 { 0x9216, EXIF_FORMAT_BYTE_UNSIGNED, 4, "TIFF/EPStandardID", NULL, NULL },
398 ExifMarker ExifUnknownMarkersList[] = {
399 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL },
400 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL },
401 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL },
402 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL },
403 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL },
404 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL },
405 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL },
406 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL },
407 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL },
408 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL },
409 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL },
410 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL },
411 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL },
414 /* human readable key list */
416 ExifFormattedText ExifFormattedList[] = {
417 { "fCamera", N_("Camera") },
418 { "fDateTime", N_("Date") },
419 { "fShutterSpeed", N_("Shutter speed") },
420 { "fAperture", N_("Aperture") },
421 { "fExposureBias", N_("Exposure bias") },
422 { "fISOSpeedRating", N_("ISO sensitivity") },
423 { "fFocalLength", N_("Focal length") },
424 { "fSubjectDistance", N_("Subject distance") },
425 { "fFlash", N_("Flash") },
426 { "fResolution", N_("Resolution") },
432 *-----------------------------------------------------------------------------
434 *-----------------------------------------------------------------------------
437 #define MARKER_UNKNOWN 0x00
438 #define MARKER_SOI 0xD8
439 #define MARKER_APP1 0xE1
441 /* These data structs are packed to make sure the
442 * byte alignment matches the on-disk data format.
444 typedef struct __attribute__((packed)) {
450 typedef struct __attribute__((packed)) {
458 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list);
461 *-----------------------------------------------------------------------------
463 *-----------------------------------------------------------------------------
466 ExifItem *exif_item_new(ExifFormatType format, guint tag,
467 guint elements, const ExifMarker *marker)
471 item = g_new0(ExifItem, 1);
472 item->format = format;
474 item->marker = marker;
475 item->elements = elements;
481 case EXIF_FORMAT_UNKNOWN:
482 /* unknown, data is NULL */
485 case EXIF_FORMAT_BYTE_UNSIGNED:
486 item->data_len = sizeof(char) * elements;
488 case EXIF_FORMAT_STRING:
489 item->data_len = sizeof(char) * elements;
491 case EXIF_FORMAT_SHORT_UNSIGNED:
492 item->data_len = sizeof(guint16) * elements;
494 case EXIF_FORMAT_LONG_UNSIGNED:
495 item->data_len = sizeof(guint32) * elements;
497 case EXIF_FORMAT_RATIONAL_UNSIGNED:
498 item->data_len = sizeof(ExifRational) * elements;
500 case EXIF_FORMAT_BYTE:
501 item->data_len = sizeof(char) * elements;
503 case EXIF_FORMAT_UNDEFINED:
504 item->data_len = sizeof(char) * elements;
506 case EXIF_FORMAT_SHORT:
507 item->data_len = sizeof(gint16) * elements;
509 case EXIF_FORMAT_LONG:
510 item->data_len = sizeof(gint32) * elements;
512 case EXIF_FORMAT_RATIONAL:
513 item->data_len = sizeof(ExifRational) * elements;
515 case EXIF_FORMAT_FLOAT:
516 item->data_len = sizeof(float) * elements;
518 case EXIF_FORMAT_DOUBLE:
519 item->data_len = sizeof(double) * elements;
523 item->data = g_malloc0(item->data_len);
528 static void exif_item_free(ExifItem *item)
536 const char *exif_item_get_tag_name(ExifItem *item)
538 if (!item || !item->marker) return NULL;
539 return item->marker->key;
542 const char *exif_item_get_description(ExifItem *item)
544 if (!item || !item->marker) return NULL;
545 return _(item->marker->description);
548 const char *exif_item_get_format_name(ExifItem *item, gint brief)
550 if (!item || !item->marker) return NULL;
551 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description;
555 #define UNDEFINED_TEXT_BYTE_COUNT 16
557 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne)
561 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
563 unsigned char c = ((char *)data)[i];
564 if (c < 32 || c > 127) c = '.';
565 g_string_append_printf(string, "%c", c);
567 string = g_string_append(string, " : ");
568 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
586 g_string_append_printf(string, "%s%02x", spacer, ((char *)data)[i]);
588 if (i >= UNDEFINED_TEXT_BYTE_COUNT) g_string_append_printf(string, " (%d bytes)", ne);
593 static gchar *text_list_find_value(ExifTextList *list, guint value)
595 gchar *result = NULL;
599 while (!result && list[i].value >= 0)
601 if (value == list[i].value) result = g_strdup(_(list[i].description));
604 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown"));
610 *-------------------------------------------------------------------
612 *-------------------------------------------------------------------
615 guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo)
617 if (bo == EXIF_BYTE_ORDER_INTEL)
618 return GUINT16_FROM_LE(*(guint16*)f);
620 return GUINT16_FROM_BE(*(guint16*)f);
623 guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo)
625 if (bo == EXIF_BYTE_ORDER_INTEL)
626 return GUINT32_FROM_LE(*(guint32*)f);
628 return GUINT32_FROM_BE(*(guint32*)f);
631 guint16 exif_byte_swab_int16(guint16 n, ExifByteOrder bo)
633 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
634 if (bo == EXIF_BYTE_ORDER_MOTOROLA)
636 if (bo == EXIF_BYTE_ORDER_INTEL)
638 return GUINT16_SWAP_LE_BE(n);
643 guint32 exif_byte_swab_int32(guint32 n, ExifByteOrder bo)
645 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
646 if (bo == EXIF_BYTE_ORDER_MOTOROLA)
648 if (bo == EXIF_BYTE_ORDER_INTEL)
650 return GUINT32_SWAP_LE_BE(n);
656 *-------------------------------------------------------------------
658 *-------------------------------------------------------------------
661 static int get_marker_size(unsigned char *f)
663 /* Size is always in Motorola byte order */
664 return exif_byte_get_int16(f+2, EXIF_BYTE_ORDER_MOTOROLA);
667 static int goto_next_marker(unsigned char **f, int *size, int *marker)
671 *marker = MARKER_UNKNOWN;
673 /* It is safe to access the marker and its size since we have checked
674 * the SOI and this function guaranties the whole next marker is
677 if (*(*f+1) != MARKER_SOI)
679 marker_size += get_marker_size(*f);
682 *size -= marker_size;
684 /* size should be at least 4, so we can read the marker and its size
685 * and check data are actually available
687 if (*size < 4) return -1;
689 /* Jump to the next marker and be sure it begins with 0xFF
692 if (**f != 0xFF) return -1;
694 if (get_marker_size(*f)+2 > *size) return -1;
702 *-------------------------------------------------------------------
704 *-------------------------------------------------------------------
707 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list)
711 if (!list) return NULL;
713 while (list[i].tag != 0 && list[i].tag != tag)
718 return (list[i].tag == 0 ? NULL : &list[i]);
721 static void rational_from_data(ExifRational *r, void *src, ExifByteOrder byte_order)
723 r->num = exif_byte_swab_int32(*(guint32*)src, byte_order);
724 r->den = exif_byte_swab_int32(*(guint32*)(src + sizeof(guint32)), byte_order);
727 void exif_item_copy_data(ExifItem *item, void *src, guint len,
728 ExifFormatType src_format, ExifByteOrder byte_order)
735 bs = ExifFormatList[item->format].size;
739 if (!dest || len > item->data_len)
741 printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
745 switch (item->format)
747 case EXIF_FORMAT_UNKNOWN:
749 case EXIF_FORMAT_BYTE_UNSIGNED:
750 case EXIF_FORMAT_BYTE:
751 case EXIF_FORMAT_UNDEFINED:
752 memcpy(dest, src, len);
754 case EXIF_FORMAT_STRING:
755 memcpy(dest, src, len);
756 /* string is NULL terminated, make sure this is true */
757 if (((char *)dest)[len - 1] != '\0') ((char *)dest)[len - 1] = '\0';
759 case EXIF_FORMAT_SHORT_UNSIGNED:
760 case EXIF_FORMAT_SHORT:
761 for (i = 0; i < ne; i++)
763 ((guint16 *)dest)[i] = exif_byte_swab_int16(*(guint16*)(src + i * bs), byte_order);
766 case EXIF_FORMAT_LONG_UNSIGNED:
767 case EXIF_FORMAT_LONG:
768 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED ||
769 src_format == EXIF_FORMAT_SHORT)
771 /* a short fits into a long, so allow it */
774 ss = ExifFormatList[src_format].size;
775 for (i = 0; i < ne; i++)
777 ((gint32 *)dest)[i] =
778 (gint32)exif_byte_swab_int16(*(guint16*)(src + i * ss), byte_order);
783 for (i = 0; i < ne; i++)
785 ((gint32 *)dest)[i] =
786 exif_byte_swab_int32(*(guint32*)(src + i * bs), byte_order);
790 case EXIF_FORMAT_RATIONAL_UNSIGNED:
791 case EXIF_FORMAT_RATIONAL:
792 for (i = 0; i < ne; i++)
794 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, byte_order);
797 case EXIF_FORMAT_FLOAT:
798 for (i = 0; i < ne; i++)
800 ((float *)dest)[i] = exif_byte_swab_int32(*(guint32*)(src + i * bs), byte_order);
803 case EXIF_FORMAT_DOUBLE:
804 for (i = 0; i < ne; i++)
808 rational_from_data(&r, src + i * bs, byte_order);
809 if (r.den) ((double *)dest)[i] = (double)r.num / r.den;
815 static gint exif_parse_IFD_entry(ExifData *exif, unsigned char *tiff, guint offset,
816 guint size, ExifByteOrder byte_order,
817 const ExifMarker *list)
819 IFDEntry *ent = (IFDEntry*)(tiff+offset);
823 const ExifMarker *marker;
826 ent->tag = exif_byte_swab_int16(ent->tag, byte_order);
827 ent->format = exif_byte_swab_int16(ent->format, byte_order);
828 ent->nb = exif_byte_swab_int32(ent->nb, byte_order);
829 swabed_data = exif_byte_swab_int32(ent->data, byte_order);
831 /* Check tag type. If it does not match, either the format is wrong,
832 * either it is a unknown tag; so it is not really an error.
834 marker = exif_marker_from_tag(ent->tag, list);
837 if (ent->format > EXIF_FORMAT_DOUBLE)
839 printf("warning: exif tag 0x%4x has invalid format %d\n", ent->tag, ent->format);
842 /* allow non recognized tags to be displayed */
843 marker = &ExifUnknownMarkersList[ent->format];
845 if (marker->format != ent->format)
847 /* Some cameras got mixed up signed/unsigned_rational
848 * eg KODAK DC4800 on object_distance tag
850 * FIXME: what exactly is this test trying to do?
851 * ok, so this test is to allow the case of swapped signed/unsigned mismatch to leak through?
853 if ( !(marker->format == EXIF_FORMAT_RATIONAL_UNSIGNED && ent->format == EXIF_FORMAT_RATIONAL) &&
854 !(marker->format == EXIF_FORMAT_RATIONAL && ent->format == EXIF_FORMAT_RATIONAL_UNSIGNED) &&
855 /* short fits into a long so allow this mismatch
856 * as well (some tags allowed to be unsigned short _or_ unsigned long)
858 !(marker->format == EXIF_FORMAT_LONG_UNSIGNED && ent->format == EXIF_FORMAT_SHORT_UNSIGNED) )
860 if (ent->format <= EXIF_FORMAT_DOUBLE)
862 printf("warning: exif tag %s format mismatch, found %s exif spec requests %s\n",
863 marker->key, ExifFormatList[ent->format].short_name,
864 ExifFormatList[marker->format].short_name);
868 printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n",
869 marker->key, ent->format, marker->format,
870 ExifFormatList[marker->format].short_name);
876 /* Where is the data, is it available?
878 if (marker->components > 0 && marker->components != ent->nb)
880 printf("warning: exif tag %s has %d elements, exif spec requests %d\n",
881 marker->key, ent->nb, marker->components);
883 data_len = ExifFormatList[marker->format].size * ent->nb;
884 if (data_len > sizeof(ent->data))
886 if (size < swabed_data+data_len)
888 printf("warning: exif tag %s will overrun IFD segment, ignored.\n", marker->key);
891 data = (void*)tiff + swabed_data;
895 data = (void*)(&(ent->data));
898 item = exif_item_new(marker->format, ent->tag, ent->nb, marker);
899 exif_item_copy_data(item, data, data_len, ent->format, byte_order);
900 exif->items = g_list_prepend(exif->items, item);
902 if (list == ExifKnownMarkersList)
907 exif_parse_IFD_table(exif, tiff, swabed_data, size, byte_order, list);
909 case TAG_EXIFMAKERNOTE:
910 format_exif_makernote_parse(exif, tiff, swabed_data, size, byte_order);
918 gint exif_parse_IFD_table(ExifData *exif,
919 unsigned char *tiff, guint offset,
920 guint size, ExifByteOrder byte_order,
921 const ExifMarker *list)
925 /* We should be able to read number of entries in IFD0) */
926 if (size < offset+2) return -1;
928 nb_entries = exif_byte_get_int16(tiff+offset, byte_order);
930 /* Entries and next IFD offset must be readable */
931 if (size < offset+nb_entries*12+4) return -1;
933 for (i=0; i<nb_entries; ++i)
935 exif_parse_IFD_entry(exif, tiff, offset+2+i*sizeof(IFDEntry), size, byte_order, list);
942 *-------------------------------------------------------------------
944 *-------------------------------------------------------------------
947 gint exif_parse_TIFF(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list)
949 ExifByteOrder byte_order;
952 if (size < sizeof(TIFFHeader))
957 if (strncmp(((TIFFHeader*)tiff)->byte_order, "II", 2) == 0)
959 byte_order = EXIF_BYTE_ORDER_INTEL;
961 else if (strncmp(((TIFFHeader*)tiff)->byte_order, "MM", 2) == 0)
963 byte_order = EXIF_BYTE_ORDER_MOTOROLA;
970 if (exif_byte_swab_int16(((TIFFHeader*)tiff)->magic, byte_order) != 0x002A)
975 offset = exif_byte_swab_int32(((TIFFHeader*)tiff)->IFD_offset, byte_order);
977 return exif_parse_IFD_table(exif, tiff, offset, size, byte_order, list);
980 static gint exif_parse_JPEG(ExifData *exif, unsigned char *f, guint size, ExifMarker *list)
982 guint marker, marker_size;
984 if (size<2 || *f!=0xFF || *(f+1)!=MARKER_SOI)
990 if (goto_next_marker(&f, &size, &marker) == -1)
994 } while (marker != MARKER_APP1);
996 if (marker != MARKER_APP1)
1001 marker_size = get_marker_size(f)-2;
1003 if (marker_size<6 || strncmp((char*)f+4, "Exif\0\0", 6)!=0)
1008 return exif_parse_TIFF(exif, f+10, marker_size-6, list);
1011 static gint map_file(const gchar *path, void **mapping, int *size)
1016 if ((fd = open(path, O_RDONLY)) == -1)
1022 if (fstat(fd, &fs) == -1)
1031 if ((*mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
1042 static gint unmap_file(void *mapping, int size)
1044 if (munmap(mapping, size) == -1)
1053 void exif_free(ExifData *exif)
1062 ExifItem *item = work->data;
1064 exif_item_free(item);
1067 g_list_free(exif->items);
1071 ExifData *exif_read(const gchar *path)
1078 if (!path) return NULL;
1080 pathl = path_from_utf8(path);
1081 if (map_file(pathl, &f, &size) == -1)
1088 exif = g_new0(ExifData, 1);
1091 if ((res = exif_parse_JPEG(exif, (unsigned char *)f, size, ExifKnownMarkersList)) == -2)
1093 res = exif_parse_TIFF(exif, (unsigned char *)f, size, ExifKnownMarkersList);
1100 if (format_raw_img_exif_offsets(f, size, NULL, &offset))
1102 res = exif_parse_TIFF(exif, (unsigned char*)f + offset, size - offset, ExifKnownMarkersList);
1112 unmap_file(f, size);
1114 if (exif) exif->items = g_list_reverse(exif->items);
1117 exif_write_data_list(exif, stdout, TRUE);
1118 exif_write_data_list(exif, stdout, FALSE);
1124 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
1128 if (!key) return NULL;
1137 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item;
1142 gchar *exif_item_get_data_as_text(ExifItem *item)
1144 const ExifMarker *marker;
1151 if (!item) return NULL;
1153 marker = item->marker;
1154 if (!marker) return NULL;
1157 ne = item->elements;
1158 string = g_string_new("");
1159 switch (item->format)
1161 case EXIF_FORMAT_UNKNOWN:
1163 case EXIF_FORMAT_BYTE_UNSIGNED:
1164 case EXIF_FORMAT_BYTE:
1165 case EXIF_FORMAT_UNDEFINED:
1166 if (ne == 1 && marker->list)
1171 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED ||
1172 item->format == EXIF_FORMAT_UNDEFINED)
1174 val = ((unsigned char *)data)[0];
1178 val = (unsigned char)(((signed char *)data)[0]);
1181 result = text_list_find_value(marker->list, (guint)val);
1182 string = g_string_append(string, result);
1187 string = string_append_raw_bytes(string, data, ne);
1190 case EXIF_FORMAT_STRING:
1191 string = g_string_append(string, (gchar *)(item->data));
1193 case EXIF_FORMAT_SHORT_UNSIGNED:
1194 if (ne == 1 && marker->list)
1198 result = text_list_find_value(marker->list, ((unsigned short *)data)[0]);
1199 string = g_string_append(string, result);
1202 else for (i = 0; i < ne; i++)
1204 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1205 ((unsigned short *)data)[i]);
1208 case EXIF_FORMAT_LONG_UNSIGNED:
1209 for (i = 0; i < ne; i++)
1211 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1212 ((unsigned long *)data)[i]);
1215 case EXIF_FORMAT_RATIONAL_UNSIGNED:
1216 for (i = 0; i < ne; i++)
1220 r = &((ExifRational *)data)[i];
1221 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1222 (unsigned long)r->num, (unsigned long)r->den);
1225 case EXIF_FORMAT_SHORT:
1226 for (i = 0; i < ne; i++)
1228 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1229 ((short *)data)[i]);
1232 case EXIF_FORMAT_LONG:
1233 for (i = 0; i < ne; i++)
1235 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1239 case EXIF_FORMAT_RATIONAL:
1240 for (i = 0; i < ne; i++)
1244 r = &((ExifRational *)data)[i];
1245 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1246 (long)r->num, (long)r->den);
1249 case EXIF_FORMAT_FLOAT:
1250 for (i = 0; i < ne; i++)
1252 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1253 ((float *)data)[i]);
1256 case EXIF_FORMAT_DOUBLE:
1257 for (i = 0; i < ne; i++)
1259 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1260 ((double *)data)[i]);
1265 text = g_strdup(string->str);
1266 g_string_free(string, TRUE);
1271 gint exif_item_get_integer(ExifItem *item, gint *value)
1273 if (!item) return FALSE;
1275 switch (item->format)
1277 case EXIF_FORMAT_SHORT:
1278 *value = (gint)(((short *)(item->data))[0]);
1281 case EXIF_FORMAT_SHORT_UNSIGNED:
1282 *value = (gint)(((unsigned short *)(item->data))[0]);
1285 case EXIF_FORMAT_LONG:
1286 *value = (gint)(((long *)(item->data))[0]);
1289 case EXIF_FORMAT_LONG_UNSIGNED:
1290 /* FIXME: overflow possible */
1291 *value = (gint)(((unsigned long *)(item->data))[0]);
1294 /* all other type return FALSE */
1300 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
1304 item = exif_get_item(exif, key);
1305 return exif_item_get_integer(item, value);
1308 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
1310 if (!item) return NULL;
1312 if (item->format == EXIF_FORMAT_RATIONAL ||
1313 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED)
1315 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL);
1316 return &((ExifRational *)(item->data))[0];
1322 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
1326 item = exif_get_item(exif, key);
1327 return exif_item_get_rational(item, sign);
1330 double exif_rational_to_double(ExifRational *r, gint sign)
1332 if (!r || r->den == 0.0) return 0.0;
1334 if (sign) return (double)((int)r->num) / (double)((int)r->den);
1335 return (double)r->num / r->den;
1338 static double exif_get_rational_as_double(ExifData *exif, const gchar *key)
1343 r = exif_get_rational(exif, key, &sign);
1344 return exif_rational_to_double(r, sign);
1347 static GString *append_comma_text(GString *string, const gchar *text)
1349 string = g_string_append(string, ", ");
1350 string = g_string_append(string, text);
1355 static gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
1357 /* must begin with f, else not formatted */
1360 if (key_valid) *key_valid = FALSE;
1364 if (key_valid) *key_valid = TRUE;
1366 if (strcmp(key, "fCamera") == 0)
1369 gchar *make = exif_get_data_as_text(exif, "Make");
1370 gchar *model = exif_get_data_as_text(exif, "Model");
1371 gchar *software = exif_get_data_as_text(exif, "Software");
1373 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
1374 (model) ? model : "",
1375 (software) ? " (" : "",
1376 (software) ? software : "",
1377 (software) ? ")" : "");
1384 if (strcmp(key, "fDateTime") == 0)
1386 gchar *text = exif_get_data_as_text(exif, "DateTimeOriginal");
1387 gchar *subsec = NULL;
1388 if (text) subsec = exif_get_data_as_text(exif, "SubsecTimeOriginal");
1391 text = exif_get_data_as_text(exif, "DateTime");
1392 if (text) subsec = exif_get_data_as_text(exif, "SubsecTime");
1397 text = g_strconcat(tmp, ".", subsec, NULL);
1403 if (strcmp(key, "fShutterSpeed") == 0)
1407 r = exif_get_rational(exif, "ExposureTime", NULL);
1408 if (r && r->num && r->den)
1410 double n = (double)r->den / (double)r->num;
1411 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1412 n > 1.0 ? n : 1.0 / n);
1414 r = exif_get_rational(exif, "ShutterSpeedValue", NULL);
1415 if (r && r->num && r->den)
1417 double n = pow(2.0, exif_rational_to_double(r, TRUE));
1419 /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
1420 if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
1422 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1423 n > 1.0 ? floor(n) : 1.0 / n);
1427 if (strcmp(key, "fAperture") == 0)
1431 n = exif_get_rational_as_double(exif, "FNumber");
1432 if (n == 0.0) n = exif_get_rational_as_double(exif, "ApertureValue");
1433 if (n == 0.0) return NULL;
1435 return g_strdup_printf("f/%.1f", n);
1437 if (strcmp(key, "fExposureBias") == 0)
1443 r = exif_get_rational(exif, "ExposureBiasValue", &sign);
1444 if (!r) return NULL;
1446 n = exif_rational_to_double(r, sign);
1447 return g_strdup_printf("%+.1f", n);
1449 if (strcmp(key, "fFocalLength") == 0)
1453 n = exif_get_rational_as_double(exif, "FocalLength");
1454 if (n == 0.0) return NULL;
1455 return g_strdup_printf("%.2f mm", n);
1457 if (strcmp(key, "fISOSpeedRating") == 0)
1461 text = exif_get_data_as_text(exif, "ISOSpeedRatings");
1462 /* kodak may set this instead */
1463 if (!text) text = exif_get_data_as_text(exif, "ExposureIndex");
1466 if (strcmp(key, "fSubjectDistance") == 0)
1472 r = exif_get_rational(exif, "SubjectDistance", &sign);
1473 if (!r) return NULL;
1475 if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
1476 if ((long)r->num == 0) return g_strdup(_("unknown"));
1478 n = exif_rational_to_double(r, sign);
1479 if (n == 0.0) return _("unknown");
1480 return g_strdup_printf("%.3f m", n);
1482 if (strcmp(key, "fFlash") == 0)
1484 /* grr, flash is a bitmask... */
1490 if (!exif_get_integer(exif, "Flash", &n)) return NULL;
1492 /* Exif 2.1 only defines first 3 bits */
1493 if (n <= 0x07) return g_strdup(text_list_find_value(ExifFlashList, n));
1495 /* must be Exif 2.2 */
1496 string = g_string_new("");
1498 /* flash fired (bit 0) */
1499 string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
1501 /* flash mode (bits 3, 4) */
1502 v = (n >> 3) & 0x03;
1503 if (v) string = append_comma_text(string, _("mode:"));
1507 string = g_string_append(string, _("on"));
1510 string = g_string_append(string, _("off"));
1513 string = g_string_append(string, _("auto"));
1517 /* return light (bits 1, 2) */
1518 v = (n >> 1) & 0x03;
1519 if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
1520 if (v == 3) string = append_comma_text(string, _("detected by strobe"));
1522 /* we ignore flash function (bit 5) */
1524 /* red-eye (bit 6) */
1525 if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
1528 g_string_free(string, FALSE);
1531 if (strcmp(key, "fResolution") == 0)
1533 ExifRational *rx, *ry;
1537 rx = exif_get_rational(exif, "XResolution", NULL);
1538 ry = exif_get_rational(exif, "YResolution", NULL);
1539 if (!rx || !ry) return NULL;
1541 units = exif_get_data_as_text(exif, "ResolutionUnit");
1542 text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
1543 ry->den ? (double)ry->num / ry->den : 1.0,
1544 _("dot"), (units) ? units : _("unknown"));
1550 if (key_valid) *key_valid = FALSE;
1554 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
1560 if (!key) return NULL;
1562 text = exif_get_formatted_by_key(exif, key, &key_valid);
1563 if (key_valid) return text;
1565 item = exif_get_item(exif, key);
1566 if (item) return exif_item_get_data_as_text(item);
1571 const gchar *exif_get_description_by_key(const gchar *key)
1575 if (!key) return NULL;
1578 while (ExifFormattedList[i].key != NULL)
1580 if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
1585 while (ExifKnownMarkersList[i].tag > 0)
1587 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
1594 static void exif_write_item(FILE *f, ExifItem *item)
1598 text = exif_item_get_data_as_text(item);
1601 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
1602 exif_item_get_tag_name(item), text);
1607 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list)
1609 if (!f || !exif) return;
1611 fprintf(f, " tag format key value\n");
1612 fprintf(f, "----------------------------------------------------\n");
1614 if (human_readable_list)
1619 while (ExifFormattedList[i].key)
1623 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL);
1626 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text);
1643 exif_write_item(f, item);
1646 fprintf(f, "----------------------------------------------------\n");