1 /*
2  * Copyright (c) 2004 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: asahi.c,v 1.5 2004/12/23 20:38:52 ejohnst Exp $
33  */
34 
35 /*
36  * Exif tag definitions for Asahi Optical Co. (Pentax) maker notes.
37  * Note that the format is similar to Casio's, though has byte order
38  * weirdness like Fuji.
39  *
40  */
41 
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 
46 #include "makers.h"
47 
48 
49 /* Quality. */
50 
51 static struct descrip asahi_qual[] = {
52 	{ 0,	"Economy" },
53 	{ 1,	"Fine" },
54 	{ 2,	"Super Fine" },
55 	{ -1,	"Unknown" },
56 };
57 
58 
59 /* Resolution. */
60 
61 static struct descrip asahi_res[] = {
62 	{ 0,	"640x480" },
63 	{ 2,	"1024x768" },
64 	{ 4,	"1600x1200" },
65 	{ 22,	"2304x1728" },
66 	{ -1,	"Unknown" },
67 };
68 
69 
70 /* Focus mode. */
71 
72 static struct descrip asahi_focus[] = {
73 	{ 0,	"Normal" },
74 	{ 1,	"Macro" },
75 	{ 2,	"Macro" },
76 	{ 3,	"Infinity" },
77 	{ -1,	"Unknown" },
78 };
79 
80 
81 /* White balance. */
82 
83 static struct descrip asahi_whiteb[] = {
84 	{ 0,	"Auto" },
85 	{ 1,	"Daylight" },
86 	{ 2,	"Shade" },
87 	{ 3,	"Fluorescent" },
88 	{ 4,	"Tungsten" },
89 	{ 5,	"Manual" },
90 	{ -1,	"Unknown" },
91 };
92 
93 
94 /* Saturation, contrast, & sharpness. */
95 
96 static struct descrip asahi_range[] = {
97 	{ 0,	"Soft" },
98 	{ 1,	"Normal" },
99 	{ 2,	"Hard" },
100 	{ 3,	"Medium Soft" },
101 	{ 4,	"Medium Hard" },
102 	{ -1,	"Unknown" },
103 };
104 
105 
106 /* Maker note IFD tags. */
107 
108 static struct exiftag asahi_tags[] = {
109 	{ 0x0008, TIFF_SHORT, 1, ED_IMG, "AsahiQuality",
110 	  "Quality Level", asahi_qual },
111 	{ 0x0009, TIFF_SHORT, 1, ED_VRB, "AsahiRes",
112 	  "Recorded Pixels", asahi_res },
113 	{ 0x000d, TIFF_SHORT, 1, ED_IMG, "AsahiFocus",
114 	  "Focusing Mode", asahi_focus },
115 	{ 0x0019, TIFF_SHORT, 1, ED_IMG, "AsahiWhiteB",
116 	  "White Balance", asahi_whiteb },
117 	{ 0x001f, TIFF_SHORT, 1, ED_IMG, "AsahiSaturate",
118 	  "Saturation", asahi_range },
119 	{ 0x0020, TIFF_SHORT, 1, ED_IMG, "AsahiContrast",
120 	  "Contrast", asahi_range },
121 	{ 0x0021, TIFF_SHORT, 1, ED_IMG, "AsahiSharp",
122 	  "Sharpness", asahi_range },
123 	{ 0xffff, TIFF_UNKN, 0, ED_UNK, "AsahiUnknown",
124 	  "Asahi Unknown", NULL },
125 };
126 
127 
128 /*
129  * Process Asahi maker note tags.
130  */
131 void
asahi_prop(struct exifprop * prop,struct exiftags * t)132 asahi_prop(struct exifprop *prop, struct exiftags *t)
133 {
134 
135 	/* Override a couple of standard tags. */
136 
137 	switch (prop->tag) {
138 
139 	case 0x0019:
140 		prop->override = EXIF_T_WHITEBAL;
141 		break;
142 
143 	case 0x001f:
144 		prop->override = EXIF_T_SATURATION;
145 		break;
146 
147 	case 0x0020:
148 		prop->override = EXIF_T_CONTRAST;
149 		break;
150 
151 	case 0x0021:
152 		prop->override = EXIF_T_SHARPNESS;
153 		break;
154 	}
155 }
156 
157 
158 /*
159  * Try to read an Asahi maker note IFD.
160  */
161 struct ifd *
asahi_ifd(u_int32_t offset,struct tiffmeta * md)162 asahi_ifd(u_int32_t offset, struct tiffmeta *md)
163 {
164 
165 	/*
166 	 * It appears that there are a couple of maker note schemes for
167 	 * for Asahi cameras, most with a 6 byte offset.  ("AOC" stands
168 	 * for "Asahi Optical Co.")
169 	 */
170 
171 	if (!memcmp("AOC\0", md->btiff + offset, 4)) {
172 
173 		/*
174 		 * If the prefix includes two spaces, fix at big-endian.
175 		 * E.g., Optio 230, 330GS, 33L.
176 		 */
177 
178 		if (!memcmp("  ", md->btiff + offset + 4, 2)) {
179 			md->order = BIG;
180 			return (readifds(offset + 6, asahi_tags, md));
181 		}
182 
183 		/*
184 		 * With two zero bytes, try file byte order (?).
185 		 * E.g., Optio 330RS, 33WR, 430RS, 450, 550, 555, S, S4.
186 		 */
187 
188 		if (!memcmp("\0\0", md->btiff + offset + 4, 2))
189 			return (readifds(offset + 6, asahi_tags, md));
190 
191 		/*
192 		 * Two M's seems to be a different tag set we don't grok.
193 		 * E.g., *ist D.
194 		 */
195 
196 		if (!memcmp("MM", md->btiff + offset + 4, 2)) {
197 			exifwarn("Asahi maker note version not supported");
198 			return (NULL);
199 		}
200 
201 		exifwarn("Asahi maker note version not supported");
202 		return (NULL);
203 	}
204 
205 	/*
206 	 * The EI-200 seems to have a non-IFD note; we'll use the heuristic
207 	 * of a minimum 10 tags before we look at it as an IFD.
208 	 */
209 
210 	if (exif2byte(md->btiff + offset, md->order) < 10) {
211 		exifwarn("Asahi maker note version not supported");
212 		return (NULL);
213 	}
214 
215 	/* E.g., Optio 330, 430. */
216 
217 	md->order = BIG;
218 	return (readifds(offset, asahi_tags, md));
219 }
220