1 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
2 /*          EXIFPROBE - TIFF/JPEG/EXIF image file probe               */
3 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
4 /* Copyright (C) 2002,2005 by Duane H. Hesser. All rights reserved.   */
5 /*                                                                    */
6 /* See the file LICENSE.EXIFPROBE for terms of use.                   */
7 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
8 
9 #ifndef lint
10 static char *ModuleId = "@(#) $Id: maker_sigma.c,v 1.4 2005/07/24 22:56:27 alex Exp $";
11 #endif
12 
13 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
14 /* Sigma camera maker-specific routines.                              */
15 /* Tag information from;                                              */
16 /*   http://www.x3f.info/technotes/FileDocs/MakerNoteDoc.html         */
17 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
18 
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include "defs.h"
23 #include "datadefs.h"
24 #include "maker_datadefs.h"
25 #include "summary.h"
26 #include "maker.h"
27 #include "misc.h"
28 #include "tags.h"
29 #include "maker_extern.h"
30 #include "extern.h"
31 
32 extern struct camera_id sigma_model_id[];
33 
34 /* Find the id number assigned to known Sigma camera models.          */
35 /* This number is used to dispatch print and interpret routines       */
36 /* apporopriate to the current image.                                 */
37 
38 int
sigma_model_number(char * model,char * software)39 sigma_model_number(char *model,char *software)
40 {
41     struct camera_id *model_id;
42     int number = NO_MODEL;
43 
44     for(model_id = &sigma_model_id[0]; model_id && model_id->name; ++model_id)
45     {
46         if(strncasecmp(model,model_id->name,model_id->namelen) == 0)
47         {
48             number = model_id->id;
49             setnoteversion(model_id->noteversion);
50             setnotetagset(model_id->notetagset);    /* info only      */
51             break;
52         }
53     }
54     return(number);
55 }
56 
57 /* Dispatch a print routine based upon model                          */
58 
59 void
print_sigma_makervalue(struct ifd_entry * entry_ptr,int make,int model,char * prefix)60 print_sigma_makervalue(struct ifd_entry *entry_ptr,int make, int model,
61 					char *prefix)
62 {
63     int noteversion = 0;
64 
65     if(entry_ptr && (PRINT_VALUE))
66     {
67         noteversion = getnoteversion();
68         switch(noteversion)
69         {
70             case 1:
71                 print_sigma1_makervalue(entry_ptr,make,model,prefix);
72                 break;
73             default:
74                 print_value(entry_ptr,PREFIX);
75                 break;
76         }
77     }
78 }
79 
80 /* Model-specific print routine for sigma cameras. This routine is    */
81 /* responsible for picking off any direct entry tags which are        */
82 /* peculiar and will not be handled properly by print_value()         */
83 /* (usually UNDEFINED values which fit in the 4-byte entry value). If */
84 /* there are no such entries, this function simply calls              */
85 /* print_value().                                                     */
86 
87 void
print_sigma1_makervalue(struct ifd_entry * entry_ptr,int make,int model,char * prefix)88 print_sigma1_makervalue(struct ifd_entry *entry_ptr,int make, int model,
89 					char *prefix)
90 {
91     if(entry_ptr && (PRINT_VALUE))
92     {
93 		switch(entry_ptr->tag)
94 		{
95 			default:
96 				print_value(entry_ptr,PREFIX);
97 				break;
98 		}
99 	}
100 }
101 
102 /* Dispatch a routine to decode and print offset values for sigma     */
103 /* cameras.                                                           */
104 
105 void
print_sigma_offset_makervalue(FILE * inptr,unsigned short byteorder,struct ifd_entry * entry_ptr,unsigned long fileoffset_base,struct image_summary * summary_entry,char * parent_name,char * prefix,int indent,int make,int model,int at_offset)106 print_sigma_offset_makervalue(FILE *inptr,unsigned short byteorder,
107 	struct ifd_entry *entry_ptr,unsigned long fileoffset_base,
108     struct image_summary *summary_entry,char *parent_name,char *prefix,
109     int indent,int make,int model,int at_offset)
110 {
111     int noteversion = 0;
112 
113     if(entry_ptr)
114     {
115         noteversion = getnoteversion();
116         switch(noteversion)
117         {
118             case 1:
119                 sigma1_offset_makervalue(inptr,byteorder,entry_ptr,
120                                         fileoffset_base,summary_entry,
121                                         parent_name,prefix,indent,
122                                         make,model,at_offset);
123                 break;
124             default:
125                     print_generic_offset_makervalue(inptr,byteorder,entry_ptr,
126                                         fileoffset_base,parent_name,prefix,
127                                         indent,make,model,at_offset);
128                 break;
129         }
130     }
131 }
132 
133 /* Model-specific routine to print values found at an offset from the */
134 /* IFD entry in sigma makernotes.                                     */
135 
136 void
sigma1_offset_makervalue(FILE * inptr,unsigned short byteorder,struct ifd_entry * entry_ptr,unsigned long fileoffset_base,struct image_summary * summary_entry,char * parent_name,char * prefix,int indent,int make,int model,int at_offset)137 sigma1_offset_makervalue(FILE *inptr,unsigned short byteorder,
138 	struct ifd_entry *entry_ptr,unsigned long fileoffset_base,
139     struct image_summary *summary_entry,char *parent_name,char *prefix,
140     int indent,int make,int model,int at_offset)
141 {
142 	char *nameoftag;
143     char *fulldirname = NULL;
144 
145 	if(entry_ptr)
146 	{
147 		nameoftag = maker_tagname(entry_ptr->tag,make,model);
148         fulldirname = splice(parent_name,".",nameoftag);
149 
150 		switch(entry_ptr->tag)
151 		{
152 			default:
153 				print_generic_offset_makervalue(inptr,byteorder,entry_ptr,
154 										fileoffset_base,fulldirname,prefix,indent,
155 										make,model,at_offset);
156 				break;
157 		}
158         if(fulldirname)
159             free(fulldirname);
160 	}
161 }
162 
163 /* The tagname routine is the first place in the code path which      */
164 /* requires knowledge of the note version. If the version is not      */
165 /* given in the model table (e.g. the model is unknown), then switch  */
166 /* code in find_maker_scheme() should have set it. This routine       */
167 /* repeats the check for non-zero noteversion and is prepared to set  */
168 /* the noteversion first time through, but should never need to do    */
169 /* so. Noteversion should always be non-zero; it should be set to -1  */
170 /* if generic processing is required.                                 */
171 
172 char *
maker_sigma_tagname(unsigned short tag,int model)173 maker_sigma_tagname(unsigned short tag,int model)
174 {
175 	char *tagname = CNULL;
176     int noteversion = 0;
177 
178     if((noteversion = getnoteversion()) == 0)
179     {
180         /* Need more model samples before it is safe to assume a      */
181         /* default                                                    */
182         noteversion = 1;
183         setnoteversion(1);
184     }
185 
186 	switch(noteversion)
187 	{
188 		case 1:
189 			tagname = maker_sigma1_tagname(tag,model);
190 			break;
191 		default:
192 			break;
193 	}
194 
195     /* If no model-specific tag is found, check "generic" tags        */
196     if(tagname == NULL)
197     {
198         switch(tag)
199         {
200             case 0x0e00: tagname = "PrintIM"; break;
201             default: break;
202         }
203     }
204 	return(tagname);
205 }
206 
207 char *
maker_sigma1_tagname(unsigned short tag,int model)208 maker_sigma1_tagname(unsigned short tag,int model)
209 {
210 	char *tagname = CNULL;
211 
212 	switch(tag)
213 	{
214         case 0x0002: tagname = "CameraSerialNumber"; break;
215         case 0x0003: tagname = "DriveMode"; break;
216         case 0x0004: tagname = "ResolutionMode"; break;
217         case 0x0005: tagname = "AutofocusMode"; break;
218         case 0x0006: tagname = "FocusSetting"; break;
219         case 0x0007: tagname = "WhiteBalance"; break;
220         case 0x0008: tagname = "ExposureMode"; break;
221         case 0x0009: tagname = "MeteringMode"; break;
222         case 0x000A: tagname = "LensFocalLengthRange"; break;
223         case 0x000B: tagname = "ColorSpace"; break;
224         case 0x000C: tagname = "Exposure"; break;
225         case 0x000D: tagname = "Contrast"; break;
226         case 0x000E: tagname = "Shadow"; break;
227         case 0x000F: tagname = "Highlight"; break;
228         case 0x0010: tagname = "Saturation"; break;
229         case 0x0011: tagname = "Sharpness"; break;
230         case 0x0012: tagname = "X3FillLight"; break;
231         case 0x0014: tagname = "ColorAdjustment"; break;
232         case 0x0015: tagname = "AdjustmentMode"; break;
233         case 0x0016: tagname = "Quality"; break;
234         case 0x0017: tagname = "Firmware"; break;
235         case 0x0018: tagname = "Software"; break;
236         case 0x0019: tagname = "AutoBracket"; break;
237 			default: break;
238 	}
239 	return(tagname);
240 }
241