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

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