Source for file PelJpegMarker.php

Documentation is available at PelJpegMarker.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 for dealing with JPEG markers.
  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('Pel.php');
  40. /**#@-*/
  41.  
  42.  
  43. /**
  44.  * Class with static methods for JPEG markers.
  45.  *
  46.  * This class defines the constants to be used whenever one refers to
  47.  * a JPEG marker.  All the methods defined are static, and they all
  48.  * operate on one argument which should be one of the class constants.
  49.  * They will all be denoted by PelJpegMarker in the documentation.
  50.  *
  51.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  52.  * @package PEL
  53.  */
  54. class PelJpegMarker {
  55.  
  56.   /** Encoding (baseline) */
  57.   const SOF0  0xC0;
  58.   /** Encoding (extended sequential) */
  59.   const SOF1  0xC1;
  60.   /** Encoding (progressive) */
  61.   const SOF2  0xC2;
  62.   /** Encoding (lossless) */
  63.   const SOF3  0xC3;
  64.   /** Define Huffman table */
  65.   const DHT   0xC4;
  66.   /** Encoding (differential sequential) */
  67.   const SOF5  0xC5;
  68.   /** Encoding (differential progressive) */
  69.   const SOF6  0xC6;
  70.   /** Encoding (differential lossless) */
  71.   const SOF7  0xC7;
  72.   /** Extension */
  73.   const JPG   0xC8;
  74.   /** Encoding (extended sequential, arithmetic) */
  75.   const SOF9  0xC9;
  76.   /** Encoding (progressive, arithmetic) */
  77.   const SOF10 0xCA;
  78.   /** Encoding (lossless, arithmetic) */
  79.   const SOF11 0xCB;
  80.   /** Define arithmetic coding conditioning */
  81.   const DAC   0xCC;
  82.   /** Encoding (differential sequential, arithmetic) */
  83.   const SOF13 0xCD;
  84.   /** Encoding (differential progressive, arithmetic) */
  85.   const SOF14 0xCE;
  86.   /** Encoding (differential lossless, arithmetic) */
  87.   const SOF15 0xCF;
  88.   /** Restart 0 */
  89.   const RST0  0xD0;
  90.   /** Restart 1 */
  91.   const RST1  0xD1;
  92.   /** Restart 2 */
  93.   const RST2  0xD2;
  94.   /** Restart 3 */
  95.   const RST3  0xD3;
  96.   /** Restart 4 */
  97.   const RST4  0xD4;
  98.   /** Restart 5 */
  99.   const RST5  0xD5;
  100.   /** Restart 6 */
  101.   const RST6  0xD6;
  102.   /** Restart 7 */
  103.   const RST7  0xD7;
  104.   /** Start of image */
  105.   const SOI   0xD8;
  106.   /** End of image */
  107.   const EOI   0xD9;
  108.   /** Start of scan */
  109.   const SOS   0xDA;
  110.   /** Define quantization table */
  111.   const DQT   0xDB;
  112.   /** Define number of lines */
  113.   const DNL   0xDC;
  114.   /** Define restart interval */
  115.   const DRI   0xDD;
  116.   /** Define hierarchical progression */
  117.   const DHP   0xDE;
  118.   /** Expand reference component */
  119.   const EXP   0xDF;
  120.   /** Application segment 0 */
  121.   const APP0  0xE0;
  122.   /**
  123.    * Application segment 1
  124.    *
  125.    * When a JPEG image contains Exif data, the data will normally be
  126.    * stored in this section and a call to {@link PelJpeg::getExif()}
  127.    * will return a {@link PelExif} object representing it.
  128.    */
  129.   const APP1  0xE1;
  130.   /** Application segment 2 */
  131.   const APP2  0xE2;
  132.   /** Application segment 3 */
  133.   const APP3  0xE3;
  134.   /** Application segment 4 */
  135.   const APP4  0xE4;
  136.   /** Application segment 5 */
  137.   const APP5  0xE5;
  138.   /** Application segment 6 */
  139.   const APP6  0xE6;
  140.   /** Application segment 7 */
  141.   const APP7  0xE7;
  142.   /** Application segment 8 */
  143.   const APP8  0xE8;
  144.   /** Application segment 9 */
  145.   const APP9  0xE9;
  146.   /** Application segment 10 */
  147.   const APP10 0xEA;
  148.   /** Application segment 11 */
  149.   const APP11 0xEB;
  150.   /** Application segment 12 */
  151.   const APP12 0xEC;
  152.   /** Application segment 13 */
  153.   const APP13 0xED;
  154.   /** Application segment 14 */
  155.   const APP14 0xEE;
  156.   /** Application segment 15 */
  157.   const APP15 0xEF;
  158.   /** Extension 0 */
  159.   const JPG0  0xF0;
  160.   /** Extension 1 */
  161.   const JPG1  0xF1;
  162.   /** Extension 2 */
  163.   const JPG2  0xF2;
  164.   /** Extension 3 */
  165.   const JPG3  0xF3;
  166.   /** Extension 4 */
  167.   const JPG4  0xF4;
  168.   /** Extension 5 */
  169.   const JPG5  0xF5;
  170.   /** Extension 6 */
  171.   const JPG6  0xF6;
  172.   /** Extension 7 */
  173.   const JPG7  0xF7;
  174.   /** Extension 8 */
  175.   const JPG8  0xF8;
  176.   /** Extension 9 */
  177.   const JPG9  0xF9;
  178.   /** Extension 10 */
  179.   const JPG10 0xFA;
  180.   /** Extension 11 */
  181.   const JPG11 0xFB;
  182.   /** Extension 12 */
  183.   const JPG12 0xFC;
  184.   /** Extension 13 */
  185.   const JPG13 0xFD;
  186.   /** Comment */
  187.   const COM   0xFE;
  188.  
  189.   /**
  190.    * Check if a byte is a valid JPEG marker.
  191.    *
  192.    * @param PelJpegMarker the byte that will be checked.
  193.    *
  194.    * @return boolean if the byte is recognized true is returned,
  195.    *  otherwise false will be returned.
  196.    */
  197.   static function isValid($m{
  198.     return ($m >= self::SOF0 && $m <= self::COM);
  199.   }
  200.   
  201.   /**
  202.    * Turn a JPEG marker into bytes.
  203.    *
  204.    * @param PelJpegMarker the marker.
  205.    *
  206.    * @return string the marker as a string.  This will be a string
  207.    *  with just a single byte since all JPEG markers are simply single
  208.    *  bytes.
  209.    */
  210.   static function getBytes($m{
  211.     return chr($m);
  212.   }
  213.  
  214.   /**
  215.    * Return the short name for a marker.
  216.    *
  217.    * @param PelJpegMarker the marker.
  218.    *
  219.    * @return string the name of the marker, e.g., 'SOI' for the Start
  220.    *  of Image marker.
  221.    */
  222.   static function getName($m{
  223.     switch ($m{
  224.     case self::SOF0:  return 'SOF0';
  225.     case self::SOF1:  return 'SOF1';
  226.     case self::SOF2:  return 'SOF2';
  227.     case self::SOF3:  return 'SOF3';
  228.     case self::SOF5:  return 'SOF5';
  229.     case self::SOF6:  return 'SOF6';
  230.     case self::SOF7:  return 'SOF7';
  231.     case self::SOF9:  return 'SOF9';
  232.     case self::SOF10return 'SOF10';
  233.     case self::SOF11return 'SOF11';
  234.     case self::SOF13return 'SOF13';
  235.     case self::SOF14return 'SOF14';
  236.     case self::SOF15return 'SOF15';
  237.     case self::SOI:   return 'SOI';
  238.     case self::EOI:   return 'EOI';
  239.     case self::SOS:   return 'SOS';
  240.     case self::COM:   return 'COM';
  241.     case self::DHT:   return 'DHT';
  242.     case self::JPG:   return 'JPG';
  243.     case self::DAC:   return 'DAC';
  244.     case self::RST0:  return 'RST0';
  245.     case self::RST1:  return 'RST1';
  246.     case self::RST2:  return 'RST2';
  247.     case self::RST3:  return 'RST3';
  248.     case self::RST4:  return 'RST4';
  249.     case self::RST5:  return 'RST5';
  250.     case self::RST6:  return 'RST6';
  251.     case self::RST7:  return 'RST7';
  252.     case self::DQT:   return 'DQT';
  253.     case self::DNL:   return 'DNL';
  254.     case self::DRI:   return 'DRI';
  255.     case self::DHP:   return 'DHP';
  256.     case self::EXP:   return 'EXP';
  257.     case self::APP0:  return 'APP0';
  258.     case self::APP1:  return 'APP1';
  259.     case self::APP2:  return 'APP2';
  260.     case self::APP3:  return 'APP3';
  261.     case self::APP4:  return 'APP4';
  262.     case self::APP5:  return 'APP5';
  263.     case self::APP6:  return 'APP6';
  264.     case self::APP7:  return 'APP7';
  265.     case self::APP8:  return 'APP8';
  266.     case self::APP9:  return 'APP9';
  267.     case self::APP10return 'APP10';
  268.     case self::APP11return 'APP11';
  269.     case self::APP12return 'APP12';
  270.     case self::APP13return 'APP13';
  271.     case self::APP14return 'APP14';
  272.     case self::APP15return 'APP15';
  273.     case self::JPG0:  return 'JPG0';
  274.     case self::JPG1:  return 'JPG1';
  275.     case self::JPG2:  return 'JPG2';
  276.     case self::JPG3:  return 'JPG3';
  277.     case self::JPG4:  return 'JPG4';
  278.     case self::JPG5:  return 'JPG5';
  279.     case self::JPG6:  return 'JPG6';
  280.     case self::JPG7:  return 'JPG7';
  281.     case self::JPG8:  return 'JPG8';
  282.     case self::JPG9:  return 'JPG9';
  283.     case self::JPG10return 'JPG10';
  284.     case self::JPG11return 'JPG11';
  285.     case self::JPG12return 'JPG12';
  286.     case self::JPG13return 'JPG13';
  287.     case self::COM:   return 'COM';
  288.     default:          return Pel::fmt('Unknown marker: 0x%02X'$m);
  289.     }
  290.   }
  291.  
  292.   /**
  293.    * Returns a description of a JPEG marker.
  294.    *
  295.    * @param PelJpegMarker the marker.
  296.    *
  297.    * @return string the description of the marker.
  298.    */
  299.   static function getDescription($m{
  300.     switch ($m{
  301.     case self::SOF0:
  302.       return Pel::tra('Encoding (baseline)');
  303.     case self::SOF1:
  304.       return Pel::tra('Encoding (extended sequential)');
  305.     case self::SOF2:
  306.       return Pel::tra('Encoding (progressive)');
  307.     case self::SOF3:
  308.       return Pel::tra('Encoding (lossless)');
  309.     case self::SOF5:
  310.       return Pel::tra('Encoding (differential sequential)');
  311.     case self::SOF6:
  312.       return Pel::tra('Encoding (differential progressive)');
  313.     case self::SOF7:
  314.       return Pel::tra('Encoding (differential lossless)');
  315.     case self::SOF9:
  316.       return Pel::tra('Encoding (extended sequential, arithmetic)');
  317.     case self::SOF10:
  318.       return Pel::tra('Encoding (progressive, arithmetic)');
  319.     case self::SOF11:
  320.       return Pel::tra('Encoding (lossless, arithmetic)');
  321.     case self::SOF13:
  322.       return Pel::tra('Encoding (differential sequential, arithmetic)');
  323.     case self::SOF14:
  324.       return Pel::tra('Encoding (differential progressive, arithmetic)');
  325.     case self::SOF15:
  326.       return Pel::tra('Encoding (differential lossless, arithmetic)');
  327.     case self::SOI:
  328.       return Pel::tra('Start of image');
  329.     case self::EOI:
  330.       return Pel::tra('End of image');
  331.     case self::SOS:
  332.       return Pel::tra('Start of scan');
  333.     case self::COM:
  334.       return Pel::tra('Comment');
  335.     case self::DHT:
  336.       return Pel::tra('Define Huffman table');
  337.     case self::JPG:
  338.       return Pel::tra('Extension');
  339.     case self::DAC:
  340.       return Pel::tra('Define arithmetic coding conditioning');
  341.     case self::RST0:
  342.       return Pel::fmt('Restart %d'0);
  343.     case self::RST1:
  344.       return Pel::fmt('Restart %d'1);
  345.     case self::RST2:
  346.       return Pel::fmt('Restart %d'2);
  347.     case self::RST3:
  348.       return Pel::fmt('Restart %d'3);
  349.     case self::RST4:
  350.       return Pel::fmt('Restart %d'4);
  351.     case self::RST5:
  352.       return Pel::fmt('Restart %d'5);
  353.     case self::RST6:
  354.       return Pel::fmt('Restart %d'6);
  355.     case self::RST7:
  356.       return Pel::fmt('Restart %d'7);
  357.     case self::DQT:
  358.       return Pel::tra('Define quantization table');
  359.     case self::DNL:
  360.       return Pel::tra('Define number of lines');
  361.     case self::DRI:
  362.       return Pel::tra('Define restart interval');
  363.     case self::DHP:
  364.       return Pel::tra('Define hierarchical progression');
  365.     case self::EXP:
  366.       return Pel::tra('Expand reference component');
  367.     case self::APP0:
  368.       return Pel::fmt('Application segment %d'0);
  369.     case self::APP1:
  370.       return Pel::fmt('Application segment %d'1);
  371.     case self::APP2:
  372.       return Pel::fmt('Application segment %d'2);
  373.     case self::APP3:
  374.       return Pel::fmt('Application segment %d'3);
  375.     case self::APP4:
  376.       return Pel::fmt('Application segment %d'4);
  377.     case self::APP5:
  378.       return Pel::fmt('Application segment %d'5);
  379.     case self::APP6:
  380.       return Pel::fmt('Application segment %d'6);
  381.     case self::APP7:
  382.       return Pel::fmt('Application segment %d'7);
  383.     case self::APP8:
  384.       return Pel::fmt('Application segment %d'8);
  385.     case self::APP9:
  386.       return Pel::fmt('Application segment %d'9);
  387.     case self::APP10:
  388.       return Pel::fmt('Application segment %d'10);
  389.     case self::APP11:
  390.       return Pel::fmt('Application segment %d'11);
  391.     case self::APP12:
  392.       return Pel::fmt('Application segment %d'12);
  393.     case self::APP13:
  394.       return Pel::fmt('Application segment %d'13);
  395.     case self::APP14:
  396.       return Pel::fmt('Application segment %d'14);
  397.     case self::APP15:
  398.       return Pel::fmt('Application segment %d'15);
  399.     case self::JPG0:
  400.       return Pel::fmt('Extension %d'0);
  401.     case self::JPG1:
  402.       return Pel::fmt('Extension %d'1);
  403.     case self::JPG2:
  404.       return Pel::fmt('Extension %d'2);
  405.     case self::JPG3:
  406.       return Pel::fmt('Extension %d'3);
  407.     case self::JPG4:
  408.       return Pel::fmt('Extension %d'4);
  409.     case self::JPG5:
  410.       return Pel::fmt('Extension %d'5);
  411.     case self::JPG6:
  412.       return Pel::fmt('Extension %d'6);
  413.     case self::JPG7:
  414.       return Pel::fmt('Extension %d'7);
  415.     case self::JPG8:
  416.       return Pel::fmt('Extension %d'8);
  417.     case self::JPG9:
  418.       return Pel::fmt('Extension %d'9);
  419.     case self::JPG10:
  420.       return Pel::fmt('Extension %d'10);
  421.     case self::JPG11:
  422.       return Pel::fmt('Extension %d'11);
  423.     case self::JPG12:
  424.       return Pel::fmt('Extension %d'12);
  425.     case self::JPG13:
  426.       return Pel::fmt('Extension %d'13);
  427.     case self::COM:
  428.       return Pel::tra('Comment');
  429.     default:
  430.       return Pel::fmt('Unknown marker: 0x%02X'$m);
  431.     }
  432.   }
  433. }
  434.  
  435. ?>

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