1 /*
2 * Copyright (c) 2004, 2005, Eric M. Johnston <emj@postal.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Eric M. Johnston.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: sigma.c,v 1.6 2005/01/04 23:37:57 ejohnst Exp $
33 */
34
35 /*
36 * Exif tag definitions for Sigma/Foveon maker notes.
37 * Developed from http://www.x3f.info/technotes/FileDocs/MakerNoteDoc.html.
38 *
39 */
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44
45 #include "makers.h"
46
47
48 /* Maker note IFD tags. */
49
50 static struct exiftag sigma_tags[] = {
51 { 0x0002, TIFF_ASCII, 0, ED_CAM, "SigmaSerial",
52 "Serial Number", NULL },
53 { 0x0003, TIFF_ASCII, 0, ED_IMG, "SigmaDrive",
54 "Drive Mode", NULL },
55 { 0x0004, TIFF_ASCII, 0, ED_IMG, "SigmaResolution",
56 "Resolution", NULL },
57 { 0x0005, TIFF_ASCII, 0, ED_IMG, "SigmaAutofocus",
58 "Autofocus Mode", NULL },
59 { 0x0006, TIFF_ASCII, 0, ED_IMG, "SigmaFocusSet",
60 "Focus Setting", NULL },
61 { 0x0007, TIFF_ASCII, 0, ED_IMG, "SigmaWhiteBal",
62 "White Balance", NULL },
63 { 0x0008, TIFF_ASCII, 0, ED_IMG, "SigmaExpMode",
64 "Exposure Mode", NULL },
65 { 0x0009, TIFF_ASCII, 0, ED_IMG, "SigmaMeterMode",
66 "Metering Mode", NULL },
67 { 0x000a, TIFF_ASCII, 0, ED_CAM, "SigmaLensRange",
68 "Focal Length Range", NULL },
69 { 0x000b, TIFF_ASCII, 0, ED_VRB, "SigmaColor",
70 "Color Space", NULL },
71 { 0x000c, TIFF_ASCII, 0, ED_IMG, "SigmaExposure",
72 "Exposure", NULL },
73 { 0x000d, TIFF_ASCII, 0, ED_IMG, "SigmaContrast",
74 "Contrast", NULL },
75 { 0x000e, TIFF_ASCII, 0, ED_IMG, "SigmaShadow",
76 "Shadow", NULL },
77 { 0x000f, TIFF_ASCII, 0, ED_IMG, "SigmaHighlight",
78 "Highlight", NULL },
79 { 0x0010, TIFF_ASCII, 0, ED_IMG, "SigmaSaturate",
80 "Saturation", NULL },
81 { 0x0011, TIFF_ASCII, 0, ED_IMG, "SigmaSharp",
82 "Sharpness", NULL },
83 { 0x0012, TIFF_ASCII, 0, ED_IMG, "SigmaFill",
84 "Fill Light", NULL },
85 { 0x0014, TIFF_ASCII, 0, ED_IMG, "SigmaColorAdj",
86 "Color Adjustment", NULL },
87 { 0x0015, TIFF_ASCII, 0, ED_IMG, "SigmaAdjMode",
88 "Adjustment Mode", NULL },
89 { 0x0016, TIFF_ASCII, 0, ED_IMG, "SigmaQuality",
90 "Quality", NULL },
91 { 0x0017, TIFF_ASCII, 0, ED_CAM, "SigmaFirmware",
92 "Firmware Version", NULL },
93 { 0x0018, TIFF_ASCII, 0, ED_CAM, "SigmaSoftware",
94 "Camera Software", NULL },
95 { 0x0019, TIFF_ASCII, 0, ED_IMG, "SigmaAutoBrack",
96 "Auto Bracket", NULL },
97 { 0xffff, TIFF_UNKN, 0, ED_UNK, "SigmaUnknown",
98 "Sigma Unknown", NULL },
99 };
100
101
102 static void
sigma_deprefix(char * str,const char * prefix)103 sigma_deprefix(char *str, const char *prefix)
104 {
105 int l;
106
107 l = strlen(prefix);
108 if (!strncmp(str, prefix, l))
109 memmove(str, str + l, strlen(str + l) + 1);
110 }
111
112
113 /*
114 * Process Sigma maker note tags.
115 */
116 void
sigma_prop(struct exifprop * prop,struct exiftags * t)117 sigma_prop(struct exifprop *prop, struct exiftags *t)
118 {
119
120 /* Couldn't grok the value somewhere upstream, so nevermind. */
121
122 if (prop->type == TIFF_ASCII && !prop->str)
123 return;
124
125 /*
126 * For these, I suppose it's safe to assume that the value prefix
127 * will always be the same. But, for safety's sake...
128 */
129 switch (prop->tag) {
130
131 case 0x000c:
132 sigma_deprefix(prop->str, "Expo:");
133 break;
134 case 0x000d:
135 sigma_deprefix(prop->str, "Cont:");
136 break;
137 case 0x000e:
138 sigma_deprefix(prop->str, "Shad:");
139 break;
140 case 0x000f:
141 sigma_deprefix(prop->str, "High:");
142 break;
143 case 0x0010:
144 sigma_deprefix(prop->str, "Satu:");
145 break;
146 case 0x0011:
147 sigma_deprefix(prop->str, "Shar:");
148 break;
149 case 0x0012:
150 sigma_deprefix(prop->str, "Fill:");
151 break;
152 case 0x0014:
153 sigma_deprefix(prop->str, "CC:");
154 break;
155 case 0x0016:
156 sigma_deprefix(prop->str, "Qual:");
157 break;
158 }
159 }
160
161
162 /*
163 * Try to read a Sigma maker note IFD.
164 */
165 struct ifd *
sigma_ifd(u_int32_t offset,struct tiffmeta * md)166 sigma_ifd(u_int32_t offset, struct tiffmeta *md)
167 {
168
169 /*
170 * The IFD starts after an 10 byte ID string offset. The first
171 * 8 bytes are a usual offset, but the next two bytes might be a
172 * version of some sort. For now, we'll ignore it...
173 */
174
175 if (memcmp("SIGMA\0\0\0", md->btiff + offset, 8) ||
176 memcmp("FOVEON\0\0", md->btiff + offset, 8))
177 return (readifds(offset + 10, sigma_tags, md));
178
179 exifwarn("Sigma maker note version not supported");
180 return (NULL);
181 }
182