1 /*
2  * Copyright (c) 2004, Tom Hughes <tom@compton.nu>
3  * Copyright (c) 2004, Eric M. Johnston <emj@postal.net>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Eric M. Johnston.
17  * 4. Neither the name of the author nor the names of any co-contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $Id: panasonic.c,v 1.6 2004/12/28 17:33:22 ejohnst Exp $
34  *
35  */
36 
37 /*
38  * Exif tag definitions for Panasonic Lumix maker notes.
39  * Tags deciphered by Tom Hughes <tom@compton.nu>; updated for FZ20
40  * by Laurent Monin <zas@norz.org> & Lee Kindness <lkindness@csl.co.uk>.
41  *
42  * Tested models: DMC-FZ10, DMC-FZ20.
43  *
44  */
45 
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #include "makers.h"
51 
52 
53 /* Image quality. */
54 
55 static struct descrip panasonic_quality[] = {
56 	{ 2,	"Fine" },
57 	{ 3,	"Standard" },
58 	{ -1,	"Unknown" },
59 };
60 
61 
62 /* White balance. */
63 
64 static struct descrip panasonic_whitebal[] = {
65 	{ 1,	"Auto" },
66 	{ 2,	"Daylight" },
67 	{ 3,	"Cloudy" },
68 	{ 4,	"Halogen" },
69 	{ 5,	"Manual" },
70 	{ 8,	"Flash" },
71 	{ -1,	"Unknown" },
72 };
73 
74 
75 /* Focus mode. */
76 
77 static struct descrip panasonic_focus[] = {
78 	{ 1,	"Auto" },
79 	{ 2,	"Manual" },
80 	{ -1,	"Unknown" },
81 };
82 
83 
84 /* Spot mode. */
85 
86 static struct descrip panasonic_spot[] = {
87 	{ 256,	"On" },
88 	{ 4096,	"Off" },
89 	{ -1,	"Unknown" },
90 };
91 
92 
93 /* Optical Image Stabilizer mode. */
94 
95 static struct descrip panasonic_ois[] = {
96 	{ 2,	"Mode 1" },
97 	{ 3,	"Off" },
98 	{ 4,	"Mode 2" },
99 	{ -1,	"Unknown" },
100 };
101 
102 
103 /* Macro. */
104 
105 static struct descrip panasonic_macro[] = {
106 	{ 1,	"Macro" },
107 	{ 2,	"Normal" },
108 	{ -1,	"Unknown" },
109 };
110 
111 
112 /* Shooting mode. */
113 
114 static struct descrip panasonic_shoot[] = {
115 	{ 2,	"Portrait" },
116 	{ 3,	"Scenery" },
117 	{ 4,	"Sports" },
118 	{ 5,	"Night Portrait" },
119 	{ 6,	"Program" },
120 	{ 7,	"Aperture Priority" },
121 	{ 8,	"Shutter Priority" },
122 	{ 9,	"Macro" },
123 	{ 11,	"Manual" },
124 	{ 13,	"Panning" },
125 	{ 18,	"Fireworks" },
126 	{ 19,	"Party" },
127 	{ 20,	"Snow" },
128 	{ 21,	"Night Scenery" },
129 	{ -1,	"Unknown" },
130 };
131 
132 
133 /* Audio. */
134 
135 static struct descrip panasonic_audio[] = {
136 	{ 1,	"Yes" },
137 	{ 2,	"No" },
138 	{ -1,	"Unknown" },
139 };
140 
141 
142 /* Color effect. */
143 
144 static struct descrip panasonic_color[] = {
145 	{ 1,	"Off" },
146 	{ 2,	"Warm" },
147 	{ 3,	"Cool" },
148 	{ 4,	"Black & White" },
149 	{ 5,	"Sepia" },
150 	{ -1,	"Unknown" },
151 };
152 
153 
154 /* Contrast & noise. */
155 
156 static struct descrip panasonic_range[] = {
157 	{ 0,	"Standard" },
158 	{ 1,	"Low" },
159 	{ 2,	"High" },
160 	{ -1,	"Unknown" },
161 };
162 
163 
164 /* Maker note IFD tags. */
165 
166 static struct exiftag panasonic_tags0[] = {
167 	{ 0x0001, TIFF_SHORT, 1, ED_IMG, "PanasonicQuality",
168 	  "Image Quality", panasonic_quality },
169 	{ 0x0003, TIFF_SHORT, 1, ED_IMG, "PanasonicWhiteB",
170 	  "White Balance", panasonic_whitebal },
171 	{ 0x0007, TIFF_SHORT, 1, ED_IMG, "PanasonicFocus",
172 	  "Focus Mode", panasonic_focus },
173 	{ 0x000f, TIFF_BYTE, 1, ED_IMG, "PanasonicSpotMode",
174 	  "Spot Mode", panasonic_spot },
175 	{ 0x001a, TIFF_SHORT, 1, ED_IMG, "PanasonicOIS",
176 	  "Image Stabilizer", panasonic_ois },
177 	{ 0x001c, TIFF_SHORT, 1, ED_IMG, "PanasonicMacroMode",
178 	  "Macro Mode", panasonic_macro },
179 	{ 0x001f, TIFF_SHORT, 1, ED_IMG, "PanasonicShootMode",
180 	  "Shooting Mode", panasonic_shoot },
181 	{ 0x0020, TIFF_SHORT, 1, ED_IMG, "PanasonicAudio",
182 	  "Audio", panasonic_audio },
183 	{ 0x0023, TIFF_SHORT, 1, ED_UNK, "PanasonicWBAdjust",
184 	  "White Balance Adjust", NULL },
185 	{ 0x0024, TIFF_SSHORT, 1, ED_IMG, "PanasonicFlashBias",
186 	  "Flash Bias", NULL },
187 	{ 0x0028, TIFF_SHORT, 1, ED_IMG, "PanasonicColorEffect",
188 	  "Color Effect", panasonic_color },
189 	{ 0x002c, TIFF_SHORT, 1, ED_IMG, "PanasonicContrast",
190 	  "Contrast", panasonic_range },
191 	{ 0x002d, TIFF_SHORT, 1, ED_IMG, "PanasonicNoiseReduce",
192 	  "Noise Reduction", panasonic_range },
193 	{ 0xffff, TIFF_UNKN, 0, ED_UNK, "PanasonicUnknown",
194 	  "Panasonic Unknown", NULL },
195 };
196 
197 
198 /*
199  * Process Panasonic maker note tags.
200  */
201 void
panasonic_prop(struct exifprop * prop,struct exiftags * t)202 panasonic_prop(struct exifprop *prop, struct exiftags *t)
203 {
204 
205 	switch (prop->tag) {
206 
207 	/* White balance. */
208 
209 	case 0x0003:
210 		prop->override = EXIF_T_WHITEBAL;
211 		break;
212 
213 	/* White balance adjust (unknown). */
214 
215 	case 0x0023:
216 		exifstralloc(&prop->str, 10);
217 		snprintf(prop->str, 9, "%d", (int16_t)prop->value);
218 		break;
219 
220 	/* Flash bias. */
221 
222 	case 0x0024:
223 		exifstralloc(&prop->str, 10);
224 		snprintf(prop->str, 9, "%.2f EV", (int16_t)prop->value / 3.0);
225 		break;
226 
227 	/* Contrast. */
228 
229 	case 0x002c:
230 		prop->override = EXIF_T_CONTRAST;
231 		break;
232 	}
233 }
234 
235 
236 /*
237  * Try to read a Panasonic maker note IFD.
238  */
239 struct ifd *
panasonic_ifd(u_int32_t offset,struct tiffmeta * md)240 panasonic_ifd(u_int32_t offset, struct tiffmeta *md)
241 {
242 
243 	if (memcmp("Panasonic\0\0\0", md->btiff + offset, 12)) {
244 		exifwarn("Maker note format not supported");
245 		return (NULL);
246 	}
247 
248 	return (readifds(offset + 12, panasonic_tags0, md));
249 }
250