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