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 "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
104 *-----------------------------------------------------------------------------
106 *-----------------------------------------------------------------------------
109 #define EXIF_TEXT_LIST_END { -1, NULL }
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 },
395 /* end is marked by 0 tag */
396 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, NULL, NULL, NULL }
399 ExifMarker ExifUnknownMarkersList[] = {
400 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL },
401 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL },
402 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL },
403 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL },
404 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL },
405 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL },
406 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL },
407 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL },
408 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL },
409 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL },
410 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL },
411 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL },
412 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL },
415 /* human readable key list */
417 ExifFormattedText ExifFormattedList[] = {
418 { "fCamera", N_("Camera") },
419 { "fDateTime", N_("Date") },
420 { "fShutterSpeed", N_("Shutter speed") },
421 { "fAperture", N_("Aperture") },
422 { "fExposureBias", N_("Exposure bias") },
423 { "fISOSpeedRating", N_("ISO sensitivity") },
424 { "fFocalLength", N_("Focal length") },
425 { "fSubjectDistance", N_("Subject distance") },
426 { "fFlash", N_("Flash") },
427 { "fResolution", N_("Resolution") },
433 *-----------------------------------------------------------------------------
435 *-----------------------------------------------------------------------------
438 #define BYTE_ORDER_INTEL 1
439 #define BYTE_ORDER_MOTOROLA 2
441 #define MARKER_UNKNOWN 0x00
442 #define MARKER_SOI 0xD8
443 #define MARKER_APP1 0xE1
459 static ExifMarker *exif_marker_from_tag(uint16_t tag);
460 static int parse_IFD_table(ExifData *exif, unsigned char *tiff, int offset,
461 int size, int byte_order);
464 *-----------------------------------------------------------------------------
466 *-----------------------------------------------------------------------------
469 static ExifItem *exif_item_new(ExifFormatType format, unsigned int tag, unsigned int elements, ExifMarker *marker)
473 item = g_new0(ExifItem, 1);
474 item->format = format;
476 item->marker = marker;
477 item->elements = elements;
483 case EXIF_FORMAT_UNKNOWN:
484 /* unknown, data is NULL */
487 case EXIF_FORMAT_BYTE_UNSIGNED:
488 item->data_len = sizeof(char) * elements;
490 case EXIF_FORMAT_STRING:
491 item->data_len = sizeof(char) * elements;
493 case EXIF_FORMAT_SHORT_UNSIGNED:
494 item->data_len = sizeof(unsigned short int) * elements;
496 case EXIF_FORMAT_LONG_UNSIGNED:
497 item->data_len = sizeof(unsigned long int) * elements;
499 case EXIF_FORMAT_RATIONAL_UNSIGNED:
500 item->data_len = sizeof(ExifRational) * elements;
502 case EXIF_FORMAT_BYTE:
503 item->data_len = sizeof(char) * elements;
505 case EXIF_FORMAT_UNDEFINED:
506 item->data_len = sizeof(char) * elements;
508 case EXIF_FORMAT_SHORT:
509 item->data_len = sizeof(short int) * elements;
511 case EXIF_FORMAT_LONG:
512 item->data_len = sizeof(long int) * elements;
514 case EXIF_FORMAT_RATIONAL:
515 item->data_len = sizeof(ExifRational) * elements;
517 case EXIF_FORMAT_FLOAT:
518 item->data_len = sizeof(float) * elements;
520 case EXIF_FORMAT_DOUBLE:
521 item->data_len = sizeof(double) * elements;
525 item->data = g_malloc0(item->data_len);
530 static void exif_item_free(ExifItem *item)
538 const char *exif_item_get_tag_name(ExifItem *item)
540 if (!item || !item->marker) return NULL;
541 return item->marker->key;
544 const char *exif_item_get_description(ExifItem *item)
546 if (!item || !item->marker) return NULL;
547 return _(item->marker->description);
550 const char *exif_item_get_format_name(ExifItem *item, gint brief)
552 if (!item || !item->marker) return NULL;
553 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description;
557 #define UNDEFINED_TEXT_BYTE_COUNT 16
559 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne)
563 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
565 unsigned char c = ((char *)data)[i];
566 if (c < 32 || c > 127) c = '.';
567 g_string_append_printf(string, "%c", c);
569 string = g_string_append(string, " : ");
570 for (i = 0 ; i < ne && i < UNDEFINED_TEXT_BYTE_COUNT; i++)
588 g_string_append_printf(string, "%s%02x", spacer, ((char *)data)[i]);
590 if (i >= UNDEFINED_TEXT_BYTE_COUNT) g_string_append_printf(string, " (%d bytes)", ne);
595 static gchar *text_list_find_value(ExifTextList *list, gint value)
597 gchar *result = NULL;
601 while (!result && list[i].value >= 0)
603 if (value == list[i].value) result = g_strdup(_(list[i].description));
606 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown"));
612 *-------------------------------------------------------------------
614 *-------------------------------------------------------------------
617 static uint16_t get_int16(unsigned char *f, int bo)
619 if (bo == BYTE_ORDER_INTEL)
620 return *f + (*(f+1)<<8);
622 return ((*f)<<8) + *(f+1);
627 static uint32_t get_int32(unsigned char *f, int bo)
629 if (bo == BYTE_ORDER_INTEL)
630 return get_int16(f, BYTE_ORDER_INTEL) + (get_int16(f+2, BYTE_ORDER_INTEL)<<16);
632 return (get_int16(f, BYTE_ORDER_MOTOROLA)<<16) + get_int16(f+2, BYTE_ORDER_MOTOROLA);
636 static uint16_t swab_int16(uint16_t n, int bo)
638 #if BYTE_ORDER == LITTLE_ENDIAN
639 if (bo == BYTE_ORDER_MOTOROLA)
641 if (bo == BYTE_ORDER_INTEL)
648 static uint32_t swab_int32(uint32_t n, int bo)
650 #if BYTE_ORDER == LITTLE_ENDIAN
651 if (bo == BYTE_ORDER_MOTOROLA)
653 if (bo == BYTE_ORDER_INTEL)
655 return n<<24 | n>>24 | (n & 0xFF0000)>>8 | (n & 0xFF00)<<8;
661 *-------------------------------------------------------------------
663 *-------------------------------------------------------------------
666 static int get_marker_size(unsigned char *f)
668 /* Size is always in Motorola byte order */
669 return get_int16(f+2, BYTE_ORDER_MOTOROLA);
672 static int goto_next_marker(unsigned char **f, int *size, int *marker)
676 *marker = MARKER_UNKNOWN;
678 /* It is safe to access the marker and its size since we have checked
679 * the SOI and this function guaranties the whole next marker is
682 if (*(*f+1) != MARKER_SOI)
684 marker_size += get_marker_size(*f);
687 *size -= marker_size;
689 /* size should be at least 4, so we can read the marker and its size
690 * and check data are actually available
692 if (*size < 4) return -1;
694 /* Jump to the next marker and be sure it begins with 0xFF
697 if (**f != 0xFF) return -1;
699 if (get_marker_size(*f)+2 > *size) return -1;
707 *-------------------------------------------------------------------
709 *-------------------------------------------------------------------
712 static ExifMarker *exif_marker_from_tag(uint16_t tag)
714 static int len = sizeof(ExifKnownMarkersList)/sizeof(ExifMarker) - 1;
717 while (i < len && ExifKnownMarkersList[i].tag != tag)
722 return (i >= len ? NULL : &ExifKnownMarkersList[i]);
725 static void rational_from_data(ExifRational *r, void *src, int byte_order)
727 r->num = swab_int32(*(uint32_t*)src, byte_order);
728 r->den = swab_int32(*(uint32_t*)(src + sizeof(uint32_t)), byte_order);
731 static void exif_item_copy_data(ExifItem *item, void *src, int len, ExifFormatType src_format, int byte_order)
738 bs = ExifFormatList[item->format].size;
742 if (!dest || len > item->data_len)
744 printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
748 switch (item->format)
750 case EXIF_FORMAT_UNKNOWN:
752 case EXIF_FORMAT_BYTE_UNSIGNED:
753 case EXIF_FORMAT_BYTE:
754 case EXIF_FORMAT_UNDEFINED:
755 memcpy(dest, src, len);
757 case EXIF_FORMAT_STRING:
758 memcpy(dest, src, len);
759 /* string is NULL terminated, make sure this is true */
760 if (((char *)dest)[len - 1] != '\0') ((char *)dest)[len - 1] = '\0';
762 case EXIF_FORMAT_SHORT_UNSIGNED:
763 case EXIF_FORMAT_SHORT:
764 for (i = 0; i < ne; i++)
766 ((short *)dest)[i] = swab_int16(*(uint16_t*)(src + i * bs), byte_order);
769 case EXIF_FORMAT_LONG_UNSIGNED:
770 case EXIF_FORMAT_LONG:
771 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED ||
772 src_format == EXIF_FORMAT_SHORT)
774 /* a short fits into a long, so allow it */
777 ss = ExifFormatList[src_format].size;
778 for (i = 0; i < ne; i++)
780 ((long *)dest)[i] = (long)swab_int16(*(uint16_t*)(src + i * ss), byte_order);
785 for (i = 0; i < ne; i++)
787 ((long *)dest)[i] = swab_int32(*(uint32_t*)(src + i * bs), byte_order);
791 case EXIF_FORMAT_RATIONAL_UNSIGNED:
792 case EXIF_FORMAT_RATIONAL:
793 for (i = 0; i < ne; i++)
795 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, byte_order);
798 case EXIF_FORMAT_FLOAT:
799 for (i = 0; i < ne; i++)
801 ((float *)dest)[i] = swab_int32(*(uint32_t*)(src + i * bs), byte_order);
804 case EXIF_FORMAT_DOUBLE:
805 for (i = 0; i < ne; i++)
809 rational_from_data(&r, src + i * bs, byte_order);
810 if (r.den) ((double *)dest)[i] = (double)r.num / r.den;
816 static int parse_IFD_entry(ExifData *exif, unsigned char *tiff, int offset,
817 int size, int byte_order)
819 IFDEntry *ent = (IFDEntry*)(tiff+offset);
820 uint32_t swabed_data;
826 ent->tag = swab_int16(ent->tag, byte_order);
827 ent->format = swab_int16(ent->format, byte_order);
828 ent->nb = swab_int32(ent->nb, byte_order);
829 swabed_data = 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);
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, ExifFormatList[marker->format].short_name);
867 printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n",
868 marker->key, ent->format, marker->format, ExifFormatList[marker->format].short_name);
874 /* Where is the data, is it available?
876 if (marker->components > 0 && marker->components != ent->nb)
878 printf("warning: exif tag %s has %d elements, exif spec requests %d\n", marker->key, ent->nb, marker->components);
880 data_len = ExifFormatList[marker->format].size * ent->nb;
881 if (data_len > sizeof(ent->data))
883 if (size < swabed_data+data_len)
885 printf("warning: exif tag %s will overrun IFD segment, ignored.\n", marker->key);
888 data = (void*)tiff + swabed_data;
892 data = (void*)(&(ent->data));
895 item = exif_item_new(marker->format, ent->tag, ent->nb, marker);
896 exif_item_copy_data(item, data, data_len, ent->format, byte_order);
897 exif->items = g_list_prepend(exif->items, item);
899 if (item->tag == TAG_EXIFOFFSET)
901 parse_IFD_table(exif, tiff, swabed_data, size, byte_order);
907 static int parse_IFD_table(ExifData *exif, unsigned char *tiff, int offset,
908 int size, int byte_order)
912 /* We should be able to read number of entries in IFD0) */
913 if (size < offset+2) return -1;
915 nb_entries = get_int16(tiff+offset, byte_order);
917 /* Entries and next IFD offset must be readable */
918 if (size < offset+nb_entries*12+4) return -1;
920 for (i=0; i<nb_entries; ++i)
922 parse_IFD_entry(exif, tiff, offset+2+i*sizeof(IFDEntry), size, byte_order);
929 *-------------------------------------------------------------------
931 *-------------------------------------------------------------------
934 static int parse_TIFF(ExifData *exif, unsigned char *tiff, int size)
936 int byte_order, offset=0;
938 if (size < sizeof(TIFFHeader))
943 if (strncmp(((TIFFHeader*)tiff)->byte_order, "II", 2) == 0)
945 byte_order = BYTE_ORDER_INTEL;
947 else if (strncmp(((TIFFHeader*)tiff)->byte_order, "MM", 2) == 0)
949 byte_order = BYTE_ORDER_MOTOROLA;
956 if (swab_int16(((TIFFHeader*)tiff)->magic, byte_order) != 0x002A)
961 offset = swab_int32(((TIFFHeader*)tiff)->IFD_offset, byte_order);
963 return parse_IFD_table(exif, tiff, offset, size, byte_order);
966 static int parse_JPEG(ExifData *exif, unsigned char *f, int size)
968 int marker, marker_size;
970 if (size<2 || *f!=0xFF || *(f+1)!=MARKER_SOI)
976 if (goto_next_marker(&f, &size, &marker) == -1)
980 } while (marker != MARKER_APP1);
982 if (marker != MARKER_APP1)
987 marker_size = get_marker_size(f)-2;
989 if (marker_size<6 || strncmp((char*)f+4, "Exif\0\0", 6)!=0)
994 return parse_TIFF(exif, f+10, marker_size-6);
997 static gint map_file(const gchar *path, void **mapping, int *size)
1002 if ((fd = open(path, O_RDONLY)) == -1)
1008 if (fstat(fd, &fs) == -1)
1017 if ((*mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
1028 static gint unmap_file(void *mapping, int size)
1030 if (munmap(mapping, size) == -1)
1039 void exif_free(ExifData *exif)
1048 ExifItem *item = work->data;
1050 exif_item_free(item);
1053 g_list_free(exif->items);
1057 ExifData *exif_read(const gchar *path)
1064 if (!path) return NULL;
1066 pathl = path_from_utf8(path);
1067 if (map_file(pathl, &f, &size) == -1)
1074 exif = g_new0(ExifData, 1);
1077 if ((res = parse_JPEG(exif, (unsigned char *)f, size)) == -2)
1079 res = parse_TIFF(exif, (unsigned char *)f, size);
1088 unmap_file(f, size);
1090 if (exif) exif->items = g_list_reverse(exif->items);
1093 exif_write_data_list(exif, stdout, TRUE);
1094 exif_write_data_list(exif, stdout, FALSE);
1100 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
1104 if (!key) return NULL;
1113 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item;
1118 gchar *exif_item_get_data_as_text(ExifItem *item)
1127 if (!item) return NULL;
1129 marker = item->marker;
1130 if (!marker) return NULL;
1133 ne = item->elements;
1134 string = g_string_new("");
1135 switch (item->format)
1137 case EXIF_FORMAT_UNKNOWN:
1139 case EXIF_FORMAT_BYTE_UNSIGNED:
1140 case EXIF_FORMAT_BYTE:
1141 case EXIF_FORMAT_UNDEFINED:
1142 if (ne == 1 && marker->list)
1147 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED ||
1148 item->format == EXIF_FORMAT_UNDEFINED)
1150 val = ((unsigned char *)data)[0];
1154 val = (unsigned char)(((signed char *)data)[0]);
1157 result = text_list_find_value(marker->list, (unsigned short)val);
1158 string = g_string_append(string, result);
1163 string = string_append_raw_bytes(string, data, ne);
1166 case EXIF_FORMAT_STRING:
1167 string = g_string_append(string, (gchar *)(item->data));
1169 case EXIF_FORMAT_SHORT_UNSIGNED:
1170 if (ne == 1 && marker->list)
1174 result = text_list_find_value(marker->list, ((unsigned short *)data)[0]);
1175 string = g_string_append(string, result);
1178 else for (i = 0; i < ne; i++)
1180 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1181 ((unsigned short *)data)[i]);
1184 case EXIF_FORMAT_LONG_UNSIGNED:
1185 for (i = 0; i < ne; i++)
1187 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1188 ((unsigned long *)data)[i]);
1191 case EXIF_FORMAT_RATIONAL_UNSIGNED:
1192 for (i = 0; i < ne; i++)
1196 r = &((ExifRational *)data)[i];
1197 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1198 (unsigned long)r->num, (unsigned long)r->den);
1201 case EXIF_FORMAT_SHORT:
1202 for (i = 0; i < ne; i++)
1204 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1205 ((short *)data)[i]);
1208 case EXIF_FORMAT_LONG:
1209 for (i = 0; i < ne; i++)
1211 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1215 case EXIF_FORMAT_RATIONAL:
1216 for (i = 0; i < ne; i++)
1220 r = &((ExifRational *)data)[i];
1221 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1222 (long)r->num, (long)r->den);
1225 case EXIF_FORMAT_FLOAT:
1226 for (i = 0; i < ne; i++)
1228 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1229 ((float *)data)[i]);
1232 case EXIF_FORMAT_DOUBLE:
1233 for (i = 0; i < ne; i++)
1235 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1236 ((double *)data)[i]);
1241 text = g_strdup(string->str);
1242 g_string_free(string, TRUE);
1247 gint exif_item_get_integer(ExifItem *item, gint *value)
1249 if (!item) return FALSE;
1251 switch (item->format)
1253 case EXIF_FORMAT_SHORT:
1254 *value = (gint)(((short *)(item->data))[0]);
1257 case EXIF_FORMAT_SHORT_UNSIGNED:
1258 *value = (gint)(((unsigned short *)(item->data))[0]);
1261 case EXIF_FORMAT_LONG:
1262 *value = (gint)(((long *)(item->data))[0]);
1265 case EXIF_FORMAT_LONG_UNSIGNED:
1266 /* FIXME: overflow possible */
1267 *value = (gint)(((unsigned long *)(item->data))[0]);
1270 /* all other type return FALSE */
1276 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
1280 item = exif_get_item(exif, key);
1281 return exif_item_get_integer(item, value);
1284 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
1286 if (!item) return NULL;
1288 if (item->format == EXIF_FORMAT_RATIONAL ||
1289 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED)
1291 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL);
1292 return &((ExifRational *)(item->data))[0];
1298 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
1302 item = exif_get_item(exif, key);
1303 return exif_item_get_rational(item, sign);
1306 double exif_rational_to_double(ExifRational *r, gint sign)
1308 if (!r || r->den == 0.0) return 0.0;
1310 if (sign) return (double)((int)r->num) / (double)((int)r->den);
1311 return (double)r->num / r->den;
1314 static double exif_get_rational_as_double(ExifData *exif, const gchar *key)
1319 r = exif_get_rational(exif, key, &sign);
1320 return exif_rational_to_double(r, sign);
1323 static GString *append_comma_text(GString *string, const gchar *text)
1325 string = g_string_append(string, ", ");
1326 string = g_string_append(string, text);
1331 static gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
1333 /* must begin with f, else not formatted */
1336 if (key_valid) *key_valid = FALSE;
1340 if (key_valid) *key_valid = TRUE;
1342 if (strcmp(key, "fCamera") == 0)
1345 gchar *make = exif_get_data_as_text(exif, "Make");
1346 gchar *model = exif_get_data_as_text(exif, "Model");
1347 gchar *software = exif_get_data_as_text(exif, "Software");
1349 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
1350 (model) ? model : "",
1351 (software) ? " (" : "",
1352 (software) ? software : "",
1353 (software) ? ")" : "");
1360 if (strcmp(key, "fDateTime") == 0)
1362 gchar *text = exif_get_data_as_text(exif, "DateTimeOriginal");
1363 gchar *subsec = NULL;
1364 if (text) subsec = exif_get_data_as_text(exif, "SubsecTimeOriginal");
1367 text = exif_get_data_as_text(exif, "DateTime");
1368 if (text) subsec = exif_get_data_as_text(exif, "SubsecTime");
1373 text = g_strconcat(tmp, ".", subsec, NULL);
1379 if (strcmp(key, "fShutterSpeed") == 0)
1383 r = exif_get_rational(exif, "ExposureTime", NULL);
1384 if (r && r->num && r->den)
1386 double n = (double)r->den / (double)r->num;
1387 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1388 n > 1.0 ? n : 1.0 / n);
1390 r = exif_get_rational(exif, "ShutterSpeedValue", NULL);
1391 if (r && r->num && r->den)
1393 double n = pow(2.0, exif_rational_to_double(r, TRUE));
1395 /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
1396 if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
1398 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
1399 n > 1.0 ? floor(n) : 1.0 / n);
1403 if (strcmp(key, "fAperture") == 0)
1407 n = exif_get_rational_as_double(exif, "FNumber");
1408 if (n == 0.0) n = exif_get_rational_as_double(exif, "ApertureValue");
1409 if (n == 0.0) return NULL;
1411 return g_strdup_printf("f/%.1f", n);
1413 if (strcmp(key, "fExposureBias") == 0)
1419 r = exif_get_rational(exif, "ExposureBiasValue", &sign);
1420 if (!r) return NULL;
1422 n = exif_rational_to_double(r, sign);
1423 return g_strdup_printf("%+.1f", n);
1425 if (strcmp(key, "fFocalLength") == 0)
1429 n = exif_get_rational_as_double(exif, "FocalLength");
1430 if (n == 0.0) return NULL;
1431 return g_strdup_printf("%.2f mm", n);
1433 if (strcmp(key, "fISOSpeedRating") == 0)
1437 text = exif_get_data_as_text(exif, "ISOSpeedRatings");
1438 /* kodak may set this instead */
1439 if (!text) text = exif_get_data_as_text(exif, "ExposureIndex");
1442 if (strcmp(key, "fSubjectDistance") == 0)
1448 r = exif_get_rational(exif, "SubjectDistance", &sign);
1449 if (!r) return NULL;
1451 if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
1452 if ((long)r->num == 0) return g_strdup(_("unknown"));
1454 n = exif_rational_to_double(r, sign);
1455 if (n == 0.0) return _("unknown");
1456 return g_strdup_printf("%.3f m", n);
1458 if (strcmp(key, "fFlash") == 0)
1460 /* grr, flash is a bitmask... */
1466 if (!exif_get_integer(exif, "Flash", &n)) return NULL;
1468 /* Exif 2.1 only defines first 3 bits */
1469 if (n <= 0x07) return g_strdup(text_list_find_value(ExifFlashList, n));
1471 /* must be Exif 2.2 */
1472 string = g_string_new("");
1474 /* flash fired (bit 0) */
1475 string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
1477 /* flash mode (bits 3, 4) */
1478 v = (n >> 3) & 0x03;
1479 if (v) string = append_comma_text(string, _("mode:"));
1483 string = g_string_append(string, _("on"));
1486 string = g_string_append(string, _("off"));
1489 string = g_string_append(string, _("auto"));
1493 /* return light (bits 1, 2) */
1494 v = (n >> 1) & 0x03;
1495 if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
1496 if (v == 3) string = append_comma_text(string, _("detected by strobe"));
1498 /* we ignore flash function (bit 5) */
1500 /* red-eye (bit 6) */
1501 if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
1504 g_string_free(string, FALSE);
1507 if (strcmp(key, "fResolution") == 0)
1509 ExifRational *rx, *ry;
1513 rx = exif_get_rational(exif, "XResolution", NULL);
1514 ry = exif_get_rational(exif, "YResolution", NULL);
1515 if (!rx || !ry) return NULL;
1517 units = exif_get_data_as_text(exif, "ResolutionUnit");
1518 text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
1519 ry->den ? (double)ry->num / ry->den : 1.0,
1520 _("dot"), (units) ? units : _("unknown"));
1526 if (key_valid) *key_valid = FALSE;
1530 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
1536 if (!key) return NULL;
1538 text = exif_get_formatted_by_key(exif, key, &key_valid);
1539 if (key_valid) return text;
1541 item = exif_get_item(exif, key);
1542 if (item) return exif_item_get_data_as_text(item);
1547 const gchar *exif_get_description_by_key(const gchar *key)
1551 if (!key) return NULL;
1554 while (ExifFormattedList[i].key != NULL)
1556 if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
1561 while (ExifKnownMarkersList[i].tag > 0)
1563 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
1570 static void exif_write_item(FILE *f, ExifItem *item)
1574 text = exif_item_get_data_as_text(item);
1577 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
1578 exif_item_get_tag_name(item), text);
1583 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list)
1585 if (!f || !exif) return;
1587 fprintf(f, " tag format key value\n");
1588 fprintf(f, "----------------------------------------------------\n");
1590 if (human_readable_list)
1595 while (ExifFormattedList[i].key)
1599 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL);
1602 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text);
1619 exif_write_item(f, item);
1622 fprintf(f, "----------------------------------------------------\n");