PageRenderTime 180ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://buddypress-media.googlecode.com/
PHP | 353 lines | 115 code | 84 blank | 154 comment | 7 complexity | f288f3b5c2cb04772d96804d729adc91 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /******************************************************************************
  3. *
  4. * Filename: pentax.php
  5. *
  6. * Description: Pentax (Asahi) Makernote Parser
  7. * Provides functions to decode an Pentax (Asahi) EXIF makernote and to interpret
  8. * the resulting array into html.
  9. *
  10. * Pentax Makernote Format:
  11. *
  12. * Type 1
  13. *
  14. * Field Size Description
  15. * ----------------------------------------------------------------
  16. * IFD Data Variable NON-Standard IFD Data using Pentax Tags
  17. * IFD has no Next-IFD pointer at end of IFD,
  18. * and Offsets are relative to the start
  19. * of the current IFD tag, not the TIFF header
  20. * ----------------------------------------------------------------
  21. *
  22. *
  23. * Type 2
  24. *
  25. * Field Size Description
  26. * ----------------------------------------------------------------
  27. * Header 4 Bytes "AOC\x00"
  28. * Unknown 2 Bytes Unknown field
  29. * IFD Data Variable NON-Standard IFD Data using Casio Type 2 Tags
  30. * IFD has no Next-IFD pointer at end of IFD,
  31. * and Offsets are relative to the start
  32. * of the current IFD tag, not the TIFF header
  33. * ----------------------------------------------------------------
  34. *
  35. *
  36. *
  37. * Author: Evan Hunter
  38. *
  39. * Date: 30/7/2004
  40. *
  41. * Project: JPEG Metadata
  42. *
  43. * Revision: 1.00
  44. *
  45. * URL: http://electronics.ozhiker.com
  46. *
  47. * Copyright: Copyright Evan Hunter 2004
  48. * This file may be used freely for non-commercial purposes.For
  49. * commercial uses please contact the author: evan@ozhiker.com
  50. *
  51. ******************************************************************************/
  52. // Pentax Type 2 makernote uses Casio Type 2 tags - ensure they are included
  53. include_once 'casio.php';
  54. // Add the parser and interpreter functions to the list of Makernote parsers and interpreters.
  55. $GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Pentax_Makernote";
  56. $GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Pentax_Text_Value";
  57. $GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Pentax_Makernote_Html";
  58. /******************************************************************************
  59. *
  60. * Function: get_Pentax_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. function get_Pentax_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field )
  86. {
  87. // Check if the Make Field contains the word Pentax or Asahi
  88. if ( ( stristr( $Make_Field, "Pentax" ) === FALSE ) &&
  89. ( stristr( $Make_Field, "Asahi" ) === FALSE ) )
  90. {
  91. // Couldn't find Pentax or Asahi in the maker - abort
  92. return FALSE;
  93. }
  94. // Check if the header exists at the start of the Makernote
  95. if ( substr( $Makernote_Tag['Data'], 0, 4 ) == "AOC\x00" )
  96. {
  97. // Type 2 Pentax Makernote
  98. // Seek to the start of the IFD
  99. fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 6 );
  100. // Read the IFD(s) into an array
  101. $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Casio Type 2" );
  102. // Save some information into the Tag element to aid interpretation
  103. $Makernote_Tag['Decoded'] = TRUE;
  104. $Makernote_Tag['Makernote Type'] = "Casio Type 2";
  105. $Makernote_Tag['Makernote Tags'] = "Casio Type 2";
  106. // Return the new tag
  107. return $Makernote_Tag;
  108. }
  109. else
  110. {
  111. // Type 1 Penax Makernote
  112. // Seek to the start of the IFD
  113. fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 0 );
  114. // Read the IFD(s) into an array
  115. $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Pentax" );
  116. // Save some information into the Tag element to aid interpretation
  117. $Makernote_Tag['Decoded'] = TRUE;
  118. $Makernote_Tag['Makernote Type'] = "Pentax";
  119. $Makernote_Tag['Makernote Tags'] = "Pentax";
  120. // Return the new tag
  121. return $Makernote_Tag;
  122. }
  123. // Shouldn't get here
  124. return FALSE;
  125. }
  126. /******************************************************************************
  127. * End of Function: get_Pentax_Makernote
  128. ******************************************************************************/
  129. /******************************************************************************
  130. *
  131. * Function: get_Pentax_Text_Value
  132. *
  133. * Description: Provides a text value for any tag marked as special for makernotes
  134. * that this script can decode. Returns false if this is not a makernote
  135. * that can be processed with this script
  136. *
  137. * Parameters: Exif_Tag - the element of an the Makernote array containing the
  138. * tag in question, as returned from get_Pentax_Makernote
  139. * Tag_Definitions_Name - The name of the Tag Definitions group
  140. * within the global array IFD_Tag_Definitions
  141. *
  142. *
  143. * Returns: output - the text value for the tag
  144. * FALSE - If this script could not decode the makernote, or if
  145. * an error occured in decoding
  146. *
  147. ******************************************************************************/
  148. function get_Pentax_Text_Value( $Exif_Tag, $Tag_Definitions_Name )
  149. {
  150. // Check that this tag uses the Pentax tags, otherwise it can't be interpreted here
  151. if ( $Tag_Definitions_Name == "Pentax" )
  152. {
  153. // No Special Tags so far
  154. return FALSE;
  155. }
  156. return FALSE;
  157. }
  158. /******************************************************************************
  159. * End of Function: get_Pentax_Text_Value
  160. ******************************************************************************/
  161. /******************************************************************************
  162. *
  163. * Function: get_Pentax_Makernote_Html
  164. *
  165. * Description: Attempts to interpret a makernote into html. Returns false if
  166. * it is not a makernote that can be processed with this script
  167. *
  168. * Parameters: Makernote_Tag - the element of an EXIF array containing the
  169. * makernote, as returned from get_EXIF_JPEG
  170. * filename - the name of the JPEG file being processed ( used
  171. * by scripts which display embedded thumbnails)
  172. *
  173. *
  174. * Returns: output - the html representing the makernote
  175. * FALSE - If this script could not interpret the makernote, or if
  176. * an error occured in decoding
  177. *
  178. ******************************************************************************/
  179. function get_Pentax_Makernote_Html( $Makernote_tag, $filename )
  180. {
  181. // Check that this is a Pentax type makernote
  182. if ( $Makernote_tag['Makernote Type'] != "Pentax" )
  183. {
  184. // Not a Pentax makernote - abort
  185. return False;
  186. }
  187. // Interpret the IFD and return the html
  188. return interpret_IFD( $Makernote_tag['Decoded Data'][0], $filename );
  189. }
  190. /******************************************************************************
  191. * End of Function: get_Pentax_Makernote_Html
  192. ******************************************************************************/
  193. /******************************************************************************
  194. * Global Variable: IFD_Tag_Definitions, Pentax
  195. *
  196. * Contents: This global variable provides definitions of the known Pentax Type 1
  197. * Makernote tags, indexed by their tag number.
  198. *
  199. ******************************************************************************/
  200. $GLOBALS[ "IFD_Tag_Definitions" ]["Pentax"] = array(
  201. 0x0001 => array( 'Name' => "Capture Mode",
  202. 'Type' => "Lookup",
  203. 0 => "Auto",
  204. 1 => "Night-scene",
  205. 2 => "Manual",
  206. 4 => "Multiple" ),
  207. 0x0002 => array( 'Name' => "Quality Level",
  208. 'Type' => "Lookup",
  209. 0 => "Good",
  210. 1 => "Better",
  211. 2 => "Best" ),
  212. 0x0003 => array( 'Name' => "Focus Mode",
  213. 'Type' => "Lookup",
  214. 2 => "Custom",
  215. 3 => "Auto" ),
  216. 0x0004 => array( 'Name' => "Flash Mode",
  217. 'Type' => "Lookup",
  218. 1 => "Auto",
  219. 2 => "Flash on",
  220. 4 => "Flash off",
  221. 6 => "Red-eye Reduction" ),
  222. 0x0007 => array( 'Name' => "White Balance",
  223. 'Type' => "Lookup",
  224. 0 => "Auto",
  225. 1 => "Daylight",
  226. 2 => "Shade",
  227. 3 => "Tungsten",
  228. 4 => "Fluorescent",
  229. 5 => "Manual" ),
  230. 0x000a => array( 'Name' => "Digital Zoom",
  231. 'Type' => "Numeric",
  232. 'Units' => " (0 = Off)" ),
  233. 0x000b => array( 'Name' => "Sharpness",
  234. 'Type' => "Lookup",
  235. 0 => "Normal",
  236. 1 => "Soft",
  237. 2 => "Hard" ),
  238. 0x000c => array( 'Name' => "Contrast",
  239. 'Type' => "Lookup",
  240. 0 => "Normal",
  241. 1 => "Low",
  242. 2 => "High" ),
  243. 0x000d => array( 'Name' => "Saturation",
  244. 'Type' => "Lookup",
  245. 0 => "Normal",
  246. 1 => "Low",
  247. 2 => "High" ),
  248. 0x0014 => array( 'Name' => "ISO Speed",
  249. 'Type' => "Lookup",
  250. 10 => "100",
  251. 16 => "200",
  252. 100 => "100",
  253. 200 => "200" ),
  254. 0x0017 => array( 'Name' => "Colour",
  255. 'Type' => "Lookup",
  256. 1 => "Normal",
  257. 2 => "Black & White",
  258. 3 => "Sepia" ),
  259. 0x0e00 => array( 'Name' => "Print Image Matching Info",
  260. 'Type' => "PIM" ),
  261. 0x1000 => array( 'Name' => "Time Zone",
  262. 'Type' => "String" ),
  263. 0x1001 => array( 'Name' => "Daylight Savings",
  264. 'Type' => "String" ),
  265. );
  266. /******************************************************************************
  267. * End of Global Variable: IFD_Tag_Definitions, Pentax
  268. ******************************************************************************/
  269. ?>