PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/exif/php-jpg/Makernotes/panasonic.php

http://buddypress-media.googlecode.com/
PHP | 292 lines | 74 code | 73 blank | 145 comment | 13 complexity | 6b71f2d2e2eb76d71fb09e538d7923cc MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /******************************************************************************
  3. *
  4. * Filename: panasonic.php
  5. *
  6. * Description: Panasonic Makernote Parser
  7. * Provides functions to decode a Panasonic EXIF makernote and to interpret
  8. * the resulting array into html.
  9. *
  10. * Panasonic Makernote Format:
  11. *
  12. * Type 1 - IFD form
  13. *
  14. * Field Size Description
  15. * ----------------------------------------------------------------
  16. * Header 12 Bytes "Panasonic\x00\x00\x00"
  17. * IFD Data Variable NON-Standard IFD Data using Panasonic Tags
  18. * There is no Next-IFD pointer after the IFD
  19. * ----------------------------------------------------------------
  20. *
  21. * Type 2 - Blank (Header only)
  22. *
  23. * Field Size Description
  24. * ----------------------------------------------------------------
  25. * Header 4 Bytes "MKED"
  26. * Junk 1 or 2 bytes Blank or Junk data
  27. * ----------------------------------------------------------------
  28. *
  29. *
  30. * Author: Evan Hunter
  31. *
  32. * Date: 30/7/2004
  33. *
  34. * Project: JPEG Metadata
  35. *
  36. * Revision: 1.00
  37. *
  38. * URL: http://electronics.ozhiker.com
  39. *
  40. * Copyright: Copyright Evan Hunter 2004
  41. * This file may be used freely for non-commercial purposes.For
  42. * commercial uses please contact the author: evan@ozhiker.com
  43. *
  44. ******************************************************************************/
  45. // Add the parser and interpreter functions to the list of Makernote parsers and interpreters.
  46. $GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Panasonic_Makernote";
  47. $GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Panasonic_Text_Value";
  48. $GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Panasonic_Makernote_Html";
  49. /******************************************************************************
  50. *
  51. * Function: get_Panasonic_Makernote
  52. *
  53. * Description: Decodes the Makernote tag and returns the new tag with the decoded
  54. * information attached. Returns false if this is not a makernote
  55. * that can be processed with this script
  56. *
  57. * Parameters: Makernote_Tag - the element of an EXIF array containing the
  58. * makernote, as returned from get_EXIF_JPEG
  59. * EXIF_Array - the entire EXIF array containing the
  60. * makernote, as returned from get_EXIF_JPEG, in
  61. * case more information is required for decoding
  62. * filehnd - an open file handle for the file containing the
  63. * makernote - does not have to be positioned at the
  64. * start of the makernote
  65. * Make_Field - The contents of the EXIF Make field, to aid
  66. * determining whether this script can decode
  67. * the makernote
  68. *
  69. *
  70. * Returns: Makernote_Tag - the Makernote_Tag from the parameters, but
  71. * modified to contain the decoded information
  72. * FALSE - If this script could not decode the makernote, or if
  73. * an error occured in decoding
  74. *
  75. ******************************************************************************/
  76. function get_Panasonic_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field )
  77. {
  78. // Check if the Make Field contains the word Panasonic
  79. if ( stristr( $Make_Field, "Panasonic" ) === FALSE )
  80. {
  81. // No Panasonic in the maker - abort
  82. return FALSE;
  83. }
  84. // Check if the header exists at the start of the Makernote
  85. if ( substr( $Makernote_Tag['Data'], 0, 4 ) == "MKED" )
  86. {
  87. // Panasonic Type 2 - Empty Makernote
  88. // No Makernote Data
  89. $Makernote_Tag['Makernote Type'] = "Panasonic Empty Makernote";
  90. $Makernote_Tag['Makernote Tags'] = "-";
  91. $Makernote_Tag['Decoded'] = TRUE;
  92. // Return the new tag
  93. return $Makernote_Tag;
  94. }
  95. else if ( substr( $Makernote_Tag['Data'], 0, 12 ) == "Panasonic\x00\x00\x00" )
  96. {
  97. // Panasonic Type 1 - IFD Makernote
  98. // Seek to the start of the IFD
  99. fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 12 );
  100. // Read the IFD(s) into an array
  101. $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Panasonic", FALSE, FALSE );
  102. // Save some information into the Tag element to aid interpretation
  103. $Makernote_Tag['Decoded'] = TRUE;
  104. $Makernote_Tag['Makernote Type'] = "Panasonic";
  105. $Makernote_Tag['Makernote Tags'] = "Panasonic";
  106. // Return the new tag
  107. return $Makernote_Tag;
  108. }
  109. else
  110. {
  111. // Unknown Header
  112. return FALSE;
  113. }
  114. // Shouldn't get here
  115. return FALSE;
  116. }
  117. /******************************************************************************
  118. * End of Function: get_Panasonic_Makernote
  119. ******************************************************************************/
  120. /******************************************************************************
  121. *
  122. * Function: get_Panasonic_Text_Value
  123. *
  124. * Description: Provides a text value for any tag marked as special for makernotes
  125. * that this script can decode. Returns false if this is not a makernote
  126. * that can be processed with this script
  127. *
  128. * Parameters: Exif_Tag - the element of an the Makernote array containing the
  129. * tag in question, as returned from get_Panasonic_Makernote
  130. * Tag_Definitions_Name - The name of the Tag Definitions group
  131. * within the global array IFD_Tag_Definitions
  132. *
  133. *
  134. * Returns: output - the text value for the tag
  135. * FALSE - If this script could not decode the makernote, or if
  136. * an error occured in decoding
  137. *
  138. ******************************************************************************/
  139. function get_Panasonic_Text_Value( $Exif_Tag, $Tag_Definitions_Name )
  140. {
  141. // Check that this tag uses the Olympus tags, otherwise it can't be decoded here
  142. if ( $Tag_Definitions_Name == "Panasonic" )
  143. {
  144. // No Special Tags yet
  145. return FALSE;
  146. }
  147. return FALSE;
  148. }
  149. /******************************************************************************
  150. * End of Function: get_Panasonic_Text_Value
  151. ******************************************************************************/
  152. /******************************************************************************
  153. *
  154. * Function: get_Panasonic_Makernote_Html
  155. *
  156. * Description: Attempts to interpret a makernote into html. Returns false if
  157. * it is not a makernote that can be processed with this script
  158. *
  159. * Parameters: Makernote_Tag - the element of an EXIF array containing the
  160. * makernote, as returned from get_EXIF_JPEG
  161. * filename - the name of the JPEG file being processed ( used
  162. * by scripts which display embedded thumbnails)
  163. *
  164. *
  165. * Returns: output - the html representing the makernote
  166. * FALSE - If this script could not interpret the makernote, or if
  167. * an error occured in decoding
  168. *
  169. ******************************************************************************/
  170. function get_Panasonic_Makernote_Html( $Makernote_tag, $filename )
  171. {
  172. if ( $Makernote_tag['Makernote Type'] == "Panasonic" )
  173. {
  174. return interpret_IFD( $Makernote_tag['Decoded Data'][0], $filename );
  175. }
  176. else if ( $Makernote_tag['Makernote Type'] == "Panasonic Empty Makernote" )
  177. {
  178. // Do Nothing
  179. return "";
  180. }
  181. else
  182. {
  183. // Unknown Makernote Type
  184. return FALSE;
  185. }
  186. // Shouldn't get here
  187. return FALSE;
  188. }
  189. /******************************************************************************
  190. * End of Function: get_Panasonic_Makernote_Html
  191. ******************************************************************************/
  192. /******************************************************************************
  193. * Global Variable: IFD_Tag_Definitions, Panasonic
  194. *
  195. * Contents: This global variable provides definitions of the known Panasonic
  196. * Makernote tags, indexed by their tag number.
  197. *
  198. ******************************************************************************/
  199. $GLOBALS[ "IFD_Tag_Definitions" ]["Panasonic"] = array(
  200. 0x01 => array( 'Name' => "Quality Mode",
  201. 'Type' => "Numeric" ),
  202. 0x02 => array( 'Name' => "Version",
  203. 'Type' => "String" ),
  204. 0x1c => array( 'Name' => "Macro Mode",
  205. 'Type' => "Lookup",
  206. 1 => "On",
  207. 2 => "Off" ),
  208. 0x1f => array( 'Name' => "Record Mode",
  209. 'Type' => "Lookup",
  210. 1 => "Normal",
  211. 2 => "Portrait",
  212. 9 => "Macro" ),
  213. 0xE00 => array( 'Name' => "Print Image Matching Info",
  214. 'Type' => "PIM" ),
  215. );
  216. /******************************************************************************
  217. * End of Global Variable: IFD_Tag_Definitions, Panasonic
  218. ******************************************************************************/
  219. ?>