source: extensions/edit_gmaps/admin/include/Makernotes/casio.php @ 9412

Last change on this file since 9412 was 9412, checked in by cljosse, 13 years ago
File size: 20.6 KB
Line 
1<?php
2
3/******************************************************************************
4*
5* Filename:     casio.php
6*
7* Description:  Casio Makernote Parser
8*               Provides functions to decode an Casio EXIF makernote and to interpret
9*               the resulting array into html.
10*
11*               Casio Makernote Format:
12*
13*               Type 1:
14*
15*               Field           Size            Description
16*               ----------------------------------------------------------------
17*               IFD Data        Variable        Standard IFD Data using Casio Type 1 Tags and Motorola Byte Alignment
18*               ----------------------------------------------------------------
19*
20*               Type 2:
21*
22*               Field           Size            Description
23*               ----------------------------------------------------------------
24*               Header          6 Bytes         "QVC\x00\x00\x00"
25*               IFD Data        Variable        Standard IFD Data using Casio Type 2 Tags and Motorola Byte Alignment
26*               ----------------------------------------------------------------
27*
28*
29* Author:      Evan Hunter
30*
31* Date:         30/7/2004
32*
33* Project:      JPEG Metadata
34*
35* Revision:     1.11
36*
37* Changes:      1.00 -> 1.11 : changed get_Casio_Makernote_Html to allow thumbnail links to work when
38*                              toolkit is portable across directories
39*
40* URL:          http://electronics.ozhiker.com
41*
42* Copyright:    Copyright " . $auteur . " 2004
43*               This file may be used freely for non-commercial purposes.For
44*               commercial uses please contact the author: evan@ozhiker.com
45*
46******************************************************************************/
47
48
49// Add the parser and interpreter functions to the list of Makernote parsers and interpreters.
50
51$GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Casio_Makernote";
52$GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Casio_Text_Value";
53$GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Casio_Makernote_Html";
54
55include_once dirname(__FILE__) .'/../pjmt_utils.php';          // Change: as of version 1.11 - added to allow directory portability
56
57
58/******************************************************************************
59*
60* Function:     get_Casio_Makernote
61*
62* Description:  Decodes the Makernote tag and returns the new tag with the decoded
63*               information attached. Returns false if this is not a makernote
64*               that can be processed with this script
65*
66* Parameters:   Makernote_Tag - the element of an EXIF array containing the
67*                               makernote, as returned from get_EXIF_JPEG
68*               EXIF_Array - the entire EXIF array containing the
69*                            makernote, as returned from get_EXIF_JPEG, in
70*                            case more information is required for decoding
71*               filehnd - an open file handle for the file containing the
72*                         makernote - does not have to be positioned at the
73*                         start of the makernote
74*               Make_Field - The contents of the EXIF Make field, to aid
75*                            determining whether this script can decode
76*                            the makernote
77*
78*
79* Returns:      Makernote_Tag - the Makernote_Tag from the parameters, but
80*                               modified to contain the decoded information
81*               FALSE - If this script could not decode the makernote, or if
82*                       an error occured in decoding
83*
84******************************************************************************/
85
86function get_Casio_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field )
87{
88
89        // Check if the Make Field contains the word Casio
90        if ( stristr( $Make_Field, "Casio" ) === FALSE )
91        {
92                return FALSE;
93        }
94
95
96        if ( substr( $Makernote_Tag['Data'],0 , 6 ) == "QVC\x00\x00\x00" )
97        {
98
99                // Seek to the start of the IFD
100                fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 6 );
101
102                $Makernote_Tag['ByteAlign'] = "MM";
103
104                // Read the IFD(s) into an array
105                $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Casio Type 2" );
106
107                // Save some information into the Tag element to aid interpretation
108                $Makernote_Tag['Decoded'] = TRUE;
109                $Makernote_Tag['Makernote Type'] = "Casio Type 2";
110                $Makernote_Tag['Makernote Tags'] = "Casio Type 2";
111
112                // Return the new tag
113                return $Makernote_Tag;
114        }
115        else
116        {
117                // Seek to the start of the IFD
118                fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 0 );
119
120                $Makernote_Tag['ByteAlign'] = "MM";
121
122                // Read the IFD(s) into an array
123                $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Casio Type 1" );
124
125                // Save some information into the Tag element to aid interpretation
126                $Makernote_Tag['Decoded'] = TRUE;
127                $Makernote_Tag['Makernote Type'] = "Casio Type 1";
128                $Makernote_Tag['Makernote Tags'] = "Casio Type 1";
129
130                // Return the new tag
131                return $Makernote_Tag;
132        }
133}
134
135/******************************************************************************
136* End of Function:     get_Casio_Makernote
137******************************************************************************/
138
139
140
141
142/******************************************************************************
143*
144* Function:     get_Casio_Text_Value
145*
146* Description:  Provides a text value for any tag marked as special for makernotes
147*               that this script can decode. Returns false if this is not a makernote
148*               that can be processed with this script
149*
150* Parameters:   Exif_Tag - the element of an the Makernote array containing the
151*                          tag in question, as returned from get_Casio_Makernote
152*               Tag_Definitions_Name - The name of the Tag Definitions group
153*                                      within the global array IFD_Tag_Definitions
154*
155*
156* Returns:      output - the text value for the tag
157*               FALSE - If this script could not decode the makernote, or if
158*                       an error occured in decoding
159*
160******************************************************************************/
161
162function get_Casio_Text_Value( $Exif_Tag, $Tag_Definitions_Name )
163{
164
165        // Check that this tag uses the Casio tag definitions, otherwise it can't be decoded here
166        if ( $Tag_Definitions_Name == "Casio Type 2" )
167        {
168                // Tag Uses Casio Type 2 Tag definitions
169                // Process the tag according to it's tag number
170                if ( $Exif_Tag['Tag Number'] == 0x001D )
171                {
172                        return  $Exif_Tag['Data'][0]/10 . $Exif_Tag['Units'];
173                }
174                else
175                {
176                        return FALSE;
177                }
178        }
179        else if ( $Tag_Definitions_Name == "Casio Type 1" )
180        {
181                // Tag Uses Casio Type 1 Tags
182                return FALSE;
183        }
184        else
185        {
186                // Tag does NOT use Casio Tag definitions
187                return FALSE;
188        }
189
190        // Shouldn't get here
191        return FALSE;
192
193}
194
195/******************************************************************************
196* End of Function:     get_Casio_Text_Value
197******************************************************************************/
198
199
200
201
202
203
204
205/******************************************************************************
206*
207* Function:     get_Casio_Makernote_Html
208*
209* Description:  Attempts to interpret a makernote into html. Returns false if
210*               it is not a makernote that can be processed with this script
211*
212* Parameters:   Makernote_Tag - the element of an EXIF array containing the
213*                               makernote, as returned from get_EXIF_JPEG
214*               filename - the name of the JPEG file being processed ( used
215*                          by scripts which display embedded thumbnails)
216*
217*
218* Returns:      output - the html representing the makernote
219*               FALSE - If this script could not interpret the makernote, or if
220*                       an error occured in decoding
221*
222******************************************************************************/
223
224function get_Casio_Makernote_Html( $Makernote_tag, $filename )
225{
226        // Check that this tag uses the Casio tags, otherwise it can't be interpreted here
227        if ( ( $Makernote_tag['Makernote Type'] != "Casio Type 1" ) &&
228             ( $Makernote_tag['Makernote Type'] != "Casio Type 2" ) )
229        {
230                // Not Casio tags - can't interpret with this function
231                return FALSE;
232        }
233
234        // Casio Thumbnail (Tag 4)
235        if ( ( array_key_exists( 4, $Makernote_tag['Decoded Data'][0] ) ) &&
236             ( $Makernote_tag['Makernote Tags'] == "Casio Type 2" ) )
237        {
238                // Change: as of version 1.11 - Changed to make thumbnail link portable across directories
239                // Build the path of the thumbnail script and its filename parameter to put in a url
240                $link_str = get_relative_path( dirname(__FILE__) . "/get_casio_thumb.php" , getcwd ( ) );
241                $link_str .= "?filename=";
242                $link_str .= get_relative_path( $filename, dirname(__FILE__) );
243
244                // Add thumbnail link to html
245                $Makernote_tag['Decoded Data'][0][4]['Text Value'] = "<a class=\"EXIF_Casio_Thumb_Link\" href=\"$link_str\"><img class=\"EXIF_Casio_Thumb\" src=\"$link_str\"></a></td></tr>\n";
246                $Makernote_tag['Decoded Data'][0][4]['Type'] = "String";
247        }
248
249
250        // Casio Thumbnail (Tag 8192)
251        if ( ( array_key_exists( 8192, $Makernote_tag['Decoded Data'][0] ) ) &&
252             ( $Makernote_tag['Makernote Tags'] == "Casio Type 2" ) )
253        {
254                // Change: as of version 1.11 - Changed to make thumbnail link portable across directories
255                // Build the path of the thumbnail script and its filename parameter to put in a url
256                $link_str = get_relative_path( dirname(__FILE__) . "/.." . "/get_casio_thumb.php" , getcwd ( ) );
257                $link_str .= "?filename=";
258                $link_str .= get_relative_path( $filename, dirname(__FILE__) . "/.." );
259
260                // Add thumbnail link to html
261                $Makernote_tag['Decoded Data'][0][8192]['Text Value'] = "<a class=\"EXIF_Casio_Thumb_Link\" href=\"$link_str\"><img class=\"EXIF_Casio_Thumb\" src=\"$link_str\"></a></td></tr>\n";
262                $Makernote_tag['Decoded Data'][0][8192]['Type'] = "String";
263        }
264
265
266        // Check if there are two thumbnail offset tags
267        if ( ( array_key_exists( 4, $Makernote_tag['Decoded Data'][0] ) ) &&
268             ( array_key_exists( 8192, $Makernote_tag['Decoded Data'][0] ) ) )
269        {
270                // There are two copies of the thumbnail offset - Remove one
271                array_splice( $Makernote_tag['Decoded Data'][0], 4, 1);
272        }
273
274
275        // Interpret the IFD and return the html
276        return interpret_IFD( $Makernote_tag['Decoded Data'][0], $filename );
277
278}
279
280/******************************************************************************
281* End of Function:     get_Casio_Makernote_Html
282******************************************************************************/
283
284
285
286
287
288
289/******************************************************************************
290* Global Variable:      IFD_Tag_Definitions, Casio Type 1
291*
292* Contents:     This global variable provides definitions of the known Casio Type 1
293*               Makernote tags, indexed by their tag number.
294*
295******************************************************************************/
296
297
298$GLOBALS[ "IFD_Tag_Definitions" ]["Casio Type 1"] = array(
299
3001 => array(     'Name' => "Recording Mode",
301                'Type' => "Lookup",
302                1 => "Single Shutter",
303                2 => "Panorama",
304                3 => "Night Scene",
305                4 => "Portrait",
306                5 => "Landscape" ),
307
3082 => array(     'Name' => "Quality",
309                'Type' => "Lookup",
310                1 => "Economy",
311                2 => "Normal",
312                3 => "Fine" ),
313
3143 => array(     'Name' => "Focusing Mode",
315                'Type' => "Lookup",
316                2 => "Macro",
317                3 => "Auto Focus",
318                4 => "Manual Focus",
319                5 => "Infinity" ),
320
3214 => array(     'Name' => "Flash Mode",
322                'Type' => "Lookup",
323                1 => "Auto",
324                2 => "On",
325                3 => "Off",
326                4 => "Off" ),
327
3285 => array(     'Name' => "Flash Intensity",
329                'Type' => "Lookup",
330                11 => "Weak",
331                13 => "Normal",
332                15 => "Strong" ),
333
3346 => array(     'Name' => "Object Distance",
335                'Type' => "Numeric",
336                'Units' => "mm" ),
337
3387 => array(     'Name' => "White Balance",
339                'Type' => "Lookup",
340                1 => "Auto",
341                2 => "Tungsten",
342                3 => "Daylight",
343                4 => "Flourescent",
344                5 => "Shade",
345                129 => "Manual" ),
346
34710 => array(    'Name' => "Digital Zoom",
348                'Type' => "Lookup",
349                0x10000 => "Off",
350                0x10001 => "2x Digital Zoom",
351                0x20000 => "2x Digital Zoom",
352                0x40000 => "4x Digital Zoom" ),
353
35411 => array(    'Name' => "Sharpness",
355                'Type' => "Lookup",
356                0 => "Normal",
357                1 => "Soft",
358                2 => "Hard" ),
359
36012 => array(    'Name' => "Contrast",
361                'Type' => "Lookup",
362                0 => "Normal",
363                1 => "Low",
364                2 => "High" ),
365
36613 => array(    'Name' => "Saturation",
367                'Type' => "Lookup",
368                0 => "Normal",
369                1 => "Low",
370                2 => "High" ),
371
37220 => array(    'Name' => "CCD Sensitivity",
373                'Type' => "Lookup",
374                64 => "Normal",
375                125 => "+1.0",
376                250 => "+2.0",
377                244 => "+3.0",
378                80 => "Normal (ISO 80 equivalent)",
379                100 => "High" ),
380
381);
382
383/******************************************************************************
384* End of Global Variable:     IFD_Tag_Definitions, Casio Type 1
385******************************************************************************/
386
387
388
389
390
391
392/******************************************************************************
393* Global Variable:      IFD_Tag_Definitions, Casio Type 2
394*
395* Contents:     This global variable provides definitions of the known Casio Type 2
396*               Makernote tags, indexed by their tag number.
397*
398******************************************************************************/
399
400$GLOBALS[ "IFD_Tag_Definitions" ]["Casio Type 2"] = array(
401
4020x0002 => array(        'Name' => "Preview Thumbnail Dimensions",
403                        'Type' => "Numeric",
404                        'Units' => "(x,y pixels)" ),
405
4060x0003 => array(        'Name' => "Preview Thumbnail Size",
407                        'Type' => "Numeric",
408                        'Units' => "bytes" ),
409
4100x0004 => array(        'Name' => "Preview Thumbnail",    // thumbnail offset
411                        'Type' => "Numeric" ),
412
413
4140x0008 => array(        'Name' => "Quality Mode",
415                        'Type' => "Lookup",
416                        1 => "Fine",
417                        2 => "Super Fine" ),
418
4190x0009 => array(        'Name' => "Image Size",
420                        'Type' => "Lookup",
421                        20 => "2288 x 1712 pixels",
422                        36 => "3008 x 2008 pixels",
423                        5 => "2048 x 1536 pixels",
424                        4 => "1600 x 1200 pixels",
425                        21 => "2592 x 1944 pixels",
426                        0 => "640 x 480 pixels",
427                        22 => "2304 x 1728 pixels" ),
428
4290x000D => array(        'Name' => "Focus Mode",
430                        'Type' => "Lookup",
431                        0 => "Normal",
432                        1 => "Macro" ),
433
434
4350x0014 => array(        'Name' => "Iso Sensitivity",
436                        'Type' => "Lookup",
437                        3 => "50",
438                        4 => "64",
439                        6 => "100",
440                        9 => "200" ),
441
442
4430x0019 => array(        'Name' => "White Balance",
444                        'Type' => "Lookup",
445                        0 => "Auto",
446                        1 => "Daylight",
447                        2 => "Shade",
448                        3 => "Tungsten",
449                        4 => "Fluorescent",
450                        5 => "Manual" ),
451
4520x001D => array(        'Name' => "Focal Length",
453                        'Type' => "Special",
454                        'Units' => "mm" ),
455
4560x001F => array(        'Name' => "Saturation",
457                        'Type' => "Lookup",
458                        0 => "-1",
459                        1 => "Normal",
460                        2 => "+1", ),
461
4620x0020 => array(        'Name' => "Contrast",
463                        'Type' => "Lookup",
464                        0 => "-1",
465                        1 => "Normal",
466                        2 => "+1", ),
467
4680x0021 => array(        'Name' => "Sharpness",
469                        'Type' => "Lookup",
470                        0 => "-1",
471                        1 => "Normal",
472                        2 => "+1", ),
473
474
4750x0e00 => array(        'Name' => "Print Image Matching Info",
476                        'Type' => "PIM" ),
477
478
4790x2000 => array(        'Name' => "Casio Preview Thumbnail",    // thumbnail offset
480                        'Type' => "String" ),
481
482
483
4840x2011 => array(        'Name' => "White Balance Bias",
485                        'Type' => "Numeric" ),
486
487
4880x2012 => array(        'Name' => "White Balance",
489                        'Type' => "Lookup",
490                        12 => "Flash",
491                        0 =>  "Manual",
492                        1 => "Auto?",
493                        4 => "Flash?", ),
494
4950x2022 => array(        'Name' => "Object Distance",
496                        'Type' => "Numeric",
497                        'Units' => "mm" ),
498
499
5000x2034 => array(        'Name' => "Flash Distance",
501                        'Type' => "Numeric",
502                        'Units' => "   (0=Off)" ),
503
5040x3000 => array(        'Name' => "Record Mode",
505                        'Type' => "Lookup",
506                        2 => "Normal Mode" ),
507
5080x3001 => array(        'Name' => "Self Timer?",
509                        'Type' => "Lookup",
510                        1 => "Off?" ),
511
512
5130x3002 => array(        'Name' => "Quality",
514                        'Type' => "Lookup",
515                        3 => "Fine" ),
516
5170x3003 => array(        'Name' => "Focus Mode",
518                        'Type' => "Lookup",
519                        6 => "Multi-Area Auto Focus",
520                        1 => "Fixation" ),
521
522
5230x3006 => array(        'Name' => "Time Zone",
524                        'Type' => "String" ),
525
526
5270x3007 => array(        'Name' => "Bestshot Mode",
528                        'Type' => "Lookup",
529                        0 => "Off",
530                        1 => "On?" ),
531
532
5330x3014 => array(        'Name' => "CCD ISO Sensitivity",
534                        'Type' => "Numeric" ),
535
536
537
5380x3015 => array(        'Name' => "Colour Mode",
539                        'Type' => "Lookup",
540                        0 => "Off" ),
541
542
5430x3016 => array(        'Name' => "Enhancement",
544                        'Type' => "Lookup",
545                        0 => "Off" ),
546
5470x3017 => array(        'Name' => "Filter",
548                        'Type' => "Lookup",
549                        0 => "Off" ),
550
551
552);
553
554/******************************************************************************
555* End of Global Variable:     IFD_Tag_Definitions, Casio Type 2
556******************************************************************************/
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575?>
Note: See TracBrowser for help on using the repository browser.