annotate src/exif-common.c @ 363:5b8617c3821c

collection_load(): accept whitespaces at start of lines.
author zas_
date Mon, 14 Apr 2008 23:08:27 +0000
parents bda275cf9821
children eff049b3d308
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
1 /*
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
2 * GQView
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
3 * (C) 2006 John Ellis
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
4 *
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
5 */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
6
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
7 #ifdef HAVE_CONFIG_H
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
8 # include "config.h"
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
9 #endif
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
10
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
11 #include <stdio.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
12 #include <string.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
13 #include <fcntl.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
14 #include <unistd.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
15 #include <sys/types.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
16 #include <sys/stat.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
17 #include <sys/mman.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
18 #include <math.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
19
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
20 #include <glib.h>
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
21
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
22 #include "intl.h"
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
23
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 239
diff changeset
24 #include "main.h"
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
25 #include "exif.h"
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
26
239
cccba3e30a44 Remove two unused variables declarations, and add a missing #include.
zas_
parents: 222
diff changeset
27 #include "filelist.h"
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
28 #include "format_raw.h"
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
29 #include "ui_fileops.h"
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
30
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
31
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
32 /* human readable key list */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
33
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
34 ExifFormattedText ExifFormattedList[] = {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
35 { "fCamera", N_("Camera") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
36 { "fDateTime", N_("Date") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
37 { "fShutterSpeed", N_("Shutter speed") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
38 { "fAperture", N_("Aperture") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
39 { "fExposureBias", N_("Exposure bias") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
40 { "fISOSpeedRating", N_("ISO sensitivity") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
41 { "fFocalLength", N_("Focal length") },
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
42 { "fFocalLength35mmFilm",N_("Focal length 35mm") },
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
43 { "fSubjectDistance", N_("Subject distance") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
44 { "fFlash", N_("Flash") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
45 { "fResolution", N_("Resolution") },
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
46 { NULL, NULL }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
47 };
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
48
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
49 double exif_rational_to_double(ExifRational *r, gint sign)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
50 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
51 if (!r || r->den == 0.0) return 0.0;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
52
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
53 if (sign) return (double)((int)r->num) / (double)((int)r->den);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
54 return (double)r->num / r->den;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
55 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
56
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
57 double exif_get_rational_as_double(ExifData *exif, const gchar *key)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
58 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
59 ExifRational *r;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
60 gint sign;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
61
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
62 r = exif_get_rational(exif, key, &sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
63 return exif_rational_to_double(r, sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
64 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
65
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
66 static GString *append_comma_text(GString *string, const gchar *text)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
67 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
68 string = g_string_append(string, ", ");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
69 string = g_string_append(string, text);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
70
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
71 return string;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
72 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
73
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
74 static gchar *remove_common_prefix(gchar *s, gchar *t)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
75 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
76 gint i;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
77
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
78 if (!s || !t) return t;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
79
297
76cdc3f1fe34 Fix broken remove_common_prefix(), fCamera didn't display model as it should.
zas_
parents: 281
diff changeset
80 for (i = 0; s[i] && t[i] && s[i] == t[i]; i++)
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
81 ;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
82 if (!i)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
83 return t;
300
bda275cf9821 Fix fCamera even more.
zas_
parents: 297
diff changeset
84 if (s[i-1] == ' ' || !s[i])
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
85 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
86 while (t[i] == ' ')
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
87 i++;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
88 return t + i;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
89 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
90 return s;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
91 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
92
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
93 static double get_crop_factor(ExifData *exif)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
94 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
95 double res_unit_tbl[] = {0.0, 25.4, 25.4, 10.0, 1.0, 0.001 };
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
96
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
97 double xres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneXResolution");
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
98 double yres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneYResolution");
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
99 int res_unit;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
100 int w, h;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
101 double xsize, ysize, size, ratio;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
102
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
103 if (xres == 0.0 || yres == 0.0) return 0.0;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
104
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
105 if (!exif_get_integer(exif, "Exif.Photo.FocalPlaneResolutionUnit", &res_unit)) return 0.0;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
106 if (res_unit < 1 || res_unit > 5) return 0.0;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
107
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
108 if (!exif_get_integer(exif, "Exif.Photo.PixelXDimension", &w)) return 0.0;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
109 if (!exif_get_integer(exif, "Exif.Photo.PixelYDimension", &h)) return 0.0;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
110
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
111 xsize = w * res_unit_tbl[res_unit] / xres;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
112 ysize = h * res_unit_tbl[res_unit] / yres;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
113
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
114 ratio = xsize / ysize;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
115
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
116 if (ratio < 0.5 || ratio > 2.0) return 0.0; /* reasonable ratio */
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
117
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
118 size = sqrt(xsize * xsize + ysize * ysize);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
119
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
120 if (size < 1.0 || size > 100.0) return 0.0; /* reasonable sensor size in mm */
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
121
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
122 return sqrt(36*36+24*24) / size;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
123
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
124 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
125
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
126
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
127 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
128 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
129 /* must begin with f, else not formatted */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
130 if (key[0] != 'f')
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
131 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
132 if (key_valid) *key_valid = FALSE;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
133 return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
134 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
135
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
136 if (key_valid) *key_valid = TRUE;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
137
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
138 if (strcmp(key, "fCamera") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
139 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
140 gchar *text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
141 gchar *make = exif_get_data_as_text(exif, "Exif.Image.Make");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
142 gchar *model = exif_get_data_as_text(exif, "Exif.Image.Model");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
143 gchar *software = exif_get_data_as_text(exif, "Exif.Image.Software");
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
144 gchar *model2;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
145 gchar *software2;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
146 gint i;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
147
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
148 if (make)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
149 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
150 g_strstrip(make);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
151 #define REMOVE_SUFFIX(str,suff) \
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
152 do { \
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
153 if (g_str_has_suffix(str,suff)) \
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
154 str[strlen(str)-(sizeof(suff)-1)] = 0; \
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
155 } while(0)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
156 REMOVE_SUFFIX(make," Corporation"); /* Pentax */
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
157 REMOVE_SUFFIX(make," OPTICAL CO.,LTD"); /* OLYMPUS */
300
bda275cf9821 Fix fCamera even more.
zas_
parents: 297
diff changeset
158 REMOVE_SUFFIX(make," CORPORATION"); /* Nikon */
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
159 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
160 if (model)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
161 g_strstrip(model);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
162 if (software)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
163 g_strstrip(software);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
164 /* remove superfluous spaces (pentax K100D) */
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
165 for (i=0; software && software[i]; i++)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
166 if (software[i] == ' ' && software[i+1] == ' ')
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
167 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
168 gint j;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
169
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
170 for (j=1; software[i+j]; j++)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
171 if (software[i+j] != ' ')
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
172 break;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
173 memmove(software+i+1, software+i+j, strlen(software+i+j)+1);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
174 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
175
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
176 model2 = remove_common_prefix(make, model);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
177 software2 = remove_common_prefix(model2, software);
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
178
300
bda275cf9821 Fix fCamera even more.
zas_
parents: 297
diff changeset
179 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", (make && model2) ? " " : "",
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
180 (model2) ? model2 : "",
300
bda275cf9821 Fix fCamera even more.
zas_
parents: 297
diff changeset
181 (software2 && (make || model2)) ? " (" : "",
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
182 (software2) ? software2 : "",
300
bda275cf9821 Fix fCamera even more.
zas_
parents: 297
diff changeset
183 (software2 && (make || model2)) ? ")" : "");
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
184
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
185 g_free(make);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
186 g_free(model);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
187 g_free(software);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
188 return text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
189 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
190 if (strcmp(key, "fDateTime") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
191 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
192 gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeOriginal");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
193 gchar *subsec = NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
194 if (text) subsec = exif_get_data_as_text(exif, "Exif.Photo.SubSecTimeOriginal");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
195 if (!text)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
196 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
197 text = exif_get_data_as_text(exif, "Exif.Image.DateTime");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
198 if (text) subsec = exif_get_data_as_text(exif, "Exif.Photo.SubSecTime");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
199 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
200 if (subsec)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
201 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
202 gchar *tmp = text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
203 text = g_strconcat(tmp, ".", subsec, NULL);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
204 g_free(tmp);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
205 g_free(subsec);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
206 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
207 return text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
208 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
209 if (strcmp(key, "fShutterSpeed") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
210 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
211 ExifRational *r;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
212
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
213 r = exif_get_rational(exif, "Exif.Photo.ExposureTime", NULL);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
214 if (r && r->num && r->den)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
215 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
216 double n = (double)r->den / (double)r->num;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
217 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
218 n > 1.0 ? n : 1.0 / n);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
219 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
220 r = exif_get_rational(exif, "Exif.Photo.ShutterSpeedValue", NULL);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
221 if (r && r->num && r->den)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
222 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
223 double n = pow(2.0, exif_rational_to_double(r, TRUE));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
224
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
225 /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
226 if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
227
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
228 return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
229 n > 1.0 ? floor(n) : 1.0 / n);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
230 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
231 return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
232 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
233 if (strcmp(key, "fAperture") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
234 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
235 double n;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
236
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
237 n = exif_get_rational_as_double(exif, "Exif.Photo.FNumber");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
238 if (n == 0.0) n = exif_get_rational_as_double(exif, "Exif.Photo.ApertureValue");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
239 if (n == 0.0) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
240
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
241 return g_strdup_printf("f/%.1f", n);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
242 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
243 if (strcmp(key, "fExposureBias") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
244 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
245 ExifRational *r;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
246 gint sign;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
247 double n;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
248
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
249 r = exif_get_rational(exif, "Exif.Photo.ExposureBiasValue", &sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
250 if (!r) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
251
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
252 n = exif_rational_to_double(r, sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
253 return g_strdup_printf("%+.1f", n);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
254 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
255 if (strcmp(key, "fFocalLength") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
256 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
257 double n;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
258
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
259 n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
260 if (n == 0.0) return NULL;
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
261 return g_strdup_printf("%.0f mm", n);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
262 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
263 if (strcmp(key, "fFocalLength35mmFilm") == 0)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
264 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
265 gint n;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
266 double f, c;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
267
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
268 if (exif_get_integer(exif, "Exif.Photo.FocalLengthIn35mmFilm", &n) && n != 0)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
269 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
270 return g_strdup_printf("%d mm", n);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
271 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
272
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
273 f = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
274 c = get_crop_factor(exif);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
275
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
276 if (f != 0.0 && c != 0.0)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
277 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
278 return g_strdup_printf("%.0f mm", f * c);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
279 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
280
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 212
diff changeset
281 return NULL;
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
282 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
283 if (strcmp(key, "fISOSpeedRating") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
284 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
285 gchar *text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
286
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
287 text = exif_get_data_as_text(exif, "Exif.Photo.ISOSpeedRatings");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
288 /* kodak may set this instead */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
289 if (!text) text = exif_get_data_as_text(exif, "Exif.Photo.ExposureIndex");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
290 return text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
291 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
292 if (strcmp(key, "fSubjectDistance") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
293 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
294 ExifRational *r;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
295 gint sign;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
296 double n;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
297
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
298 r = exif_get_rational(exif, "Exif.Photo.SubjectDistance", &sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
299 if (!r) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
300
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
301 if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
302 if ((long)r->num == 0) return g_strdup(_("unknown"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
303
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
304 n = exif_rational_to_double(r, sign);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
305 if (n == 0.0) return _("unknown");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
306 return g_strdup_printf("%.3f m", n);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
307 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
308 if (strcmp(key, "fFlash") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
309 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
310 /* grr, flash is a bitmask... */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
311 GString *string;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
312 gchar *text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
313 gint n;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
314 gint v;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
315
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
316 if (!exif_get_integer(exif, "Exif.Photo.Flash", &n)) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
317
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
318 /* Exif 2.1 only defines first 3 bits */
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
319 if (n <= 0x07) return exif_get_data_as_text(exif, "Exif.Photo.Flash");
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
320
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
321 /* must be Exif 2.2 */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
322 string = g_string_new("");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
323
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
324 /* flash fired (bit 0) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
325 string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
326
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
327 /* flash mode (bits 3, 4) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
328 v = (n >> 3) & 0x03;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
329 if (v) string = append_comma_text(string, _("mode:"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
330 switch (v)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
331 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
332 case 1:
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
333 string = g_string_append(string, _("on"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
334 break;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
335 case 2:
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
336 string = g_string_append(string, _("off"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
337 break;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
338 case 3:
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
339 string = g_string_append(string, _("auto"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
340 break;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
341 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
342
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
343 /* return light (bits 1, 2) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
344 v = (n >> 1) & 0x03;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
345 if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
346 if (v == 3) string = append_comma_text(string, _("detected by strobe"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
347
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
348 /* we ignore flash function (bit 5) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
349
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
350 /* red-eye (bit 6) */
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
351 if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
352
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
353 text = string->str;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
354 g_string_free(string, FALSE);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
355 return text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
356 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
357 if (strcmp(key, "fResolution") == 0)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
358 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
359 ExifRational *rx, *ry;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
360 gchar *units;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
361 gchar *text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
362
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
363 rx = exif_get_rational(exif, "Exif.Image.XResolution", NULL);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
364 ry = exif_get_rational(exif, "Exif.Image.YResolution", NULL);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
365 if (!rx || !ry) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
366
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
367 units = exif_get_data_as_text(exif, "Exif.Image.ResolutionUnit");
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
368 text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
369 ry->den ? (double)ry->num / ry->den : 1.0,
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
370 _("dot"), (units) ? units : _("unknown"));
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
371
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
372 g_free(units);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
373 return text;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
374 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
375
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
376 if (key_valid) *key_valid = FALSE;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
377 return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
378 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
379
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
380 const gchar *exif_get_description_by_key(const gchar *key)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
381 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
382 gint i;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
383
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
384 if (!key) return NULL;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
385
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
386 i = 0;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
387 while (ExifFormattedList[i].key != NULL)
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
388 {
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
389 if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
390 i++;
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
391 }
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
392
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
393 return exif_get_tag_description_by_key(key);
8a417f10ba09 more exiv2 fixes
nadvornik
parents:
diff changeset
394 }
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
395
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
396 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
397 {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
398 ExifItem *item;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
399
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
400 item = exif_get_item(exif, key);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
401 return exif_item_get_integer(item, value);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
402 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
403
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
404 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
405 {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
406 ExifItem *item;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
407
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
408 item = exif_get_item(exif, key);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
409 return exif_item_get_rational(item, sign);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
410 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
411
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
412 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
413 {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
414 ExifItem *item;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
415 gchar *text;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
416 gint key_valid;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
417
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
418 if (!key) return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
419
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
420 text = exif_get_formatted_by_key(exif, key, &key_valid);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
421 if (key_valid) return text;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
422
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
423 item = exif_get_item(exif, key);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
424 if (item) return exif_item_get_data_as_text(item);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
425
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
426 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 182
diff changeset
427 }
188
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
428
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
429 ExifData *exif_read_fd(FileData *fd, gint parse_color_profile)
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
430 {
204
d662d680250d improved xmp vs. legacy metadata handling
nadvornik
parents: 190
diff changeset
431 GList *work;
188
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
432 gchar *sidecar_path = NULL;
190
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
433
204
d662d680250d improved xmp vs. legacy metadata handling
nadvornik
parents: 190
diff changeset
434 if (!fd) return NULL;
d662d680250d improved xmp vs. legacy metadata handling
nadvornik
parents: 190
diff changeset
435
d662d680250d improved xmp vs. legacy metadata handling
nadvornik
parents: 190
diff changeset
436 work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
d662d680250d improved xmp vs. legacy metadata handling
nadvornik
parents: 190
diff changeset
437
212
c7021159079d differentiate among normal image, raw image and metadata
nadvornik
parents: 204
diff changeset
438 if (filter_file_class(fd->extension, FORMAT_CLASS_RAWIMAGE))
188
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
439 {
190
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
440 while(work)
188
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
441 {
190
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
442 FileData *sfd = work->data;
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
443 work = work->next;
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
444 if (strcasecmp(sfd->extension, ".xmp") == 0)
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
445 {
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
446 sidecar_path = sfd->path;
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
447 break;
c2923efebfdc whitelist of files that can have an xmp sidecar, sample external command
nadvornik
parents: 188
diff changeset
448 }
188
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
449 }
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
450 }
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
451
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
452
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
453 // FIXME: some caching would be nice
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
454 return exif_read(fd->path, sidecar_path, parse_color_profile);
0584cb78aa14 write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents: 184
diff changeset
455 }