Blind fix macOS build
[geeqie.git] / src / format-fuji.cc
1 /*
2  * Copyright (C) 2005 Lars Ellenberg
3  * Copyright (C) 2005 John Ellis
4  * Copyright (C) 2008 - 2016 The Geeqie Team
5  *
6  * Author: Lars Ellenberg
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "format-fuji.h"
24
25 #include <cstring>
26
27 #include <glib.h>
28
29 #include "exif.h"
30
31
32 /*
33  *-----------------------------------------------------------------------------
34  * Raw (RAF) embedded jpeg extraction for Fujifilm
35  *-----------------------------------------------------------------------------
36  */
37
38
39 gboolean format_fuji_raw(guchar *data, const guint len,
40                          guint *image_offset, guint *exif_offset)
41 {
42         guint io;
43         guint eo;
44
45         if (len < 128 ||
46             memcmp(data, "FUJIFILM", 8) != 0)
47                 {
48                 return FALSE;
49                 }
50
51         /* offset to jpeg is embedded at bytes 84-87 */
52         io = exif_byte_get_int32(data + 84, EXIF_BYTE_ORDER_MOTOROLA);
53         if (io + 4 > len) return FALSE;
54
55         /* verify jpeg marker */
56         if (memcmp(data + io, "\xff\xd8\xff\xe1", 4) != 0)
57                 {
58                 return FALSE;
59                 }
60
61         /* Exif is stored in the jpeg, so use the same offset */
62         eo=io;
63
64         if (image_offset) *image_offset = io;
65         if (exif_offset) *exif_offset = eo;
66
67         return TRUE;
68 }
69
70
71 /*
72  *-----------------------------------------------------------------------------
73  * EXIF Makernote for Fujifilm
74  *-----------------------------------------------------------------------------
75  */
76
77 static ExifTextList FujiTagSharpness[] = {
78         { 1,    "soft" },
79         { 2,    "soft" },
80         { 3,    "normal" },
81         { 4,    "hard" },
82         { 5,    "hard" },
83         EXIF_TEXT_LIST_END
84 };
85
86 static ExifTextList FujiTagWhiteBalance[]= {
87         { 0,    "auto" },
88         { 256,  "daylight" },
89         { 512,  "cloudy" },
90         { 768,  "daylight color-fluorescence" },
91         { 769,  "daywhite color-fluorescence" },
92         { 770,  "white-fluorescence" },
93         { 1024, "incandescent" },
94         { 3840, "custom" },
95         EXIF_TEXT_LIST_END
96 };
97
98 static ExifTextList FujiTagColorTone[]= {
99         { 0,    "normal" },
100         { 256,  "high" },
101         { 512,  "low" },
102         EXIF_TEXT_LIST_END
103 };
104
105 static ExifTextList FujiTagFlashMode[]= {
106         { 0,    "auto" },
107         { 1,    "on" },
108         { 2,    "off" },
109         { 3,    "red-eye reduction" },
110         EXIF_TEXT_LIST_END
111 };
112
113 static ExifTextList FujiTagOffOn[]= {
114         { 0,    "off" },
115         { 1,    "on" },
116         EXIF_TEXT_LIST_END
117 };
118
119 static ExifTextList FujiTagFocusMode[]= {
120         { 0,    "auto" },
121         { 1,    "manual" },
122         EXIF_TEXT_LIST_END
123 };
124
125 static ExifTextList FujiTagPictureMode[]= {
126         { 0,    "auto" },
127         { 1,    "portrait" },
128         { 2,    "landscape" },
129         { 4,    "sports" },
130         { 5,    "night" },
131         { 6,    "program AE" },
132         { 256,  "aperture priority AE" },
133         { 512,  "shutter priority AE" },
134         { 768,  "manual" },
135         EXIF_TEXT_LIST_END
136 };
137
138 static ExifTextList FujiTagNoYes[]= {
139         { 0,    "no" },
140         { 1,    "yes" },
141         EXIF_TEXT_LIST_END
142 };
143
144
145 static ExifMarker FujiExifMarkersList[] = {
146 { 0x1000,       EXIF_FORMAT_STRING, 8,          "Fuji.Quality",         "Quality",      nullptr },
147 { 0x1001,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.Sharpness",       "Sharpness",    FujiTagSharpness },
148 { 0x1002,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.WhiteBalance",    "White balance",FujiTagWhiteBalance },
149 { 0x1003,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.Color",           "Color",        FujiTagColorTone },
150 { 0x1004,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.Tone",            "Tone",         FujiTagColorTone },
151 { 0x1010,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.FlashMode",       "Flash mode",   FujiTagFlashMode },
152 { 0x1011,       EXIF_FORMAT_RATIONAL, 1,        "Fuji.FlashStrength",   "Flash strength", nullptr },
153 { 0x1020,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.Macro",           "Macro",        FujiTagOffOn },
154 { 0x1021,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.FocusMode",       "Focus mode",   FujiTagFocusMode },
155 { 0x1030,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.SlowSync",        "Slow synchro", FujiTagOffOn },
156 { 0x1031,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.PictureMode",     "Picture mode", FujiTagPictureMode },
157 { 0x1100,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.ContTake/Bracket",
158                                                         "Continuous / Auto bracket",    FujiTagOffOn },
159 { 0x1300,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.BlurWarning",     "Blue warning", FujiTagNoYes },
160 { 0x1301,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.FocusWarning",    "Focus warning",FujiTagNoYes },
161 { 0x1302,       EXIF_FORMAT_SHORT_UNSIGNED, 1,  "Fuji.AEWarning",       "AE warning",   FujiTagNoYes },
162 EXIF_MARKER_LIST_END
163 };
164
165
166
167 gboolean format_fuji_makernote(ExifData *exif, guchar *tiff, guint offset,
168                                guint size, ExifByteOrder)
169 {
170         guchar *data;
171         guint ifdstart;
172
173         if (offset + 8 + 4 >= size) return FALSE;
174
175         data = tiff + offset;
176
177         /* Fuji tag format starts with "FUJIFILM",
178          * followed by 4 bytes indicating offset to IFD directory using Fuji tags,
179          * byte order is always little endian (II).
180          */
181         if (memcmp(data, "FUJIFILM", 8) != 0) return FALSE;
182
183         ifdstart = exif_byte_get_int32(data + 8, EXIF_BYTE_ORDER_INTEL);
184         if (offset + ifdstart >= size) return FALSE;
185
186         if (exif_parse_IFD_table(exif, tiff + offset, ifdstart, size - offset,
187                                  EXIF_BYTE_ORDER_INTEL, 0, FujiExifMarkersList) != 0)
188                 {
189                 return FALSE;
190                 }
191
192         return TRUE;
193 }
194
195 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */