/FSN/mediatheque/zp-core/exif/makers/sanyo.php

https://gitlab.com/r.collas/site_central · PHP · 157 lines · 86 code · 31 blank · 40 comment · 51 complexity · 65058fb6cebb2002b81a97a626da59f0 MD5 · raw file

  1. <?php //================================================================================================
  2. //================================================================================================
  3. //================================================================================================
  4. /*
  5. Exifer
  6. Extracts EXIF information from digital photos.
  7. Copyright � 2003 Jake Olefsky
  8. http://www.offsky.com/software/exif/index.php
  9. jake@olefsky.com
  10. Please see exif.php for the complete information about this software.
  11. ------------
  12. This program is free software; you can redistribute it and/or modify it under the terms of
  13. the GNU General Public License as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  16. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. See the GNU General Public License for more details. http://www.gnu.org/copyleft/gpl.html
  18. */
  19. //================================================================================================
  20. //================================================================================================
  21. //================================================================================================
  22. //=================
  23. // Looks up the name of the tag for the MakerNote (Depends on Manufacturer)
  24. //====================================================================
  25. function lookup_Sanyo_tag($tag) {
  26. switch($tag) {
  27. case "0200": $tag = "SpecialMode";break;
  28. case "0201": $tag = "Quality";break;
  29. case "0202": $tag = "Macro";break;
  30. case "0203": $tag = "Unknown";break;
  31. case "0204": $tag = "DigiZoom";break;
  32. case "0f00": $tag = "DataDump";break;
  33. default: $tag = "unknown:".$tag;break;
  34. }
  35. return $tag;
  36. }
  37. //=================
  38. // Formats Data for the data type
  39. //====================================================================
  40. function formatSanyoData($type,$tag,$intel,$data) {
  41. if($type=="ASCII") {
  42. } else if($type=="URATIONAL" || $type=="SRATIONAL") {
  43. $data = unRational($data,$type,$intel);
  44. } else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
  45. $data = rational($data,$type,$intel);
  46. if($tag=="0200") { //SpecialMode
  47. if($data == 0) $data = gettext("Normal");
  48. else $data = gettext("Unknown").": ".$data;
  49. }
  50. if($tag=="0201") { //Quality
  51. if($data == 2) $data = gettext("High");
  52. else $data = gettext("Unknown").": ".$data;
  53. }
  54. if($tag=="0202") { //Macro
  55. if($data == 0) $data = gettext("Normal");
  56. else $data = gettext("Unknown").": ".$data;
  57. }
  58. } else if($type=="UNDEFINED") {
  59. } else {
  60. $data = bin2hex($data);
  61. if($intel==1) $data = intel2Moto($data);
  62. }
  63. return $data;
  64. }
  65. //=================
  66. // Sanyo Special data section
  67. //====================================================================
  68. function parseSanyo($block,&$result,$seek, $globalOffset) {
  69. if($result['Endien']=="Intel") $intel=1;
  70. else $intel=0;
  71. $model = $result['IFD0']['Model'];
  72. $place=8; //current place
  73. $offset=8;
  74. //Get number of tags (2 bytes)
  75. $num = bin2hex(substr($block,$place,2));$place+=2;
  76. if($intel==1) $num = intel2Moto($num);
  77. $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num);
  78. //loop thru all tags Each field is 12 bytes
  79. for($i=0;$i<hexdec($num);$i++) {
  80. //2 byte tag
  81. $tag = bin2hex(substr($block,$place,2));$place+=2;
  82. if($intel==1) $tag = intel2Moto($tag);
  83. $tag_name = lookup_Sanyo_tag($tag);
  84. //2 byte type
  85. $type = bin2hex(substr($block,$place,2));$place+=2;
  86. if($intel==1) $type = intel2Moto($type);
  87. lookup_type($type,$size);
  88. //4 byte count of number of data units
  89. $count = bin2hex(substr($block,$place,4));$place+=4;
  90. if($intel==1) $count = intel2Moto($count);
  91. $bytesofdata = validSize($size*hexdec($count));
  92. //4 byte value of data or pointer to data
  93. $value = substr($block,$place,4);$place+=4;
  94. if($bytesofdata<=4) {
  95. $data = substr($value,0,$bytesofdata);
  96. } else {
  97. $value = bin2hex($value);
  98. if($intel==1) $value = intel2Moto($value);
  99. $v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
  100. if($tag!=0) {
  101. $data = fread($seek, $bytesofdata);
  102. } else if($v==-1) {
  103. $result['Errors'] = $result['Errors']++;
  104. }
  105. }
  106. $formated_data = formatSanyoData($type,$tag,$intel,$data);
  107. if($result['VerboseOutput']==1) {
  108. $result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
  109. if($type=="URATIONAL" || $type=="SRATIONAL" || $type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
  110. $data = bin2hex($data);
  111. if($intel==1) $data = intel2Moto($data);
  112. }
  113. $result['SubIFD']['MakerNote'][$tag_name."_Verbose"]['RawData'] = $data;
  114. $result['SubIFD']['MakerNote'][$tag_name."_Verbose"]['Type'] = $type;
  115. $result['SubIFD']['MakerNote'][$tag_name."_Verbose"]['Bytes'] = $bytesofdata;
  116. } else {
  117. $result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
  118. }
  119. }
  120. }
  121. ?>