-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathformat-olympus.cc
366 lines (308 loc) · 11.6 KB
/
format-olympus.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Copyright (C) 2005 John Ellis
* Copyright (C) 2008 - 2016 The Geeqie Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "format-olympus.h"
#include <cstring>
#include <glib.h>
#include "exif.h"
/*
*-----------------------------------------------------------------------------
* Raw ORF embedded jpeg extraction for Olympus
*-----------------------------------------------------------------------------
*/
static guint olympus_tiff_table(guchar *data, guint len, guint offset, ExifByteOrder bo,
gint level,
guint *image_offset, guint *exif_offset);
static void olympus_tiff_entry(guchar *data, const guint len, guint offset, ExifByteOrder bo,
gint,
guint *image_offset, guint *exif_offset)
{
guint tag;
guint type;
guint count;
guint segment;
guint seg_len;
tag = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_TAG, bo);
type = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
count = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_COUNT, bo);
/* so far, we only care about tags with type long */
if (type != EXIF_FORMAT_LONG_UNSIGNED && type != EXIF_FORMAT_LONG) return;
seg_len = ExifFormatList[type].size * count;
if (seg_len > 4)
{
segment = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_DATA, bo);
if (segment + seg_len > len) return;
}
else
{
segment = offset + EXIF_TIFD_OFFSET_DATA;
}
if (tag == 0x201)
{
/* start of embedded jpeg, not all olympus cameras embed a jpeg */
*image_offset = exif_byte_get_int32(data + segment, bo);
}
if (tag == 0x8769)
{
/* This is the Exif info */
*exif_offset = exif_byte_get_int32(data + segment, bo);
}
}
static guint olympus_tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
gint level,
guint *image_offset, guint *exif_offset)
{
guint count;
guint i;
if (level > EXIF_TIFF_MAX_LEVELS) return 0;
if (len < offset + 2) return FALSE;
count = exif_byte_get_int16(data + offset, bo);
offset += 2;
if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0;
for (i = 0; i < count; i++)
{
olympus_tiff_entry(data, len, offset + (i * EXIF_TIFD_SIZE), bo, level,
image_offset, exif_offset);
}
return exif_byte_get_int32(data + offset + (count * EXIF_TIFD_SIZE), bo);
}
gboolean format_olympus_raw(guchar *data, const guint len,
guint *image_offset, guint *exif_offset)
{
guint i_off = 0;
guint e_off = 0;
guint offset;
gint level;
if (len < 8) return FALSE;
/* these are in tiff file format with a different magick header */
if (memcmp(data, "IIR", 3) != 0) return FALSE;
offset = exif_byte_get_int32(data + 4, EXIF_BYTE_ORDER_INTEL);
level = 0;
while (offset && level < EXIF_TIFF_MAX_LEVELS)
{
offset = olympus_tiff_table(data, len, offset, EXIF_BYTE_ORDER_INTEL, 0, &i_off, &e_off);
level++;
}
if (i_off != 0 || e_off != 0)
{
if (image_offset) *image_offset = i_off;
if (exif_offset) *exif_offset = e_off;
return TRUE;
}
return FALSE;
}
/*
*-----------------------------------------------------------------------------
* EXIF Makernote for Olympus
*-----------------------------------------------------------------------------
*/
static ExifTextList KonMinTagColorMode[]= {
{ 0, "natural" },
{ 1, "black and white" },
{ 2, "vivid" },
{ 3, "solarization" },
{ 4, "Adobe RGB" },
EXIF_TEXT_LIST_END
};
static ExifTextList KonMinTagQuality[]= {
{ 0, "raw" },
{ 1, "super fine" },
{ 2, "find" },
{ 3, "standard" },
{ 4, "extra fine" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagJpegQuality[]= {
{ 1, "standard" },
{ 2, "high" },
{ 3, "super high" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagMacro[]= {
{ 0, "off" },
{ 1, "on" },
{ 2, "view" },
{ 3, "manual" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagFlashMode[]= {
{ 0, "auto" },
{ 1, "red-eye reduction" },
{ 2, "fill" },
{ 3, "off" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagFocusMode[]= {
{ 0, "auto" },
{ 1, "manual" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagSharpness[]= {
{ 0, "normal" },
{ 1, "hard" },
{ 2, "soft" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusTagContrast[]= {
{ 0, "hard" },
{ 1, "normal" },
{ 2, "soft" },
EXIF_TEXT_LIST_END
};
static ExifMarker OlympusExifMarkersList[] = {
{ 0x0001, EXIF_FORMAT_LONG_UNSIGNED, -1, "Konica/MinoltaSettings", "Konica / Minolta settings", nullptr },
{ 0x0003, EXIF_FORMAT_LONG_UNSIGNED, -1, "Konica/MinoltaSettings", "Konica / Minolta settings", nullptr },
{ 0x0040, EXIF_FORMAT_LONG_UNSIGNED, -1, "CompressedImageSize", "Compressed image size", nullptr },
{ 0x0081, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailOffset", "Thumbnail offset", nullptr },
{ 0x0088, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailOffset", "Thumbnail offset", nullptr },
{ 0x0089, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailLength", "Thumbnail length", nullptr },
{ 0x0101, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.ColorMode", "Color mode", KonMinTagColorMode },
{ 0x0102, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.Quality", "Quality", KonMinTagQuality },
{ 0x0103, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.Quality", "Quality", KonMinTagQuality },
{ 0x0200, EXIF_FORMAT_LONG_UNSIGNED, 3, "Olympus.SpecialMode", "Special mode", nullptr },
{ 0x0201, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.JpegQuality", "Jpeg quality", OlympusTagJpegQuality },
{ 0x0202, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Macro", "Macro", OlympusTagMacro },
{ 0x0204, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Olympus.DigitalZoom", "Digital zoom", nullptr },
{ 0x0207, EXIF_FORMAT_STRING, -1, "Olympus.Firmware", "Firmware version", nullptr },
{ 0x0208, EXIF_FORMAT_STRING, -1, "Olympus.PictureInfo", "Picture info", nullptr },
{ 0x0209, EXIF_FORMAT_UNDEFINED, -1, "Olympus.CameraID", "Camera ID", nullptr },
{ 0x020b, EXIF_FORMAT_LONG_UNSIGNED, 1, "Epson.ImageWidth", "Image width", nullptr },
{ 0x020c, EXIF_FORMAT_LONG_UNSIGNED, 1, "Epson.ImageHeight", "Image height", nullptr },
{ 0x020d, EXIF_FORMAT_STRING, -1, "Epson.Manufacturer", "Manufacturer", nullptr },
{ 0x0e00, EXIF_FORMAT_BYTE, -1, "Olympus.PrintImageMatching", "Print image matching", nullptr },
{ 0x1004, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FlashMode", "Flash mode", OlympusTagFlashMode },
{ 0x1006, EXIF_FORMAT_RATIONAL, 1, "Olympus.Bracket", "Bracket", nullptr },
{ 0x100b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FocusMode", "Focus mode", OlympusTagFocusMode },
{ 0x100c, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Olympus.FocusDistance", "Focus distance", nullptr },
{ 0x100d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Zoom", "Zoom", nullptr },
{ 0x1006, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.MacroFocus", "Macro focus", nullptr },
{ 0x100f, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Sharpness", "Sharpness", OlympusTagSharpness },
{ 0x1011, EXIF_FORMAT_SHORT_UNSIGNED, 9, "Olympus.ColorMatrix", "Color matrix", nullptr },
{ 0x1012, EXIF_FORMAT_SHORT_UNSIGNED, 4, "Olympus.BlackLevel", "Black level", nullptr },
{ 0x1015, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.WhiteBalance", "White balance", nullptr },
{ 0x1017, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.RedBias", "Red bias", nullptr },
{ 0x1018, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.BlueBias", "Blue bias", nullptr },
{ 0x101a, EXIF_FORMAT_STRING, -1, "Olympus.SerialNumber", "Serial number", nullptr },
{ 0x1023, EXIF_FORMAT_RATIONAL, 1, "Olympus.FlashBias", "Flash bias", nullptr },
{ 0x1029, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Contrast", "Contrast", OlympusTagContrast },
{ 0x102a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.SharpnessFactor", "Sharpness factor", nullptr },
{ 0x102b, EXIF_FORMAT_SHORT_UNSIGNED, 6, "Olympus.ColorControl", "Color control", nullptr },
{ 0x102c, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.ValidBits", "Valid bits", nullptr },
{ 0x102d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.CoringFilter", "Coring filter", nullptr },
{ 0x102e, EXIF_FORMAT_LONG_UNSIGNED, 1, "Olympus.FinalWidth", "Final width", nullptr },
{ 0x102f, EXIF_FORMAT_LONG_UNSIGNED, 1, "Olympus.FinalHeight", "Final height", nullptr },
{ 0x1034, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.CompressionRatio", "Compression ratio", nullptr },
EXIF_MARKER_LIST_END
};
static ExifTextList OlympusShootingMode[]= {
{ 0, "normal" },
{ 1, "unknown" },
{ 2, "fast" },
{ 3, "panorama" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusPanoramaDirection[]= {
{ 1, "left to right" },
{ 2, "right to left" },
{ 3, "bottom to top" },
{ 4, "top to bottom" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusWB[]= {
{ 1, "auto" },
{ 2, "manual" },
{ 3, "one-touch" },
EXIF_TEXT_LIST_END
};
static ExifTextList OlympusWBColorTemp[]= {
{ 2, "3000" },
{ 3, "3700" },
{ 4, "4000" },
{ 5, "4500" },
{ 6, "5500" },
{ 7, "6500" },
{ 8, "7500" },
EXIF_TEXT_LIST_END
};
gboolean format_olympus_makernote(ExifData *exif, guchar *tiff, guint offset,
guint size, ExifByteOrder bo)
{
guchar *data;
ExifItem *item;
if (offset + 8 + 4 >= size) return FALSE;
data = tiff + offset;
/* Olympus tag format starts with "OLYMP\x00\x01" or "OLYMP\x00\x02",
* plus an unknown byte,
* followed by IFD data using Olympus tags.
*/
if (memcmp(data, "OLYMP\x00\x01", 7) != 0 &&
memcmp(data, "OLYMP\x00\x02", 7) != 0) return FALSE;
if (exif_parse_IFD_table(exif, tiff, offset + 8, size,
bo, 0, OlympusExifMarkersList) != 0)
{
return FALSE;
}
item = exif_get_item(exif, "Olympus.SpecialMode");
if (item && item->data_len == 3 * sizeof(guint32))
{
static ExifMarker marker = { 0x0200, EXIF_FORMAT_STRING, -1,
"Olympus.ShootingMode", "Shooting mode", nullptr };
auto array = static_cast<guint32 *>(item->data);
g_autofree gchar *text = nullptr;
gint l;
g_autofree gchar *mode = exif_text_list_find_value(OlympusShootingMode, array[0]);
if (array[0] == 3)
{
g_autofree gchar *pdir = exif_text_list_find_value(OlympusPanoramaDirection, array[2]);
text = g_strdup_printf("%s %s, seq %d", mode, pdir, array[1] + 1);
}
else
{
text = g_strdup_printf("%s, seq %d", mode, array[1] + 1);
}
l = strlen(text) + 1;
item = exif_item_new(marker.format, marker.tag, l, &marker);
memcpy(item->data, text, l);
exif->items = g_list_prepend(exif->items, item);
}
item = exif_get_item(exif, "Olympus.WhiteBalance");
if (item && item->data_len == 2 * sizeof(guint16))
{
static ExifMarker marker = { 0x1015, EXIF_FORMAT_STRING, -1,
"Olympus.WhiteBalance", "White balance", nullptr };
auto array = static_cast<guint16 *>(item->data);
g_autofree gchar *text = nullptr;
gint l;
g_autofree gchar *mode = exif_text_list_find_value(OlympusWB, array[0]);
if (array[0] == 2)
{
g_autofree gchar *color = exif_text_list_find_value(OlympusWBColorTemp, array[1]);
text = g_strdup_printf("%s %s", mode, color);
}
else
{
text = g_steal_pointer(&mode);
}
l = strlen(text) + 1;
item = exif_item_new(marker.format, marker.tag, l, &marker);
memcpy(item->data, text, l);
exif->items = g_list_prepend(exif->items, item);
}
return TRUE;
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */