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

Documentation generated on Tue, 19 Dec 2006 01:08:23 +0100 by phpDocumentor 1.3.0 SourceForge.net Logo