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