Source for file PelEntryShort.php

Documentation is available at PelEntryShort.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, 2006  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 shorts, both signed and unsigned.
  29.  *
  30.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  31.  * @version $Revision$
  32.  * @date $Date$
  33.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  34.  *  License (GPL)
  35.  * @package PEL
  36.  */
  37.  
  38. /**#@+ Required class definitions. */
  39. require_once('PelEntryNumber.php');
  40. require_once('PelConvert.php');
  41. require_once('Pel.php');
  42. /**#@-*/
  43.  
  44.  
  45. /**
  46.  * Class for holding signed shorts.
  47.  *
  48.  * This class can hold shorts, either just a single short or an array
  49.  * of shorts.  The class will be used to manipulate any of the Exif
  50.  * tags which has format {@link PelFormat::SHORT} like in this
  51.  * example:
  52.  *
  53.  * <code>
  54.  * $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
  55.  * $w->setValue($w->getValue() / 2);
  56.  * $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
  57.  * $h->setValue($h->getValue() / 2);
  58.  * </code>
  59.  *
  60.  * Here the width and height is updated to 50% of their original
  61.  * values.
  62.  *
  63.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  64.  * @package PEL
  65.  */
  66. class PelEntryShort extends PelEntryNumber {
  67.  
  68.   /**
  69.    * Make a new entry that can hold an unsigned short.
  70.    *
  71.    * The method accept several integer arguments.  The {@link }
  72.    * getValue} method will always return an array except for when a
  73.    * single integer argument is given here.
  74.    *
  75.    * This means that one can conveniently use objects like this:
  76.    * <code>
  77.    * $a = new PelEntryShort(PelTag::EXIF_IMAGE_HEIGHT, 42);
  78.    * $b = $a->getValue() + 314;
  79.    * </code>
  80.    * where the call to {@link getValue} will return an integer
  81.    * instead of an array with one integer element, which would then
  82.    * have to be extracted.
  83.    *
  84.    * @param PelTag the tag which this entry represents.  This should be
  85.    *  one of the constants defined in {@link PelTag}, e.g., {@link }
  86.    *  PelTag::IMAGE_WIDTH}, {@link PelTag::ISO_SPEED_RATINGS},
  87.    *  or any other tag with format {@link PelFormat::SHORT}.
  88.    *
  89.    * @param int $value... the short(s) that this entry will
  90.    *  represent.  The argument passed must obey the same rules as the
  91.    *  argument to {@link setValue}, namely that it should be within
  92.    *  range of an unsigned short, that is between 0 and 65535
  93.    *  (inclusive).  If not, then a {@link PelOverFlowException} will be
  94.    *  thrown.
  95.    */
  96.   function __construct($tag /* $value... */{
  97.     $this->tag    = $tag;
  98.     $this->min    = 0;
  99.     $this->max    = 65535;
  100.     $this->format = PelFormat::SHORT;
  101.  
  102.     $value func_get_args();
  103.     array_shift($value);
  104.     $this->setValueArray($value);
  105.   }
  106.  
  107.  
  108.   /**
  109.    * Convert a number into bytes.
  110.    *
  111.    * @param int the number that should be converted.
  112.    *
  113.    * @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
  114.    *  {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
  115.    *
  116.    * @return string bytes representing the number given.
  117.    */
  118.   function numberToBytes($number$order{
  119.     return PelConvert::shortToBytes($number$order);
  120.   }
  121.  
  122.  
  123.   /**
  124.    * Get the value of an entry as text.
  125.    *
  126.    * The value will be returned in a format suitable for presentation,
  127.    * e.g., instead of returning '2' for a {@link }
  128.    * PelTag::METERING_MODE} tag, 'Center-Weighted Average' is
  129.    * returned.
  130.    *
  131.    * @param boolean some values can be returned in a long or more
  132.    *  brief form, and this parameter controls that.
  133.    *
  134.    * @return string the value as text.
  135.    */
  136.   function getText($brief false{
  137.     switch ($this->tag{
  138.     case PelTag::METERING_MODE:
  139.       //CC (e->components, 1, v);
  140.       switch ($this->value[0]{
  141.       case 0:
  142.         return Pel::tra('Unknown');
  143.       case 1:
  144.         return Pel::tra('Average');
  145.       case 2:
  146.         return Pel::tra('Center-Weighted Average');
  147.       case 3:
  148.         return Pel::tra('Spot');
  149.       case 4:
  150.         return Pel::tra('Multi Spot');
  151.       case 5:
  152.         return Pel::tra('Pattern');
  153.       case 6:
  154.         return Pel::tra('Partial');
  155.       case 255:
  156.         return Pel::tra('Other');
  157.       default:
  158.         return $this->value[0];
  159.       }
  160.  
  161.     case PelTag::COMPRESSION:
  162.       //CC (e->components, 1, v);
  163.       switch ($this->value[0]{
  164.       case 1:
  165.         return Pel::tra('Uncompressed');
  166.       case 6:
  167.         return Pel::tra('JPEG compression');
  168.       default:
  169.         return $this->value[0];
  170.       
  171.       }
  172.  
  173.     case PelTag::PLANAR_CONFIGURATION:
  174.       //CC (e->components, 1, v);
  175.       switch ($this->value[0]{
  176.       case 1:
  177.         return Pel::tra('chunky format');
  178.       case 2:
  179.         return Pel::tra('planar format');
  180.       default:
  181.         return $this->value[0];
  182.       }
  183.       
  184.     case PelTag::SENSING_METHOD:
  185.       //CC (e->components, 1, v);
  186.       switch ($this->value[0]{
  187.       case 1:
  188.         return Pel::tra('Not defined');
  189.       case 2:
  190.         return Pel::tra('One-chip color area sensor');
  191.       case 3:
  192.         return Pel::tra('Two-chip color area sensor');
  193.       case 4:
  194.         return Pel::tra('Three-chip color area sensor');
  195.       case 5:
  196.         return Pel::tra('Color sequential area sensor');
  197.       case 7:
  198.         return Pel::tra('Trilinear sensor');
  199.       case 8:
  200.         return Pel::tra('Color sequential linear sensor');
  201.       default:
  202.         return $this->value[0];
  203.       }
  204.  
  205.     case PelTag::LIGHT_SOURCE:
  206.       //CC (e->components, 1, v);
  207.       switch ($this->value[0]{
  208.       case 0:
  209.         return Pel::tra('Unknown');
  210.       case 1:
  211.         return Pel::tra('Daylight');
  212.       case 2:
  213.         return Pel::tra('Fluorescent');
  214.       case 3:
  215.         return Pel::tra('Tungsten (incandescent light)');
  216.       case 4:
  217.         return Pel::tra('Flash');
  218.       case 9:
  219.         return Pel::tra('Fine weather');
  220.       case 10:
  221.         return Pel::tra('Cloudy weather');
  222.       case 11:
  223.         return Pel::tra('Shade');
  224.       case 12:
  225.         return Pel::tra('Daylight fluorescent');
  226.       case 13:
  227.         return Pel::tra('Day white fluorescent');
  228.       case 14:
  229.         return Pel::tra('Cool white fluorescent');
  230.       case 15:
  231.         return Pel::tra('White fluorescent');
  232.       case 17:
  233.         return Pel::tra('Standard light A');
  234.       case 18:
  235.         return Pel::tra('Standard light B');
  236.       case 19:
  237.         return Pel::tra('Standard light C');
  238.       case 20:
  239.         return Pel::tra('D55');
  240.       case 21:
  241.         return Pel::tra('D65');
  242.       case 22:
  243.         return Pel::tra('D75');
  244.       case 24:
  245.         return Pel::tra('ISO studio tungsten');
  246.       case 255:
  247.         return Pel::tra('Other');
  248.       default:
  249.         return $this->value[0];
  250.       }
  251.  
  252.     case PelTag::FOCAL_PLANE_RESOLUTION_UNIT:
  253.     case PelTag::RESOLUTION_UNIT:
  254.       //CC (e->components, 1, v);
  255.       switch ($this->value[0]{
  256.       case 2:
  257.         return Pel::tra('Inch');
  258.       case 3:
  259.         return Pel::tra('Centimeter');
  260.       default:
  261.         return $this->value[0];
  262.       }
  263.  
  264.     case PelTag::EXPOSURE_PROGRAM:
  265.       //CC (e->components, 1, v);
  266.       switch ($this->value[0]{
  267.       case 0:
  268.         return Pel::tra('Not defined');
  269.       case 1:
  270.         return Pel::tra('Manual');
  271.       case 2:
  272.         return Pel::tra('Normal program');
  273.       case 3:
  274.         return Pel::tra('Aperture priority');
  275.       case 4:
  276.         return Pel::tra('Shutter priority');
  277.       case 5:
  278.         return Pel::tra('Creative program (biased toward depth of field)');
  279.       case 6:
  280.         return Pel::tra('Action program (biased toward fast shutter speed)');
  281.       case 7:
  282.         return Pel::tra('Portrait mode (for closeup photos with the background out of focus');
  283.       case 8:
  284.         return Pel::tra('Landscape mode (for landscape photos with the background in focus');
  285.       default:
  286.         return $this->value[0];
  287.       }
  288.    
  289.     case PelTag::ORIENTATION:
  290.       //CC (e->components, 1, v);
  291.       switch ($this->value[0]{
  292.       case 1:
  293.         return Pel::tra('top - left');
  294.       case 2:
  295.         return Pel::tra('top - right');
  296.       case 3:
  297.         return Pel::tra('bottom - right');
  298.       case 4:
  299.         return Pel::tra('bottom - left');
  300.       case 5:
  301.         return Pel::tra('left - top');
  302.       case 6:
  303.         return Pel::tra('right - top');
  304.       case 7:
  305.         return Pel::tra('right - bottom');
  306.       case 8:
  307.         return Pel::tra('left - bottom');
  308.       default:
  309.         return $this->value[0];
  310.       }
  311.  
  312.     case PelTag::YCBCR_POSITIONING:
  313.       //CC (e->components, 1, v);
  314.       switch ($this->value[0]{
  315.       case 1:
  316.         return Pel::tra('centered');
  317.       case 2:
  318.         return Pel::tra('co-sited');
  319.       default:
  320.         return $this->value[0];
  321.       }
  322.  
  323.     case PelTag::YCBCR_SUB_SAMPLING:
  324.       //CC (e->components, 2, v);
  325.       if ($this->value[0== && $this->value[1== 1)
  326.         return 'YCbCr4:2:2';
  327.       if ($this->value[0== && $this->value[1== 2)
  328.         return 'YCbCr4:2:0';
  329.       
  330.       return $this->value[0', ' $this->value[1];
  331.    
  332.     case PelTag::PHOTOMETRIC_INTERPRETATION:
  333.       //CC (e->components, 1, v);
  334.       switch ($this->value[0]{
  335.       case 2:
  336.         return 'RGB';
  337.       case 6:
  338.         return 'YCbCr';
  339.       default:
  340.         return $this->value[0];
  341.       }
  342.    
  343.     case PelTag::COLOR_SPACE:
  344.       //CC (e->components, 1, v); 
  345.       switch ($this->value[0]
  346.       case 1:
  347.         return 'sRGB';
  348.       case 2:
  349.         return 'Adobe RGB';
  350.       case 0xffff:
  351.         return Pel::tra('Uncalibrated');
  352.       default:
  353.         return $this->value[0];
  354.       }
  355.  
  356.     case PelTag::FLASH:
  357.       //CC (e->components, 1, v);
  358.       switch ($this->value[0]{
  359.       case 0x0000:
  360.         return Pel::tra('Flash did not fire.');
  361.       case 0x0001:
  362.         return Pel::tra('Flash fired.');
  363.       case 0x0005:
  364.         return Pel::tra('Strobe return light not detected.');
  365.       case 0x0007:
  366.         return Pel::tra('Strobe return light detected.');
  367.       case 0x0009:
  368.         return Pel::tra('Flash fired, compulsory flash mode.');
  369.       case 0x000d:
  370.         return Pel::tra('Flash fired, compulsory flash mode, return light not detected.');
  371.       case 0x000f:
  372.         return Pel::tra('Flash fired, compulsory flash mode, return light detected.');
  373.       case 0x0010:
  374.         return Pel::tra('Flash did not fire, compulsory flash mode.');
  375.       case 0x0018:
  376.         return Pel::tra('Flash did not fire, auto mode.');
  377.       case 0x0019:
  378.         return Pel::tra('Flash fired, auto mode.');
  379.       case 0x001d:
  380.         return Pel::tra('Flash fired, auto mode, return light not detected.');
  381.       case 0x001f:
  382.         return Pel::tra('Flash fired, auto mode, return light detected.');
  383.       case 0x0020:
  384.         return Pel::tra('No flash function.');
  385.       case 0x0041:
  386.         return Pel::tra('Flash fired, red-eye reduction mode.');
  387.       case 0x0045:
  388.         return Pel::tra('Flash fired, red-eye reduction mode, return light not detected.');
  389.       case 0x0047:
  390.         return Pel::tra('Flash fired, red-eye reduction mode, return light detected.');
  391.       case 0x0049:
  392.         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode.');
  393.       case 0x004d:
  394.         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected.');
  395.       case 0x004f:
  396.         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light detected.');
  397.       case 0x0058:
  398.         return Pel::tra('Flash did not fire, auto mode, red-eye reduction mode.');
  399.       case 0x0059:
  400.         return Pel::tra('Flash fired, auto mode, red-eye reduction mode.');
  401.       case 0x005d:
  402.         return Pel::tra('Flash fired, auto mode, return light not detected, red-eye reduction mode.');
  403.       case 0x005f:
  404.         return Pel::tra('Flash fired, auto mode, return light detected, red-eye reduction mode.');
  405.       default:
  406.         return $this->value[0];
  407.       }
  408.  
  409.     case PelTag::CUSTOM_RENDERED:
  410.       //CC (e->components, 1, v);
  411.       switch ($this->value[0]{
  412.       case 0:
  413.         return Pel::tra('Normal process');
  414.       case 1:
  415.         return Pel::tra('Custom process');
  416.       default:
  417.         return $this->value[0];
  418.       }
  419.  
  420.     case PelTag::EXPOSURE_MODE:
  421.       //CC (e->components, 1, v);
  422.       switch ($this->value[0]{
  423.       case 0:
  424.         return Pel::tra('Auto exposure');
  425.       case 1:
  426.         return Pel::tra('Manual exposure');
  427.       case 2:
  428.         return Pel::tra('Auto bracket');
  429.       default:
  430.         return $this->value[0];
  431.       }
  432.    
  433.     case PelTag::WHITE_BALANCE:
  434.       //CC (e->components, 1, v);
  435.       switch ($this->value[0]{
  436.       case 0:
  437.         return Pel::tra('Auto white balance');
  438.       case 1:
  439.         return Pel::tra('Manual white balance');
  440.       default:
  441.         return $this->value[0];
  442.       }
  443.  
  444.     case PelTag::SCENE_CAPTURE_TYPE:
  445.       //CC (e->components, 1, v);
  446.       switch ($this->value[0]{
  447.       case 0:
  448.         return Pel::tra('Standard');
  449.       case 1:
  450.         return Pel::tra('Landscape');
  451.       case 2:
  452.         return Pel::tra('Portrait');
  453.       case 3:
  454.         return Pel::tra('Night scene');
  455.       default:
  456.         return $this->value[0];
  457.       }
  458.  
  459.     case PelTag::GAIN_CONTROL:
  460.       //CC (e->components, 1, v);
  461.       switch ($this->value[0]{
  462.       case 0:
  463.         return Pel::tra('Normal');
  464.       case 1:
  465.         return Pel::tra('Low gain up');
  466.       case 2:
  467.         return Pel::tra('High gain up');
  468.       case 3:
  469.         return Pel::tra('Low gain down');
  470.       case 4:
  471.         return Pel::tra('High gain down');
  472.       default:
  473.         return $this->value[0];
  474.       }
  475.  
  476.     case PelTag::SATURATION:
  477.       //CC (e->components, 1, v);
  478.       switch ($this->value[0]{
  479.       case 0:
  480.         return Pel::tra('Normal');
  481.       case 1:
  482.         return Pel::tra('Low saturation');
  483.       case 2:
  484.         return Pel::tra('High saturation');
  485.       default:
  486.         return $this->value[0];
  487.       }
  488.  
  489.     case PelTag::CONTRAST:
  490.     case PelTag::SHARPNESS:
  491.       //CC (e->components, 1, v);
  492.       switch ($this->value[0]{
  493.       case 0:
  494.         return Pel::tra('Normal');
  495.       case 1:
  496.         return Pel::tra('Soft');
  497.       case 2:
  498.         return Pel::tra('Hard');
  499.       default:
  500.         return $this->value[0];
  501.       }
  502.  
  503.     case PelTag::SUBJECT_DISTANCE_RANGE:
  504.       //CC (e->components, 1, v);
  505.       switch ($this->value[0]{
  506.       case 0:
  507.         return Pel::tra('Unknown');
  508.       case 1:
  509.         return Pel::tra('Macro');
  510.       case 2:
  511.         return Pel::tra('Close view');
  512.       case 3:
  513.         return Pel::tra('Distant view');
  514.       default:
  515.         return $this->value[0];
  516.       }
  517.  
  518.     case PelTag::SUBJECT_AREA:
  519.       switch ($this->components{
  520.       case 2:
  521.         return Pel::fmt('(x,y) = (%d,%d)'$this->value[0]$this->value[1]);
  522.       case 3:
  523.         return Pel::fmt('Within distance %d of (x,y) = (%d,%d)',
  524.                         $this->value[0]$this->value[1]$this->value[2]);
  525.       case 4:
  526.         return Pel::fmt('Within rectangle (width %d, height %d) around (x,y) = (%d,%d)',
  527.                         $this->value[0]$this->value[1],
  528.                         $this->value[2]$this->value[3]);
  529.         
  530.       default:
  531.         return Pel::fmt('Unexpected number of components (%d, expected 2, 3, or 4).'$this->components);
  532.       }
  533.  
  534.     default:
  535.       return parent::getText($brief);
  536.     }
  537.   }
  538. }
  539.  
  540.  
  541. /**
  542.  * Class for holding signed shorts.
  543.  *
  544.  * This class can hold shorts, either just a single short or an array
  545.  * of shorts.  The class will be used to manipulate any of the Exif
  546.  * tags which has format {@link PelFormat::SSHORT}.
  547.  *
  548.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  549.  * @package PEL
  550.  */
  551. class PelEntrySShort extends PelEntryNumber {
  552.  
  553.   /**
  554.    * Make a new entry that can hold a signed short.
  555.    *
  556.    * The method accept several integer arguments.  The {@link }
  557.    * getValue} method will always return an array except for when a
  558.    * single integer argument is given here.
  559.    *
  560.    * @param PelTag the tag which this entry represents.  This
  561.    *  should be one of the constants defined in {@link PelTag}
  562.    *  which has format {@link PelFormat::SSHORT}.
  563.    *
  564.    * @param int $value... the signed short(s) that this entry will
  565.    *  represent.  The argument passed must obey the same rules as the
  566.    *  argument to {@link setValue}, namely that it should be within
  567.    *  range of a signed short, that is between -32768 to 32767
  568.    *  (inclusive).  If not, then a {@link PelOverFlowException} will be
  569.    *  thrown.
  570.    */
  571.   function __construct($tag /* $value... */{
  572.     $this->tag    = $tag;
  573.     $this->min    = -32768;
  574.     $this->max    = 32767;
  575.     $this->format = PelFormat::SSHORT;
  576.  
  577.     $value func_get_args();
  578.     array_shift($value);
  579.     $this->setValueArray($value);
  580.   }
  581.  
  582.  
  583.   /**
  584.    * Convert a number into bytes.
  585.    *
  586.    * @param int the number that should be converted.
  587.    *
  588.    * @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
  589.    *  {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
  590.    *
  591.    * @return string bytes representing the number given.
  592.    */
  593.   function numberToBytes($number$order{
  594.     return PelConvert::sShortToBytes($number$order);
  595.   }
  596. }
  597.  
  598.  
  599. ?>

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