1 | <?php |
---|
2 | |
---|
3 | /****************************************************************************** |
---|
4 | * |
---|
5 | * Filename: ricoh.php |
---|
6 | * |
---|
7 | * Description: Ricoh Makernote Parser |
---|
8 | * Provides functions to decode an Ricoh EXIF makernote and to interpret |
---|
9 | * the resulting array into html. |
---|
10 | * |
---|
11 | * Ricoh Makernote Format: |
---|
12 | * |
---|
13 | * Type 1 - Text Makernote |
---|
14 | * |
---|
15 | * Field Size Description |
---|
16 | * ---------------------------------------------------------------- |
---|
17 | * Text Variable Text, beginning with "Rv" or "Rev" |
---|
18 | * --------------------------------------------------------------- |
---|
19 | * |
---|
20 | * |
---|
21 | * Type 2 - Empty Makernote |
---|
22 | * |
---|
23 | * Field Size Description |
---|
24 | * ---------------------------------------------------------------- |
---|
25 | * Blank Variable Blank field filled with 0x00 characters |
---|
26 | * ---------------------------------------------------------------* |
---|
27 | * |
---|
28 | * |
---|
29 | * Type 3 - IFD Makernote |
---|
30 | * |
---|
31 | * Field Size Description |
---|
32 | * ---------------------------------------------------------------- |
---|
33 | * Header 5 Bytes "Ricoh" or "RICOH" |
---|
34 | * Unknown 1 Byte Unknown field |
---|
35 | * Zeros 2 Bytes Two 0x00 characters |
---|
36 | * IFD Data Variable Standard IFD Data using Ricoh Tags |
---|
37 | * with Motorola byte alignment |
---|
38 | * --------------------------------------------------------------- |
---|
39 | * |
---|
40 | * Within Makernote Type 3, Tag 0x2001 is the Ricoh Camera Info Sub-IFD |
---|
41 | * It has the following format: |
---|
42 | * |
---|
43 | * Field Size Description |
---|
44 | * ---------------------------------------------------------------- |
---|
45 | * Header 19 Bytes "[Ricoh Camera Info]" |
---|
46 | * Unknown 1 Byte Unknown field |
---|
47 | * IFD Data Variable NON-Standard IFD Data using Ricoh |
---|
48 | * Sub-IFD Tags with Motorola byte alignment |
---|
49 | * and has No final Next-IFD pointer |
---|
50 | * --------------------------------------------------------------- |
---|
51 | * |
---|
52 | * |
---|
53 | * |
---|
54 | * |
---|
55 | * Author: Evan Hunter |
---|
56 | * |
---|
57 | * Date: 30/7/2004 |
---|
58 | * |
---|
59 | * Project: JPEG Metadata |
---|
60 | * |
---|
61 | * Revision: 1.00 |
---|
62 | * |
---|
63 | * URL: http://electronics.ozhiker.com |
---|
64 | * |
---|
65 | * Copyright: Copyright " . $auteur . " 2004 |
---|
66 | * This file may be used freely for non-commercial purposes.For |
---|
67 | * commercial uses please contact the author: evan@ozhiker.com |
---|
68 | * |
---|
69 | ******************************************************************************/ |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | // Add the parser and interpreter functions to the list of Makernote parsers and interpreters. |
---|
74 | |
---|
75 | $GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Ricoh_Makernote"; |
---|
76 | $GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Ricoh_Text_Value"; |
---|
77 | $GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Ricoh_Makernote_Html"; |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | /****************************************************************************** |
---|
83 | * |
---|
84 | * Function: get_Ricoh_Makernote |
---|
85 | * |
---|
86 | * Description: Decodes the Makernote tag and returns the new tag with the decoded |
---|
87 | * information attached. Returns false if this is not a makernote |
---|
88 | * that can be processed with this script |
---|
89 | * |
---|
90 | * Parameters: Makernote_Tag - the element of an EXIF array containing the |
---|
91 | * makernote, as returned from get_EXIF_JPEG |
---|
92 | * EXIF_Array - the entire EXIF array containing the |
---|
93 | * makernote, as returned from get_EXIF_JPEG, in |
---|
94 | * case more information is required for decoding |
---|
95 | * filehnd - an open file handle for the file containing the |
---|
96 | * makernote - does not have to be positioned at the |
---|
97 | * start of the makernote |
---|
98 | * Make_Field - The contents of the EXIF Make field, to aid |
---|
99 | * determining whether this script can decode |
---|
100 | * the makernote |
---|
101 | * |
---|
102 | * |
---|
103 | * Returns: Makernote_Tag - the Makernote_Tag from the parameters, but |
---|
104 | * modified to contain the decoded information |
---|
105 | * FALSE - If this script could not decode the makernote, or if |
---|
106 | * an error occured in decoding |
---|
107 | * |
---|
108 | ******************************************************************************/ |
---|
109 | |
---|
110 | function get_Ricoh_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field ) |
---|
111 | { |
---|
112 | // Check if the Make Field contains the word Ricoh |
---|
113 | if ( stristr( $Make_Field, "Ricoh" ) === FALSE ) |
---|
114 | { |
---|
115 | // Ricoh not in the Maker field - abort |
---|
116 | return FALSE; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | // Check if the Text Makernote header exists at the start of the Makernote |
---|
121 | if ( ( substr( $Makernote_Tag['Data'], 0, 2 ) === "Rv" ) || |
---|
122 | ( substr( $Makernote_Tag['Data'], 0, 3 ) === "Rev" ) ) |
---|
123 | { |
---|
124 | // This is a text makernote - Label it as such |
---|
125 | $Makernote_Tag['Makernote Type'] = "Ricoh Text"; |
---|
126 | $Makernote_Tag['Makernote Tags'] = "None"; |
---|
127 | $Makernote_Tag['Decoded'] = TRUE; |
---|
128 | |
---|
129 | // Return the new Makernote tag |
---|
130 | return $Makernote_Tag; |
---|
131 | |
---|
132 | } |
---|
133 | // Check if the Empty Makernote header exists at the start of the Makernote |
---|
134 | else if ( $Makernote_Tag['Data'] === str_repeat ( "\x00", strlen( $Makernote_Tag['Data'] )) ) |
---|
135 | { |
---|
136 | // This is an Empty Makernote - Label it as such |
---|
137 | $Makernote_Tag['Makernote Type'] = "Ricoh Empty Makernote"; |
---|
138 | $Makernote_Tag['Makernote Tags'] = "None"; |
---|
139 | $Makernote_Tag['Decoded'] = TRUE; |
---|
140 | |
---|
141 | // Return the new Makernote tag |
---|
142 | return $Makernote_Tag; |
---|
143 | |
---|
144 | } |
---|
145 | // Check if the IFD Makernote header exists at the start of the Makernote |
---|
146 | else if ( ( substr( $Makernote_Tag['Data'], 0, 5 ) === "RICOH" ) || |
---|
147 | ( substr( $Makernote_Tag['Data'], 0, 5 ) === "Ricoh" ) ) |
---|
148 | { |
---|
149 | //This is an IFD Makernote |
---|
150 | |
---|
151 | // Seek to the start of the IFD |
---|
152 | fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 8 ); |
---|
153 | |
---|
154 | // Ricoh Makernote always uses Motorola Byte Alignment |
---|
155 | $Makernote_Tag['ByteAlign'] = "MM"; |
---|
156 | |
---|
157 | // Read the IFD(s) into an array |
---|
158 | $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Ricoh" ); |
---|
159 | |
---|
160 | // Save some information into the Tag element to aid interpretation |
---|
161 | $Makernote_Tag['Decoded'] = TRUE; |
---|
162 | $Makernote_Tag['Makernote Type'] = "Ricoh"; |
---|
163 | $Makernote_Tag['Makernote Tags'] = "Ricoh"; |
---|
164 | |
---|
165 | // Ricoh Makernotes can have a tag 0x2001 which is a Sub-IFD |
---|
166 | // Check if the tag exists |
---|
167 | if ( ( $Makernote_Tag['Decoded Data'][0] !== FALSE ) && |
---|
168 | ( array_key_exists( 0x2001, $Makernote_Tag['Decoded Data'][0] ) ) ) |
---|
169 | { |
---|
170 | // Ricoh Sub-IFD tag exists - Process it |
---|
171 | |
---|
172 | // Grab the Sub-IFD tag for easier processing |
---|
173 | $SubIFD_Tag = &$Makernote_Tag['Decoded Data'][0][0x2001]; |
---|
174 | |
---|
175 | // Check if the Sub-IFD starts with the correct header |
---|
176 | if ( substr( $SubIFD_Tag['Data'], 0, 19 ) === "[Ricoh Camera Info]" ) |
---|
177 | { |
---|
178 | // Correct Header found |
---|
179 | |
---|
180 | // Seek to the start of the Sub-IFD |
---|
181 | fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $SubIFD_Tag['Offset'] + 20 ); |
---|
182 | |
---|
183 | // Ricoh Makernote Sub-IFD always uses Motorola Byte Alignment |
---|
184 | $SubIFD_Tag['ByteAlign'] = "MM"; |
---|
185 | |
---|
186 | |
---|
187 | // Read the IFD(s) into an array |
---|
188 | $SubIFD_Tag['Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $SubIFD_Tag['ByteAlign'], "RicohSubIFD", False, False ); |
---|
189 | |
---|
190 | // Save some information into the Tag element to aid interpretation |
---|
191 | $SubIFD_Tag['Decoded'] = TRUE; |
---|
192 | $SubIFD_Tag['Makernote Type'] = "Ricoh"; |
---|
193 | $SubIFD_Tag['Makernote Tags'] = "RicohSubIFD"; |
---|
194 | |
---|
195 | // Change the tag type to a Sub-IFD so it is handled automatically for interpretation |
---|
196 | $SubIFD_Tag['Type'] = "SubIFD"; |
---|
197 | $SubIFD_Tag['Tags Name'] = "RicohSubIFD"; |
---|
198 | |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | // Couldn't find header of Sub-IFD - Probably corrupt |
---|
203 | $SubIFD_Tag['Type'] = "String"; |
---|
204 | $SubIFD_Tag['Text Value'] = "Corrupted Ricoh Sub IFD"; |
---|
205 | } |
---|
206 | |
---|
207 | } |
---|
208 | |
---|
209 | // Return the new makernote tag |
---|
210 | return $Makernote_Tag; |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | // Unrecognised header for makernote - abort |
---|
215 | return FALSE; |
---|
216 | } |
---|
217 | |
---|
218 | // Shouldn't get here |
---|
219 | return False; |
---|
220 | } |
---|
221 | |
---|
222 | /****************************************************************************** |
---|
223 | * End of Function: get_Ricoh_Makernote |
---|
224 | ******************************************************************************/ |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | /****************************************************************************** |
---|
233 | * |
---|
234 | * Function: get_Ricoh_Makernote_Html |
---|
235 | * |
---|
236 | * Description: Attempts to interpret a makernote into html. Returns false if |
---|
237 | * it is not a makernote that can be processed with this script |
---|
238 | * |
---|
239 | * Parameters: Makernote_Tag - the element of an EXIF array containing the |
---|
240 | * makernote, as returned from get_EXIF_JPEG |
---|
241 | * filename - the name of the JPEG file being processed ( used |
---|
242 | * by scripts which display embedded thumbnails) |
---|
243 | * |
---|
244 | * |
---|
245 | * Returns: output - the html representing the makernote |
---|
246 | * FALSE - If this script could not interpret the makernote, or if |
---|
247 | * an error occured in decoding |
---|
248 | * |
---|
249 | ******************************************************************************/ |
---|
250 | |
---|
251 | function get_Ricoh_Makernote_Html( $Makernote_tag, $filename ) |
---|
252 | { |
---|
253 | |
---|
254 | // Check if this makernote is Ricoh IFD type |
---|
255 | if ( $Makernote_tag['Makernote Type'] == "Ricoh" ) |
---|
256 | { |
---|
257 | // This is a Ricoh IFD makernote - interpret it |
---|
258 | return interpret_IFD( $Makernote_tag['Decoded Data'][0], $filename ); |
---|
259 | } |
---|
260 | // Check if this makernote is Ricoh Text type |
---|
261 | else if ( $Makernote_tag['Makernote Type'] == "Ricoh Text" ) |
---|
262 | { |
---|
263 | // This is a Ricoh text makernote |
---|
264 | // Construct the start of enclosing html for the text |
---|
265 | $output_str = "<table class=\"EXIF_Table\"border=1><tr class=\"EXIF_Table_Row\"><td class=\"EXIF_Value_Cell\">"; |
---|
266 | |
---|
267 | // Replace the semicolon dividers with line break html tags |
---|
268 | $output_str .= str_replace ( ";", "<BR>\n", $Makernote_tag['Data'] ); |
---|
269 | |
---|
270 | // Close the html |
---|
271 | $output_str .= "</td></tr></table>"; |
---|
272 | |
---|
273 | // Return the html |
---|
274 | return $output_str; |
---|
275 | } |
---|
276 | // Check if this makernote is a Ricoh Empty makernote |
---|
277 | else if ( $Makernote_tag['Makernote Type'] == "Ricoh Empty Makernote" ) |
---|
278 | { |
---|
279 | // Do Nothing |
---|
280 | return ""; |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | // Don't recognise the Makernote type - not a Ricoh makernote |
---|
285 | return FALSE; |
---|
286 | } |
---|
287 | |
---|
288 | // shouldn't get here |
---|
289 | return FALSE; |
---|
290 | } |
---|
291 | |
---|
292 | /****************************************************************************** |
---|
293 | * End of Function: get_Ricoh_Makernote_Html |
---|
294 | ******************************************************************************/ |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | /****************************************************************************** |
---|
304 | * |
---|
305 | * Function: get_Ricoh_Text_Value |
---|
306 | * |
---|
307 | * Description: Provides a text value for any tag marked as special for makernotes |
---|
308 | * that this script can decode. Returns false if this is not a makernote |
---|
309 | * that can be processed with this script |
---|
310 | * |
---|
311 | * Parameters: Exif_Tag - the element of an the Makernote array containing the |
---|
312 | * tag in question, as returned from get_Ricoh_Makernote |
---|
313 | * Tag_Definitions_Name - The name of the Tag Definitions group |
---|
314 | * within the global array IFD_Tag_Definitions |
---|
315 | * |
---|
316 | * |
---|
317 | * Returns: output - the text value for the tag |
---|
318 | * FALSE - If this script could not decode the makernote, or if |
---|
319 | * an error occured in decoding |
---|
320 | * |
---|
321 | ******************************************************************************/ |
---|
322 | |
---|
323 | function get_Ricoh_Text_Value( $Exif_Tag, $Tag_Definitions_Name ) |
---|
324 | { |
---|
325 | |
---|
326 | // Check that this tag uses the Ricoh tags, otherwise it can't be decoded here |
---|
327 | if ( $Tag_Definitions_Name == "Ricoh" ) |
---|
328 | { |
---|
329 | |
---|
330 | // Process the tag acording to it's tag number, to produce a text value |
---|
331 | if ( $Exif_Tag['Tag Number'] == 0x0002 ) // Version tag |
---|
332 | { |
---|
333 | $tmp = implode ( "\x00", $Exif_Tag['Data']); |
---|
334 | return "\"" .HTML_UTF8_Escape( $tmp ) . "\" (" . bin2hex( $tmp ) . " hex)"; |
---|
335 | } |
---|
336 | |
---|
337 | } |
---|
338 | |
---|
339 | // Unknown tag or tag definitions |
---|
340 | return FALSE; |
---|
341 | |
---|
342 | } |
---|
343 | |
---|
344 | /****************************************************************************** |
---|
345 | * End of Function: get_Ricoh_Text_Value |
---|
346 | ******************************************************************************/ |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | |
---|
351 | |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | |
---|
356 | |
---|
357 | |
---|
358 | /****************************************************************************** |
---|
359 | * Global Variable: IFD_Tag_Definitions, Ricoh |
---|
360 | * |
---|
361 | * Contents: This global variable provides definitions of the known Ricoh |
---|
362 | * Makernote tags, indexed by their tag number. |
---|
363 | * |
---|
364 | ******************************************************************************/ |
---|
365 | |
---|
366 | $GLOBALS[ "IFD_Tag_Definitions" ]["Ricoh"] = array( |
---|
367 | |
---|
368 | |
---|
369 | 0x0001 => array( 'Name' => "Makernote Data Type", |
---|
370 | 'Type' => "String" ), |
---|
371 | |
---|
372 | 0x0002 => array( 'Name' => "Version", |
---|
373 | 'Type' => "Special" ), |
---|
374 | |
---|
375 | 0x0e00 => array( 'Name' => "Print Image Matching Info", |
---|
376 | 'Type' => "PIM" ), |
---|
377 | |
---|
378 | 0x2001 => array( 'Name' => "Ricoh Camera Info Makernote Sub-IFD", |
---|
379 | 'Type' => "Special" ), |
---|
380 | |
---|
381 | ); |
---|
382 | |
---|
383 | /****************************************************************************** |
---|
384 | * End of Global Variable: IFD_Tag_Definitions, Ricoh |
---|
385 | ******************************************************************************/ |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | |
---|
394 | /****************************************************************************** |
---|
395 | * Global Variable: IFD_Tag_Definitions, RicohSubIFD |
---|
396 | * |
---|
397 | * Contents: This global variable provides definitions of the known Ricoh |
---|
398 | * Camera Info Sub-IFD Makernote tags, indexed by their tag number. |
---|
399 | * |
---|
400 | ******************************************************************************/ |
---|
401 | |
---|
402 | $GLOBALS[ "IFD_Tag_Definitions" ]["RicohSubIFD"] = array( |
---|
403 | |
---|
404 | ); |
---|
405 | |
---|
406 | /****************************************************************************** |
---|
407 | * End of Global Variable: IFD_Tag_Definitions, RicohSubIFD |
---|
408 | ******************************************************************************/ |
---|
409 | |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | |
---|
414 | |
---|
415 | ?> |
---|