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