4 * Copyright (C) 2008 - 2012 The Geeqie Team
6 * This software is released under the GNU General Public License (GNU GPL).
7 * Please read the included file COPYING for more information.
8 * This software comes with no warranty of any kind, use at your own risk!
26 #include "format_olympus.h"
27 #include "format_raw.h"
33 *-----------------------------------------------------------------------------
34 * Raw ORF embedded jpeg extraction for Olympus
35 *-----------------------------------------------------------------------------
38 static guint olympus_tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
40 guint *image_offset, guint *exif_offset);
43 static void olympus_tiff_entry(guchar *data, const guint len, guint offset, ExifByteOrder bo,
45 guint *image_offset, guint *exif_offset)
53 tag = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_TAG, bo);
54 type = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
55 count = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_COUNT, bo);
57 /* so far, we only care about tags with type long */
58 if (type != EXIF_FORMAT_LONG_UNSIGNED && type != EXIF_FORMAT_LONG) return;
60 seg_len = ExifFormatList[type].size * count;
63 segment = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_DATA, bo);
64 if (segment + seg_len > len) return;
68 segment = offset + EXIF_TIFD_OFFSET_DATA;
73 /* start of embedded jpeg, not all olympus cameras embed a jpeg */
74 *image_offset = exif_byte_get_int32(data + segment, bo);
79 /* This is the Exif info */
80 *exif_offset = exif_byte_get_int32(data + segment, bo);
84 static guint olympus_tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
86 guint *image_offset, guint *exif_offset)
91 if (level > EXIF_TIFF_MAX_LEVELS) return 0;
93 if (len < offset + 2) return FALSE;
95 count = exif_byte_get_int16(data + offset, bo);
97 if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0;
99 for (i = 0; i < count; i++)
101 olympus_tiff_entry(data, len, offset + i * EXIF_TIFD_SIZE, bo, level,
102 image_offset, exif_offset);
105 return exif_byte_get_int32(data + offset + count * EXIF_TIFD_SIZE, bo);
108 gboolean format_olympus_raw(guchar *data, const guint len,
109 guint *image_offset, guint *exif_offset)
116 if (len < 8) return FALSE;
118 /* these are in tiff file format with a different magick header */
119 if (memcmp(data, "IIR", 3) != 0) return FALSE;
121 offset = exif_byte_get_int32(data + 4, EXIF_BYTE_ORDER_INTEL);
124 while (offset && level < EXIF_TIFF_MAX_LEVELS)
126 offset = olympus_tiff_table(data, len, offset, EXIF_BYTE_ORDER_INTEL, 0, &i_off, &e_off);
130 if (i_off != 0 || e_off != 0)
132 if (image_offset) *image_offset = i_off;
133 if (exif_offset) *exif_offset = e_off;
142 *-----------------------------------------------------------------------------
143 * EXIF Makernote for Olympus
144 *-----------------------------------------------------------------------------
147 static ExifTextList KonMinTagColorMode[]= {
149 { 1, "black and white" },
151 { 3, "solarization" },
156 static ExifTextList KonMinTagQuality[]= {
165 static ExifTextList OlympusTagJpegQuality[]= {
172 static ExifTextList OlympusTagMacro[]= {
180 static ExifTextList OlympusTagFlashMode[]= {
182 { 1, "red-eye reduction" },
188 static ExifTextList OlympusTagFocusMode[]= {
194 static ExifTextList OlympusTagSharpness[]= {
201 static ExifTextList OlympusTagContrast[]= {
209 static ExifTextList OlympusTag[]= {
217 static ExifMarker OlympusExifMarkersList[] = {
218 { 0x0001, EXIF_FORMAT_LONG_UNSIGNED, -1, "Konica/MinoltaSettings", "Konica / Minolta settings", NULL },
219 { 0x0003, EXIF_FORMAT_LONG_UNSIGNED, -1, "Konica/MinoltaSettings", "Konica / Minolta settings", NULL },
220 { 0x0040, EXIF_FORMAT_LONG_UNSIGNED, -1, "CompressedImageSize", "Compressed image size", NULL },
221 { 0x0081, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailOffset", "Thumbnail offset", NULL },
222 { 0x0088, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailOffset", "Thumbnail offset", NULL },
223 { 0x0089, EXIF_FORMAT_LONG_UNSIGNED, 1, "ThumbnailLength", "Thumbnail length", NULL },
224 { 0x0101, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.ColorMode", "Color mode", KonMinTagColorMode },
225 { 0x0102, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.Quality", "Quality", KonMinTagQuality },
226 { 0x0103, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Konica/Minolta.Quality", "Quality", KonMinTagQuality },
227 { 0x0200, EXIF_FORMAT_LONG_UNSIGNED, 3, "Olympus.SpecialMode", "Special mode", NULL },
228 { 0x0201, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.JpegQuality", "Jpeg quality", OlympusTagJpegQuality },
229 { 0x0202, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Macro", "Macro", OlympusTagMacro },
230 { 0x0204, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Olympus.DigitalZoom", "Digital zoom", NULL },
231 { 0x0207, EXIF_FORMAT_STRING, -1, "Olympus.Firmware", "Firmware version", NULL },
232 { 0x0208, EXIF_FORMAT_STRING, -1, "Olympus.PictureInfo", "Picture info", NULL },
233 { 0x0209, EXIF_FORMAT_UNDEFINED, -1, "Olympus.CameraID", "Camera ID", NULL },
234 { 0x020b, EXIF_FORMAT_LONG_UNSIGNED, 1, "Epson.ImageWidth", "Image width", NULL },
235 { 0x020c, EXIF_FORMAT_LONG_UNSIGNED, 1, "Epson.ImageHeight", "Image height", NULL },
236 { 0x020d, EXIF_FORMAT_STRING, -1, "Epson.Manufacturer", "Manufacturer", NULL },
237 { 0x0e00, EXIF_FORMAT_BYTE, -1, "Olympus.PrintImageMatching", "Print image matching", NULL },
238 { 0x1004, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FlashMode", "Flash mode", OlympusTagFlashMode },
239 { 0x1006, EXIF_FORMAT_RATIONAL, 1, "Olympus.Bracket", "Bracket", NULL },
240 { 0x100b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FocusMode", "Focus mode", OlympusTagFocusMode },
241 { 0x100c, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Olympus.FocusDistance", "Focus distance", NULL },
242 { 0x100d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Zoom", "Zoom", NULL },
243 { 0x1006, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.MacroFocus", "Macro focus", NULL },
244 { 0x100f, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Sharpness", "Sharpness", OlympusTagSharpness },
245 { 0x1011, EXIF_FORMAT_SHORT_UNSIGNED, 9, "Olympus.ColorMatrix", "Color matrix", NULL },
246 { 0x1012, EXIF_FORMAT_SHORT_UNSIGNED, 4, "Olympus.BlackLevel", "Black level", NULL },
247 { 0x1015, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.WhiteBalance", "White balance", NULL },
248 { 0x1017, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.RedBias", "Red bias", NULL },
249 { 0x1018, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.BlueBias", "Blue bias", NULL },
250 { 0x101a, EXIF_FORMAT_STRING, -1, "Olympus.SerialNumber", "Serial number", NULL },
251 { 0x1023, EXIF_FORMAT_RATIONAL, 1, "Olympus.FlashBias", "Flash bias", NULL },
252 { 0x1029, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Contrast", "Contrast", OlympusTagContrast },
253 { 0x102a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.SharpnessFactor", "Sharpness factor", NULL },
254 { 0x102b, EXIF_FORMAT_SHORT_UNSIGNED, 6, "Olympus.ColorControl", "Color control", NULL },
255 { 0x102c, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.ValidBits", "Valid bits", NULL },
256 { 0x102d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.CoringFilter", "Coring filter", NULL },
257 { 0x102e, EXIF_FORMAT_LONG_UNSIGNED, 1, "Olympus.FinalWidth", "Final width", NULL },
258 { 0x102f, EXIF_FORMAT_LONG_UNSIGNED, 1, "Olympus.FinalHeight", "Final height", NULL },
259 { 0x1034, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.CompressionRatio", "Compression ratio", NULL },
263 static ExifTextList OlympusShootingMode[]= {
271 static ExifTextList OlympusPanoramaDirection[]= {
272 { 1, "left to right" },
273 { 2, "right to left" },
274 { 3, "bottom to top" },
275 { 4, "top to bottom" },
279 static ExifTextList OlympusWB[]= {
286 static ExifTextList OlympusWBColorTemp[]= {
297 gboolean format_olympus_makernote(ExifData *exif, guchar *tiff, guint offset,
298 guint size, ExifByteOrder bo)
303 if (offset + 8 + 4 >= size) return FALSE;
305 data = tiff + offset;
307 /* Olympus tag format starts with "OLYMP\x00\x01" or "OLYMP\x00\x02",
308 * plus an unknown byte,
309 * followed by IFD data using Olympus tags.
311 if (memcmp(data, "OLYMP\x00\x01", 7) != 0 &&
312 memcmp(data, "OLYMP\x00\x02", 7) != 0) return FALSE;
314 if (exif_parse_IFD_table(exif, tiff, offset + 8, size,
315 bo, 0, OlympusExifMarkersList) != 0)
320 item = exif_get_item(exif, "Olympus.SpecialMode");
321 if (item && item->data_len == 3 * sizeof(guint32))
323 static ExifMarker marker = { 0x0200, EXIF_FORMAT_STRING, -1,
324 "Olympus.ShootingMode", "Shooting mode", NULL };
325 guint32 *array = item->data;
331 mode = exif_text_list_find_value(OlympusShootingMode, array[0]);
334 pdir = exif_text_list_find_value(OlympusPanoramaDirection, array[2]);
337 text = g_strdup_printf("%s%s%s, seq %d", mode,
338 (pdir) ? " " : "", (pdir) ? pdir : "",
340 l = strlen(text) + 1;
341 item = exif_item_new(marker.format, marker.tag, l, &marker);
342 memcpy(item->data, text, l);
348 exif->items = g_list_prepend(exif->items, item);
351 item = exif_get_item(exif, "Olympus.WhiteBalance");
352 if (item && item->data_len == 2 * sizeof(guint16))
354 static ExifMarker marker = { 0x1015, EXIF_FORMAT_STRING, -1,
355 "Olympus.WhiteBalance", "White balance", NULL };
356 guint16 *array = item->data;
362 mode = exif_text_list_find_value(OlympusWB, array[0]);
365 color = exif_text_list_find_value(OlympusWBColorTemp, array[1]);
368 text = g_strdup_printf("%s%s%s", mode,
369 (color) ? " " : "", (color) ? color : "");
370 l = strlen(text) + 1;
371 item = exif_item_new(marker.format, marker.tag, l, &marker);
372 memcpy(item->data, text, l);
378 exif->items = g_list_prepend(exif->items, item);
387 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */