Mercurial > geeqie
annotate src/exif.c @ 1206:d79305a42a9b
Switch to fullscreen when double clicking on file in icon or list view. Feature request 1966042. The code was there since a long time but disabled, please report any issue.
author | zas_ |
---|---|
date | Sat, 20 Dec 2008 21:30:27 +0000 |
parents | 43bfcbb62cd6 |
children | e2bbe90b0dcd |
rev | line source |
---|---|
9 | 1 /* |
541 | 2 * Geeqie |
3 * (C) 2006 John Ellis | |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Authors: | |
442 | 7 * Support for Exif file format, originally written by Eric Swalens. |
9 | 8 * Modified by Quy Tonthat |
9 * | |
10 * Reimplemented with generic data storage by John Ellis (Nov 2003) | |
11 * | |
12 * The tags were added with information from the FREE document: | |
13 * http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html | |
14 * | |
15 * For the official Exif Format, please refer to: | |
16 * http://www.exif.org | |
17 * http://www.exif.org/specifications.html (PDF spec sheets) | |
18 * | |
19 * Notes: | |
20 * Additional tag formats should be added to the proper | |
21 * location in ExifKnownMarkersList[]. | |
22 * | |
23 * Human readable ouput (that needs additional processing of data to | |
24 * be useable) can be defined by adding a key to ExifFormattedList[], | |
25 * then handling that tag in the function exif_get_formatted_by_key(). | |
26 * The human readable formatted keys must begin with the character 'f'. | |
27 * | |
28 * Unsupported at this time: | |
29 * IFD1 (thumbnail) | |
30 * MakerNote | |
31 * | |
32 * TODO: | |
33 * Convert data to useable form in the ??_as_text function for: | |
34 * ComponentsConfiguration | |
35 * UserComment (convert this to UTF-8?) | |
1052 | 36 * Add support for marker tag 0x0000 |
9 | 37 * |
38 | |
39 This program is free software; you can redistribute it and/or modify | |
40 it under the terms of the GNU General Public License as published by | |
41 the Free Software Foundation; either version 2 of the License, or | |
42 (at your option) any later version. | |
43 | |
44 This program is distributed in the hope that it will be useful, | |
45 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
46 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
47 GNU General Public License for more details. | |
48 | |
49 You should have received a copy of the GNU General Public License | |
50 along with this program; if not, write to the Free Software | |
51 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
52 */ | |
53 | |
54 #ifdef HAVE_CONFIG_H | |
55 # include "config.h" | |
56 #endif | |
57 | |
177 | 58 #ifndef HAVE_EXIV2 |
59 | |
9 | 60 #include <stdio.h> |
61 #include <string.h> | |
62 #include <fcntl.h> | |
63 #include <unistd.h> | |
64 #include <sys/types.h> | |
65 #include <sys/stat.h> | |
66 #include <sys/mman.h> | |
67 #include <math.h> | |
442 | 68 |
9 | 69 #include <glib.h> |
70 | |
71 #include "intl.h" | |
72 | |
281 | 73 #include "main.h" |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
74 #include "exif-int.h" |
9 | 75 |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
76 #include "format_raw.h" |
9 | 77 #include "ui_fileops.h" |
78 | |
79 | |
80 /* | |
81 *----------------------------------------------------------------------------- | |
82 * Tag formats | |
83 *----------------------------------------------------------------------------- | |
84 */ | |
85 | |
86 ExifFormatAttrib ExifFormatList[] = { | |
87 { EXIF_FORMAT_UNKNOWN, 1, "unknown", "unknown" }, | |
88 { EXIF_FORMAT_BYTE_UNSIGNED, 1, "ubyte", "unsigned byte" }, | |
89 { EXIF_FORMAT_STRING, 1, "string", "string" }, | |
90 { EXIF_FORMAT_SHORT_UNSIGNED, 2, "ushort", "unsigned short" }, | |
91 { EXIF_FORMAT_LONG_UNSIGNED, 4, "ulong", "unsigned long" }, | |
92 { EXIF_FORMAT_RATIONAL_UNSIGNED,8, "urational", "unsigned rational" }, | |
93 { EXIF_FORMAT_BYTE, 1, "byte", "byte" }, | |
94 { EXIF_FORMAT_UNDEFINED, 1, "undefined", "undefined" }, | |
95 { EXIF_FORMAT_SHORT, 2, "sshort", "signed short" }, | |
96 { EXIF_FORMAT_LONG, 4, "slong", "signed long" }, | |
97 { EXIF_FORMAT_RATIONAL, 8, "srational", "signed rational" }, | |
98 { EXIF_FORMAT_FLOAT, 4, "float", "float" }, | |
99 { EXIF_FORMAT_DOUBLE, 8, "double", "double" }, | |
749
f606e8962329
Silent few warnings that appeared when using --disable-exiv2 configure option.
zas_
parents:
673
diff
changeset
|
100 { -1, 0, NULL, NULL } |
9 | 101 }; |
102 | |
103 /* tags that are special, or need special treatment */ | |
104 #define TAG_EXIFOFFSET 0x8769 | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
105 #define TAG_EXIFMAKERNOTE 0x927c |
1052 | 106 #define TAG_GPSOFFSET 0x8825 |
9 | 107 |
108 | |
109 /* | |
110 *----------------------------------------------------------------------------- | |
111 * Data | |
112 *----------------------------------------------------------------------------- | |
113 */ | |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
114 static ExifTextList ExifCompressionList[] = { |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
115 { 1, "Uncompressed" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
116 { 2, "CCITT 1D" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
117 { 3, "T4/Group 3 Fax" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
118 { 4, "T6/Group 4 Fax" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
119 { 5, "LZW" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
120 { 6, "JPEG (old style)" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
121 { 7, "JPEG" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
122 { 8, "Adobe Deflate" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
123 { 9, "JBIG B&W" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
124 { 10, "JBIG Color" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
125 { 32766, "Next" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
126 { 32771, "CCIRLEW" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
127 { 32773, "PackBits" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
128 { 32809, "ThunderScan" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
129 { 32895, "IT8CTPAD" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
130 { 32896, "IT8LW" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
131 { 32897, "IT8MP" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
132 { 32898, "IT8BL" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
133 { 32908, "PixasFilm" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
134 { 32909, "PixasLog" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
135 { 32946, "Deflate" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
136 { 32947, "DCS" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
137 { 34661, "JBIG" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
138 { 34676, "SGILog" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
139 { 34677, "SGILog24" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
140 { 34712, "JPEF 2000" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
141 { 34713, "Nikon NEF Compressed" }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
142 EXIF_TEXT_LIST_END |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
143 }; |
9 | 144 |
145 static ExifTextList ExifOrientationList[] = { | |
146 { EXIF_ORIENTATION_UNKNOWN, N_("unknown") }, | |
147 { EXIF_ORIENTATION_TOP_LEFT, N_("top left") }, | |
148 { EXIF_ORIENTATION_TOP_RIGHT, N_("top right") }, | |
149 { EXIF_ORIENTATION_BOTTOM_RIGHT,N_("bottom right") }, | |
150 { EXIF_ORIENTATION_BOTTOM_LEFT, N_("bottom left") }, | |
151 { EXIF_ORIENTATION_LEFT_TOP, N_("left top") }, | |
152 { EXIF_ORIENTATION_RIGHT_TOP, N_("right top") }, | |
153 { EXIF_ORIENTATION_RIGHT_BOTTOM,N_("right bottom") }, | |
154 { EXIF_ORIENTATION_LEFT_BOTTOM, N_("left bottom") }, | |
155 EXIF_TEXT_LIST_END | |
156 }; | |
157 | |
158 static ExifTextList ExifUnitList[] = { | |
159 { EXIF_UNIT_UNKNOWN, N_("unknown") }, | |
160 { EXIF_UNIT_NOUNIT, "" }, | |
161 { EXIF_UNIT_INCH, N_("inch") }, | |
162 { EXIF_UNIT_CENTIMETER, N_("centimeter") }, | |
163 EXIF_TEXT_LIST_END | |
164 }; | |
165 | |
166 static ExifTextList ExifYCbCrPosList[] = { | |
167 { 1, "center" }, | |
168 { 2, "datum" }, | |
169 EXIF_TEXT_LIST_END | |
170 }; | |
171 | |
172 static ExifTextList ExifMeteringModeList[] = { | |
173 { 0, N_("unknown") }, | |
174 { 1, N_("average") }, | |
175 { 2, N_("center weighted") }, | |
176 { 3, N_("spot") }, | |
177 { 4, N_("multi-spot") }, | |
178 { 5, N_("multi-segment") }, | |
179 { 6, N_("partial") }, | |
180 { 255, N_("other") }, | |
181 EXIF_TEXT_LIST_END | |
182 }; | |
183 | |
184 static ExifTextList ExifExposureProgramList[] = { | |
185 { 0, N_("not defined") }, | |
186 { 1, N_("manual") }, | |
187 { 2, N_("normal") }, | |
188 { 3, N_("aperture") }, | |
189 { 4, N_("shutter") }, | |
190 { 5, N_("creative") }, | |
191 { 6, N_("action") }, | |
192 { 7, N_("portrait") }, | |
193 { 8, N_("landscape") }, | |
194 EXIF_TEXT_LIST_END | |
195 }; | |
196 | |
197 static ExifTextList ExifLightSourceList[] = { | |
198 { 0, N_("unknown") }, | |
199 { 1, N_("daylight") }, | |
200 { 2, N_("fluorescent") }, | |
201 { 3, N_("tungsten (incandescent)") }, | |
202 { 4, N_("flash") }, | |
262 | 203 { 9, N_("fine weather") }, |
204 { 10, N_("cloudy weather") }, | |
205 { 11, N_("shade") }, | |
206 { 12, N_("daylight fluorescent") }, | |
207 { 13, N_("day white fluorescent") }, | |
208 { 14, N_("cool white fluorescent") }, | |
293
faeda3c7c8f8
Fix a typo: "while fluorescent" -> "white fluorescent"
zas_
parents:
281
diff
changeset
|
209 { 15, N_("white fluorescent") }, |
262 | 210 { 17, N_("standard light A") }, |
211 { 18, N_("standard light B") }, | |
212 { 19, N_("standard light C") }, | |
213 { 20, N_("D55") }, | |
214 { 21, N_("D65") }, | |
215 { 22, N_("D75") }, | |
216 { 23, N_("D50") }, | |
217 { 24, N_("ISO studio tungsten") }, | |
9 | 218 { 255, N_("other") }, |
219 EXIF_TEXT_LIST_END | |
220 }; | |
221 | |
222 static ExifTextList ExifFlashList[] = { | |
223 { 0, N_("no") }, | |
224 { 1, N_("yes") }, | |
225 { 5, N_("yes, not detected by strobe") }, | |
226 { 7, N_("yes, detected by strobe") }, | |
227 EXIF_TEXT_LIST_END | |
228 }; | |
229 | |
230 static ExifTextList ExifColorSpaceList[] = { | |
262 | 231 { 1, N_("sRGB") }, |
232 { 65535,N_("uncalibrated") }, | |
9 | 233 EXIF_TEXT_LIST_END |
234 }; | |
235 | |
236 static ExifTextList ExifSensorList[] = { | |
262 | 237 { 1, N_("not defined") }, |
238 { 2, N_("1 chip color area") }, | |
239 { 2, N_("2 chip color area") }, | |
240 { 4, N_("3 chip color area") }, | |
241 { 5, N_("color sequential area") }, | |
242 { 7, N_("trilinear") }, | |
243 { 8, N_("color sequential linear") }, | |
9 | 244 EXIF_TEXT_LIST_END |
245 }; | |
246 | |
247 static ExifTextList ExifSourceList[] = { | |
262 | 248 { 3, N_("digital still camera") }, |
9 | 249 EXIF_TEXT_LIST_END |
250 }; | |
251 | |
252 static ExifTextList ExifSceneList[] = { | |
262 | 253 { 1, N_("direct photo") }, |
9 | 254 EXIF_TEXT_LIST_END |
255 }; | |
256 | |
257 static ExifTextList ExifCustRenderList[] = { | |
262 | 258 { 0, N_("normal") }, |
259 { 1, N_("custom") }, | |
9 | 260 EXIF_TEXT_LIST_END |
261 }; | |
262 | |
263 static ExifTextList ExifExposureModeList[] = { | |
262 | 264 { 0, N_("auto") }, |
265 { 1, N_("manual") }, | |
266 { 2, N_("auto bracket") }, | |
9 | 267 EXIF_TEXT_LIST_END |
268 }; | |
269 | |
270 static ExifTextList ExifWhiteBalanceList[] = { | |
262 | 271 { 0, N_("auto") }, |
272 { 1, N_("manual") }, | |
9 | 273 EXIF_TEXT_LIST_END |
274 }; | |
275 | |
276 static ExifTextList ExifSceneCaptureList[] = { | |
262 | 277 { 0, N_("standard") }, |
278 { 1, N_("landscape") }, | |
279 { 2, N_("portrait") }, | |
280 { 3, N_("night scene") }, | |
9 | 281 EXIF_TEXT_LIST_END |
282 }; | |
283 | |
284 static ExifTextList ExifGainControlList[] = { | |
262 | 285 { 0, N_("none") }, |
286 { 1, N_("low gain up") }, | |
287 { 2, N_("high gain up") }, | |
288 { 3, N_("low gain down") }, | |
289 { 4, N_("high gain down") }, | |
9 | 290 EXIF_TEXT_LIST_END |
291 }; | |
292 | |
293 static ExifTextList ExifContrastList[] = { | |
262 | 294 { 0, N_("normal") }, |
295 { 1, N_("soft") }, | |
296 { 2, N_("hard") }, | |
9 | 297 EXIF_TEXT_LIST_END |
298 }; | |
299 | |
300 static ExifTextList ExifSaturationList[] = { | |
262 | 301 { 0, N_("normal") }, |
302 { 1, N_("low") }, | |
303 { 2, N_("high") }, | |
9 | 304 EXIF_TEXT_LIST_END |
305 }; | |
306 | |
307 static ExifTextList ExifSharpnessList[] = { | |
262 | 308 { 0, N_("normal") }, |
309 { 1, N_("soft") }, | |
310 { 2, N_("hard") }, | |
9 | 311 EXIF_TEXT_LIST_END |
312 }; | |
313 | |
314 static ExifTextList ExifSubjectRangeList[] = { | |
262 | 315 { 0, N_("unknown") }, |
316 { 1, N_("macro") }, | |
317 { 2, N_("close") }, | |
318 { 3, N_("distant") }, | |
9 | 319 EXIF_TEXT_LIST_END |
320 }; | |
321 | |
442 | 322 /* |
323 Tag names should match to exiv2 keys, http://www.exiv2.org/metadata.html | |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
324 Tags that don't match are not supported by exiv2 and should not be used anywhere in the code |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
325 */ |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
326 |
9 | 327 ExifMarker ExifKnownMarkersList[] = { |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
328 { 0x0100, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Image.ImageWidth", N_("Image Width"), NULL }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
329 { 0x0101, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Image.ImageLength", N_("Image Height"), NULL }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
330 { 0x0102, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.BitsPerSample", N_("Bits per Sample/Pixel"), NULL }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
331 { 0x0103, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.Compression", N_("Compression"), ExifCompressionList }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
332 { 0x010e, EXIF_FORMAT_STRING, -1, "Exif.Image.ImageDescription", N_("Image description"), NULL }, |
262 | 333 { 0x010f, EXIF_FORMAT_STRING, -1, "Exif.Image.Make", N_("Camera make"), NULL }, |
334 { 0x0110, EXIF_FORMAT_STRING, -1, "Exif.Image.Model", N_("Camera model"), NULL }, | |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
335 { 0x0112, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.Orientation", N_("Orientation"), ExifOrientationList }, |
262 | 336 { 0x011a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.XResolution", N_("X resolution"), NULL }, |
337 { 0x011b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.YResolution", N_("Y Resolution"), NULL }, | |
338 { 0x0128, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.ResolutionUnit", N_("Resolution units"), ExifUnitList }, | |
339 { 0x0131, EXIF_FORMAT_STRING, -1, "Exif.Image.Software", N_("Firmware"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
340 { 0x0132, EXIF_FORMAT_STRING, 20, "Exif.Image.DateTime", N_("Date"), NULL }, |
262 | 341 { 0x013e, EXIF_FORMAT_RATIONAL_UNSIGNED, 2, "Exif.Image.WhitePoint", N_("White point"), NULL }, |
342 { 0x013f, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "Exif.Image.PrimaryChromaticities",N_("Primary chromaticities"), NULL }, | |
343 { 0x0211, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.Image.YCbCrCoefficients", N_("YCbCy coefficients"), NULL }, | |
344 { 0x0213, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Image.YCbCrPositioning", N_("YCbCr positioning"), ExifYCbCrPosList }, | |
345 { 0x0214, EXIF_FORMAT_RATIONAL_UNSIGNED, 6, "Exif.Image.ReferenceBlackWhite",N_("Black white reference"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
346 { 0x8298, EXIF_FORMAT_STRING, -1, "Exif.Image.Copyright", N_("Copyright"), NULL }, |
262 | 347 { 0x8769, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Image.ExifTag", N_("SubIFD Exif offset"), NULL }, |
9 | 348 /* subIFD follows */ |
262 | 349 { 0x829a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureTime", N_("Exposure time (seconds)"), NULL }, |
350 { 0x829d, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FNumber", N_("FNumber"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
351 { 0x8822, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ExposureProgram", N_("Exposure program"), ExifExposureProgramList }, |
262 | 352 { 0x8824, EXIF_FORMAT_STRING, -1, "Exif.Photo.SpectralSensitivity",N_("Spectral Sensitivity"), NULL }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
353 { 0x8827, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.ISOSpeedRatings", N_("ISO sensitivity"), NULL }, |
262 | 354 { 0x8828, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.OECF", N_("Optoelectric conversion factor"), NULL }, |
355 { 0x9000, EXIF_FORMAT_UNDEFINED, 4, "Exif.Photo.ExifVersion", N_("Exif version"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
356 { 0x9003, EXIF_FORMAT_STRING, 20, "Exif.Photo.DateTimeOriginal", N_("Date original"), NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
357 { 0x9004, EXIF_FORMAT_STRING, 20, "Exif.Photo.DateTimeDigitized", N_("Date digitized"), NULL }, |
262 | 358 { 0x9101, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.ComponentsConfiguration",N_("Pixel format"), NULL }, |
359 { 0x9102, EXIF_FORMAT_RATIONAL_UNSIGNED,1, "Exif.Photo.CompressedBitsPerPixel",N_("Compression ratio"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
360 { 0x9201, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.ShutterSpeedValue", N_("Shutter speed"), NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
361 { 0x9202, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ApertureValue", N_("Aperture"), NULL }, |
262 | 362 { 0x9203, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.BrightnessValue", N_("Brightness"), NULL }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
363 { 0x9204, EXIF_FORMAT_RATIONAL, 1, "Exif.Photo.ExposureBiasValue", N_("Exposure bias"), NULL }, |
262 | 364 { 0x9205, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.MaxApertureValue", N_("Maximum aperture"), NULL }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
365 { 0x9206, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.SubjectDistance", N_("Subject distance"), NULL }, |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
366 { 0x9207, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.MeteringMode", N_("Metering mode"), ExifMeteringModeList }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
367 { 0x9208, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.LightSource", N_("Light source"), ExifLightSourceList }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
368 { 0x9209, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Flash", N_("Flash"), ExifFlashList }, |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
369 { 0x920a, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalLength", N_("Focal length"), NULL }, |
262 | 370 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.SubjectArea", N_("Subject area"), NULL }, |
371 { 0x927c, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.MakerNote", N_("MakerNote"), NULL }, | |
372 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.UserComment", N_("UserComment"), NULL }, | |
373 { 0x9290, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTime", N_("Subsecond time"), NULL }, | |
374 { 0x9291, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTimeOriginal",N_("Subsecond time original"), NULL }, | |
375 { 0x9292, EXIF_FORMAT_STRING, -1, "Exif.Photo.SubSecTimeDigitized",N_("Subsecond time digitized"), NULL }, | |
376 { 0xa000, EXIF_FORMAT_UNDEFINED, 4, "Exif.Photo.FlashpixVersion", N_("FlashPix version"), NULL }, | |
377 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ColorSpace", N_("Colorspace"), ExifColorSpaceList }, | |
9 | 378 /* ExifImageWidth, ExifImageHeight can also be unsigned short */ |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
379 { 0xa002, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Photo.PixelXDimension", N_("Width"), NULL }, |
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
380 { 0xa003, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Photo.PixelYDimension", N_("Height"), NULL }, |
262 | 381 { 0xa004, EXIF_FORMAT_STRING, -1, "Exif.Photo.RelatedSoundFile", N_("Audio data"), NULL }, |
382 { 0xa005, EXIF_FORMAT_LONG_UNSIGNED, 1, "ExifInteroperabilityOffset", N_("ExifR98 extension"), NULL }, | |
383 { 0xa20b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FlashEnergy", N_("Flash strength"), NULL }, | |
384 { 0xa20c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.SpatialFrequencyResponse",N_("Spatial frequency response"), NULL }, | |
385 { 0xa20e, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalPlaneXResolution", N_("X Pixel density"), NULL }, | |
386 { 0xa20f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FocalPlaneYResolution", N_("Y Pixel density"), NULL }, | |
387 { 0xa210, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.FocalPlaneResolutionUnit", N_("Pixel density units"), ExifUnitList }, | |
388 { 0x0214, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Exif.Photo.SubjectLocation", N_("Subject location"), NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
389 { 0xa215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureIndex", N_("ISO sensitivity"), NULL }, |
262 | 390 { 0xa217, EXIF_FORMAT_SHORT_UNSIGNED, -1, "Exif.Photo.SensingMethod", N_("Sensor type"), ExifSensorList }, |
391 { 0xa300, EXIF_FORMAT_UNDEFINED, 1, "Exif.Photo.FileSource", N_("Source type"), ExifSourceList }, | |
392 { 0xa301, EXIF_FORMAT_UNDEFINED, 1, "Exif.Photo.SceneType", N_("Scene type"), ExifSceneList }, | |
393 { 0xa302, EXIF_FORMAT_UNDEFINED, -1, "Exif.Image.CFAPattern", N_("Color filter array pattern"), NULL }, | |
9 | 394 /* tags a4xx were added for Exif 2.2 (not just these - some above, as well) */ |
262 | 395 { 0xa401, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.CustomRendered", N_("Render process"), ExifCustRenderList }, |
396 { 0xa402, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.ExposureMode", N_("Exposure mode"), ExifExposureModeList }, | |
397 { 0xa403, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.WhiteBalance", N_("White balance"), ExifWhiteBalanceList }, | |
398 { 0xa404, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.DigitalZoomRatio", N_("Digital zoom ratio"), NULL }, | |
399 { 0xa405, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.FocalLengthIn35mmFilm",N_("Focal length (35mm)"), NULL }, | |
400 { 0xa406, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.SceneCaptureType", N_("Scene capture type"), ExifSceneCaptureList }, | |
401 { 0xa407, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.GainControl", N_("Gain control"), ExifGainControlList }, | |
402 { 0xa408, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Contrast", N_("Contrast"), ExifContrastList }, | |
403 { 0xa409, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Saturation", N_("Saturation"), ExifSaturationList }, | |
404 { 0xa40a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.Sharpness", N_("Sharpness"), ExifSharpnessList }, | |
405 { 0xa40b, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.DeviceSettingDescription",N_("Device setting"), NULL }, | |
406 { 0xa40c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Exif.Photo.SubjectDistanceRange",N_("Subject range"), ExifSubjectRangeList }, | |
407 { 0xa420, EXIF_FORMAT_STRING, -1, "Exif.Photo.ImageUniqueID", N_("Image serial number"), NULL }, | |
9 | 408 /* place known, but undocumented or lesser used tags here */ |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
409 { 0x00fe, EXIF_FORMAT_LONG_UNSIGNED, 1, "Exif.Image.NewSubfileType", NULL, NULL }, |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
410 { 0x00ff, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SubfileType", NULL, NULL }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
411 { 0x012d, EXIF_FORMAT_SHORT_UNSIGNED, 3, "Exif.Image.TransferFunction", NULL, NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
412 { 0x013b, EXIF_FORMAT_STRING, -1, "Exif.Image.Artist", "Artist", NULL }, |
9 | 413 { 0x013d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Predictor", NULL, NULL }, |
414 { 0x0142, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileWidth", NULL, NULL }, | |
415 { 0x0143, EXIF_FORMAT_SHORT_UNSIGNED, 1, "TileLength", NULL, NULL }, | |
416 { 0x0144, EXIF_FORMAT_LONG_UNSIGNED, -1, "TileOffsets", NULL, NULL }, | |
417 { 0x0145, EXIF_FORMAT_SHORT_UNSIGNED, -1, "TileByteCounts", NULL, NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
418 { 0x014a, EXIF_FORMAT_LONG_UNSIGNED, -1, "Exif.Image.SubIFDs", NULL, NULL }, |
9 | 419 { 0x015b, EXIF_FORMAT_UNDEFINED, -1, "JPEGTables", NULL, NULL }, |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
420 { 0x828d, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Exif.Image.CFARepeatPatternDim", NULL, NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
421 { 0x828e, EXIF_FORMAT_BYTE_UNSIGNED, -1, "Exif.Image.CFAPattern", NULL, NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
422 { 0x828f, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Image.BatteryLevel", NULL, NULL }, |
9 | 423 { 0x83bb, EXIF_FORMAT_LONG_UNSIGNED, -1, "IPTC/NAA", NULL, NULL }, |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
424 { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "Exif.Image.InterColorProfile", NULL, NULL }, |
9 | 425 { 0x8825, EXIF_FORMAT_LONG_UNSIGNED, 1, "GPSInfo", "SubIFD GPS offset", NULL }, |
426 { 0x8829, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Interlace", NULL, NULL }, | |
427 { 0x882a, EXIF_FORMAT_SHORT, 1, "TimeZoneOffset", NULL, NULL }, | |
428 { 0x882b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "SelfTimerMode", NULL, NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
429 { 0x920b, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.FlashEnergy", NULL, NULL }, |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
430 { 0x920c, EXIF_FORMAT_UNDEFINED, -1, "Exif.Photo.SpatialFrequencyResponse", NULL, NULL }, |
9 | 431 { 0x920d, EXIF_FORMAT_UNDEFINED, -1, "Noise", NULL, NULL }, |
432 { 0x9211, EXIF_FORMAT_LONG_UNSIGNED, 1, "ImageNumber", NULL, NULL }, | |
433 { 0x9212, EXIF_FORMAT_STRING, 1, "SecurityClassification", NULL, NULL }, | |
434 { 0x9213, EXIF_FORMAT_STRING, -1, "ImageHistory", NULL, NULL }, | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
435 { 0x9215, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.Photo.ExposureIndex", NULL, NULL }, |
9 | 436 { 0x9216, EXIF_FORMAT_BYTE_UNSIGNED, 4, "TIFF/EPStandardID", NULL, NULL }, |
437 | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
438 EXIF_MARKER_LIST_END |
9 | 439 }; |
440 | |
1052 | 441 ExifMarker ExifKnownGPSInfoMarkersList[] = { |
442 /* The following do not work at the moment as the tag value 0x0000 has a | |
443 * special meaning. */ | |
444 /* { 0x0000, EXIF_FORMAT_BYTE, -1, "Exif.GPSInfo.GPSVersionID", NULL, NULL }, */ | |
445 { 0x0001, EXIF_FORMAT_STRING, 2, "Exif.GPSInfo.GPSLatitudeRef", NULL, NULL }, | |
446 { 0x0002, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.GPSInfo.GPSLatitude", NULL, NULL }, | |
447 { 0x0003, EXIF_FORMAT_STRING, 2, "Exif.GPSInfo.GPSLongitudeRef", NULL, NULL }, | |
448 { 0x0004, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.GPSInfo.GPSLongitude", NULL, NULL }, | |
449 { 0x0005, EXIF_FORMAT_BYTE_UNSIGNED, 1, "Exif.GPSInfo.GPSAltitudeRef", NULL, NULL }, | |
450 { 0x0006, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Exif.GPSInfo.GPSAltitude", NULL, NULL }, | |
451 { 0x0007, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.GPSInfo.GPSTimeStamp", NULL, NULL }, | |
452 { 0x0008, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSSatellites", NULL, NULL }, | |
453 { 0x0009, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSStatus", NULL, NULL }, | |
454 { 0x000a, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSMeasureMode", NULL, NULL }, | |
455 { 0x000b, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSDOP", NULL, NULL }, | |
456 { 0x000c, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSSpeedRef", NULL, NULL }, | |
457 { 0x000d, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSSpeed", NULL, NULL }, | |
458 { 0x000e, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSTrackRef", NULL, NULL }, | |
459 { 0x000f, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSTrack", NULL, NULL }, | |
460 { 0x0010, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSImgDirectionRef", NULL, NULL }, | |
461 { 0x0011, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSImgDirection", NULL, NULL }, | |
462 { 0x0012, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSMapDatum", NULL, NULL }, | |
463 { 0x0013, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSDestLatitudeRef", NULL, NULL }, | |
464 { 0x0014, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSDestLatitude", NULL, NULL }, | |
465 { 0x0015, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSDestLongitudeRef", NULL, NULL }, | |
466 { 0x0016, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSDestLongitude", NULL, NULL }, | |
467 { 0x0017, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSDestBearingRef", NULL, NULL }, | |
468 { 0x0018, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSDestBearing", NULL, NULL }, | |
469 { 0x0019, EXIF_FORMAT_STRING, -1, "Exif.GPSInfo.GPSDestDistanceRef", NULL, NULL }, | |
470 { 0x001a, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "Exif.GPSInfo.GPSDestDistance", NULL, NULL }, | |
471 { 0x001b, EXIF_FORMAT_UNDEFINED, -1, "Exif.GPSInfo.GPSProcessingMethod", NULL, NULL }, | |
472 { 0x001c, EXIF_FORMAT_UNDEFINED, -1, "Exif.GPSInfo.GPSAreaInformation", NULL, NULL }, | |
473 { 0x001d, EXIF_FORMAT_RATIONAL_UNSIGNED, 3, "Exif.GPSInfo.GPSDateStamp", NULL, NULL }, | |
474 { 0x001e, EXIF_FORMAT_SHORT, -1, "Exif.GPSInfo.GPSDifferential", NULL, NULL }, | |
475 | |
476 EXIF_MARKER_LIST_END | |
477 }; | |
478 | |
9 | 479 ExifMarker ExifUnknownMarkersList[] = { |
480 { 0x0000, EXIF_FORMAT_UNKNOWN, 0, "unknown", NULL, NULL }, | |
481 { 0x0000, EXIF_FORMAT_BYTE_UNSIGNED, -1, "unknown", NULL, NULL }, | |
482 { 0x0000, EXIF_FORMAT_STRING, -1, "unknown", NULL, NULL }, | |
483 { 0x0000, EXIF_FORMAT_SHORT_UNSIGNED, -1, "unknown", NULL, NULL }, | |
484 { 0x0000, EXIF_FORMAT_LONG_UNSIGNED, -1, "unknown", NULL, NULL }, | |
485 { 0x0000, EXIF_FORMAT_RATIONAL_UNSIGNED, -1, "unknown", NULL, NULL }, | |
486 { 0x0000, EXIF_FORMAT_BYTE, -1, "unknown", NULL, NULL }, | |
487 { 0x0000, EXIF_FORMAT_UNDEFINED, -1, "unknown", NULL, NULL }, | |
488 { 0x0000, EXIF_FORMAT_SHORT, -1, "unknown", NULL, NULL }, | |
489 { 0x0000, EXIF_FORMAT_LONG, -1, "unknown", NULL, NULL }, | |
490 { 0x0000, EXIF_FORMAT_RATIONAL, -1, "unknown", NULL, NULL }, | |
491 { 0x0000, EXIF_FORMAT_FLOAT, -1, "unknown", NULL, NULL }, | |
492 { 0x0000, EXIF_FORMAT_DOUBLE, -1, "unknown", NULL, NULL }, | |
493 }; | |
494 | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
495 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list); |
9 | 496 |
497 /* | |
498 *----------------------------------------------------------------------------- | |
499 * ExifItem | |
500 *----------------------------------------------------------------------------- | |
501 */ | |
502 | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
503 ExifItem *exif_item_new(ExifFormatType format, guint tag, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
504 guint elements, const ExifMarker *marker) |
9 | 505 { |
506 ExifItem *item; | |
507 | |
508 item = g_new0(ExifItem, 1); | |
509 item->format = format; | |
510 item->tag = tag; | |
511 item->marker = marker; | |
512 item->elements = elements; | |
513 item->data = NULL; | |
514 item->data_len = 0; | |
515 | |
516 switch (format) | |
517 { | |
518 case EXIF_FORMAT_UNKNOWN: | |
519 /* unknown, data is NULL */ | |
520 return item; | |
521 break; | |
522 case EXIF_FORMAT_BYTE_UNSIGNED: | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
523 item->data_len = sizeof(gchar) * elements; |
9 | 524 break; |
525 case EXIF_FORMAT_STRING: | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
526 item->data_len = sizeof(gchar) * elements; |
9 | 527 break; |
528 case EXIF_FORMAT_SHORT_UNSIGNED: | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
529 item->data_len = sizeof(guint16) * elements; |
9 | 530 break; |
531 case EXIF_FORMAT_LONG_UNSIGNED: | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
532 item->data_len = sizeof(guint32) * elements; |
9 | 533 break; |
534 case EXIF_FORMAT_RATIONAL_UNSIGNED: | |
535 item->data_len = sizeof(ExifRational) * elements; | |
536 break; | |
537 case EXIF_FORMAT_BYTE: | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
538 item->data_len = sizeof(gchar) * elements; |
9 | 539 break; |
540 case EXIF_FORMAT_UNDEFINED: | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
541 item->data_len = sizeof(gchar) * elements; |
9 | 542 break; |
543 case EXIF_FORMAT_SHORT: | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
544 item->data_len = sizeof(gint16) * elements; |
9 | 545 break; |
546 case EXIF_FORMAT_LONG: | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
547 item->data_len = sizeof(gint32) * elements; |
9 | 548 break; |
549 case EXIF_FORMAT_RATIONAL: | |
550 item->data_len = sizeof(ExifRational) * elements; | |
551 break; | |
552 case EXIF_FORMAT_FLOAT: | |
553 item->data_len = sizeof(float) * elements; | |
554 break; | |
555 case EXIF_FORMAT_DOUBLE: | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
556 item->data_len = sizeof(gdouble) * elements; |
9 | 557 break; |
558 } | |
559 | |
560 item->data = g_malloc0(item->data_len); | |
561 | |
562 return item; | |
563 } | |
564 | |
565 static void exif_item_free(ExifItem *item) | |
566 { | |
567 if (!item) return; | |
568 | |
569 g_free(item->data); | |
570 g_free(item); | |
571 } | |
572 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
573 gchar *exif_item_get_tag_name(ExifItem *item) |
9 | 574 { |
575 if (!item || !item->marker) return NULL; | |
185 | 576 return g_strdup(item->marker->key); |
9 | 577 } |
578 | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
579 guint exif_item_get_tag_id(ExifItem *item) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
580 { |
242
59eac2063093
Fix a segfault occuring when using --without-exiv2 and
zas_
parents:
222
diff
changeset
|
581 if (!item) return 0; |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
582 return item->tag; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
583 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
584 |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
585 guint exif_item_get_elements(ExifItem *item) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
586 { |
242
59eac2063093
Fix a segfault occuring when using --without-exiv2 and
zas_
parents:
222
diff
changeset
|
587 if (!item) return 0; |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
588 return item->elements; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
589 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
590 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
591 gchar *exif_item_get_data(ExifItem *item, guint *data_len) |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
592 { |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
593 if (data_len) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
594 *data_len = item->data_len; |
414
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
293
diff
changeset
|
595 return g_memdup(item->data, item->data_len); |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
596 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
597 |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
598 guint exif_item_get_format_id(ExifItem *item) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
599 { |
242
59eac2063093
Fix a segfault occuring when using --without-exiv2 and
zas_
parents:
222
diff
changeset
|
600 if (!item) return EXIF_FORMAT_UNKNOWN; |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
601 return item->format; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
602 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
603 |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
604 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
605 gchar *exif_item_get_description(ExifItem *item) |
9 | 606 { |
607 if (!item || !item->marker) return NULL; | |
182 | 608 return g_strdup(_(item->marker->description)); |
9 | 609 } |
610 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
611 const gchar *exif_item_get_format_name(ExifItem *item, gint brief) |
9 | 612 { |
442 | 613 if (!item || !item->marker) return NULL; |
9 | 614 return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description; |
615 } | |
616 | |
617 static GString *string_append_raw_bytes(GString *string, gpointer data, gint ne) | |
618 { | |
619 gint i; | |
620 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
621 for (i = 0 ; i < ne; i++) |
9 | 622 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
623 guchar c = ((gchar *)data)[i]; |
9 | 624 if (c < 32 || c > 127) c = '.'; |
625 g_string_append_printf(string, "%c", c); | |
626 } | |
627 string = g_string_append(string, " : "); | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
628 for (i = 0 ; i < ne; i++) |
9 | 629 { |
630 const gchar *spacer; | |
631 if (i > 0) | |
632 { | |
633 if (i%8 == 0) | |
634 { | |
635 spacer = " - "; | |
636 } | |
637 else | |
638 { | |
639 spacer = " "; | |
640 } | |
641 } | |
642 else | |
643 { | |
644 spacer = ""; | |
645 } | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
646 g_string_append_printf(string, "%s%02x", spacer, ((gchar *)data)[i]); |
9 | 647 } |
648 | |
649 return string; | |
650 } | |
651 | |
182 | 652 |
57
a8c9992320f4
Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
55
diff
changeset
|
653 gchar *exif_text_list_find_value(ExifTextList *list, guint value) |
9 | 654 { |
655 gchar *result = NULL; | |
656 gint i; | |
657 | |
658 i = 0; | |
659 while (!result && list[i].value >= 0) | |
660 { | |
749
f606e8962329
Silent few warnings that appeared when using --disable-exiv2 configure option.
zas_
parents:
673
diff
changeset
|
661 if (value == (guint) list[i].value) result = g_strdup(_(list[i].description)); |
9 | 662 i++; |
663 } | |
664 if (!result) result = g_strdup_printf("%d (%s)", value, _("unknown")); | |
665 | |
666 return result; | |
667 } | |
668 | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
669 |
9 | 670 /* |
671 *------------------------------------------------------------------- | |
107 | 672 * byte order utils |
9 | 673 *------------------------------------------------------------------- |
674 */ | |
675 | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
676 /* note: the align_buf is used to avoid alignment issues (on sparc) */ |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
677 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
678 guint16 exif_byte_get_int16(guchar *f, ExifByteOrder bo) |
9 | 679 { |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
680 guint16 align_buf; |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
681 |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
682 memcpy(&align_buf, f, sizeof(guint16)); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
683 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
684 if (bo == EXIF_BYTE_ORDER_INTEL) |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
685 return GUINT16_FROM_LE(align_buf); |
9 | 686 else |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
687 return GUINT16_FROM_BE(align_buf); |
9 | 688 } |
689 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
690 guint32 exif_byte_get_int32(guchar *f, ExifByteOrder bo) |
9 | 691 { |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
692 guint32 align_buf; |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
693 |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
694 memcpy(&align_buf, f, sizeof(guint32)); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
695 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
696 if (bo == EXIF_BYTE_ORDER_INTEL) |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
697 return GUINT32_FROM_LE(align_buf); |
9 | 698 else |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
699 return GUINT32_FROM_BE(align_buf); |
9 | 700 } |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
701 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
702 void exif_byte_put_int16(guchar *f, guint16 n, ExifByteOrder bo) |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
703 { |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
704 guint16 align_buf; |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
705 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
706 if (bo == EXIF_BYTE_ORDER_INTEL) |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
707 { |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
708 align_buf = GUINT16_TO_LE(n); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
709 } |
9 | 710 else |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
711 { |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
712 align_buf = GUINT16_TO_BE(n); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
713 } |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
714 |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
715 memcpy(f, &align_buf, sizeof(guint16)); |
9 | 716 } |
717 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
718 void exif_byte_put_int32(guchar *f, guint32 n, ExifByteOrder bo) |
9 | 719 { |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
720 guint32 align_buf; |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
721 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
722 if (bo == EXIF_BYTE_ORDER_INTEL) |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
723 { |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
724 align_buf = GUINT32_TO_LE(n); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
725 } |
9 | 726 else |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
727 { |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
728 align_buf = GUINT32_TO_BE(n); |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
729 } |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
730 |
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
731 memcpy(f, &align_buf, sizeof(guint32)); |
9 | 732 } |
733 | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
734 |
9 | 735 /* |
736 *------------------------------------------------------------------- | |
737 * IFD utils | |
738 *------------------------------------------------------------------- | |
739 */ | |
740 | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
741 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list) |
9 | 742 { |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
743 gint i = 0; |
9 | 744 |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
745 if (!list) return NULL; |
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
746 |
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
747 while (list[i].tag != 0 && list[i].tag != tag) |
9 | 748 { |
749 i++; | |
750 } | |
751 | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
752 return (list[i].tag == 0 ? NULL : &list[i]); |
9 | 753 } |
754 | |
1002 | 755 static void rational_from_data(ExifRational *r, gpointer src, ExifByteOrder bo) |
9 | 756 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
757 r->num = exif_byte_get_int32(src, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
758 r->den = exif_byte_get_int32(src + sizeof(guint32), bo); |
9 | 759 } |
760 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
761 /* src_format and item->format must be compatible |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
762 * and not overrun src or item->data. |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
763 */ |
1002 | 764 void exif_item_copy_data(ExifItem *item, gpointer src, guint len, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
765 ExifFormatType src_format, ExifByteOrder bo) |
9 | 766 { |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
767 gint bs; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
768 gint ne; |
9 | 769 gpointer dest; |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
770 gint i; |
9 | 771 |
772 bs = ExifFormatList[item->format].size; | |
773 ne = item->elements; | |
774 dest = item->data; | |
775 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
776 if (!dest || |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
777 ExifFormatList[src_format].size * ne > len) |
9 | 778 { |
185 | 779 gchar *tag = exif_item_get_tag_name(item); |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
780 log_printf("exif tag %s data size mismatch\n", tag); |
185 | 781 g_free(tag); |
9 | 782 return; |
783 } | |
784 | |
785 switch (item->format) | |
786 { | |
787 case EXIF_FORMAT_UNKNOWN: | |
788 break; | |
789 case EXIF_FORMAT_BYTE_UNSIGNED: | |
790 case EXIF_FORMAT_BYTE: | |
791 case EXIF_FORMAT_UNDEFINED: | |
792 memcpy(dest, src, len); | |
793 break; | |
794 case EXIF_FORMAT_STRING: | |
795 memcpy(dest, src, len); | |
796 /* string is NULL terminated, make sure this is true */ | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
797 if (((gchar *)dest)[len - 1] != '\0') ((gchar *)dest)[len - 1] = '\0'; |
9 | 798 break; |
799 case EXIF_FORMAT_SHORT_UNSIGNED: | |
800 case EXIF_FORMAT_SHORT: | |
801 for (i = 0; i < ne; i++) | |
802 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
803 ((guint16 *)dest)[i] = exif_byte_get_int16(src + i * bs, bo); |
9 | 804 } |
805 break; | |
806 case EXIF_FORMAT_LONG_UNSIGNED: | |
807 case EXIF_FORMAT_LONG: | |
808 if (src_format == EXIF_FORMAT_SHORT_UNSIGNED || | |
809 src_format == EXIF_FORMAT_SHORT) | |
810 { | |
811 /* a short fits into a long, so allow it */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
812 gint ss; |
9 | 813 |
814 ss = ExifFormatList[src_format].size; | |
815 for (i = 0; i < ne; i++) | |
816 { | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
817 ((gint32 *)dest)[i] = |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
818 (gint32)exif_byte_get_int16(src + i * ss, bo); |
9 | 819 } |
820 } | |
821 else | |
822 { | |
823 for (i = 0; i < ne; i++) | |
824 { | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
825 ((gint32 *)dest)[i] = |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
826 exif_byte_get_int32(src + i * bs, bo); |
9 | 827 } |
828 } | |
829 break; | |
830 case EXIF_FORMAT_RATIONAL_UNSIGNED: | |
831 case EXIF_FORMAT_RATIONAL: | |
832 for (i = 0; i < ne; i++) | |
833 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
834 rational_from_data(&((ExifRational *)dest)[i], src + i * bs, bo); |
9 | 835 } |
836 break; | |
837 case EXIF_FORMAT_FLOAT: | |
838 for (i = 0; i < ne; i++) | |
839 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
840 ((float *)dest)[i] = exif_byte_get_int32(src + i * bs, bo); |
9 | 841 } |
842 break; | |
843 case EXIF_FORMAT_DOUBLE: | |
844 for (i = 0; i < ne; i++) | |
845 { | |
846 ExifRational r; | |
847 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
848 rational_from_data(&r, src + i * bs, bo); |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
849 if (r.den) ((gdouble *)dest)[i] = (gdouble)r.num / r.den; |
9 | 850 } |
851 break; | |
852 } | |
853 } | |
854 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
855 static gint exif_parse_IFD_entry(ExifData *exif, guchar *tiff, guint offset, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
856 guint size, ExifByteOrder bo, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
857 gint level, |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
858 const ExifMarker *list) |
9 | 859 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
860 guint tag; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
861 guint format; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
862 guint count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
863 guint data_val; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
864 guint data_offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
865 guint data_length; |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
866 const ExifMarker *marker; |
9 | 867 ExifItem *item; |
868 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
869 tag = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_TAG, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
870 format = exif_byte_get_int16(tiff + offset + EXIF_TIFD_OFFSET_FORMAT, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
871 count = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_COUNT, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
872 data_val = exif_byte_get_int32(tiff + offset + EXIF_TIFD_OFFSET_DATA, bo); |
9 | 873 |
874 /* Check tag type. If it does not match, either the format is wrong, | |
875 * either it is a unknown tag; so it is not really an error. | |
876 */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
877 marker = exif_marker_from_tag(tag, list); |
9 | 878 if (!marker) |
879 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
880 if (format >= EXIF_FORMAT_COUNT) |
9 | 881 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
882 log_printf("warning: exif tag 0x%4x has invalid format %d\n", tag, format); |
9 | 883 return 0; |
884 } | |
885 /* allow non recognized tags to be displayed */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
886 marker = &ExifUnknownMarkersList[format]; |
9 | 887 } |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
888 if (marker->format != format) |
9 | 889 { |
890 /* Some cameras got mixed up signed/unsigned_rational | |
891 * eg KODAK DC4800 on object_distance tag | |
892 * | |
893 * FIXME: what exactly is this test trying to do? | |
894 * ok, so this test is to allow the case of swapped signed/unsigned mismatch to leak through? | |
895 */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
896 if (!(marker->format == EXIF_FORMAT_RATIONAL_UNSIGNED && format == EXIF_FORMAT_RATIONAL) && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
897 !(marker->format == EXIF_FORMAT_RATIONAL && format == EXIF_FORMAT_RATIONAL_UNSIGNED) && |
9 | 898 /* short fits into a long so allow this mismatch |
899 * as well (some tags allowed to be unsigned short _or_ unsigned long) | |
900 */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
901 !(marker->format == EXIF_FORMAT_LONG_UNSIGNED && format == EXIF_FORMAT_SHORT_UNSIGNED) ) |
9 | 902 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
903 if (format < EXIF_FORMAT_COUNT) |
9 | 904 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
905 log_printf("warning: exif tag %s format mismatch, found %s exif spec requests %s\n", |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
906 marker->key, ExifFormatList[format].short_name, |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
907 ExifFormatList[marker->format].short_name); |
9 | 908 } |
909 else | |
910 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
911 log_printf("warning: exif tag %s format mismatch, found unknown id %d exif spec requests %d (%s)\n", |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
912 marker->key, format, marker->format, |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
913 ExifFormatList[marker->format].short_name); |
9 | 914 } |
915 return 0; | |
916 } | |
917 } | |
918 | |
919 /* Where is the data, is it available? | |
920 */ | |
749
f606e8962329
Silent few warnings that appeared when using --disable-exiv2 configure option.
zas_
parents:
673
diff
changeset
|
921 if (marker->components > 0 && (guint) marker->components != count) |
9 | 922 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
923 log_printf("warning: exif tag %s has %d elements, exif spec requests %d\n", |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
924 marker->key, count, marker->components); |
9 | 925 } |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
926 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
927 data_length = ExifFormatList[marker->format].size * count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
928 if (data_length > 4) |
9 | 929 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
930 data_offset = data_val; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
931 if (size < data_offset + data_length) |
9 | 932 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
933 log_printf("warning: exif tag %s data will overrun end of file, ignored.\n", marker->key); |
9 | 934 return -1; |
935 } | |
936 } | |
937 else | |
938 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
939 data_offset = offset + EXIF_TIFD_OFFSET_DATA; |
9 | 940 } |
941 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
942 item = exif_item_new(marker->format, tag, count, marker); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
943 exif_item_copy_data(item, tiff + data_offset, data_length, format, bo); |
9 | 944 exif->items = g_list_prepend(exif->items, item); |
945 | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
946 if (list == ExifKnownMarkersList) |
9 | 947 { |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
948 switch (item->tag) |
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
949 { |
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
950 case TAG_EXIFOFFSET: |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
951 exif_parse_IFD_table(exif, tiff, data_val, size, bo, level + 1, list); |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
952 break; |
1052 | 953 case TAG_GPSOFFSET: |
954 exif_parse_IFD_table(exif, tiff, data_val, size, bo, level + 1, ExifKnownGPSInfoMarkersList); | |
955 break; | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
956 case TAG_EXIFMAKERNOTE: |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
957 format_exif_makernote_parse(exif, tiff, data_val, size, bo); |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
958 break; |
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
959 } |
9 | 960 } |
961 | |
962 return 0; | |
963 } | |
964 | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
965 gint exif_parse_IFD_table(ExifData *exif, |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
966 guchar *tiff, guint offset, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
967 guint size, ExifByteOrder bo, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
968 gint level, |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
969 const ExifMarker *list) |
9 | 970 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
971 guint count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
972 guint i; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
973 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
974 /* limit damage from infinite loops */ |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
975 if (level > EXIF_TIFF_MAX_LEVELS) return -1; |
9 | 976 |
977 /* We should be able to read number of entries in IFD0) */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
978 if (size < offset + 2) return -1; |
9 | 979 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
980 count = exif_byte_get_int16(tiff + offset, bo); |
57
a8c9992320f4
Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
55
diff
changeset
|
981 offset += 2; |
9 | 982 |
983 /* Entries and next IFD offset must be readable */ | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
984 if (size < offset + count * EXIF_TIFD_SIZE + 4) return -1; |
9 | 985 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
986 for (i = 0; i < count; i++) |
9 | 987 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
988 exif_parse_IFD_entry(exif, tiff, offset + i * EXIF_TIFD_SIZE, size, bo, level, list); |
9 | 989 } |
990 | |
991 return 0; | |
992 } | |
993 | |
994 /* | |
995 *------------------------------------------------------------------- | |
996 * file formats | |
997 *------------------------------------------------------------------- | |
998 */ | |
999 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1000 gint exif_tiff_directory_offset(guchar *data, const guint len, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1001 guint *offset, ExifByteOrder *bo) |
9 | 1002 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1003 if (len < 8) return FALSE; |
9 | 1004 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1005 if (memcmp(data, "II", 2) == 0) |
9 | 1006 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1007 *bo = EXIF_BYTE_ORDER_INTEL; |
9 | 1008 } |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1009 else if (memcmp(data, "MM", 2) == 0) |
9 | 1010 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1011 *bo = EXIF_BYTE_ORDER_MOTOROLA; |
9 | 1012 } |
1013 else | |
1014 { | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1015 return FALSE; |
9 | 1016 } |
1017 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1018 if (exif_byte_get_int16(data + 2, *bo) != 0x002A) |
9 | 1019 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1020 return FALSE; |
9 | 1021 } |
1022 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1023 *offset = exif_byte_get_int32(data + 4, *bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1024 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1025 return (*offset < len); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1026 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1027 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1028 gint exif_tiff_parse(ExifData *exif, guchar *tiff, guint size, ExifMarker *list) |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1029 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1030 ExifByteOrder bo; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1031 guint offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1032 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1033 if (!exif_tiff_directory_offset(tiff, size, &offset, &bo)) return -1; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1034 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1035 return exif_parse_IFD_table(exif, tiff, offset, size, bo, 0, list); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1036 } |
9 | 1037 |
449 | 1038 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1039 /* |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1040 *------------------------------------------------------------------- |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1041 * jpeg marker utils |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1042 *------------------------------------------------------------------- |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1043 */ |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1044 |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1045 #define JPEG_MARKER 0xFF |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1046 #define JPEG_MARKER_SOI 0xD8 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1047 #define JPEG_MARKER_EOI 0xD9 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1048 #define JPEG_MARKER_APP1 0xE1 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1049 #define JPEG_MARKER_APP2 0xE2 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1050 |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1051 /* jpeg container format: |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1052 all data markers start with 0XFF |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1053 2 byte long file start and end markers: 0xFFD8(SOI) and 0XFFD9(EOI) |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1054 4 byte long data segment markers in format: 0xFFTTSSSSNNN... |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1055 FF: 1 byte standard marker identifier |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1056 TT: 1 byte data type |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1057 SSSS: 2 bytes in Motorola byte alignment for length of the data. |
442 | 1058 This value includes these 2 bytes in the count, making actual |
1059 length of NN... == SSSS - 2. | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1060 NNN.: the data in this segment |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1061 */ |
222
77f1bcc6c161
various exif improvements based on patch by Uwe Ohse
nadvornik
parents:
192
diff
changeset
|
1062 static ExifMarker jpeg_color_marker = { 0x8773, EXIF_FORMAT_UNDEFINED, -1, "Exif.Image.InterColorProfile", NULL, NULL }; |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1063 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1064 void exif_add_jpeg_color_profile(ExifData *exif, guchar *cp_data, guint cp_length) |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1065 { |
449 | 1066 ExifItem *item = exif_item_new(jpeg_color_marker.format, jpeg_color_marker.tag, 1, |
1067 &jpeg_color_marker); | |
1068 g_free(item->data); | |
1069 item->data = cp_data; | |
1070 item->elements = cp_length; | |
1071 item->data_len = cp_length; | |
1072 exif->items = g_list_prepend(exif->items, item); | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1073 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1074 } |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1075 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1076 static gint exif_jpeg_parse(ExifData *exif, |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1077 guchar *data, guint size, |
449 | 1078 ExifMarker *list) |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1079 { |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1080 guint seg_offset = 0; |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1081 guint seg_length = 0; |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1082 gint res = -1; |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1083 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1084 if (size < 4 || |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1085 memcmp(data, "\xFF\xD8", 2) != 0) |
9 | 1086 { |
1087 return -2; | |
1088 } | |
1089 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1090 if (exif_jpeg_segment_find(data, size, JPEG_MARKER_APP1, |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1091 "Exif\x00\x00", 6, |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1092 &seg_offset, &seg_length)) |
9 | 1093 { |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1094 res = exif_tiff_parse(exif, data + seg_offset + 6, seg_length - 6, list); |
9 | 1095 } |
1096 | |
449 | 1097 if (exif_jpeg_parse_color(exif, data, size)) |
9 | 1098 { |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1099 res = 0; |
9 | 1100 } |
1101 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1102 return res; |
9 | 1103 } |
1104 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1105 guchar *exif_get_color_profile(ExifData *exif, guint *data_len) |
449 | 1106 { |
1107 ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile"); | |
1108 if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED) | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1109 return (guchar *) exif_item_get_data(prof_item, data_len); |
449 | 1110 return NULL; |
1111 } | |
1112 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1113 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1114 /* |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1115 *------------------------------------------------------------------- |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1116 * misc |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1117 *------------------------------------------------------------------- |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1118 */ |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
1119 |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1120 |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1121 ExifItem *exif_get_first_item(ExifData *exif) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1122 { |
442 | 1123 if (exif->items) |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1124 { |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1125 ExifItem *ret = (ExifItem *)exif->items->data; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1126 exif->current = exif->items->next; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1127 return ret; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1128 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1129 exif->current = NULL; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1130 return NULL; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1131 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1132 |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1133 ExifItem *exif_get_next_item(ExifData *exif) |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1134 { |
442 | 1135 if (exif->current) |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1136 { |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1137 ExifItem *ret = (ExifItem *)exif->current->data; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1138 exif->current = exif->current->next; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1139 return ret; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1140 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1141 return NULL; |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1142 } |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1143 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1144 static gint map_file(const gchar *path, void **mapping, gint *size) |
9 | 1145 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1146 gint fd; |
9 | 1147 struct stat fs; |
1148 | |
855 | 1149 fd = open(path, O_RDONLY); |
1150 if (fd == -1) | |
9 | 1151 { |
1152 perror(path); | |
1153 return -1; | |
1154 } | |
1155 | |
1156 if (fstat(fd, &fs) == -1) | |
1157 { | |
1158 perror(path); | |
1159 close(fd); | |
1160 return -1; | |
1161 } | |
1162 | |
1163 *size = fs.st_size; | |
1164 | |
855 | 1165 *mapping = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); |
1166 if (*mapping == MAP_FAILED) | |
9 | 1167 { |
1168 perror(path); | |
1169 close(fd); | |
1170 return -1; | |
1171 } | |
1172 | |
1173 close(fd); | |
1174 return 0; | |
1175 } | |
1176 | |
1002 | 1177 static gint unmap_file(gpointer mapping, gint size) |
9 | 1178 { |
1179 if (munmap(mapping, size) == -1) | |
1180 { | |
1181 perror("munmap"); | |
1182 return -1; | |
1183 } | |
1184 | |
1185 return 0; | |
1186 } | |
1187 | |
1069 | 1188 ExifData *exif_get_original(ExifData *processed) |
1189 { | |
1190 return processed; | |
1191 } | |
1192 | |
9 | 1193 void exif_free(ExifData *exif) |
1194 { | |
1195 GList *work; | |
1196 | |
1197 if (!exif) return; | |
1198 | |
1199 work = exif->items; | |
1200 while (work) | |
1201 { | |
1202 ExifItem *item = work->data; | |
1203 work = work->next; | |
1204 exif_item_free(item); | |
1205 } | |
1206 | |
1207 g_list_free(exif->items); | |
1010 | 1208 g_free(exif->path); |
9 | 1209 g_free(exif); |
1210 } | |
1211 | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1183
diff
changeset
|
1212 ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp) |
9 | 1213 { |
1214 ExifData *exif; | |
1002 | 1215 gpointer f; |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1216 gint size, res; |
9 | 1217 gchar *pathl; |
1218 | |
182 | 1219 if (!path) return NULL; |
9 | 1220 |
177 | 1221 pathl = path_from_utf8(path); |
9 | 1222 if (map_file(pathl, &f, &size) == -1) |
1223 { | |
1224 g_free(pathl); | |
1225 return NULL; | |
1226 } | |
1227 g_free(pathl); | |
1228 | |
1229 exif = g_new0(ExifData, 1); | |
1230 exif->items = NULL; | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
1231 exif->current = NULL; |
1010 | 1232 exif->path = g_strdup(path); |
9 | 1233 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1234 res = exif_jpeg_parse(exif, (guchar *)f, size, ExifKnownMarkersList); |
855 | 1235 if (res == -2) |
9 | 1236 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1237 res = exif_tiff_parse(exif, (guchar *)f, size, ExifKnownMarkersList); |
9 | 1238 } |
1239 | |
1240 if (res != 0) | |
1241 { | |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1242 FormatRawExifType exif_type; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1243 FormatRawExifParseFunc exif_parse_func; |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1244 guint32 offset = 0; |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1245 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1246 exif_type = format_raw_exif_offset(f, size, &offset, &exif_parse_func); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1247 switch (exif_type) |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1248 { |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1249 case FORMAT_RAW_EXIF_NONE: |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1250 default: |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1251 break; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1252 case FORMAT_RAW_EXIF_TIFF: |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1253 res = exif_tiff_parse(exif, (guchar *)f + offset, size - offset, |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1254 ExifKnownMarkersList); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1255 break; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1256 case FORMAT_RAW_EXIF_JPEG: |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1257 res = exif_jpeg_parse(exif, (guchar *)f + offset, size - offset, |
449 | 1258 ExifKnownMarkersList); |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1259 break; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1260 case FORMAT_RAW_EXIF_IFD_II: |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1261 case FORMAT_RAW_EXIF_IFD_MM: |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1262 res = exif_parse_IFD_table(exif, (guchar *)f, offset, size - offset, |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1263 (exif_type == FORMAT_RAW_EXIF_IFD_II) ? |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1264 EXIF_BYTE_ORDER_INTEL : EXIF_BYTE_ORDER_MOTOROLA, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1265 0, ExifKnownMarkersList); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1266 break; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1267 case FORMAT_RAW_EXIF_PROPRIETARY: |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1268 if (exif_parse_func) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1269 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1270 res = exif_parse_func((guchar *)f + offset, size - offset, exif); |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1271 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1272 break; |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1273 } |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1274 } |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1275 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1276 if (res != 0) |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1277 { |
9 | 1278 exif_free(exif); |
1279 exif = NULL; | |
1280 } | |
1281 | |
1282 unmap_file(f, size); | |
1283 | |
1284 if (exif) exif->items = g_list_reverse(exif->items); | |
1285 | |
1286 #if 0 | |
1287 exif_write_data_list(exif, stdout, TRUE); | |
1288 exif_write_data_list(exif, stdout, FALSE); | |
1289 #endif | |
1290 | |
1291 return exif; | |
1292 } | |
1293 | |
1294 ExifItem *exif_get_item(ExifData *exif, const gchar *key) | |
1295 { | |
1296 GList *work; | |
1297 | |
1298 if (!key) return NULL; | |
1299 | |
1300 work = exif->items; | |
1301 while (work) | |
995 | 1302 { |
9 | 1303 ExifItem *item; |
1304 | |
1305 item = work->data; | |
1306 work = work->next; | |
1307 if (item->marker->key && strcmp(key, item->marker->key) == 0) return item; | |
442 | 1308 } |
9 | 1309 return NULL; |
1310 } | |
1311 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1312 #define EXIF_DATA_AS_TEXT_MAX_COUNT 16 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1313 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1314 gchar *exif_item_get_string(ExifItem *item, gint idx) |
192 | 1315 { |
1316 return exif_item_get_data_as_text(item); | |
1317 } | |
1318 | |
1319 | |
9 | 1320 gchar *exif_item_get_data_as_text(ExifItem *item) |
1321 { | |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
1322 const ExifMarker *marker; |
9 | 1323 gpointer data; |
1324 GString *string; | |
1325 gchar *text; | |
1326 gint ne; | |
1327 gint i; | |
1328 | |
1329 if (!item) return NULL; | |
1330 | |
1331 marker = item->marker; | |
1332 if (!marker) return NULL; | |
1333 | |
1334 data = item->data; | |
1335 ne = item->elements; | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1336 if (ne > EXIF_DATA_AS_TEXT_MAX_COUNT) ne = EXIF_DATA_AS_TEXT_MAX_COUNT; |
9 | 1337 string = g_string_new(""); |
1338 switch (item->format) | |
1339 { | |
1340 case EXIF_FORMAT_UNKNOWN: | |
1341 break; | |
1342 case EXIF_FORMAT_BYTE_UNSIGNED: | |
1343 case EXIF_FORMAT_BYTE: | |
1344 case EXIF_FORMAT_UNDEFINED: | |
1345 if (ne == 1 && marker->list) | |
1346 { | |
1347 gchar *result; | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1348 guchar val; |
9 | 1349 |
1350 if (item->format == EXIF_FORMAT_BYTE_UNSIGNED || | |
1351 item->format == EXIF_FORMAT_UNDEFINED) | |
1352 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1353 val = ((guchar *)data)[0]; |
9 | 1354 } |
1355 else | |
1356 { | |
1010 | 1357 val = (guchar)(((gchar *)data)[0]); |
9 | 1358 } |
1359 | |
57
a8c9992320f4
Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
55
diff
changeset
|
1360 result = exif_text_list_find_value(marker->list, (guint)val); |
9 | 1361 string = g_string_append(string, result); |
1362 g_free(result); | |
1363 } | |
1364 else | |
1365 { | |
1366 string = string_append_raw_bytes(string, data, ne); | |
1367 } | |
1368 break; | |
1369 case EXIF_FORMAT_STRING: | |
1370 string = g_string_append(string, (gchar *)(item->data)); | |
1371 break; | |
1372 case EXIF_FORMAT_SHORT_UNSIGNED: | |
1373 if (ne == 1 && marker->list) | |
1374 { | |
1375 gchar *result; | |
1376 | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1377 result = exif_text_list_find_value(marker->list, ((guint16 *)data)[0]); |
9 | 1378 string = g_string_append(string, result); |
1379 g_free(result); | |
1380 } | |
1381 else for (i = 0; i < ne; i++) | |
1382 { | |
1383 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "", | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1384 ((guint16 *)data)[i]); |
9 | 1385 } |
1386 break; | |
1387 case EXIF_FORMAT_LONG_UNSIGNED: | |
1388 for (i = 0; i < ne; i++) | |
1389 { | |
1390 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "", | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1391 (gulong)((guint32 *)data)[i]); |
9 | 1392 } |
1393 break; | |
1394 case EXIF_FORMAT_RATIONAL_UNSIGNED: | |
1395 for (i = 0; i < ne; i++) | |
1396 { | |
1397 ExifRational *r; | |
1398 | |
1399 r = &((ExifRational *)data)[i]; | |
1400 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "", | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1401 (gulong)r->num, (gulong)r->den); |
9 | 1402 } |
1403 break; | |
1404 case EXIF_FORMAT_SHORT: | |
1405 for (i = 0; i < ne; i++) | |
1406 { | |
1407 g_string_append_printf(string, "%s%hd", (i > 0) ? ", " : "", | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1408 ((gint16 *)data)[i]); |
9 | 1409 } |
1410 break; | |
1411 case EXIF_FORMAT_LONG: | |
1412 for (i = 0; i < ne; i++) | |
1413 { | |
1414 g_string_append_printf(string, "%s%ld", (i > 0) ? ", " : "", | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1415 (glong)((gint32 *)data)[i]); |
9 | 1416 } |
1417 break; | |
1418 case EXIF_FORMAT_RATIONAL: | |
1419 for (i = 0; i < ne; i++) | |
1420 { | |
1421 ExifRational *r; | |
1422 | |
1423 r = &((ExifRational *)data)[i]; | |
1424 g_string_append_printf(string, "%s%ld/%ld", (i > 0) ? ", " : "", | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1425 (glong)r->num, (glong)r->den); |
9 | 1426 } |
1427 break; | |
1428 case EXIF_FORMAT_FLOAT: | |
1429 for (i = 0; i < ne; i++) | |
1430 { | |
1431 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "", | |
1432 ((float *)data)[i]); | |
1433 } | |
1434 break; | |
1435 case EXIF_FORMAT_DOUBLE: | |
1436 for (i = 0; i < ne; i++) | |
1437 { | |
1438 g_string_append_printf(string, "%s%f", (i > 0) ? ", " : "", | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1439 ((gdouble *)data)[i]); |
9 | 1440 } |
1441 break; | |
1442 } | |
1443 | |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1444 if (item->elements > EXIF_DATA_AS_TEXT_MAX_COUNT && |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1445 item->format != EXIF_FORMAT_STRING) |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1446 { |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1447 g_string_append(string, " ..."); |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1448 } |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1449 |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1450 text = string->str; |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
110
diff
changeset
|
1451 g_string_free(string, FALSE); |
9 | 1452 |
1453 return text; | |
1454 } | |
1455 | |
1456 gint exif_item_get_integer(ExifItem *item, gint *value) | |
1457 { | |
1458 if (!item) return FALSE; | |
1459 | |
1460 switch (item->format) | |
1461 { | |
1462 case EXIF_FORMAT_SHORT: | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1463 *value = (gint)(((gint16 *)(item->data))[0]); |
9 | 1464 return TRUE; |
1465 break; | |
1466 case EXIF_FORMAT_SHORT_UNSIGNED: | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1467 *value = (gint)(((guint16 *)(item->data))[0]); |
9 | 1468 return TRUE; |
1469 break; | |
1470 case EXIF_FORMAT_LONG: | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1471 *value = (gint)(((gint32 *)(item->data))[0]); |
9 | 1472 return TRUE; |
1473 break; | |
1474 case EXIF_FORMAT_LONG_UNSIGNED: | |
1475 /* FIXME: overflow possible */ | |
110
9fbf210edc6f
Tue Nov 14 15:36:14 2006 John Ellis <johne@verizon.net>
gqview
parents:
107
diff
changeset
|
1476 *value = (gint)(((guint32 *)(item->data))[0]); |
9 | 1477 return TRUE; |
1478 default: | |
1479 /* all other type return FALSE */ | |
1480 break; | |
1481 } | |
1482 return FALSE; | |
1483 } | |
1484 | |
1485 | |
1058
b600689a677e
Fix up few signed vs unsigned warnings: exif_item_get_rational() last parameter is now of guint type.
zas_
parents:
1055
diff
changeset
|
1486 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n) |
9 | 1487 { |
1488 if (!item) return NULL; | |
1058
b600689a677e
Fix up few signed vs unsigned warnings: exif_item_get_rational() last parameter is now of guint type.
zas_
parents:
1055
diff
changeset
|
1489 if (n >= item->elements) return NULL; |
9 | 1490 |
1491 if (item->format == EXIF_FORMAT_RATIONAL || | |
1492 item->format == EXIF_FORMAT_RATIONAL_UNSIGNED) | |
1493 { | |
1494 if (sign) *sign = (item->format == EXIF_FORMAT_RATIONAL); | |
1052 | 1495 return &((ExifRational *)(item->data))[n]; |
9 | 1496 } |
1497 | |
1498 return NULL; | |
1499 } | |
1500 | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
1501 gchar *exif_get_tag_description_by_key(const gchar *key) |
9 | 1502 { |
1503 gint i; | |
1504 | |
1505 if (!key) return NULL; | |
1506 | |
1507 i = 0; | |
1508 while (ExifKnownMarkersList[i].tag > 0) | |
1509 { | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
1510 if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return g_strdup(_(ExifKnownMarkersList[i].description)); |
9 | 1511 i++; |
1512 } | |
1513 | |
1052 | 1514 i = 0; |
1515 while (ExifKnownGPSInfoMarkersList[i].tag > 0) | |
1516 { | |
1517 if (strcmp(key, ExifKnownGPSInfoMarkersList[i].key) == 0) return _(ExifKnownGPSInfoMarkersList[i].description); | |
1518 i++; | |
1519 } | |
1520 | |
9 | 1521 return NULL; |
1522 } | |
1523 | |
1524 static void exif_write_item(FILE *f, ExifItem *item) | |
1525 { | |
1526 gchar *text; | |
1527 | |
1528 text = exif_item_get_data_as_text(item); | |
1529 if (text) | |
1530 { | |
185 | 1531 gchar *tag = exif_item_get_tag_name(item); |
9 | 1532 fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name, |
185 | 1533 tag, text); |
1534 g_free(tag); | |
9 | 1535 } |
1536 g_free(text); | |
1537 } | |
1538 | |
1539 void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list) | |
1540 { | |
1541 if (!f || !exif) return; | |
1542 | |
1543 fprintf(f, " tag format key value\n"); | |
1544 fprintf(f, "----------------------------------------------------\n"); | |
1545 | |
1546 if (human_readable_list) | |
1547 { | |
1548 gint i; | |
1549 | |
1550 i = 0; | |
1551 while (ExifFormattedList[i].key) | |
1552 { | |
1553 gchar *text; | |
1554 | |
1555 text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL); | |
1556 if (text) | |
1557 { | |
1558 fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text); | |
1559 } | |
1560 i++; | |
1561 } | |
1562 } | |
1563 else | |
1564 { | |
1565 GList *work; | |
1566 | |
1567 work = exif->items; | |
1568 while (work) | |
1569 { | |
1570 ExifItem *item; | |
1571 | |
1572 item = work->data; | |
1573 work = work->next; | |
1574 | |
1575 exif_write_item(f, item); | |
1576 } | |
1577 } | |
1578 fprintf(f, "----------------------------------------------------\n"); | |
1579 } | |
1580 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
1581 gint exif_write(ExifData *exif) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1582 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
541
diff
changeset
|
1583 log_printf("Not compiled with EXIF write support"); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1584 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1585 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1586 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1587 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1183
diff
changeset
|
1588 gint exif_update_metadata(ExifData *exif, const gchar *key, const GList *values) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1589 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1590 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1591 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1592 |
1010 | 1593 typedef struct _UnmapData UnmapData; |
1594 struct _UnmapData | |
1595 { | |
1596 guchar *ptr; | |
1597 guchar *map_data; | |
1598 size_t map_len; | |
1599 }; | |
1600 | |
1601 static GList *exif_unmap_list = 0; | |
1602 | |
1060 | 1603 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1010 | 1604 { |
1605 guint offset; | |
1606 const gchar* path; | |
1607 struct stat st; | |
1608 guchar *map_data; | |
1609 size_t map_len; | |
1610 int fd; | |
1611 | |
1612 if (!exif) return NULL; | |
1613 path = exif->path; | |
1614 | |
1615 fd = open(path, O_RDONLY); | |
1616 | |
1617 | |
1618 if (fd == -1) | |
1619 { | |
1620 return 0; | |
1621 } | |
1622 | |
1623 if (fstat(fd, &st) == -1) | |
1624 { | |
1625 close(fd); | |
1626 return 0; | |
1627 } | |
1628 map_len = st.st_size; | |
1629 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); | |
1630 close(fd); | |
1631 | |
1632 if (map_data == MAP_FAILED) | |
1633 { | |
1634 return 0; | |
1635 } | |
1636 | |
1637 if (format_raw_img_exif_offsets(map_data, map_len, &offset, NULL) && offset) | |
1638 { | |
1639 UnmapData *ud; | |
1640 | |
1179 | 1641 DEBUG_1("%s: offset %u", path, offset); |
1010 | 1642 |
1643 *data_len = map_len - offset; | |
1644 ud = g_new(UnmapData, 1); | |
1645 ud->ptr = map_data + offset; | |
1646 ud->map_data = map_data; | |
1647 ud->map_len = map_len; | |
1648 | |
1649 exif_unmap_list = g_list_prepend(exif_unmap_list, ud); | |
1650 return ud->ptr; | |
1651 } | |
1652 | |
1653 munmap(map_data, map_len); | |
1654 return NULL; | |
1655 | |
1656 } | |
1657 | |
1658 void exif_free_preview(guchar *buf) | |
1659 { | |
1660 GList *work = exif_unmap_list; | |
1661 | |
1662 while (work) | |
1663 { | |
1664 UnmapData *ud = (UnmapData *)work->data; | |
1665 if (ud->ptr == buf) | |
1666 { | |
1667 exif_unmap_list = g_list_remove_link(exif_unmap_list, work); | |
1668 g_free(ud); | |
1669 return; | |
1670 } | |
1025 | 1671 work = work->next; |
1010 | 1672 } |
1673 g_assert_not_reached(); | |
1674 } | |
1675 | |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
185
diff
changeset
|
1676 |
442 | 1677 #endif |
177 | 1678 /* not HAVE_EXIV2 */ |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1053
diff
changeset
|
1679 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |