Mercurial > geeqie.yaz
comparison src/exif-common.c @ 222:77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
try to compute 35mm focal length
author | nadvornik |
---|---|
date | Wed, 02 Apr 2008 20:44:40 +0000 |
parents | c7021159079d |
children | cccba3e30a44 |
comparison
equal
deleted
inserted
replaced
221:79ef86f3b325 | 222:77f1bcc6c161 |
---|---|
36 { "fShutterSpeed", N_("Shutter speed") }, | 36 { "fShutterSpeed", N_("Shutter speed") }, |
37 { "fAperture", N_("Aperture") }, | 37 { "fAperture", N_("Aperture") }, |
38 { "fExposureBias", N_("Exposure bias") }, | 38 { "fExposureBias", N_("Exposure bias") }, |
39 { "fISOSpeedRating", N_("ISO sensitivity") }, | 39 { "fISOSpeedRating", N_("ISO sensitivity") }, |
40 { "fFocalLength", N_("Focal length") }, | 40 { "fFocalLength", N_("Focal length") }, |
41 { "fFocalLength35mmFilm",N_("Focal length 35mm") }, | |
41 { "fSubjectDistance", N_("Subject distance") }, | 42 { "fSubjectDistance", N_("Subject distance") }, |
42 { "fFlash", N_("Flash") }, | 43 { "fFlash", N_("Flash") }, |
43 { "fResolution", N_("Resolution") }, | 44 { "fResolution", N_("Resolution") }, |
44 { NULL, NULL } | 45 { NULL, NULL } |
45 }; | 46 }; |
50 { 5, N_("yes, not detected by strobe") }, | 51 { 5, N_("yes, not detected by strobe") }, |
51 { 7, N_("yes, detected by strobe") }, | 52 { 7, N_("yes, detected by strobe") }, |
52 EXIF_TEXT_LIST_END | 53 EXIF_TEXT_LIST_END |
53 }; | 54 }; |
54 | 55 |
55 | |
56 double exif_rational_to_double(ExifRational *r, gint sign) | 56 double exif_rational_to_double(ExifRational *r, gint sign) |
57 { | 57 { |
58 if (!r || r->den == 0.0) return 0.0; | 58 if (!r || r->den == 0.0) return 0.0; |
59 | 59 |
60 if (sign) return (double)((int)r->num) / (double)((int)r->den); | 60 if (sign) return (double)((int)r->num) / (double)((int)r->den); |
74 { | 74 { |
75 string = g_string_append(string, ", "); | 75 string = g_string_append(string, ", "); |
76 string = g_string_append(string, text); | 76 string = g_string_append(string, text); |
77 | 77 |
78 return string; | 78 return string; |
79 } | |
80 | |
81 static gchar *remove_common_prefix(gchar *s, gchar *t) | |
82 { | |
83 gint i; | |
84 | |
85 if (!s || !t) return t; | |
86 | |
87 for (i = 0; s[i] == t[i]; i++) | |
88 ; | |
89 if (!i) | |
90 return t; | |
91 if (s[i]==' ' || s[i]==0) | |
92 { | |
93 while (t[i] == ' ') | |
94 i++; | |
95 return t + i; | |
96 } | |
97 return s; | |
98 } | |
99 | |
100 static double get_crop_factor(ExifData *exif) | |
101 { | |
102 double res_unit_tbl[] = {0.0, 25.4, 25.4, 10.0, 1.0, 0.001 }; | |
103 | |
104 double xres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneXResolution"); | |
105 double yres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneYResolution"); | |
106 int res_unit; | |
107 int w, h; | |
108 double xsize, ysize, size, ratio; | |
109 | |
110 if (xres == 0.0 || yres == 0.0) return 0.0; | |
111 | |
112 if (!exif_get_integer(exif, "Exif.Photo.FocalPlaneResolutionUnit", &res_unit)) return 0.0; | |
113 if (res_unit < 1 || res_unit > 5) return 0.0; | |
114 | |
115 if (!exif_get_integer(exif, "Exif.Photo.PixelXDimension", &w)) return 0.0; | |
116 if (!exif_get_integer(exif, "Exif.Photo.PixelYDimension", &h)) return 0.0; | |
117 | |
118 xsize = w * res_unit_tbl[res_unit] / xres; | |
119 ysize = h * res_unit_tbl[res_unit] / yres; | |
120 | |
121 ratio = xsize / ysize; | |
122 | |
123 if (ratio < 0.5 || ratio > 2.0) return 0.0; /* reasonable ratio */ | |
124 | |
125 size = sqrt(xsize * xsize + ysize * ysize); | |
126 | |
127 if (size < 1.0 || size > 100.0) return 0.0; /* reasonable sensor size in mm */ | |
128 | |
129 return sqrt(36*36+24*24) / size; | |
130 | |
79 } | 131 } |
80 | 132 |
81 | 133 |
82 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid) | 134 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid) |
83 { | 135 { |
94 { | 146 { |
95 gchar *text; | 147 gchar *text; |
96 gchar *make = exif_get_data_as_text(exif, "Exif.Image.Make"); | 148 gchar *make = exif_get_data_as_text(exif, "Exif.Image.Make"); |
97 gchar *model = exif_get_data_as_text(exif, "Exif.Image.Model"); | 149 gchar *model = exif_get_data_as_text(exif, "Exif.Image.Model"); |
98 gchar *software = exif_get_data_as_text(exif, "Exif.Image.Software"); | 150 gchar *software = exif_get_data_as_text(exif, "Exif.Image.Software"); |
151 gchar *model2; | |
152 gchar *software2; | |
153 gint i; | |
154 | |
155 if (make) | |
156 { | |
157 gchar *x; | |
158 | |
159 g_strstrip(make); | |
160 #define REMOVE_SUFFIX(str,suff) \ | |
161 do { \ | |
162 if (g_str_has_suffix(str,suff)) \ | |
163 str[strlen(str)-(sizeof(suff)-1)] = 0; \ | |
164 } while(0) | |
165 REMOVE_SUFFIX(make," Corporation"); /* Pentax */ | |
166 REMOVE_SUFFIX(make," OPTICAL CO.,LTD"); /* OLYMPUS */ | |
167 } | |
168 if (model) | |
169 g_strstrip(model); | |
170 if (software) | |
171 g_strstrip(software); | |
172 /* remove superfluous spaces (pentax K100D) */ | |
173 for (i=0; software && software[i]; i++) | |
174 if (software[i] == ' ' && software[i+1] == ' ') | |
175 { | |
176 gint j; | |
177 | |
178 for (j=1; software[i+j]; j++) | |
179 if (software[i+j] != ' ') | |
180 break; | |
181 memmove(software+i+1, software+i+j, strlen(software+i+j)+1); | |
182 } | |
183 | |
184 model2 = remove_common_prefix(make, model); | |
185 software2 = remove_common_prefix(model2, software); | |
99 | 186 |
100 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "", | 187 text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "", |
101 (model) ? model : "", | 188 (model2) ? model2 : "", |
102 (software) ? " (" : "", | 189 (software2) ? " (" : "", |
103 (software) ? software : "", | 190 (software2) ? software2 : "", |
104 (software) ? ")" : ""); | 191 (software2) ? ")" : ""); |
105 | 192 |
106 g_free(make); | 193 g_free(make); |
107 g_free(model); | 194 g_free(model); |
108 g_free(software); | 195 g_free(software); |
109 return text; | 196 return text; |
177 { | 264 { |
178 double n; | 265 double n; |
179 | 266 |
180 n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength"); | 267 n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength"); |
181 if (n == 0.0) return NULL; | 268 if (n == 0.0) return NULL; |
182 return g_strdup_printf("%.2f mm", n); | 269 return g_strdup_printf("%.0f mm", n); |
270 } | |
271 if (strcmp(key, "fFocalLength35mmFilm") == 0) | |
272 { | |
273 gint n; | |
274 double f, c; | |
275 | |
276 if (exif_get_integer(exif, "Exif.Photo.FocalLengthIn35mmFilm", &n) && n != 0) | |
277 { | |
278 return g_strdup_printf("%d mm", n); | |
279 } | |
280 | |
281 f = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength"); | |
282 c = get_crop_factor(exif); | |
283 | |
284 if (f != 0.0 && c != 0.0) | |
285 { | |
286 return g_strdup_printf("%.0f mm", f * c); | |
287 } | |
288 | |
289 return NULL; | |
183 } | 290 } |
184 if (strcmp(key, "fISOSpeedRating") == 0) | 291 if (strcmp(key, "fISOSpeedRating") == 0) |
185 { | 292 { |
186 gchar *text; | 293 gchar *text; |
187 | 294 |