Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
[geeqie.git] / src / format_fuji.c
1 /*
2  *  GQView
3  *  (C) 2005 John Ellis
4  *
5  *  Authors:
6  *    Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
7  *
8  * This software is released under the GNU General Public License (GNU GPL).
9  * Please read the included file COPYING for more information.
10  * This software comes with no warranty of any kind, use at your own risk!
11  */
12
13 #ifdef HAVE_CONFIG_H
14 #  include "config.h"
15 #endif
16
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <unistd.h>
21
22 #include <glib.h>
23
24 #include "intl.h"
25
26 #include "format_fuji.h"
27 #include "format_raw.h"
28
29 #include "exif.h"
30
31
32 gint format_fuji_raw(const void *data, const guint len,
33                      guint *image_offset, guint *exif_offset)
34 {
35         guint io;
36         guint eo;
37
38         if (len < 128 ||
39             memcmp(data, "FUJIFILM", 8) != 0)
40                 {
41                 return FALSE;
42                 }
43
44         io = GUINT32_FROM_BE(*(guint32*)(data + 84));
45         eo = *image_offset + 12;
46
47         /* verify jpeg marker */
48         if (memcmp(data + io, "\xff\xd8\xff\xe1", 4) != 0)
49                 {
50                 return FALSE;
51                 }
52
53         if (image_offset) *image_offset = io;
54         if (exif_offset) *exif_offset = eo;
55
56         printf("raw Fuji format file\n");
57
58         return TRUE;
59 }
60
61
62 /*
63  *-----------------------------------------------------------------------------
64  * EXIF Makernote for Fujifilm
65  *-----------------------------------------------------------------------------
66  */
67
68 static ExifTextList FujiTagSharpness[] = {
69         { 1,    "soft" },
70         { 2,    "soft" },
71         { 3,    "normal" },
72         { 4,    "hard" },
73         { 5,    "hard" },
74         EXIF_TEXT_LIST_END
75 };
76
77 static ExifTextList FujiTagWhiteBalance[]= {
78         { 0,    "auto" },
79         { 256,  "daylight" },
80         { 512,  "cloudy" },
81         { 768,  "daylight color-fluorescence" },
82         { 769,  "daywhite color-fluorescence" },
83         { 770,  "white-fluorescence" },
84         { 1024, "incandescent" },
85         { 3840, "custom" },
86         EXIF_TEXT_LIST_END
87 };
88
89 static ExifTextList FujiTagColorTone[]= {
90         { 0,    "normal" },
91         { 256,  "high" },
92         { 512,  "low" },
93         EXIF_TEXT_LIST_END
94 };
95
96 static ExifTextList FujiTagFlashMode[]= {
97         { 0,    "auto" },
98         { 1,    "on" },
99         { 2,    "off" },
100         { 3,    "red-eye reduction" },
101         EXIF_TEXT_LIST_END
102 };
103
104 static ExifTextList FujiTagOffOn[]= {
105         { 0,    "off" },
106         { 1,    "on" },
107         EXIF_TEXT_LIST_END
108 };
109
110 static ExifTextList FujiTagFocusMode[]= {
111         { 0,    "auto" },
112         { 1,    "manual" },
113         EXIF_TEXT_LIST_END
114 };
115
116 static ExifTextList FujiTagPictureMode[]= {
117         { 0,    "auto" },
118         { 1,    "portrait" },
119         { 2,    "landscape" },
120         { 4,    "sports" },
121         { 5,    "night" },
122         { 6,    "program AE" },
123         { 256,  "aperture priority AE" },
124         { 512,  "shutter priority AE" },
125         { 768,  "manual" },
126         EXIF_TEXT_LIST_END
127 };
128
129 static ExifTextList FujiTagNoYes[]= {
130         { 0,    "no" },
131         { 1,    "yes" },
132         EXIF_TEXT_LIST_END
133 };
134
135 #if 0
136 static ExifTextList FujiTag[]= {
137         { ,     "" },
138         { ,     "" },
139         EXIF_TEXT_LIST_END
140 };
141 #endif
142
143
144 static ExifMarker FujiExifMarkersList[] = {
145 { 0x1000,       EXIF_FORMAT_STRING, 8,          "MkN.Fuji.Quality",     "Quality",      NULL },
146 { 0x1001,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.Sharpness",   "Sharpness",    FujiTagSharpness },
147 { 0x1002,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.WhiteBalance","White balance",FujiTagWhiteBalance },
148 { 0x1003,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.Color",       "Color",        FujiTagColorTone },
149 { 0x1004,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.Tone",        "Tone",         FujiTagColorTone },
150 { 0x1010,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.FlashMode",   "Flash mode",   FujiTagFlashMode },
151 { 0x1011,       EXIF_FORMAT_RATIONAL, 1,        "MkN.Fuji.FlashStrength", "Flash strength", NULL },
152 { 0x1020,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.Macro",       "Macro",        FujiTagOffOn },
153 { 0x1021,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.FocusMode",   "Focus mode",   FujiTagFocusMode },
154 { 0x1030,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.SlowSync",    "Slow synchro", FujiTagOffOn },
155 { 0x1031,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.PictureMode", "Picture mode", FujiTagPictureMode },
156 { 0x1100,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.ContTake/Bracket",
157                                                         "Continuous / Auto bracket",    FujiTagOffOn },
158 { 0x1300,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.BlurWarning", "Blue warning", FujiTagNoYes },
159 { 0x1301,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.FocusWarning","Focus warning",FujiTagNoYes },
160 { 0x1302,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "MkN.Fuji.AEWarning",   "AE warning",   FujiTagNoYes },
161 EXIF_MARKER_LIST_END
162 };
163
164
165
166 gint format_fuji_makernote(ExifData *exif, unsigned char *tiff, guint offset,
167                            guint size, ExifByteOrder byte_order)
168 {
169         unsigned char *data;
170         guint ifdstart;
171
172         if (offset + 8 + 4 >= size) return FALSE;
173
174         data = tiff + offset;
175         if (memcmp(data, "FUJIFILM", 8) != 0) return FALSE;
176
177         ifdstart = exif_byte_get_int32(data + 8, EXIF_BYTE_ORDER_INTEL);
178         if (offset + ifdstart >= size) return FALSE;
179
180         if (exif_parse_IFD_table(exif, tiff + offset, ifdstart, size - offset,
181                                  EXIF_BYTE_ORDER_INTEL, FujiExifMarkersList) != 0)
182                 {
183                 return FALSE;
184                 }
185
186         return TRUE;
187 }
188