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_sony.c,v 1.3 2005/07/24 22:56:27 alex Exp $";
11 #endif
12 
13 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
14 /* Sony camera maker-specific routines                                */
15 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
16 /*                                                                    */
17 /* A bare minimum is known at this time (4/22/03)...just the PrintIM  */
18 /* tag.                                                               */
19 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include "defs.h"
25 #include "datadefs.h"
26 #include "maker_datadefs.h"
27 #include "summary.h"
28 #include "maker.h"
29 #include "misc.h"
30 #include "tags.h"
31 #include "maker_extern.h"
32 #include "extern.h"
33 
34 extern struct camera_id sony_model_id[];
35 
36 /* Find the identifying number assigned to known Sony camera models.  */
37 /* This number is used to dispatch print and interpret routines       */
38 /* approopriate to the current image.                                 */
39 
40 int
sony_model_number(char * model,char * software)41 sony_model_number(char *model,char *software)
42 {
43     struct camera_id *model_id;
44     int number = NO_MODEL;
45 
46     for(model_id = &sony_model_id[0]; model_id && model_id->name; ++model_id)
47     {
48         if(strncasecmp(model,model_id->name,model_id->namelen) == 0)
49         {
50             number = model_id->id;
51             setnoteversion(model_id->noteversion);
52             setnotetagset(model_id->notetagset);    /* info only      */
53             break;
54         }
55     }
56 
57     return(number);
58 }
59 
60 
61 /* Dispatch a print routine for direct values in Sony cameras,        */
62 /* based upon noteversion.                                            */
63 
64 void
print_sony_makervalue(struct ifd_entry * entry_ptr,int make,int model,char * prefix)65 print_sony_makervalue(struct ifd_entry *entry_ptr,int make,int model,
66                     char *prefix)
67 {
68     int noteversion = 0;
69 
70     noteversion = getnoteversion();
71 
72     if(entry_ptr && (PRINT_VALUE))
73     {
74         switch(noteversion)
75         {
76             case 1:
77                 print_sony1_makervalue(entry_ptr,make,model,prefix);
78                 break;
79             default:
80                 print_value(entry_ptr,PREFIX);
81                 break;
82         }
83     }
84 }
85 
86 /* Model-specific print routine for Sony cameras. This routine is     */
87 /* responsible for picking off any direct entry tags which are        */
88 /* peculiar and will not be handled properly by print_value()         */
89 /* (usually UNDEFINED values which fit in the 4-byte entry value). If */
90 /* there are no such entries, this function simply calls              */
91 /* print_value().                                                     */
92 
93 /* This routine is currently unnecessary                              */
94 
95 void
print_sony1_makervalue(struct ifd_entry * entry_ptr,int make,int model,char * prefix)96 print_sony1_makervalue(struct ifd_entry *entry_ptr,int make,int model,
97                     char *prefix)
98 {
99     if(entry_ptr && (PRINT_VALUE))
100     {
101         switch(entry_ptr->tag)
102         {
103             default:
104                 print_value(entry_ptr,PREFIX);
105                 break;
106         }
107     }
108 }
109 
110 
111 /* Dispatch a routine to decode and print offset values for Sony      */
112 /* cameras.                                                           */
113 
114 void
print_sony_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)115 print_sony_offset_makervalue(FILE *inptr,unsigned short byteorder,
116     struct ifd_entry *entry_ptr,unsigned long fileoffset_base,
117     struct image_summary *summary_entry,char *parent_name,char *prefix,
118     int indent,int make,int model,int at_offset)
119 {
120     int noteversion = 0;
121 
122     if(entry_ptr)
123     {
124         noteversion = getnoteversion();
125         switch(noteversion)
126         {
127             case 1:
128                 sony1_offset_makervalue(inptr,byteorder,entry_ptr,
129                                             fileoffset_base,summary_entry,
130                                             parent_name,prefix,indent,
131                                             make,model,at_offset);
132                 break;
133             default:
134                 break;
135         }
136     }
137 }
138 
139 /* Model-specific routine to print UNDEFINED values found at offsets  */
140 /* in Sony makernotes.                                                */
141 
142 void
sony1_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)143 sony1_offset_makervalue(FILE *inptr,unsigned short byteorder,
144     struct ifd_entry *entry_ptr,unsigned long fileoffset_base,
145     struct image_summary *summary_entry,char *parent_name,char *prefix,
146     int indent,int make,int model,int at_offset)
147 {
148     unsigned long value_offset,count;
149     char *nameoftag;
150     char *fulldirname = NULL;
151     int chpr = 0;
152 
153     if(entry_ptr)
154     {
155         nameoftag = maker_tagname(entry_ptr->tag,make,model);
156         fulldirname = splice(parent_name,".",nameoftag);
157         value_offset = fileoffset_base + entry_ptr->value;
158         count = entry_ptr->count;
159 
160         switch(entry_ptr->tag)
161         {
162             case 0x0e00: /* PrintIM (Epson Print Image matching)      */
163                 if(!at_offset && (PRINT_VALUE))
164                 {
165                     if(!(PRINT_OFFSET))
166                     {
167                         chpr += printf("@%lu:%lu",value_offset,count);
168                         chpr = newline(chpr);
169                     }
170                 }
171                 process_pim(inptr,byteorder,entry_ptr->value,fileoffset_base,
172                     count,nameoftag,parent_name,prefix,indent);
173                 break;
174             default:
175                 print_generic_offset_makervalue(inptr,byteorder,entry_ptr,
176                                         fileoffset_base,fulldirname,prefix,indent,
177                                         make,model,at_offset);
178                 break;
179         }
180         if(fulldirname)
181             free(fulldirname);
182     }
183     setcharsprinted(chpr);
184 }
185 
186 
187 /* sony-specific tagnames for makernotes.                          */
188 
189 /* The tagname routine is the first place in the code path which      */
190 /* requires knowledge of the note version. If the version is not      */
191 /* given in the model table (e.g. the model is unknown), then switch  */
192 /* code in find_maker_scheme() should have set it. This routine       */
193 /* repeats the check for non-zero noteversion and is prepared to set  */
194 /* the noteversion first time through, but should never need to do    */
195 /* so. Noteversion should always be non-zero; it should be set to -1  */
196 /* if generic processing is required.                                 */
197 
198 char *
maker_sony_tagname(unsigned short tag,int model)199 maker_sony_tagname(unsigned short tag,int model)
200 {
201     char *tagname = (char *)0;
202     int noteversion = 0;
203 
204     if((noteversion = getnoteversion()) == 0)
205     {
206         noteversion = 1;
207         setnoteversion(1);
208     }
209 
210     switch(noteversion)
211     {
212         default:
213             break;
214     }
215 
216     /* If no model-specific tag is found, check "generic" tags        */
217     if(tagname == NULL)
218     {
219         switch(tag)
220         {
221             case 0x0e00: tagname = "PrintIM"; break;
222             default: break;
223         }
224     }
225     return(tagname);
226 }
227