Source for file PelEntryUndefined.php

Documentation is available at PelEntryUndefined.php

  1. <?php
  2.  
  3. /*  PEL: PHP Exif Library.  A library with support for reading and
  4.  *  writing all Exif headers in JPEG and TIFF images using PHP.
  5.  *
  6.  *  Copyright (C) 2004, 2005  Martin Geisler.
  7.  *
  8.  *  This program is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2 of the License, or
  11.  *  (at your option) any later version.
  12.  *
  13.  *  This program is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program in the file COPYING; if not, write to the
  20.  *  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21.  *  Boston, MA 02110-1301 USA
  22.  */
  23.  
  24. /* $Id$ */
  25.  
  26.  
  27. /**
  28.  * Classes used to hold data for Exif tags of format undefined.
  29.  *
  30.  * This file contains the base class {@link PelEntryUndefined} and
  31.  * the subclasses {@link PelEntryUserComment} which should be used
  32.  * to manage the {@link PelTag::USER_COMMENT} tag, and {@link }
  33.  * PelEntryVersion} which is used to manage entries with version
  34.  * information.
  35.  *
  36.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  37.  * @version $Revision$
  38.  * @date $Date$
  39.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  40.  *  License (GPL)
  41.  * @package PEL
  42.  */
  43.  
  44. /**#@+ Required class definitions. */
  45. require_once('PelEntry.php');
  46. /**#@-*/
  47.  
  48.  
  49. /**
  50.  * Class for holding data of any kind.
  51.  *
  52.  * This class can hold bytes of undefined format.
  53.  *
  54.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  55.  * @package PEL
  56.  */
  57. class PelEntryUndefined extends PelEntry {
  58.  
  59.   /**
  60.    * Make a new PelEntry that can hold undefined data.
  61.    *
  62.    * @param PelTag the tag which this entry represents.  This
  63.    *  should be one of the constants defined in {@link PelTag},
  64.    *  e.g., {@link PelTag::SCENE_TYPE}{@link }
  65.    *  PelTag::MAKER_NOTE} or any other tag with format {@link }
  66.    *  PelFormat::UNDEFINED}.
  67.    *
  68.    * @param string the data that this entry will be holding.  Since
  69.    *  the format is undefined, no checking will be done on the data.
  70.    */
  71.   function __construct($tag$data ''{
  72.     $this->tag        = $tag;
  73.     $this->format     = PelFormat::UNDEFINED;
  74.     $this->setValue($data);
  75.   }
  76.  
  77.  
  78.   /**
  79.    * Set the data of this undefined entry.
  80.    *
  81.    * @param string the data that this entry will be holding.  Since
  82.    *  the format is undefined, no checking will be done on the data.
  83.    */
  84.   function setValue($data{
  85.     $this->components = strlen($data);
  86.     $this->bytes      = $data;
  87.   }
  88.  
  89.  
  90.   /**
  91.    * Get the data of this undefined entry.
  92.    *
  93.    * @return string the data that this entry is holding.
  94.    */
  95.   function getValue({
  96.     return $this->bytes;
  97.   }
  98.  
  99.  
  100.   /**
  101.    * Get the value of this entry as text.
  102.    *
  103.    * The value will be returned in a format suitable for presentation.
  104.    *
  105.    * @param boolean some values can be returned in a long or more
  106.    *  brief form, and this parameter controls that.
  107.    *
  108.    * @return string the value as text.
  109.    */
  110.   function getText($brief false{
  111.     switch ($this->tag{
  112.     case PelTag::FILE_SOURCE:
  113.       //CC (e->components, 1, v);
  114.       switch (ord($this->bytes{0})) {
  115.       case 0x03:
  116.         return 'DSC';
  117.       default:
  118.         return sprintf('0x%02X'ord($this->bytes{0}));
  119.       }
  120.    
  121.     case PelTag::SCENE_TYPE:
  122.       //CC (e->components, 1, v);
  123.       switch (ord($this->bytes{0})) {
  124.       case 0x01:
  125.         return 'Directly photographed';
  126.       default:
  127.         return sprintf('0x%02X'ord($this->bytes{0}));
  128.       }
  129.    
  130.     case PelTag::COMPONENTS_CONFIGURATION:
  131.       //CC (e->components, 4, v);
  132.       $v '';
  133.       for ($i 0$i 4$i++{
  134.         switch (ord($this->bytes{$i})) {
  135.         case 0:
  136.           $v .= '-';
  137.           break;
  138.         case 1:
  139.           $v .= 'Y';
  140.           break;
  141.         case 2:
  142.           $v .= 'Cb';
  143.           break;
  144.         case 3:
  145.           $v .= 'Cr';
  146.           break;
  147.         case 4:
  148.           $v .= 'R';
  149.           break;
  150.         case 5:
  151.           $v .= 'G';
  152.           break;
  153.         case 6:
  154.           $v .= 'B';
  155.           break;
  156.         default:
  157.           $v .= 'reserved';
  158.           break;
  159.         }
  160.         if ($i 3$v .= ' ';
  161.       }
  162.       return $v;
  163.  
  164.     case PelTag::MAKER_NOTE:
  165.       // TODO: handle maker notes.
  166.       return $this->components ' bytes unknown MakerNote data';
  167.  
  168.     default:
  169.       return '(undefined)';
  170.     }
  171.   }
  172.  
  173. }
  174.  
  175.  
  176. /**
  177.  * Class for a user comment.
  178.  *
  179.  * This class is used to hold user comments, which can come in several
  180.  * different character encodings.  The Exif standard specifies a
  181.  * certain format of the {@link PelTag::USER_COMMENT user comment}
  182.  * tag}, and this class will make sure that the format is kept.
  183.  *
  184.  * The most basic use of this class simply stores an ASCII encoded
  185.  * string for later retrieval using {@link getValue}:
  186.  *
  187.  * <code>
  188.  * $entry = new PelEntryUserComment('An ASCII string');
  189.  * echo $entry->getValue();
  190.  * </code>
  191.  *
  192.  * The string can be encoded with a different encoding, and if so, the
  193.  * encoding must be given using the second argument.  The Exif
  194.  * standard specifies three known encodings: 'ASCII', 'JIS', and
  195.  * 'Unicode'.  If the user comment is encoded using a character
  196.  * encoding different from the tree known encodings, then the empty
  197.  * string should be passed as encoding, thereby specifying that the
  198.  * encoding is undefined.
  199.  *
  200.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  201.  * @package PEL
  202.  */
  203.  
  204.   /**
  205.    * The user comment.
  206.    *
  207.    * @var string 
  208.    */
  209.   private $comment;
  210.  
  211.   /**
  212.    * The encoding.
  213.    *
  214.    * This should be one of 'ASCII', 'JIS', 'Unicode', or ''.
  215.    *
  216.    * @var string 
  217.    */
  218.   private $encoding;
  219.  
  220.   /**
  221.    * Make a new entry for holding a user comment.
  222.    *
  223.    * @param string the new user comment.
  224.    *
  225.    * @param string the encoding of the comment.  This should be either
  226.    *  'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  227.    *  undefined encoding.
  228.    */
  229.   function __construct($comment ''$encoding 'ASCII'{
  230.     parent::__construct(PelTag::USER_COMMENT);
  231.     $this->setValue($comment$encoding);
  232.   }
  233.  
  234.   
  235.   /**
  236.    * Set the user comment.
  237.    *
  238.    * @param string the new user comment.
  239.    *
  240.    * @param string the encoding of the comment.  This should be either
  241.    *  'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  242.    *  unknown encoding.
  243.    */
  244.   function setValue($comment ''$encoding 'ASCII'{
  245.     $this->comment  $comment;
  246.     $this->encoding $encoding;
  247.     parent::setValue(str_pad($encoding8chr(0)) $comment);
  248.   }
  249.  
  250.  
  251.   /**
  252.    * Returns the user comment.
  253.    *
  254.    * The comment is returned with the same character encoding as when
  255.    * it was set using {@link setValue} or {@link __construct the}
  256.    * constructor}.
  257.    *
  258.    * @return string the user comment.
  259.    */
  260.   function getValue({
  261.     return $this->comment;
  262.   }
  263.  
  264.  
  265.   /**
  266.    * Returns the encoding.
  267.    *
  268.    * @return string the encoding of the user comment.
  269.    */
  270.   function getEncoding({
  271.     return $this->encoding;
  272.   }
  273.  
  274.  
  275.   /**
  276.    * Returns the user comment.
  277.    *
  278.    * @return string the user comment.
  279.    */
  280.   function getText($brief false{
  281.     return $this->comment;
  282.   }
  283.  
  284. }
  285.  
  286.  
  287. /**
  288.  * Class to hold version information.
  289.  *
  290.  * There are three Exif entries that hold version information: the
  291.  * {@link PelTag::EXIF_VERSION}{@link }
  292.  * PelTag::FLASH_PIX_VERSION}, and {@link }
  293.  * PelTag::INTEROPERABILITY_VERSION} tags.  This class manages
  294.  * those tags.
  295.  *
  296.  * The class is used in a very straight-forward way:
  297.  * <code>
  298.  * $entry = new PelEntryVersion(PelTag::EXIF_VERSION, 2.2);
  299.  * </code>
  300.  * This creates an entry for an file complying to the Exif 2.2
  301.  * standard.  It is easy to test for standards level of an unknown
  302.  * entry:
  303.  * <code>
  304.  * if ($entry->getTag() == PelTag::EXIF_VERSION &&
  305.  *     $entry->getValue() > 2.0) {
  306.  *   echo 'Recent Exif version.';
  307.  * }
  308.  * </code>
  309.  *
  310.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  311.  * @package PEL
  312.  */
  313.  
  314.   /**
  315.    * The version held by this entry.
  316.    *
  317.    * @var float 
  318.    */
  319.   private $version;
  320.  
  321.  
  322.   /**
  323.    * Make a new entry for holding a version.
  324.    *
  325.    * @param PelTag the tag.  This should be one of {@link }
  326.    *  PelTag::EXIF_VERSION}, {@link PelTag::FLASH_PIX_VERSION},
  327.    *  or {@link PelTag::INTEROPERABILITY_VERSION}.
  328.    *
  329.    * @param float the version.  The size of the entries leave room for
  330.    *  exactly four digits: two digits on either side of the decimal
  331.    *  point.
  332.    */
  333.   function __construct($tag$version 0.0{
  334.     parent::__construct($tag);
  335.     $this->setValue($version);
  336.   }
  337.  
  338.  
  339.   /**
  340.    * Set the version held by this entry.
  341.    *
  342.    * @param float the version.  The size of the entries leave room for
  343.    *  exactly four digits: two digits on either side of the decimal
  344.    *  point.
  345.    */
  346.   function setValue($version 0.0{
  347.     $this->version $version;
  348.     $major floor($version);
  349.     $minor ($version $major)*100;
  350.     parent::setValue(sprintf('%02.0f%02.0f'$major$minor));
  351.   }
  352.  
  353.  
  354.   /**
  355.    * Return the version held by this entry.
  356.    *
  357.    * @return float the version.  This will be the same as the value
  358.    *  given to {@link setValue} or {@link __construct the}
  359.    *  constructor}.
  360.    */
  361.   function getValue({
  362.     return $this->version;
  363.   }
  364.  
  365.  
  366.   /**
  367.    * Return a text string with the version.
  368.    *
  369.    * @param boolean controls if the output should be brief.  Brief
  370.    *  output omits the word 'Version' so the result is just 'Exif x.y'
  371.    *  instead of 'Exif Version x.y' if the entry holds information
  372.    *  about the Exif version --- the output for FlashPix is similar.
  373.    *
  374.    * @return string the version number with the type of the tag,
  375.    *  either 'Exif' or 'FlashPix'.
  376.    */
  377.   function getText($brief false{
  378.     $v $this->version;
  379.  
  380.     /* Versions numbers like 2.0 would be output as just 2 if we don't
  381.      * add the '.0' ourselves. */
  382.     if (floor($this->version== $this->version)
  383.       $v .= '.0';
  384.  
  385.     switch ($this->tag{
  386.     case PelTag::EXIF_VERSION:
  387.       if ($brief)
  388.         return Pel::fmt('Exif %s'$v);
  389.       else
  390.         return Pel::fmt('Exif Version %s'$v);
  391.       
  392.     case PelTag::FLASH_PIX_VERSION:
  393.       if ($brief)
  394.         return Pel::fmt('FlashPix %s'$v);
  395.       else
  396.         return Pel::fmt('FlashPix Version %s'$v);
  397.       
  398.     case PelTag::INTEROPERABILITY_VERSION:
  399.       if ($brief)
  400.         return Pel::fmt('Interoperability %s'$v);
  401.       else
  402.         return Pel::fmt('Interoperability Version %s'$v);
  403.     }
  404.  
  405.     if ($brief)
  406.       return $v;
  407.     else
  408.       return Pel::fmt('Version %s'$v);
  409.     
  410.   }
  411.  
  412. }
  413.  
  414. ?>

Documentation generated on Thu, 05 May 2011 07:19:10 +0200 by phpDocumentor 1.4.3