PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://buddypress-media.googlecode.com/
PHP | 241 lines | 45 code | 63 blank | 133 comment | 7 complexity | dd657a4db16c15139bd315c10141523a MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /******************************************************************************
  3. *
  4. * Filename: kyocera.php
  5. *
  6. * Description: Kyocera Makernote Parser
  7. * Provides functions to decode an Kyocera EXIF makernote and to interpret
  8. * the resulting array into html. Includes Kyocera's Contax brand
  9. *
  10. * Kyocera Makernote Format:
  11. *
  12. * Field Size Description
  13. * ----------------------------------------------------------------
  14. * Header 22 Bytes "KYOCERA \x00\x00\x00"
  15. * IFD Data Variable NON-Standard IFD Data using Kyocera Tags
  16. * IFD has no Next-IFD pointer at end of IFD,
  17. * and Offsets are relative to the start
  18. * of the current IFD tag, not the TIFF header
  19. * ----------------------------------------------------------------
  20. *
  21. *
  22. *
  23. * Author: Evan Hunter
  24. *
  25. * Date: 30/7/2004
  26. *
  27. * Project: JPEG Metadata
  28. *
  29. * Revision: 1.00
  30. *
  31. * URL: http://electronics.ozhiker.com
  32. *
  33. * Copyright: Copyright Evan Hunter 2004
  34. * This file may be used freely for non-commercial purposes.For
  35. * commercial uses please contact the author: evan@ozhiker.com
  36. *
  37. ******************************************************************************/
  38. // Add the parser and interpreter functions to the list of Makernote parsers and interpreters.
  39. $GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Kyocera_Makernote";
  40. $GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Kyocera_Text_Value";
  41. $GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Kyocera_Makernote_Html";
  42. /******************************************************************************
  43. *
  44. * Function: get_Kyocera_Makernote
  45. *
  46. * Description: Decodes the Makernote tag and returns the new tag with the decoded
  47. * information attached. Returns false if this is not a makernote
  48. * that can be processed with this script
  49. *
  50. * Parameters: Makernote_Tag - the element of an EXIF array containing the
  51. * makernote, as returned from get_EXIF_JPEG
  52. * EXIF_Array - the entire EXIF array containing the
  53. * makernote, as returned from get_EXIF_JPEG, in
  54. * case more information is required for decoding
  55. * filehnd - an open file handle for the file containing the
  56. * makernote - does not have to be positioned at the
  57. * start of the makernote
  58. * Make_Field - The contents of the EXIF Make field, to aid
  59. * determining whether this script can decode
  60. * the makernote
  61. *
  62. *
  63. * Returns: Makernote_Tag - the Makernote_Tag from the parameters, but
  64. * modified to contain the decoded information
  65. * FALSE - If this script could not decode the makernote, or if
  66. * an error occured in decoding
  67. *
  68. ******************************************************************************/
  69. function get_Kyocera_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field )
  70. {
  71. // Check if the Make Field contains the word Contax or Kyocera
  72. if ( ( stristr( $Make_Field, "Contax" ) === FALSE ) &&
  73. ( stristr( $Make_Field, "Kyocera" ) === FALSE ) )
  74. {
  75. // Kyocera or Contax not found in maker field - abort
  76. return FALSE;
  77. }
  78. // Check if the header exists at the start of the Makernote
  79. if ( substr( $Makernote_Tag['Data'], 0, 22 ) != "KYOCERA \x00\x00\x00" )
  80. {
  81. // This isn't a Kyocera Makernote, abort
  82. return FALSE ;
  83. }
  84. // Seek to the start of the IFD
  85. fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 22 );
  86. // Read the IFD(s) into an array
  87. $Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Kyocera", True, False );
  88. // Save some information into the Tag element to aid interpretation
  89. $Makernote_Tag['Decoded'] = TRUE;
  90. $Makernote_Tag['Makernote Type'] = "Kyocera";
  91. $Makernote_Tag['Makernote Tags'] = "Kyocera";
  92. // Return the new tag
  93. return $Makernote_Tag;
  94. }
  95. /******************************************************************************
  96. * End of Function: get_Kyocera_Makernote
  97. ******************************************************************************/
  98. /******************************************************************************
  99. *
  100. * Function: get_Kyocera_Text_Value
  101. *
  102. * Description: Provides a text value for any tag marked as special for makernotes
  103. * that this script can decode. Returns false if this is not a makernote
  104. * that can be processed with this script
  105. *
  106. * Parameters: Exif_Tag - the element of an the Makernote array containing the
  107. * tag in question, as returned from get_Kyocera_Makernote
  108. * Tag_Definitions_Name - The name of the Tag Definitions group
  109. * within the global array IFD_Tag_Definitions
  110. *
  111. *
  112. * Returns: output - the text value for the tag
  113. * FALSE - If this script could not decode the makernote, or if
  114. * an error occured in decoding
  115. *
  116. ******************************************************************************/
  117. function get_Kyocera_Text_Value( $Exif_Tag, $Tag_Definitions_Name )
  118. {
  119. // Check that this tag uses Kyocera tags, otherwise it can't be interpreted here
  120. if ( $Tag_Definitions_Name == "Kyocera" )
  121. {
  122. // No Special Kyocera tags so far
  123. return FALSE;
  124. }
  125. return FALSE;
  126. }
  127. /******************************************************************************
  128. * End of Function: get_Kyocera_Text_Value
  129. ******************************************************************************/
  130. /******************************************************************************
  131. *
  132. * Function: get_Kyocera_Makernote_Html
  133. *
  134. * Description: Attempts to interpret a makernote into html. Returns false if
  135. * it is not a makernote that can be processed with this script
  136. *
  137. * Parameters: Makernote_Tag - the element of an EXIF array containing the
  138. * makernote, as returned from get_EXIF_JPEG
  139. * filename - the name of the JPEG file being processed ( used
  140. * by scripts which display embedded thumbnails)
  141. *
  142. *
  143. * Returns: output - the html representing the makernote
  144. * FALSE - If this script could not interpret the makernote, or if
  145. * an error occured in decoding
  146. *
  147. ******************************************************************************/
  148. function get_Kyocera_Makernote_Html( $Makernote_tag, $filename )
  149. {
  150. // Check that this is a Kyocera Makernote, otherwise it can't be interpreted here
  151. if ( $Makernote_tag['Makernote Type'] != "Kyocera" )
  152. {
  153. // Not a Kyocera Makernote - cannot interpret it - abort
  154. return False;
  155. }
  156. // Interpret the IFD and return the HTML
  157. return interpret_IFD( $Makernote_tag['Decoded Data'][0], $filename );
  158. }
  159. /******************************************************************************
  160. * End of Function: get_Kyocera_Makernote_Html
  161. ******************************************************************************/
  162. /******************************************************************************
  163. * Global Variable: IFD_Tag_Definitions, Kyocera
  164. *
  165. * Contents: This global variable provides definitions of the known Kyocera
  166. * Makernote tags, indexed by their tag number.
  167. *
  168. ******************************************************************************/
  169. $GLOBALS[ "IFD_Tag_Definitions" ]["Kyocera"] = array(
  170. 1 => array( 'Name' => "Kyocera Proprietory Format Thumbnail",
  171. 'Type' => "Unknown" ),
  172. 0x0E00 => array( 'Name' => "Print Image Matching Info",
  173. 'Type' => "PIM" ),
  174. );
  175. /******************************************************************************
  176. * End of Global Variable: IFD_Tag_Definitions, Kyocera
  177. ******************************************************************************/
  178. ?>