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.
61 #include <sys/types.h>
72 #include "format_raw.h"
73 #include "ui_fileops.h"
77 *-----------------------------------------------------------------------------
79 *-----------------------------------------------------------------------------
82 ExifFormatAttrib ExifFormatList[] = {
83 { EXIF_FORMAT_UNKNOWN, 1, "unknown", "unknown" },
84 { EXIF_FORMAT_BYTE_UNSIGNED, 1, "ubyte", "unsigned byte" },
85 { EXIF_FORMAT_STRING, 1, "string", "string" },
86 { EXIF_FORMAT_SHORT_UNSIGNED, 2, "ushort", "unsigned short" },
87 { EXIF_FORMAT_LONG_UNSIGNED, 4, "ulong", "unsigned long" },
88 { EXIF_FORMAT_RATIONAL_UNSIGNED,8, "urational", "unsigned rational" },
89 { EXIF_FORMAT_BYTE, 1, "byte", "byte" },
90 { EXIF_FORMAT_UNDEFINED, 1, "undefined", "undefined" },
91 { EXIF_FORMAT_SHORT, 2, "sshort", "signed short" },
92 { EXIF_FORMAT_LONG, 4, "slong", "signed long" },
93 { EXIF_FORMAT_RATIONAL, 8, "srational", "signed rational" },
94 { EXIF_FORMAT_FLOAT, 4, "float", "float" },
95 { EXIF_FORMAT_DOUBLE, 8, "double", "double" },
99 /* tags that are special, or need special treatment */
100 #define TAG_EXIFOFFSET 0x8769
101 #define TAG_EXIFMAKERNOTE 0x927c
105 *-----------------------------------------------------------------------------
107 *-----------------------------------------------------------------------------
110 static ExifTextList ExifOrientationList[] = {
111 { EXIF_ORIENTATION_UNKNOWN, N_("unknown") },
112 { EXIF_ORIENTATION_TOP_LEFT, N_("top left") },
113 { EXIF_ORIENTATION_TOP_RIGHT, N_("top right") },
114 { EXIF_ORIENTATION_BOTTOM_RIGHT,N_("bottom right") },
115 { EXIF_ORIENTATION_BOTTOM_LEFT, N_("bottom left") },
116 { EXIF_ORIENTATION_LEFT_TOP, N_("left top") },
117 { EXIF_ORIENTATION_RIGHT_TOP, N_("right top") },
118 { EXIF_ORIENTATION_RIGHT_BOTTOM,N_("right bottom") },
119 { EXIF_ORIENTATION_LEFT_BOTTOM, N_("left bottom") },
123 static ExifTextList ExifUnitList[] = {
124 { EXIF_UNIT_UNKNOWN, N_("unknown") },
125 { EXIF_UNIT_NOUNIT, "" },
126 { EXIF_UNIT_INCH, N_("inch") },
127 { EXIF_UNIT_CENTIMETER, N_("centimeter") },
131 static ExifTextList ExifYCbCrPosList[] = {
137 static ExifTextList ExifMeteringModeList[] = {
138 { 0, N_("unknown") },
139 { 1, N_("average") },
140 { 2, N_("center weighted") },
142 { 4, N_("multi-spot") },
143 { 5, N_("multi-segment") },
144 { 6, N_("partial") },
145 { 255, N_("other") },
149 static ExifTextList ExifExposureProgramList[] = {
150 { 0, N_("not defined") },
153 { 3, N_("aperture") },
154 { 4, N_("shutter") },
155 { 5, N_("creative") },
157 { 7, N_("portrait") },
158 { 8, N_("landscape") },
162 static ExifTextList ExifLightSourceList[] = {
163 { 0, N_("unknown") },
164 { 1, N_("daylight") },
165 { 2, N_("fluorescent") },
166 { 3, N_("tungsten (incandescent)") },
168 { 9, "fine weather" },
169 { 10, "cloudy weather" },
171 { 12, "daylight fluorescent" },
172 { 13, "day white fluorescent" },
173 { 14, "cool white fluorescent" },
174 { 15, "while fluorescent" },
175 { 17, "standard light A" },
176 { 18, "standard light B" },
177 { 19, "standard light C" },
182 { 24, "ISO studio tungsten" },
183 { 255, N_("other") },
187 static ExifTextList ExifFlashList[] = {
190 { 5, N_("yes, not detected by strobe") },
191 { 7, N_("yes, detected by strobe") },
195 static ExifTextList ExifColorSpaceList[] = {
197 { 65535,"uncalibrated" },
201 static ExifTextList ExifSensorList[] = {
202 { 1, "not defined" },
203 { 2, "1 chip color area" },
204 { 2, "2 chip color area" },
205 { 4, "3 chip color area" },
206 { 5, "color sequential area" },
208 { 8, "color sequential linear" },
212 static ExifTextList ExifSourceList[] = {
213 { 3, "digital still camera" },
217 static ExifTextList ExifSceneList[] = {
218 { 1, "direct photo" },
222 static ExifTextList ExifCustRenderList[] = {
228 static ExifTextList ExifExposureModeList[] = {
231 { 2, "auto bracket" },
235 static ExifTextList ExifWhiteBalanceList[] = {
241 static ExifTextList ExifSceneCaptureList[] = {
245 { 3, "night scene" },
249 static ExifTextList ExifGainControlList[] = {
251 { 1, "low gain up" },
252 { 2, "high gain up" },
253 { 3, "low gain down" },
254 { 4, "high gain down" },
258 static ExifTextList ExifContrastList[] = {
265 static ExifTextList ExifSaturationList[] = {
272 static ExifTextList ExifSharpnessList[] = {
279 static ExifTextList ExifSubjectRangeList[] = {
287 ExifMarker ExifKnownMarkersList[] = {
288 { 0x010e, EXIF_FORMAT_STRING, -1, "ImageDescription", N_("Image description"), NULL },
289 { 0x010f, EXIF_FORMAT_STRING, -1, "Make", "Camera make", NULL },
290 { 0x0110, EXIF_FORMAT_STRING, -1, "Model", "Camera model", NULL },
291 { 0x0112, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Orientation", N_("Orientation"), ExifOrientationList },
292 { 0x011a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "XResolution", "X resolution", NULL },
293 { 0x011b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "YResolution", "Y Resolution", NULL },
294 { 0x0128, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ResolutionUnit", "Resolution units", ExifUnitList },
295 { 0x0131, EXIF_FORMAT_STRING, -1, "Software", "Firmware", NULL },
296 { 0x0132, EXIF_FORMAT_STRING, 20, "DateTime", N_("Date"), NULL },
297 { 0x013e, EXIF_FORMAT_RATIONAL_UNSIGNED, 2, "WhitePoint", "White point", NULL },
298 { 0x013f, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "PrimaryChromaticities","Primary chromaticities", NULL },
299 { 0x0211, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "YCbCrCoefficients", "YCbCy coefficients", NULL },
300 { 0x0213, EXIF_FORMAT_SHORT_UNSIGNED, 1, "YCbCrPositioning", "YCbCr positioning", ExifYCbCrPosList },
301 { 0x0214, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "ReferenceBlackWhite", "Black white reference", NULL },
302 { 0x8298, EXIF_FORMAT_STRING, -1, "Copyright", N_("Copyright"), NULL },
303 { 0x8769, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifOffset", "SubIFD Exif offset", NULL },
305 { 0x829a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureTime", "Exposure time (seconds)", NULL },
306 { 0x829d, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FNumber", "FNumber", NULL },
307 { 0x8822, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureProgram", N_("Exposure program"), ExifExposureProgramList },
308 { 0x8824, EXIF_FORMAT_STRING, -1, "SpectralSensitivity", "Spectral Sensitivity", NULL },
309 { 0x8827, EXIF_FORMAT_SHORT_UNSIGNED, -1, "ISOSpeedRatings", N_("ISO sensitivity"), NULL },
310 { 0x8828, EXIF_FORMAT_UNDEFINED, -1, "OECF", "Optoelectric conversion factor", NULL },
311 { 0x9000, EXIF_FORMAT_UNDEFINED, 4, "ExifVersion", "Exif version", NULL },
312 { 0x9003, EXIF_FORMAT_STRING, 20, "DateTimeOriginal", N_("Date original"), NULL },
313 { 0x9004, EXIF_FORMAT_STRING, 20, "DateTimeDigitized", N_("Date digitized"), NULL },
314 { 0x9101, EXIF_FORMAT_UNDEFINED, -1, "ComponentsConfiguration","Pixel format", NULL },
315 { 0x9102, EXIF_FORMAT_RATIONAL_UNSIGNED,1, "CompressedBitsPerPixel","Compression ratio", NULL },
316 { 0x9201, EXIF_FORMAT_RATIONAL, 1, "ShutterSpeedValue", N_("Shutter speed"), NULL },
317 { 0x9202, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ApertureValue", N_("Aperture"), NULL },
318 { 0x9203, EXIF_FORMAT_RATIONAL, 1, "BrightnessValue", "Brightness", NULL },
319 { 0x9204, EXIF_FORMAT_RATIONAL, 1, "ExposureBiasValue", N_("Exposure bias"), NULL },
320 { 0x9205, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "MaxApertureValue", "Maximum aperture", NULL },
321 { 0x9206, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "SubjectDistance", N_("Subject distance"), NULL },
322 { 0x9207, EXIF_FORMAT_SHORT_UNSIGNED, 1, "MeteringMode", N_("Metering mode"), ExifMeteringModeList },
323 { 0x9208, EXIF_FORMAT_SHORT_UNSIGNED, 1, "LightSource", N_("Light source"), ExifLightSourceList },
324 { 0x9209, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Flash", N_("Flash"), ExifFlashList },
325 { 0x920a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalLength", N_("Focal length"), NULL },
326 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SubjectArea", "Subject area", NULL },
327 { 0x927c, EXIF_FORMAT_UNDEFINED, -1, "MakerNote", "MakerNote", NULL },
328 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, "UserComment", "UserComment", NULL },
329 { 0x9290, EXIF_FORMAT_STRING, -1, "SubsecTime", "Subsecond time", NULL },
330 { 0x9291, EXIF_FORMAT_STRING, -1, "SubsecTimeOriginal", "Subsecond time original", NULL },
331 { 0x9292, EXIF_FORMAT_STRING, -1, "SubsecTimeDigitized", "Subsecond time digitized", NULL },
332 { 0xa000, EXIF_FORMAT_UNDEFINED, 4, "FlashPixVersion", "FlashPix version", NULL },
333 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ColorSpace", "Colorspace", ExifColorSpaceList },
334 /* ExifImageWidth, ExifImageHeight can also be unsigned short */
335 { 0xa002, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageWidth", N_("Width"), NULL },
336 { 0xa003, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageHeight", N_("Height"), NULL },
337 { 0xa004, EXIF_FORMAT_STRING, -1, "RelatedSoundFile", "Audio data", NULL },
338 { 0xa005, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifInteroperabilityOffset", "ExifR98 extension", NULL },
339 { 0xa20b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", "Flash strength", NULL },
340 { 0xa20c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SpatialFrequencyResponse","Spatial frequency response", NULL },
341 { 0xa20e, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneXResolution", "X Pixel density", NULL },
342 { 0xa20f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FocalPlaneYResolution", "Y Pixel density", NULL },
343 { 0xa210, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalPlaneResolutionUnit", "Pixel density units", ExifUnitList },
344 { 0x0214, EXIF_FORMAT_SHORT_UNSIGNED, 2, "SubjectLocation", "Subject location", NULL },
345 { 0xa215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", N_("ISO sensitivity"), NULL },
346 { 0xa217, EXIF_FORMAT_SHORT_UNSIGNED, -1, "SensingMethod", "Sensor type", ExifSensorList },
347 { 0xa300, EXIF_FORMAT_UNDEFINED, 1, "FileSource", "Source type", ExifSourceList },
348 { 0xa301, EXIF_FORMAT_UNDEFINED, 1, "SceneType", "Scene type", ExifSceneList },
349 { 0xa302, EXIF_FORMAT_UNDEFINED, -1, "CFAPattern", "Color filter array pattern", NULL },
350 /* tags a4xx were added for Exif 2.2 (not just these - some above, as well) */
351 { 0xa401, EXIF_FORMAT_SHORT_UNSIGNED, 1, "CustomRendered", "Render process", ExifCustRenderList },
352 { 0xa402, EXIF_FORMAT_SHORT_UNSIGNED, 1, "ExposureMode", "Exposure mode", ExifExposureModeList },
353 { 0xa403, EXIF_FORMAT_SHORT_UNSIGNED, 1, "WhiteBalance", "White balance", ExifWhiteBalanceList },
354 { 0xa404, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "DigitalZoomRatio", "Digital zoom ratio", NULL },
355 { 0xa405, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalLength35mmFilm", "Focal length (35mm)", NULL },
356 { 0xa406, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SceneCapturetype", "Scene capture type", ExifSceneCaptureList },
357 { 0xa407, EXIF_FORMAT_SHORT_UNSIGNED, 1, "GainControl", "Gain control", ExifGainControlList },
358 { 0xa408, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Contrast", "Contrast", ExifContrastList },
359 { 0xa409, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Saturation", "Saturation", ExifSaturationList },
360 { 0xa40a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Sharpness", "Sharpness", ExifSharpnessList },
361 { 0xa40b, EXIF_FORMAT_UNDEFINED, -1, "DeviceSettingDescription","Device setting", NULL },
362 { 0xa40c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubjectDistanceRange", "Subject range", ExifSubjectRangeList },
363 { 0xa420, EXIF_FORMAT_STRING, -1, "ImageUniqueID", "Image serial number", NULL },
364 /* place known, but undocumented or lesser used tags here */
365 { 0x00fe, EXIF_FORMAT_LONG_UNSIGNED, 1, "NewSubfileType", NULL, NULL },
366 { 0x00ff, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubfileType", NULL, NULL },
367 { 0x012d, EXIF_FORMAT_SHORT_UNSIGNED, 3, "TransferFunction", NULL, NULL },
368 { 0x013b, EXIF_FORMAT_STRING, -1, "Artist", "Artist", NULL },
369 { 0x013d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Predictor", NULL, NULL },
370 { 0x0142, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileWidth", NULL, NULL },
371 { 0x0143, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileLength", NULL, NULL },
372 { 0x0144, EXIF_FORMAT_LONG_UNSIGNED, -1, "TileOffsets", NULL, NULL },
373 { 0x0145, EXIF_FORMAT_SHORT_UNSIGNED, -1, "TileByteCounts", NULL, NULL },
374 { 0x014a, EXIF_FORMAT_LONG_UNSIGNED, -1, "SubIFDs", NULL, NULL },
375 { 0x015b, EXIF_FORMAT_UNDEFINED, -1, "JPEGTables", NULL, NULL },
376 { 0x828d, EXIF_FORMAT_SHORT_UNSIGNED, 2, "CFARepeatPatternDim", NULL, NULL },
377 { 0x828e, EXIF_FORMAT_BYTE_UNSIGNED, -1, "CFAPattern", NULL, NULL },
378 { 0x828f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "BatteryLevel", NULL, NULL },
379 { 0x83bb, EXIF_FORMAT_LONG_UNSIGNED, -1, "IPTC/NAA", NULL, NULL },
380 { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "InterColorProfile", NULL, NULL },
381 { 0x8825, EXIF_FORMAT_LONG_UNSIGNED, 1, "GPSInfo", "SubIFD GPS offset", NULL },
382 { 0x8829, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Interlace", NULL, NULL },
383 { 0x882a, EXIF_FORMAT_SHORT, 1, "TimeZoneOffset", NULL, NULL },
384 { 0x882b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SelfTimerMode", NULL, NULL },
385 { 0x920b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "FlashEnergy", NULL, NULL },
386 { 0x920c, EXIF_FORMAT_UNDEFINED, -1, "SpatialFrequencyResponse", NULL, NULL },
387 { 0x920d, EXIF_FORMAT_UNDEFINED, -1, "Noise", NULL, NULL },
388 { 0x9211, EXIF_FORMAT_LONG_UNSIGNED, 1, "ImageNumber", NULL, NULL },
389 { 0x9212, EXIF_FORMAT_STRING, 1, "SecurityClassification", NULL, NULL },
390 { 0x9213, EXIF_FORMAT_STRING, -1, "ImageHistory", NULL, NULL },
391 { 0x9215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "ExposureIndex", NULL, NULL },
392 { 0x9216, EXIF_FORMAT_BYTE_UNSIGNED, 4, "TIFF/EPStandardID", NULL, NULL },
397 ExifMarker ExifUnknownMarkersList[] = {
398 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL },
399 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL },
400 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL },
401 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL },
402 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL },
403 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL },
404 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL },
405 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL },
406 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL },
407 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL },
408 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL },
409 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL },
410 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL },
413 /* human readable key list */
415 ExifFormattedText ExifFormattedList[] = {
416 { "fCamera", N_("Camera") },
417 { "fDateTime", N_("Date") },
418 { "fShutterSpeed", N_("Shutter speed") },
419 { "fAperture", N_("Aperture") },
420 { "fExposureBias", N_("Exposure bias") },
421 { "fISOSpeedRating", N_("ISO sensitivity") },
422 { "fFocalLength", N_("Focal length") },
423 { "fSubjectDistance", N_("Subject distance") },
424 { "fFlash", N_("Flash") },
425 { "fResolution", N_("Resolution") },
430 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list);
433 *-----------------------------------------------------------------------------
435 *-----------------------------------------------------------------------------
438 ExifItem *exif_item_new(ExifFormatType format, guint tag,
439 guint elements, const ExifMarker *marker)
443 item = g_new0(ExifItem, 1);
444 item->format = format;
446 item->marker = marker;
447 item->elements = elements;
453 case EXIF_FORMAT_UNKNOWN:
454 /* unknown, data is NULL */
457 case EXIF_FORMAT_BYTE_UNSIGNED:
458 item->data_len = sizeof(char) * elements;
460 case EXIF_FORMAT_STRING:
461 item->data_len = sizeof(char) * elements;
463 case EXIF_FORMAT_SHORT_UNSIGNED:
464 item->data_len = sizeof(guint16) * elements;
466 case EXIF_FORMAT_LONG_UNSIGNED:
467 item->data_len = sizeof(guint32) * elements;
469 case EXIF_FORMAT_RATIONAL_UNSIGNED:
470 item->data_len = sizeof(ExifRational) * elements;
472 case EXIF_FORMAT_BYTE:
473 item->data_len = sizeof(char) * elements;
475 case EXIF_FORMAT_UNDEFINED:
476 item->data_len = sizeof(char) * elements;
478 case EXIF_FORMAT_SHORT:
479 item->data_len = sizeof(gint16) * elements;
481 case EXIF_FORMAT_LONG:
482 item->data_len = sizeof(gint32) * elements;
484 case EXIF_FORMAT_RATIONAL:
485 item->data_len = sizeof(ExifRational) * elements;
487 case EXIF_FORMAT_FLOAT:
488 item->data_len = sizeof(float) * elements;
490 case EXIF_FORMAT_DOUBLE:
491 item->data_len = sizeof(double) * elements;
495 item->data = g_malloc0(item->data_len);
500 static void exif_item_free(ExifItem *item)
508 const char *exif_item_get_tag_name(ExifItem *item)
510 if (!item || !item->marker) return NULL;
511 return item->marker->key;
514 const char *exif_item_get_description(ExifItem *item)
516 if (!item || !item->marker) return NULL;
517 return _(item->marker->description);
520 const char *exif_item_get_format_name(ExifItem *item, gint brief)
522 if (!item || !item->marker) return NULL;
523 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description;
527 #define UNDEFINED_TEXT_BYTE_COUNT 16
529 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne)
533 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
535 unsigned char c = ((char *)data)[i];
536 if (c < 32 || c > 127) c = '.';
537 g_string_append_printf(string, "%c", c);
539 string = g_string_append(string, " : ");
540 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
558 g_string_append_printf(string, "%s%02x", spacer, ((char *)data)[i]);
560 if (i >= UNDEFINED_TEXT_BYTE_COUNT) g_string_append_printf(string, " (%d bytes)", ne);
565 static gchar *text_list_find_value(ExifTextList *list, guint value)
567 gchar *result = NULL;
571 while (!result && list[i].value >= 0)
573 if (value == list[i].value) result = g_strdup(_(list[i].description));
576 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown"));
582 *-------------------------------------------------------------------
584 *-------------------------------------------------------------------
587 guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo)
589 if (bo == EXIF_BYTE_ORDER_INTEL)
590 return GUINT16_FROM_LE(*(guint16*)f);
592 return GUINT16_FROM_BE(*(guint16*)f);
595 guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo)
597 if (bo == EXIF_BYTE_ORDER_INTEL)
598 return GUINT32_FROM_LE(*(guint32*)f);
600 return GUINT32_FROM_BE(*(guint32*)f);
603 guint16 exif_byte_swab_int16(guint16 n, ExifByteOrder bo)
605 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
606 if (bo == EXIF_BYTE_ORDER_MOTOROLA)
608 if (bo == EXIF_BYTE_ORDER_INTEL)
610 return GUINT16_SWAP_LE_BE(n);
615 guint32 exif_byte_swab_int32(guint32 n, ExifByteOrder bo)
617 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
618 if (bo == EXIF_BYTE_ORDER_MOTOROLA)
620 if (bo == EXIF_BYTE_ORDER_INTEL)
622 return GUINT32_SWAP_LE_BE(n);
628 *-------------------------------------------------------------------
630 *-------------------------------------------------------------------
633 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list)
637 if (!list) return NULL;
639 while (list[i].tag != 0 && list[i].tag != tag)
644 return (list[i].tag == 0 ? NULL : &list[i]);
647 static void rational_from_data(ExifRational *r, void *src, ExifByteOrder bo)
649 r->num = exif_byte_get_int32(src, bo);
650 r->den = exif_byte_get_int32(src + sizeof(guint32), bo);
653 /* src_format and item->format must be compatible
654 * and not overrun src or item->data.
656 void exif_item_copy_data(ExifItem *item, void *src, guint len,
657 ExifFormatType src_format, ExifByteOrder bo)
664 bs = ExifFormatList[item->format].size;
669 ExifFormatList[src_format].size * ne > len)
671 printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
675 switch (item->format)
677 case EXIF_FORMAT_UNKNOWN:
679 case EXIF_FORMAT_BYTE_UNSIGNED:
680 case EXIF_FORMAT_BYTE:
681 case EXIF_FORMAT_UNDEFINED:
682 memcpy(dest, src, len);
684 case EXIF_FORMAT_STRING:
685 memcpy(dest, src, len);
686 /* string is NULL terminated, make sure this is true */
687 if (((char *)dest)[len - 1] != '\0') ((char *)dest)[len - 1] = '\0';
689 case EXIF_FORMAT_SHORT_UNSIGNED:
690 case EXIF_FORMAT_SHORT:
691 for (i = 0; i < ne; i++)
693 ((guint16 *)dest)[i] = exif_byte_get_int16(src + i * bs, bo);
696 case EXIF_FORMAT_LONG_UNSIGNED:
697 case EXIF_FORMAT_LONG:
698 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED ||
699 src_format == EXIF_FORMAT_SHORT)
701 /* a short fits into a long, so allow it */
704 ss = ExifFormatList[src_format].size;
705 for (i = 0; i < ne; i++)
707 ((gint32 *)dest)[i] =
708 (gint32)exif_byte_get_int16(src + i * ss, bo);
713 for (i = 0; i < ne; i++)
715 ((gint32 *)dest)[i] =
716 exif_byte_get_int32(src + i * bs, bo);
720 case EXIF_FORMAT_RATIONAL_UNSIGNED:
721 case EXIF_FORMAT_RATIONAL:
722 for (i = 0; i < ne; i++)
724 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, bo);
727 case EXIF_FORMAT_FLOAT:
728 for (i = 0; i < ne; i++)
730 ((float *)dest)[i] = exif_byte_get_int32(src + i * bs, bo);
733 case EXIF_FORMAT_DOUBLE:
734 for (i = 0; i < ne; i++)
738 rational_from_data(&r, src + i * bs, bo);
739 if (r.den) ((double *)dest)[i] = (double)r.num / r.den;
745 static gint exif_parse_IFD_entry(ExifData *exif, unsigned char *tiff, guint offset,
746 guint size, ExifByteOrder bo,
748 const ExifMarker *list)
756 const ExifMarker *marker;
759 tag = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_TAG, bo);
760 format = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
761 count = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_COUNT, bo);
762 data_val = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_DATA, bo);
764 /* Check tag type. If it does not match, either the format is wrong,
765 * either it is a unknown tag; so it is not really an error.
767 marker = exif_marker_from_tag(tag, list);
770 if (format >= EXIF_FORMAT_COUNT)
772 printf("warning: exif tag 0x%4x has invalid format %d\n", tag, format);
775 /* allow non recognized tags to be displayed */
776 marker = &ExifUnknownMarkersList[format];
778 if (marker->format != format)
780 /* Some cameras got mixed up signed/unsigned_rational
781 * eg KODAK DC4800 on object_distance tag
783 * FIXME: what exactly is this test trying to do?
784 * ok, so this test is to allow the case of swapped signed/unsigned mismatch to leak through?
786 if (!(marker->format == EXIF_FORMAT_RATIONAL_UNSIGNED && format == EXIF_FORMAT_RATIONAL) &&
787 !(marker->format == EXIF_FORMAT_RATIONAL && format == EXIF_FORMAT_RATIONAL_UNSIGNED) &&
788 /* short fits into a long so allow this mismatch
789 * as well (some tags allowed to be unsigned short _or_ unsigned long)
791 !(marker->format == EXIF_FORMAT_LONG_UNSIGNED && format == EXIF_FORMAT_SHORT_UNSIGNED) )
793 if (format < EXIF_FORMAT_COUNT)
795 printf("warning: exif tag %s format mismatch, found %s exif spec requests %s\n",
796 marker->key, ExifFormatList[format].short_name,
797 ExifFormatList[marker->format].short_name);
801 printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n",
802 marker->key, format, marker->format,
803 ExifFormatList[marker->format].short_name);
809 /* Where is the data, is it available?
811 if (marker->components > 0 && marker->components != count)
813 printf("warning: exif tag %s has %d elements, exif spec requests %d\n",
814 marker->key, count, marker->components);
817 data_length = ExifFormatList[marker->format].size * count;
820 data_offset = data_val;
821 if (size < data_offset + data_length)
823 printf("warning: exif tag %s data will overrun end of file, ignored.\n", marker->key);
829 data_offset = offset + EXIF_TIFD_OFFSET_DATA;
832 item = exif_item_new(marker->format, tag, count, marker);
833 exif_item_copy_data(item, tiff + data_offset, data_length, format, bo);
834 exif->items = g_list_prepend(exif->items, item);
836 if (list == ExifKnownMarkersList)
841 exif_parse_IFD_table(exif, tiff, data_val, size, bo, level + 1, list);
843 case TAG_EXIFMAKERNOTE:
844 format_exif_makernote_parse(exif, tiff, data_val, size, bo);
852 gint exif_parse_IFD_table(ExifData *exif,
853 unsigned char *tiff, guint offset,
854 guint size, ExifByteOrder bo,
856 const ExifMarker *list)
861 /* limit damage from infinite loops */
862 if (level > EXIF_TIFF_MAX_LEVELS) return -1;
864 /* We should be able to read number of entries in IFD0) */
865 if (size < offset + 2) return -1;
867 count = exif_byte_get_int16(tiff + offset, bo);
869 /* Entries and next IFD offset must be readable */
870 if (size < offset + count * EXIF_TIFD_SIZE + 4) return -1;
873 for (i = 0; i < count; i++)
875 exif_parse_IFD_entry(exif, tiff, offset + i * EXIF_TIFD_SIZE, size, bo, level, list);
882 *-------------------------------------------------------------------
884 *-------------------------------------------------------------------
887 gint exif_tiff_directory_offset(unsigned char *data, const guint len,
888 guint *offset, ExifByteOrder *bo)
890 if (len < 8) return FALSE;
892 if (memcmp(data, "II", 2) == 0)
894 *bo = EXIF_BYTE_ORDER_INTEL;
896 else if (memcmp(data, "MM", 2) == 0)
898 *bo = EXIF_BYTE_ORDER_MOTOROLA;
905 if (exif_byte_get_int16(data + 2, *bo) != 0x002A)
910 *offset = exif_byte_get_int32(data + 4, *bo);
912 return (*offset < len);
915 gint exif_tiff_parse(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list)
920 if (!exif_tiff_directory_offset(tiff, size, &offset, &bo)) return -1;
922 return exif_parse_IFD_table(exif, tiff, offset, size, bo, 0, list);
926 *-------------------------------------------------------------------
928 *-------------------------------------------------------------------
931 #define MARKER_UNKNOWN 0x00
932 #define MARKER_SOI 0xD8
933 #define MARKER_APP1 0xE1
935 static gint jpeg_get_marker_size(unsigned char *data)
937 /* Size is always in Motorola byte order */
938 return exif_byte_get_int16(data + 2, EXIF_BYTE_ORDER_MOTOROLA);
941 static gint jpeg_goto_next_marker(unsigned char **data, gint *size, gint *marker)
943 gint marker_size = 2;
945 *marker = MARKER_UNKNOWN;
947 /* It is safe to access the marker and its size since we have checked
948 * the SOI and this function guaranties the whole next marker is
951 if (*(*data + 1) != MARKER_SOI)
953 marker_size += jpeg_get_marker_size(*data);
956 *size -= marker_size;
958 /* size should be at least 4, so we can read the marker and its size
959 * and check data are actually available
961 if (*size < 4) return -1;
963 /* Jump to the next marker and be sure it begins with 0xFF
965 *data += marker_size;
966 if (**data != 0xFF) return -1;
968 if (jpeg_get_marker_size(*data) + 2 > *size) return -1;
970 *marker = *(*data + 1);
976 static gint exif_parse_JPEG(ExifData *exif, unsigned char *data, guint size, ExifMarker *list)
981 if (size < 4 || *data != 0xFF || *(data + 1) != MARKER_SOI)
987 if (jpeg_goto_next_marker(&data, &size, &marker) == -1)
991 } while (marker != MARKER_APP1);
993 if (marker != MARKER_APP1)
998 marker_size = jpeg_get_marker_size(data) - 2;
1000 if (marker_size < 6 || memcmp(data + 4, "Exif\x00\x00", 6) != 0)
1005 return exif_tiff_parse(exif, data + 10, marker_size - 6, list);
1009 *-------------------------------------------------------------------
1011 *-------------------------------------------------------------------
1014 static gint map_file(const gchar *path, void **mapping, int *size)
1019 if ((fd = open(path, O_RDONLY)) == -1)
1025 if (fstat(fd, &fs) == -1)
1034 if ((*mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
1045 static gint unmap_file(void *mapping, int size)
1047 if (munmap(mapping, size) == -1)
1056 void exif_free(ExifData *exif)
1065 ExifItem *item = work->data;
1067 exif_item_free(item);
1070 g_list_free(exif->items);
1074 ExifData *exif_read(const gchar *path)
1081 if (!path) return NULL;
1083 pathl = path_from_utf8(path);
1084 if (map_file(pathl, &f, &size) == -1)
1091 exif = g_new0(ExifData, 1);
1094 if ((res = exif_parse_JPEG(exif, (unsigned char *)f, size, ExifKnownMarkersList)) == -2)
1096 res = exif_tiff_parse(exif, (unsigned char *)f, size, ExifKnownMarkersList);
1103 if (format_raw_img_exif_offsets(f, size, NULL, &offset))
1105 res = exif_tiff_parse(exif, (unsigned char*)f + offset, size - offset, ExifKnownMarkersList);
1115 unmap_file(f, size);
1117 if (exif) exif->items = g_list_reverse(exif->items);
1120 exif_write_data_list(exif, stdout, TRUE);
1121 exif_write_data_list(exif, stdout, FALSE);
1127 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
1131 if (!key) return NULL;
1140 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item;
1145 gchar *exif_item_get_data_as_text(ExifItem *item)
1147 const ExifMarker *marker;
1154 if (!item) return NULL;
1156 marker = item->marker;
1157 if (!marker) return NULL;
1160 ne = item->elements;
1161 string = g_string_new("");
1162 switch (item->format)
1164 case EXIF_FORMAT_UNKNOWN:
1166 case EXIF_FORMAT_BYTE_UNSIGNED:
1167 case EXIF_FORMAT_BYTE:
1168 case EXIF_FORMAT_UNDEFINED:
1169 if (ne == 1 && marker->list)
1174 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED ||
1175 item->format == EXIF_FORMAT_UNDEFINED)
1177 val = ((unsigned char *)data)[0];
1181 val = (unsigned char)(((signed char *)data)[0]);
1184 result = text_list_find_value(marker->list, (guint)val);
1185 string = g_string_append(string, result);
1190 string = string_append_raw_bytes(string, data, ne);
1193 case EXIF_FORMAT_STRING:
1194 string = g_string_append(string, (gchar *)(item->data));
1196 case EXIF_FORMAT_SHORT_UNSIGNED:
1197 if (ne == 1 && marker->list)
1201 result = text_list_find_value(marker->list, ((unsigned short *)data)[0]);
1202 string = g_string_append(string, result);
1205 else for (i = 0; i < ne; i++)
1207 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1208 ((unsigned short *)data)[i]);
1211 case EXIF_FORMAT_LONG_UNSIGNED:
1212 for (i = 0; i < ne; i++)
1214 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1215 ((unsigned long *)data)[i]);
1218 case EXIF_FORMAT_RATIONAL_UNSIGNED:
1219 for (i = 0; i < ne; i++)
1223 r = &((ExifRational *)data)[i];
1224 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1225 (unsigned long)r->num, (unsigned long)r->den);
1228 case EXIF_FORMAT_SHORT:
1229 for (i = 0; i < ne; i++)
1231 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1232 ((short *)data)[i]);
1235 case EXIF_FORMAT_LONG:
1236 for (i = 0; i < ne; i++)
1238 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1242 case EXIF_FORMAT_RATIONAL:
1243 for (i = 0; i < ne; i++)
1247 r = &((ExifRational *)data)[i];
1248 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1249 (long)r->num, (long)r->den);
1252 case EXIF_FORMAT_FLOAT:
1253 for (i = 0; i < ne; i++)
1255 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1256 ((float *)data)[i]);
1259 case EXIF_FORMAT_DOUBLE:
1260 for (i = 0; i < ne; i++)
1262 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1263 ((double *)data)[i]);
1268 text = g_strdup(string->str);
1269 g_string_free(string, TRUE);
1274 gint exif_item_get_integer(ExifItem *item, gint *value)
1276 if (!item) return FALSE;
1278 switch (item->format)
1280 case EXIF_FORMAT_SHORT:
1281 *value = (gint)(((short *)(item->data))[0]);
1284 case EXIF_FORMAT_SHORT_UNSIGNED:
1285 *value = (gint)(((unsigned short *)(item->data))[0]);
1288 case EXIF_FORMAT_LONG:
1289 *value = (gint)(((long *)(item->data))[0]);
1292 case EXIF_FORMAT_LONG_UNSIGNED:
1293 /* FIXME: overflow possible */
1294 *value = (gint)(((unsigned long *)(item->data))[0]);
1297 /* all other type return FALSE */
1303 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
1307 item = exif_get_item(exif, key);
1308 return exif_item_get_integer(item, value);
1311 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
1313 if (!item) return NULL;
1315 if (item->format == EXIF_FORMAT_RATIONAL ||
1316 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED)
1318 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL);
1319 return &((ExifRational *)(item->data))[0];
1325 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
1329 item = exif_get_item(exif, key);
1330 return exif_item_get_rational(item, sign);
1333 double exif_rational_to_double(ExifRational *r, gint sign)
1335 if (!r || r->den == 0.0) return 0.0;
1337 if (sign) return (double)((int)r->num) / (double)((int)r->den);
1338 return (double)r->num / r->den;
1341 static double exif_get_rational_as_double(ExifData *exif, const gchar *key)
1346 r = exif_get_rational(exif, key, &sign);
1347 return exif_rational_to_double(r, sign);
1350 static GString *append_comma_text(GString *string, const gchar *text)
1352 string = g_string_append(string, ", ");
1353 string = g_string_append(string, text);
1358 static gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
1360 /* must begin with f, else not formatted */
1363 if (key_valid) *key_valid = FALSE;
1367 if (key_valid) *key_valid = TRUE;
1369 if (strcmp(key, "fCamera") == 0)
1372 gchar *make = exif_get_data_as_text(exif, "Make");
1373 gchar *model = exif_get_data_as_text(exif, "Model");
1374 gchar *software = exif_get_data_as_text(exif, "Software");
1376 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
1377 (model) ? model : "",
1378 (software) ? " (" : "",
1379 (software) ? software : "",
1380 (software) ? ")" : "");
1387 if (strcmp(key, "fDateTime") == 0)
1389 gchar *text = exif_get_data_as_text(exif, "DateTimeOriginal");
1390 gchar *subsec = NULL;
1391 if (text) subsec = exif_get_data_as_text(exif, "SubsecTimeOriginal");
1394 text = exif_get_data_as_text(exif, "DateTime");
1395 if (text) subsec = exif_get_data_as_text(exif, "SubsecTime");
1400 text = g_strconcat(tmp, ".", subsec, NULL);
1406 if (strcmp(key, "fShutterSpeed") == 0)
1410 r = exif_get_rational(exif, "ExposureTime", NULL);
1411 if (r && r->num && r->den)
1413 double n = (double)r->den / (double)r->num;
1414 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1415 n > 1.0 ? n : 1.0 / n);
1417 r = exif_get_rational(exif, "ShutterSpeedValue", NULL);
1418 if (r && r->num && r->den)
1420 double n = pow(2.0, exif_rational_to_double(r, TRUE));
1422 /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
1423 if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
1425 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1426 n > 1.0 ? floor(n) : 1.0 / n);
1430 if (strcmp(key, "fAperture") == 0)
1434 n = exif_get_rational_as_double(exif, "FNumber");
1435 if (n == 0.0) n = exif_get_rational_as_double(exif, "ApertureValue");
1436 if (n == 0.0) return NULL;
1438 return g_strdup_printf("f/%.1f", n);
1440 if (strcmp(key, "fExposureBias") == 0)
1446 r = exif_get_rational(exif, "ExposureBiasValue", &sign);
1447 if (!r) return NULL;
1449 n = exif_rational_to_double(r, sign);
1450 return g_strdup_printf("%+.1f", n);
1452 if (strcmp(key, "fFocalLength") == 0)
1456 n = exif_get_rational_as_double(exif, "FocalLength");
1457 if (n == 0.0) return NULL;
1458 return g_strdup_printf("%.2f mm", n);
1460 if (strcmp(key, "fISOSpeedRating") == 0)
1464 text = exif_get_data_as_text(exif, "ISOSpeedRatings");
1465 /* kodak may set this instead */
1466 if (!text) text = exif_get_data_as_text(exif, "ExposureIndex");
1469 if (strcmp(key, "fSubjectDistance") == 0)
1475 r = exif_get_rational(exif, "SubjectDistance", &sign);
1476 if (!r) return NULL;
1478 if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
1479 if ((long)r->num == 0) return g_strdup(_("unknown"));
1481 n = exif_rational_to_double(r, sign);
1482 if (n == 0.0) return _("unknown");
1483 return g_strdup_printf("%.3f m", n);
1485 if (strcmp(key, "fFlash") == 0)
1487 /* grr, flash is a bitmask... */
1493 if (!exif_get_integer(exif, "Flash", &n)) return NULL;
1495 /* Exif 2.1 only defines first 3 bits */
1496 if (n <= 0x07) return g_strdup(text_list_find_value(ExifFlashList, n));
1498 /* must be Exif 2.2 */
1499 string = g_string_new("");
1501 /* flash fired (bit 0) */
1502 string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
1504 /* flash mode (bits 3, 4) */
1505 v = (n >> 3) & 0x03;
1506 if (v) string = append_comma_text(string, _("mode:"));
1510 string = g_string_append(string, _("on"));
1513 string = g_string_append(string, _("off"));
1516 string = g_string_append(string, _("auto"));
1520 /* return light (bits 1, 2) */
1521 v = (n >> 1) & 0x03;
1522 if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
1523 if (v == 3) string = append_comma_text(string, _("detected by strobe"));
1525 /* we ignore flash function (bit 5) */
1527 /* red-eye (bit 6) */
1528 if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
1531 g_string_free(string, FALSE);
1534 if (strcmp(key, "fResolution") == 0)
1536 ExifRational *rx, *ry;
1540 rx = exif_get_rational(exif, "XResolution", NULL);
1541 ry = exif_get_rational(exif, "YResolution", NULL);
1542 if (!rx || !ry) return NULL;
1544 units = exif_get_data_as_text(exif, "ResolutionUnit");
1545 text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
1546 ry->den ? (double)ry->num / ry->den : 1.0,
1547 _("dot"), (units) ? units : _("unknown"));
1553 if (key_valid) *key_valid = FALSE;
1557 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
1563 if (!key) return NULL;
1565 text = exif_get_formatted_by_key(exif, key, &key_valid);
1566 if (key_valid) return text;
1568 item = exif_get_item(exif, key);
1569 if (item) return exif_item_get_data_as_text(item);
1574 const gchar *exif_get_description_by_key(const gchar *key)
1578 if (!key) return NULL;
1581 while (ExifFormattedList[i].key != NULL)
1583 if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
1588 while (ExifKnownMarkersList[i].tag > 0)
1590 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
1597 static void exif_write_item(FILE *f, ExifItem *item)
1601 text = exif_item_get_data_as_text(item);
1604 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
1605 exif_item_get_tag_name(item), text);
1610 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list)
1612 if (!f || !exif) return;
1614 fprintf(f, " tag format key value\n");
1615 fprintf(f, "----------------------------------------------------\n");
1617 if (human_readable_list)
1622 while (ExifFormattedList[i].key)
1626 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL);
1629 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text);
1646 exif_write_item(f, item);
1649 fprintf(f, "----------------------------------------------------\n");