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.
63 #include <sys/types.h>
75 #include "format_raw.h"
76 #include "ui_fileops.h"
80 *-----------------------------------------------------------------------------
82 *-----------------------------------------------------------------------------
85 ExifFormatAttrib ExifFormatList[] = {
86 { EXIF_FORMAT_UNKNOWN, 1, "unknown", "unknown" },
87 { EXIF_FORMAT_BYTE_UNSIGNED, 1, "ubyte", "unsigned byte" },
88 { EXIF_FORMAT_STRING, 1, "string", "string" },
89 { EXIF_FORMAT_SHORT_UNSIGNED, 2, "ushort", "unsigned short" },
90 { EXIF_FORMAT_LONG_UNSIGNED, 4, "ulong", "unsigned long" },
91 { EXIF_FORMAT_RATIONAL_UNSIGNED,8, "urational", "unsigned rational" },
92 { EXIF_FORMAT_BYTE, 1, "byte", "byte" },
93 { EXIF_FORMAT_UNDEFINED, 1, "undefined", "undefined" },
94 { EXIF_FORMAT_SHORT, 2, "sshort", "signed short" },
95 { EXIF_FORMAT_LONG, 4, "slong", "signed long" },
96 { EXIF_FORMAT_RATIONAL, 8, "srational", "signed rational" },
97 { EXIF_FORMAT_FLOAT, 4, "float", "float" },
98 { EXIF_FORMAT_DOUBLE, 8, "double", "double" },
102 /* tags that are special, or need special treatment */
103 #define TAG_EXIFOFFSET 0x8769
104 #define TAG_EXIFMAKERNOTE 0x927c
108 *-----------------------------------------------------------------------------
110 *-----------------------------------------------------------------------------
113 static ExifTextList ExifOrientationList[] = {
114 { EXIF_ORIENTATION_UNKNOWN, N_("unknown") },
115 { EXIF_ORIENTATION_TOP_LEFT, N_("top left") },
116 { EXIF_ORIENTATION_TOP_RIGHT, N_("top right") },
117 { EXIF_ORIENTATION_BOTTOM_RIGHT,N_("bottom right") },
118 { EXIF_ORIENTATION_BOTTOM_LEFT, N_("bottom left") },
119 { EXIF_ORIENTATION_LEFT_TOP, N_("left top") },
120 { EXIF_ORIENTATION_RIGHT_TOP, N_("right top") },
121 { EXIF_ORIENTATION_RIGHT_BOTTOM,N_("right bottom") },
122 { EXIF_ORIENTATION_LEFT_BOTTOM, N_("left bottom") },
126 static ExifTextList ExifUnitList[] = {
127 { EXIF_UNIT_UNKNOWN, N_("unknown") },
128 { EXIF_UNIT_NOUNIT, "" },
129 { EXIF_UNIT_INCH, N_("inch") },
130 { EXIF_UNIT_CENTIMETER, N_("centimeter") },
134 static ExifTextList ExifYCbCrPosList[] = {
140 static ExifTextList ExifMeteringModeList[] = {
141 { 0, N_("unknown") },
142 { 1, N_("average") },
143 { 2, N_("center weighted") },
145 { 4, N_("multi-spot") },
146 { 5, N_("multi-segment") },
147 { 6, N_("partial") },
148 { 255, N_("other") },
152 static ExifTextList ExifExposureProgramList[] = {
153 { 0, N_("not defined") },
156 { 3, N_("aperture") },
157 { 4, N_("shutter") },
158 { 5, N_("creative") },
160 { 7, N_("portrait") },
161 { 8, N_("landscape") },
165 static ExifTextList ExifLightSourceList[] = {
166 { 0, N_("unknown") },
167 { 1, N_("daylight") },
168 { 2, N_("fluorescent") },
169 { 3, N_("tungsten (incandescent)") },
171 { 9, "fine weather" },
172 { 10, "cloudy weather" },
174 { 12, "daylight fluorescent" },
175 { 13, "day white fluorescent" },
176 { 14, "cool white fluorescent" },
177 { 15, "while fluorescent" },
178 { 17, "standard light A" },
179 { 18, "standard light B" },
180 { 19, "standard light C" },
185 { 24, "ISO studio tungsten" },
186 { 255, N_("other") },
190 static ExifTextList ExifFlashList[] = {
193 { 5, N_("yes, not detected by strobe") },
194 { 7, N_("yes, detected by strobe") },
198 static ExifTextList ExifColorSpaceList[] = {
200 { 65535,"uncalibrated" },
204 static ExifTextList ExifSensorList[] = {
205 { 1, "not defined" },
206 { 2, "1 chip color area" },
207 { 2, "2 chip color area" },
208 { 4, "3 chip color area" },
209 { 5, "color sequential area" },
211 { 8, "color sequential linear" },
215 static ExifTextList ExifSourceList[] = {
216 { 3, "digital still camera" },
220 static ExifTextList ExifSceneList[] = {
221 { 1, "direct photo" },
225 static ExifTextList ExifCustRenderList[] = {
231 static ExifTextList ExifExposureModeList[] = {
234 { 2, "auto bracket" },
238 static ExifTextList ExifWhiteBalanceList[] = {
244 static ExifTextList ExifSceneCaptureList[] = {
248 { 3, "night scene" },
252 static ExifTextList ExifGainControlList[] = {
254 { 1, "low gain up" },
255 { 2, "high gain up" },
256 { 3, "low gain down" },
257 { 4, "high gain down" },
261 static ExifTextList ExifContrastList[] = {
268 static ExifTextList ExifSaturationList[] = {
275 static ExifTextList ExifSharpnessList[] = {
282 static ExifTextList ExifSubjectRangeList[] = {
290 ExifMarker ExifKnownMarkersList[] = {
291 { 0x010e, EXIF_FORMAT_STRING, -1, "Exif.Image.ImageDescription", N_("Image description"), NULL },
292 { 0x010f, EXIF_FORMAT_STRING, -1, "Exif.Image.Make", "Camera make", NULL },
293 { 0x0110, EXIF_FORMAT_STRING, -1, "Exif.Image.Model", "Camera model", NULL },
294 { 0x0112, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.Orientation", N_("Orientation"), ExifOrientationList },
295 { 0x011a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.XResolution", "X resolution", NULL },
296 { 0x011b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.YResolution", "Y Resolution", NULL },
297 { 0x0128, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.ResolutionUnit", "Resolution units", ExifUnitList },
298 { 0x0131, EXIF_FORMAT_STRING, -1, "Exif.Image.Software", "Firmware", NULL },
299 { 0x0132, EXIF_FORMAT_STRING, 20, "Exif.Image.DateTime", N_("Date"), NULL },
300 { 0x013e, EXIF_FORMAT_RATIONAL_UNSIGNED, 2, "Exif.Image.WhitePoint", "White point", NULL },
301 { 0x013f, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "Exif.Image.PrimaryChromaticities","Primary chromaticities", NULL },
302 { 0x0211, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.Image.YCbCrCoefficients", "YCbCy coefficients", NULL },
303 { 0x0213, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.YCbCrPositioning", "YCbCr positioning", ExifYCbCrPosList },
304 { 0x0214, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "Exif.Image.ReferenceBlackWhite", "Black white reference", NULL },
305 { 0x8298, EXIF_FORMAT_STRING, -1, "Exif.Image.Copyright", N_("Copyright"), NULL },
306 { 0x8769, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifOffset", "SubIFD Exif offset", NULL },
308 { 0x829a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureTime", "Exposure time (seconds)", NULL },
309 { 0x829d, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FNumber", "FNumber", NULL },
310 { 0x8822, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ExposureProgram", N_("Exposure program"), ExifExposureProgramList },
311 { 0x8824, EXIF_FORMAT_STRING, -1, "Exif.Photo.SpectralSensitivity", "Spectral Sensitivity", NULL },
312 { 0x8827, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.ISOSpeedRatings", N_("ISO sensitivity"), NULL },
313 { 0x8828, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.OECF", "Optoelectric conversion factor", NULL },
314 { 0x9000, EXIF_FORMAT_UNDEFINED, 4, "Exif.Photo.ExifVersion", "Exif version", NULL },
315 { 0x9003, EXIF_FORMAT_STRING, 20, "Exif.Photo.DateTimeOriginal", N_("Date original"), NULL },
316 { 0x9004, EXIF_FORMAT_STRING, 20, "Exif.Photo.DateTimeDigitized", N_("Date digitized"), NULL },
317 { 0x9101, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.ComponentsConfiguration","Pixel format", NULL },
318 { 0x9102, EXIF_FORMAT_RATIONAL_UNSIGNED,1, "Exif.Photo.CompressedBitsPerPixel","Compression ratio", NULL },
319 { 0x9201, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.ShutterSpeedValue", N_("Shutter speed"), NULL },
320 { 0x9202, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ApertureValue", N_("Aperture"), NULL },
321 { 0x9203, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.BrightnessValue", "Brightness", NULL },
322 { 0x9204, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.ExposureBiasValue", N_("Exposure bias"), NULL },
323 { 0x9205, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.MaxApertureValue", "Maximum aperture", NULL },
324 { 0x9206, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.SubjectDistance", N_("Subject distance"), NULL },
325 { 0x9207, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.MeteringMode", N_("Metering mode"), ExifMeteringModeList },
326 { 0x9208, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.LightSource", N_("Light source"), ExifLightSourceList },
327 { 0x9209, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Flash", N_("Flash"), ExifFlashList },
328 { 0x920a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalLength", N_("Focal length"), NULL },
329 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.SubjectArea", "Subject area", NULL },
330 { 0x927c, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.MakerNote", "MakerNote", NULL },
331 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.UserComment", "UserComment", NULL },
332 { 0x9290, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTime", "Subsecond time", NULL },
333 { 0x9291, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTimeOriginal", "Subsecond time original", NULL },
334 { 0x9292, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTimeDigitized", "Subsecond time digitized", NULL },
335 { 0xa000, EXIF_FORMAT_UNDEFINED, 4, "FlashPixVersion", "FlashPix version", NULL },
336 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ColorSpace", "Colorspace", ExifColorSpaceList },
337 /* ExifImageWidth, ExifImageHeight can also be unsigned short */
338 { 0xa002, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageWidth", N_("Width"), NULL },
339 { 0xa003, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifImageHeight", N_("Height"), NULL },
340 { 0xa004, EXIF_FORMAT_STRING, -1, "Exif.Photo.RelatedSoundFile", "Audio data", NULL },
341 { 0xa005, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifInteroperabilityOffset", "ExifR98 extension", NULL },
342 { 0xa20b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FlashEnergy", "Flash strength", NULL },
343 { 0xa20c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.SpatialFrequencyResponse","Spatial frequency response", NULL },
344 { 0xa20e, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalPlaneXResolution", "X Pixel density", NULL },
345 { 0xa20f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalPlaneYResolution", "Y Pixel density", NULL },
346 { 0xa210, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.FocalPlaneResolutionUnit", "Pixel density units", ExifUnitList },
347 { 0x0214, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Exif.Photo.SubjectLocation", "Subject location", NULL },
348 { 0xa215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureIndex", N_("ISO sensitivity"), NULL },
349 { 0xa217, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.SensingMethod", "Sensor type", ExifSensorList },
350 { 0xa300, EXIF_FORMAT_UNDEFINED, 1, "Exif.Photo.FileSource", "Source type", ExifSourceList },
351 { 0xa301, EXIF_FORMAT_UNDEFINED, 1, "Exif.Photo.SceneType", "Scene type", ExifSceneList },
352 { 0xa302, EXIF_FORMAT_UNDEFINED, -1, "Exif.Image.CFAPattern", "Color filter array pattern", NULL },
353 /* tags a4xx were added for Exif 2.2 (not just these - some above, as well) */
354 { 0xa401, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.CustomRendered", "Render process", ExifCustRenderList },
355 { 0xa402, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ExposureMode", "Exposure mode", ExifExposureModeList },
356 { 0xa403, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.WhiteBalance", "White balance", ExifWhiteBalanceList },
357 { 0xa404, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.DigitalZoomRatio", "Digital zoom ratio", NULL },
358 { 0xa405, EXIF_FORMAT_SHORT_UNSIGNED, 1, "FocalLength35mmFilm", "Focal length (35mm)", NULL },
359 { 0xa406, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SceneCapturetype", "Scene capture type", ExifSceneCaptureList },
360 { 0xa407, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.GainControl", "Gain control", ExifGainControlList },
361 { 0xa408, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Contrast", "Contrast", ExifContrastList },
362 { 0xa409, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Saturation", "Saturation", ExifSaturationList },
363 { 0xa40a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Sharpness", "Sharpness", ExifSharpnessList },
364 { 0xa40b, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.DeviceSettingDescription","Device setting", NULL },
365 { 0xa40c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.SubjectDistanceRange", "Subject range", ExifSubjectRangeList },
366 { 0xa420, EXIF_FORMAT_STRING, -1, "Exif.Photo.ImageUniqueID", "Image serial number", NULL },
367 /* place known, but undocumented or lesser used tags here */
368 { 0x00fe, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Image.NewSubfileType", NULL, NULL },
369 { 0x00ff, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubfileType", NULL, NULL },
370 { 0x012d, EXIF_FORMAT_SHORT_UNSIGNED, 3, "Exif.Image.TransferFunction", NULL, NULL },
371 { 0x013b, EXIF_FORMAT_STRING, -1, "Exif.Image.Artist", "Artist", NULL },
372 { 0x013d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Predictor", NULL, NULL },
373 { 0x0142, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileWidth", NULL, NULL },
374 { 0x0143, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileLength", NULL, NULL },
375 { 0x0144, EXIF_FORMAT_LONG_UNSIGNED, -1, "TileOffsets", NULL, NULL },
376 { 0x0145, EXIF_FORMAT_SHORT_UNSIGNED, -1, "TileByteCounts", NULL, NULL },
377 { 0x014a, EXIF_FORMAT_LONG_UNSIGNED, -1, "Exif.Image.SubIFDs", NULL, NULL },
378 { 0x015b, EXIF_FORMAT_UNDEFINED, -1, "JPEGTables", NULL, NULL },
379 { 0x828d, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Exif.Image.CFARepeatPatternDim", NULL, NULL },
380 { 0x828e, EXIF_FORMAT_BYTE_UNSIGNED, -1, "Exif.Image.CFAPattern", NULL, NULL },
381 { 0x828f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.BatteryLevel", NULL, NULL },
382 { 0x83bb, EXIF_FORMAT_LONG_UNSIGNED, -1, "IPTC/NAA", NULL, NULL },
383 { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "ColorProfile", NULL, NULL },
384 { 0x8825, EXIF_FORMAT_LONG_UNSIGNED, 1, "GPSInfo", "SubIFD GPS offset", NULL },
385 { 0x8829, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Interlace", NULL, NULL },
386 { 0x882a, EXIF_FORMAT_SHORT, 1, "TimeZoneOffset", NULL, NULL },
387 { 0x882b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SelfTimerMode", NULL, NULL },
388 { 0x920b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FlashEnergy", NULL, NULL },
389 { 0x920c, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.SpatialFrequencyResponse", NULL, NULL },
390 { 0x920d, EXIF_FORMAT_UNDEFINED, -1, "Noise", NULL, NULL },
391 { 0x9211, EXIF_FORMAT_LONG_UNSIGNED, 1, "ImageNumber", NULL, NULL },
392 { 0x9212, EXIF_FORMAT_STRING, 1, "SecurityClassification", NULL, NULL },
393 { 0x9213, EXIF_FORMAT_STRING, -1, "ImageHistory", NULL, NULL },
394 { 0x9215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureIndex", NULL, NULL },
395 { 0x9216, EXIF_FORMAT_BYTE_UNSIGNED, 4, "TIFF/EPStandardID", NULL, NULL },
400 ExifMarker ExifUnknownMarkersList[] = {
401 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL },
402 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL },
403 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL },
404 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL },
405 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL },
406 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL },
407 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL },
408 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL },
409 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL },
410 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL },
411 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL },
412 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL },
413 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL },
416 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list);
419 *-----------------------------------------------------------------------------
421 *-----------------------------------------------------------------------------
424 ExifItem *exif_item_new(ExifFormatType format, guint tag,
425 guint elements, const ExifMarker *marker)
429 item = g_new0(ExifItem, 1);
430 item->format = format;
432 item->marker = marker;
433 item->elements = elements;
439 case EXIF_FORMAT_UNKNOWN:
440 /* unknown, data is NULL */
443 case EXIF_FORMAT_BYTE_UNSIGNED:
444 item->data_len = sizeof(char) * elements;
446 case EXIF_FORMAT_STRING:
447 item->data_len = sizeof(char) * elements;
449 case EXIF_FORMAT_SHORT_UNSIGNED:
450 item->data_len = sizeof(guint16) * elements;
452 case EXIF_FORMAT_LONG_UNSIGNED:
453 item->data_len = sizeof(guint32) * elements;
455 case EXIF_FORMAT_RATIONAL_UNSIGNED:
456 item->data_len = sizeof(ExifRational) * elements;
458 case EXIF_FORMAT_BYTE:
459 item->data_len = sizeof(char) * elements;
461 case EXIF_FORMAT_UNDEFINED:
462 item->data_len = sizeof(char) * elements;
464 case EXIF_FORMAT_SHORT:
465 item->data_len = sizeof(gint16) * elements;
467 case EXIF_FORMAT_LONG:
468 item->data_len = sizeof(gint32) * elements;
470 case EXIF_FORMAT_RATIONAL:
471 item->data_len = sizeof(ExifRational) * elements;
473 case EXIF_FORMAT_FLOAT:
474 item->data_len = sizeof(float) * elements;
476 case EXIF_FORMAT_DOUBLE:
477 item->data_len = sizeof(double) * elements;
481 item->data = g_malloc0(item->data_len);
486 static void exif_item_free(ExifItem *item)
494 const char *exif_item_get_tag_name(ExifItem *item)
496 if (!item || !item->marker) return NULL;
497 return item->marker->key;
500 guint exif_item_get_tag_id(ExifItem *item)
505 guint exif_item_get_elements(ExifItem *item)
507 return item->elements;
510 char *exif_item_get_data(ExifItem *item, guint *data_len)
513 *data_len = item->data_len;
517 guint exif_item_get_format_id(ExifItem *item)
523 char *exif_item_get_description(ExifItem *item)
525 if (!item || !item->marker) return NULL;
526 return g_strdup(_(item->marker->description));
529 const char *exif_item_get_format_name(ExifItem *item, gint brief)
531 if (!item || !item->marker) return NULL;
532 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description;
535 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne)
539 for (i = 0 ; i < ne; i++)
541 unsigned char c = ((char *)data)[i];
542 if (c < 32 || c > 127) c = '.';
543 g_string_append_printf(string, "%c", c);
545 string = g_string_append(string, " : ");
546 for (i = 0 ; i < ne; i++)
564 g_string_append_printf(string, "%s%02x", spacer, ((char *)data)[i]);
571 gchar *exif_text_list_find_value(ExifTextList *list, guint value)
573 gchar *result = NULL;
577 while (!result && list[i].value >= 0)
579 if (value == list[i].value) result = g_strdup(_(list[i].description));
582 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown"));
589 *-------------------------------------------------------------------
591 *-------------------------------------------------------------------
594 /* note: the align_buf is used to avoid alignment issues (on sparc) */
596 guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo)
600 memcpy(&align_buf, f, sizeof(guint16));
602 if (bo == EXIF_BYTE_ORDER_INTEL)
603 return GUINT16_FROM_LE(align_buf);
605 return GUINT16_FROM_BE(align_buf);
608 guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo)
612 memcpy(&align_buf, f, sizeof(guint32));
614 if (bo == EXIF_BYTE_ORDER_INTEL)
615 return GUINT32_FROM_LE(align_buf);
617 return GUINT32_FROM_BE(align_buf);
620 void exif_byte_put_int16(unsigned char *f, guint16 n, ExifByteOrder bo)
624 if (bo == EXIF_BYTE_ORDER_INTEL)
626 align_buf = GUINT16_TO_LE(n);
630 align_buf = GUINT16_TO_BE(n);
633 memcpy(f, &align_buf, sizeof(guint16));
636 void exif_byte_put_int32(unsigned char *f, guint32 n, ExifByteOrder bo)
640 if (bo == EXIF_BYTE_ORDER_INTEL)
642 align_buf = GUINT32_TO_LE(n);
646 align_buf = GUINT32_TO_BE(n);
649 memcpy(f, &align_buf, sizeof(guint32));
654 *-------------------------------------------------------------------
656 *-------------------------------------------------------------------
659 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list)
663 if (!list) return NULL;
665 while (list[i].tag != 0 && list[i].tag != tag)
670 return (list[i].tag == 0 ? NULL : &list[i]);
673 static void rational_from_data(ExifRational *r, void *src, ExifByteOrder bo)
675 r->num = exif_byte_get_int32(src, bo);
676 r->den = exif_byte_get_int32(src + sizeof(guint32), bo);
679 /* src_format and item->format must be compatible
680 * and not overrun src or item->data.
682 void exif_item_copy_data(ExifItem *item, void *src, guint len,
683 ExifFormatType src_format, ExifByteOrder bo)
690 bs = ExifFormatList[item->format].size;
695 ExifFormatList[src_format].size * ne > len)
697 printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
701 switch (item->format)
703 case EXIF_FORMAT_UNKNOWN:
705 case EXIF_FORMAT_BYTE_UNSIGNED:
706 case EXIF_FORMAT_BYTE:
707 case EXIF_FORMAT_UNDEFINED:
708 memcpy(dest, src, len);
710 case EXIF_FORMAT_STRING:
711 memcpy(dest, src, len);
712 /* string is NULL terminated, make sure this is true */
713 if (((char *)dest)[len - 1] != '\0') ((char *)dest)[len - 1] = '\0';
715 case EXIF_FORMAT_SHORT_UNSIGNED:
716 case EXIF_FORMAT_SHORT:
717 for (i = 0; i < ne; i++)
719 ((guint16 *)dest)[i] = exif_byte_get_int16(src + i * bs, bo);
722 case EXIF_FORMAT_LONG_UNSIGNED:
723 case EXIF_FORMAT_LONG:
724 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED ||
725 src_format == EXIF_FORMAT_SHORT)
727 /* a short fits into a long, so allow it */
730 ss = ExifFormatList[src_format].size;
731 for (i = 0; i < ne; i++)
733 ((gint32 *)dest)[i] =
734 (gint32)exif_byte_get_int16(src + i * ss, bo);
739 for (i = 0; i < ne; i++)
741 ((gint32 *)dest)[i] =
742 exif_byte_get_int32(src + i * bs, bo);
746 case EXIF_FORMAT_RATIONAL_UNSIGNED:
747 case EXIF_FORMAT_RATIONAL:
748 for (i = 0; i < ne; i++)
750 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, bo);
753 case EXIF_FORMAT_FLOAT:
754 for (i = 0; i < ne; i++)
756 ((float *)dest)[i] = exif_byte_get_int32(src + i * bs, bo);
759 case EXIF_FORMAT_DOUBLE:
760 for (i = 0; i < ne; i++)
764 rational_from_data(&r, src + i * bs, bo);
765 if (r.den) ((double *)dest)[i] = (double)r.num / r.den;
771 static gint exif_parse_IFD_entry(ExifData *exif, unsigned char *tiff, guint offset,
772 guint size, ExifByteOrder bo,
774 const ExifMarker *list)
782 const ExifMarker *marker;
785 tag = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_TAG, bo);
786 format = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
787 count = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_COUNT, bo);
788 data_val = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_DATA, bo);
790 /* Check tag type. If it does not match, either the format is wrong,
791 * either it is a unknown tag; so it is not really an error.
793 marker = exif_marker_from_tag(tag, list);
796 if (format >= EXIF_FORMAT_COUNT)
798 printf("warning: exif tag 0x%4x has invalid format %d\n", tag, format);
801 /* allow non recognized tags to be displayed */
802 marker = &ExifUnknownMarkersList[format];
804 if (marker->format != format)
806 /* Some cameras got mixed up signed/unsigned_rational
807 * eg KODAK DC4800 on object_distance tag
809 * FIXME: what exactly is this test trying to do?
810 * ok, so this test is to allow the case of swapped signed/unsigned mismatch to leak through?
812 if (!(marker->format == EXIF_FORMAT_RATIONAL_UNSIGNED && format == EXIF_FORMAT_RATIONAL) &&
813 !(marker->format == EXIF_FORMAT_RATIONAL && format == EXIF_FORMAT_RATIONAL_UNSIGNED) &&
814 /* short fits into a long so allow this mismatch
815 * as well (some tags allowed to be unsigned short _or_ unsigned long)
817 !(marker->format == EXIF_FORMAT_LONG_UNSIGNED && format == EXIF_FORMAT_SHORT_UNSIGNED) )
819 if (format < EXIF_FORMAT_COUNT)
821 printf("warning: exif tag %s format mismatch, found %s exif spec requests %s\n",
822 marker->key, ExifFormatList[format].short_name,
823 ExifFormatList[marker->format].short_name);
827 printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n",
828 marker->key, format, marker->format,
829 ExifFormatList[marker->format].short_name);
835 /* Where is the data, is it available?
837 if (marker->components > 0 && marker->components != count)
839 printf("warning: exif tag %s has %d elements, exif spec requests %d\n",
840 marker->key, count, marker->components);
843 data_length = ExifFormatList[marker->format].size * count;
846 data_offset = data_val;
847 if (size < data_offset + data_length)
849 printf("warning: exif tag %s data will overrun end of file, ignored.\n", marker->key);
855 data_offset = offset + EXIF_TIFD_OFFSET_DATA;
858 item = exif_item_new(marker->format, tag, count, marker);
859 exif_item_copy_data(item, tiff + data_offset, data_length, format, bo);
860 exif->items = g_list_prepend(exif->items, item);
862 if (list == ExifKnownMarkersList)
867 exif_parse_IFD_table(exif, tiff, data_val, size, bo, level + 1, list);
869 case TAG_EXIFMAKERNOTE:
870 format_exif_makernote_parse(exif, tiff, data_val, size, bo);
878 gint exif_parse_IFD_table(ExifData *exif,
879 unsigned char *tiff, guint offset,
880 guint size, ExifByteOrder bo,
882 const ExifMarker *list)
887 /* limit damage from infinite loops */
888 if (level > EXIF_TIFF_MAX_LEVELS) return -1;
890 /* We should be able to read number of entries in IFD0) */
891 if (size < offset + 2) return -1;
893 count = exif_byte_get_int16(tiff + offset, bo);
896 /* Entries and next IFD offset must be readable */
897 if (size < offset + count * EXIF_TIFD_SIZE + 4) return -1;
899 for (i = 0; i < count; i++)
901 exif_parse_IFD_entry(exif, tiff, offset + i * EXIF_TIFD_SIZE, size, bo, level, list);
908 *-------------------------------------------------------------------
910 *-------------------------------------------------------------------
913 gint exif_tiff_directory_offset(unsigned char *data, const guint len,
914 guint *offset, ExifByteOrder *bo)
916 if (len < 8) return FALSE;
918 if (memcmp(data, "II", 2) == 0)
920 *bo = EXIF_BYTE_ORDER_INTEL;
922 else if (memcmp(data, "MM", 2) == 0)
924 *bo = EXIF_BYTE_ORDER_MOTOROLA;
931 if (exif_byte_get_int16(data + 2, *bo) != 0x002A)
936 *offset = exif_byte_get_int32(data + 4, *bo);
938 return (*offset < len);
941 gint exif_tiff_parse(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list)
946 if (!exif_tiff_directory_offset(tiff, size, &offset, &bo)) return -1;
948 return exif_parse_IFD_table(exif, tiff, offset, size, bo, 0, list);
952 *-------------------------------------------------------------------
954 *-------------------------------------------------------------------
957 #define JPEG_MARKER 0xFF
958 #define JPEG_MARKER_SOI 0xD8
959 #define JPEG_MARKER_EOI 0xD9
960 #define JPEG_MARKER_APP1 0xE1
961 #define JPEG_MARKER_APP2 0xE2
963 /* jpeg container format:
964 all data markers start with 0XFF
965 2 byte long file start and end markers: 0xFFD8(SOI) and 0XFFD9(EOI)
966 4 byte long data segment markers in format: 0xFFTTSSSSNNN...
967 FF: 1 byte standard marker identifier
969 SSSS: 2 bytes in Motorola byte alignment for length of the data.
970 This value includes these 2 bytes in the count, making actual
971 length of NN... == SSSS - 2.
972 NNN.: the data in this segment
975 static gint exif_jpeg_segment_find(unsigned char *data, guint size,
976 guchar app_marker, const gchar *magic, guint magic_len,
977 guint *seg_offset, guint *seg_length)
983 while (marker != app_marker &&
984 marker != JPEG_MARKER_EOI)
989 if (offset + 2 >= size ||
990 data[offset] != JPEG_MARKER) return FALSE;
992 marker = data[offset + 1];
993 if (marker != JPEG_MARKER_SOI &&
994 marker != JPEG_MARKER_EOI)
996 if (offset + 4 >= size) return FALSE;
997 length += exif_byte_get_int16(data + offset + 2, EXIF_BYTE_ORDER_MOTOROLA);
1001 if (marker == app_marker &&
1002 offset + length < size &&
1003 length >= 4 + magic_len &&
1004 memcmp(data + offset + 4, magic, magic_len) == 0)
1006 *seg_offset = offset + 4;
1007 *seg_length = length - 4;
1014 static ExifMarker jpeg_color_marker = { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "ColorProfile", NULL, NULL };
1016 static gint exif_jpeg_parse_color(ExifData *exif, unsigned char *data, guint size)
1018 guint seg_offset = 0;
1019 guint seg_length = 0;
1020 guint chunk_offset[255];
1021 guint chunk_length[255];
1022 guint chunk_count = 0;
1024 /* For jpeg/jfif, ICC color profile data can be in more than one segment.
1025 the data is in APP2 data segments that start with "ICC_PROFILE\x00\xNN\xTT"
1026 NN = segment number for data
1027 TT = total number of ICC segments (TT in each ICC segment should match)
1030 while (exif_jpeg_segment_find(data + seg_offset + seg_length,
1031 size - seg_offset - seg_length,
1033 "ICC_PROFILE\x00", 12,
1034 &seg_offset, &seg_length))
1039 if (seg_length < 14) return FALSE;
1041 chunk_num = data[seg_offset + 12];
1042 chunk_tot = data[seg_offset + 13];
1044 if (chunk_num == 0 || chunk_tot == 0) return FALSE;
1046 if (chunk_count == 0)
1050 chunk_count = (guint)chunk_tot;
1051 for (i = 0; i < chunk_count; i++) chunk_offset[i] = 0;
1052 for (i = 0; i < chunk_count; i++) chunk_length[i] = 0;
1055 if (chunk_tot != chunk_count ||
1056 chunk_num > chunk_count) return FALSE;
1059 chunk_offset[chunk_num] = seg_offset + 14;
1060 chunk_length[chunk_num] = seg_length - 14;
1063 if (chunk_count > 0)
1066 unsigned char *cp_data;
1067 guint cp_length = 0;
1070 for (i = 0; i < chunk_count; i++) cp_length += chunk_length[i];
1071 cp_data = g_malloc(cp_length);
1073 for (i = 0; i < chunk_count; i++)
1075 if (chunk_offset[i] == 0)
1077 /* error, we never saw this chunk */
1081 memcpy(cp_data, data + chunk_offset[i], chunk_length[i]);
1084 item = exif_item_new(jpeg_color_marker.format, jpeg_color_marker.tag, 1,
1085 &jpeg_color_marker);
1087 item->data = cp_data;
1088 item->elements = cp_length;
1089 item->data_len = cp_length;
1090 exif->items = g_list_prepend(exif->items, item);
1098 static gint exif_jpeg_parse(ExifData *exif,
1099 unsigned char *data, guint size,
1100 ExifMarker *list, gint parse_color)
1102 guint seg_offset = 0;
1103 guint seg_length = 0;
1107 memcmp(data, "\xFF\xD8", 2) != 0)
1112 if (exif_jpeg_segment_find(data, size, JPEG_MARKER_APP1,
1114 &seg_offset, &seg_length))
1116 res = exif_tiff_parse(exif, data + seg_offset + 6, seg_length - 6, list);
1120 exif_jpeg_parse_color(exif, data, size))
1130 *-------------------------------------------------------------------
1132 *-------------------------------------------------------------------
1136 ExifItem *exif_get_first_item(ExifData *exif)
1140 ExifItem *ret = (ExifItem *)exif->items->data;
1141 exif->current = exif->items->next;
1144 exif->current = NULL;
1148 ExifItem *exif_get_next_item(ExifData *exif)
1152 ExifItem *ret = (ExifItem *)exif->current->data;
1153 exif->current = exif->current->next;
1161 static gint map_file(const gchar *path, void **mapping, int *size)
1166 if ((fd = open(path, O_RDONLY)) == -1)
1172 if (fstat(fd, &fs) == -1)
1181 if ((*mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
1192 static gint unmap_file(void *mapping, int size)
1194 if (munmap(mapping, size) == -1)
1203 void exif_free(ExifData *exif)
1212 ExifItem *item = work->data;
1214 exif_item_free(item);
1217 g_list_free(exif->items);
1221 ExifData *exif_read(gchar *path, gint parse_color_profile)
1228 if (!path) return NULL;
1230 pathl = path_from_utf8(path);
1231 if (map_file(pathl, &f, &size) == -1)
1238 exif = g_new0(ExifData, 1);
1240 exif->current = NULL;
1242 if ((res = exif_jpeg_parse(exif, (unsigned char *)f, size,
1243 ExifKnownMarkersList,
1244 parse_color_profile)) == -2)
1246 res = exif_tiff_parse(exif, (unsigned char *)f, size, ExifKnownMarkersList);
1251 FormatRawExifType exif_type;
1252 FormatRawExifParseFunc exif_parse_func;
1255 exif_type = format_raw_exif_offset(f, size, &offset, &exif_parse_func);
1258 case FORMAT_RAW_EXIF_NONE:
1261 case FORMAT_RAW_EXIF_TIFF:
1262 res = exif_tiff_parse(exif, (unsigned char*)f + offset, size - offset,
1263 ExifKnownMarkersList);
1265 case FORMAT_RAW_EXIF_JPEG:
1266 res = exif_jpeg_parse(exif, (unsigned char*)f + offset, size - offset,
1267 ExifKnownMarkersList, FALSE);
1269 case FORMAT_RAW_EXIF_IFD_II:
1270 case FORMAT_RAW_EXIF_IFD_MM:
1271 res = exif_parse_IFD_table(exif, (unsigned char*)f, offset, size - offset,
1272 (exif_type == FORMAT_RAW_EXIF_IFD_II) ?
1273 EXIF_BYTE_ORDER_INTEL : EXIF_BYTE_ORDER_MOTOROLA,
1274 0, ExifKnownMarkersList);
1276 case FORMAT_RAW_EXIF_PROPRIETARY:
1277 if (exif_parse_func)
1279 res = exif_parse_func((unsigned char*)f + offset, size - offset, exif);
1291 unmap_file(f, size);
1293 if (exif) exif->items = g_list_reverse(exif->items);
1296 exif_write_data_list(exif, stdout, TRUE);
1297 exif_write_data_list(exif, stdout, FALSE);
1303 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
1307 if (!key) return NULL;
1316 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item;
1321 #define EXIF_DATA_AS_TEXT_MAX_COUNT 16
1323 gchar *exif_item_get_data_as_text(ExifItem *item)
1325 const ExifMarker *marker;
1332 if (!item) return NULL;
1334 marker = item->marker;
1335 if (!marker) return NULL;
1338 ne = item->elements;
1339 if (ne > EXIF_DATA_AS_TEXT_MAX_COUNT) ne = EXIF_DATA_AS_TEXT_MAX_COUNT;
1340 string = g_string_new("");
1341 switch (item->format)
1343 case EXIF_FORMAT_UNKNOWN:
1345 case EXIF_FORMAT_BYTE_UNSIGNED:
1346 case EXIF_FORMAT_BYTE:
1347 case EXIF_FORMAT_UNDEFINED:
1348 if (ne == 1 && marker->list)
1353 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED ||
1354 item->format == EXIF_FORMAT_UNDEFINED)
1356 val = ((unsigned char *)data)[0];
1360 val = (unsigned char)(((signed char *)data)[0]);
1363 result = exif_text_list_find_value(marker->list, (guint)val);
1364 string = g_string_append(string, result);
1369 string = string_append_raw_bytes(string, data, ne);
1372 case EXIF_FORMAT_STRING:
1373 string = g_string_append(string, (gchar *)(item->data));
1375 case EXIF_FORMAT_SHORT_UNSIGNED:
1376 if (ne == 1 && marker->list)
1380 result = exif_text_list_find_value(marker->list, ((guint16 *)data)[0]);
1381 string = g_string_append(string, result);
1384 else for (i = 0; i < ne; i++)
1386 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1387 ((guint16 *)data)[i]);
1390 case EXIF_FORMAT_LONG_UNSIGNED:
1391 for (i = 0; i < ne; i++)
1393 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1394 (unsigned long int)((guint32 *)data)[i]);
1397 case EXIF_FORMAT_RATIONAL_UNSIGNED:
1398 for (i = 0; i < ne; i++)
1402 r = &((ExifRational *)data)[i];
1403 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1404 (unsigned long)r->num, (unsigned long)r->den);
1407 case EXIF_FORMAT_SHORT:
1408 for (i = 0; i < ne; i++)
1410 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "",
1411 ((gint16 *)data)[i]);
1414 case EXIF_FORMAT_LONG:
1415 for (i = 0; i < ne; i++)
1417 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "",
1418 (long int)((gint32 *)data)[i]);
1421 case EXIF_FORMAT_RATIONAL:
1422 for (i = 0; i < ne; i++)
1426 r = &((ExifRational *)data)[i];
1427 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "",
1428 (long)r->num, (long)r->den);
1431 case EXIF_FORMAT_FLOAT:
1432 for (i = 0; i < ne; i++)
1434 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1435 ((float *)data)[i]);
1438 case EXIF_FORMAT_DOUBLE:
1439 for (i = 0; i < ne; i++)
1441 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "",
1442 ((double *)data)[i]);
1447 if (item->elements > EXIF_DATA_AS_TEXT_MAX_COUNT &&
1448 item->format != EXIF_FORMAT_STRING)
1450 g_string_append(string, " ...");
1454 g_string_free(string, FALSE);
1459 gint exif_item_get_integer(ExifItem *item, gint *value)
1461 if (!item) return FALSE;
1463 switch (item->format)
1465 case EXIF_FORMAT_SHORT:
1466 *value = (gint)(((gint16 *)(item->data))[0]);
1469 case EXIF_FORMAT_SHORT_UNSIGNED:
1470 *value = (gint)(((guint16 *)(item->data))[0]);
1473 case EXIF_FORMAT_LONG:
1474 *value = (gint)(((gint32 *)(item->data))[0]);
1477 case EXIF_FORMAT_LONG_UNSIGNED:
1478 /* FIXME: overflow possible */
1479 *value = (gint)(((guint32 *)(item->data))[0]);
1482 /* all other type return FALSE */
1488 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
1492 item = exif_get_item(exif, key);
1493 return exif_item_get_integer(item, value);
1496 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
1498 if (!item) return NULL;
1500 if (item->format == EXIF_FORMAT_RATIONAL ||
1501 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED)
1503 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL);
1504 return &((ExifRational *)(item->data))[0];
1510 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
1514 item = exif_get_item(exif, key);
1515 return exif_item_get_rational(item, sign);
1519 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
1525 if (!key) return NULL;
1527 text = exif_get_formatted_by_key(exif, key, &key_valid);
1528 if (key_valid) return text;
1530 item = exif_get_item(exif, key);
1531 if (item) return exif_item_get_data_as_text(item);
1536 const gchar *exif_get_tag_description_by_key(const gchar *key)
1540 if (!key) return NULL;
1543 while (ExifKnownMarkersList[i].tag > 0)
1545 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
1552 static void exif_write_item(FILE *f, ExifItem *item)
1556 text = exif_item_get_data_as_text(item);
1559 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
1560 exif_item_get_tag_name(item), text);
1565 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list)
1567 if (!f || !exif) return;
1569 fprintf(f, " tag format key value\n");
1570 fprintf(f, "----------------------------------------------------\n");
1572 if (human_readable_list)
1577 while (ExifFormattedList[i].key)
1581 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL);
1584 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text);
1601 exif_write_item(f, item);
1604 fprintf(f, "----------------------------------------------------\n");
1608 /* not HAVE_EXIV2 */