From 4135abea31a926b5cbfceeb43b7e79ff8846d329 Mon Sep 17 00:00:00 2001 From: svollbehr Date: Thu, 26 Jan 2012 05:29:00 +0000 Subject: [PATCH] Add support for basic RIFF format git-svn-id: http://php-reader.googlecode.com/svn/trunk@256 51a70ab9-7547-0410-9469-37e369ee0574 --- src/Zend/Media/Riff.php | 75 +++++++++++ src/Zend/Media/Riff/Chunk.php | 125 ++++++++++++++++++ src/Zend/Media/Riff/Chunk/Cgrp.php | 47 +++++++ src/Zend/Media/Riff/Chunk/Cset.php | 172 +++++++++++++++++++++++++ src/Zend/Media/Riff/Chunk/Ctoc.php | 47 +++++++ src/Zend/Media/Riff/Chunk/Iarl.php | 28 ++++ src/Zend/Media/Riff/Chunk/Iart.php | 28 ++++ src/Zend/Media/Riff/Chunk/Icms.php | 28 ++++ src/Zend/Media/Riff/Chunk/Icmt.php | 29 +++++ src/Zend/Media/Riff/Chunk/Icop.php | 29 +++++ src/Zend/Media/Riff/Chunk/Icrd.php | 29 +++++ src/Zend/Media/Riff/Chunk/Icrp.php | 28 ++++ src/Zend/Media/Riff/Chunk/Idim.php | 28 ++++ src/Zend/Media/Riff/Chunk/Idpi.php | 28 ++++ src/Zend/Media/Riff/Chunk/Ieng.php | 29 +++++ src/Zend/Media/Riff/Chunk/Ignr.php | 28 ++++ src/Zend/Media/Riff/Chunk/Ikey.php | 29 +++++ src/Zend/Media/Riff/Chunk/Ilgt.php | 29 +++++ src/Zend/Media/Riff/Chunk/Imed.php | 28 ++++ src/Zend/Media/Riff/Chunk/Inam.php | 28 ++++ src/Zend/Media/Riff/Chunk/Iplt.php | 28 ++++ src/Zend/Media/Riff/Chunk/Iprd.php | 28 ++++ src/Zend/Media/Riff/Chunk/Isbj.php | 28 ++++ src/Zend/Media/Riff/Chunk/Isft.php | 28 ++++ src/Zend/Media/Riff/Chunk/Ishp.php | 29 +++++ src/Zend/Media/Riff/Chunk/Isrc.php | 28 ++++ src/Zend/Media/Riff/Chunk/Isrf.php | 29 +++++ src/Zend/Media/Riff/Chunk/Itch.php | 28 ++++ src/Zend/Media/Riff/Chunk/Junk.php | 29 +++++ src/Zend/Media/Riff/Chunk/List.php | 28 ++++ src/Zend/Media/Riff/ContainerChunk.php | 142 ++++++++++++++++++++ src/Zend/Media/Riff/Exception.php | 28 ++++ src/Zend/Media/Riff/StringChunk.php | 67 ++++++++++ 33 files changed, 1412 insertions(+) create mode 100644 src/Zend/Media/Riff.php create mode 100644 src/Zend/Media/Riff/Chunk.php create mode 100644 src/Zend/Media/Riff/Chunk/Cgrp.php create mode 100644 src/Zend/Media/Riff/Chunk/Cset.php create mode 100644 src/Zend/Media/Riff/Chunk/Ctoc.php create mode 100644 src/Zend/Media/Riff/Chunk/Iarl.php create mode 100644 src/Zend/Media/Riff/Chunk/Iart.php create mode 100644 src/Zend/Media/Riff/Chunk/Icms.php create mode 100644 src/Zend/Media/Riff/Chunk/Icmt.php create mode 100644 src/Zend/Media/Riff/Chunk/Icop.php create mode 100644 src/Zend/Media/Riff/Chunk/Icrd.php create mode 100644 src/Zend/Media/Riff/Chunk/Icrp.php create mode 100644 src/Zend/Media/Riff/Chunk/Idim.php create mode 100644 src/Zend/Media/Riff/Chunk/Idpi.php create mode 100644 src/Zend/Media/Riff/Chunk/Ieng.php create mode 100644 src/Zend/Media/Riff/Chunk/Ignr.php create mode 100644 src/Zend/Media/Riff/Chunk/Ikey.php create mode 100644 src/Zend/Media/Riff/Chunk/Ilgt.php create mode 100644 src/Zend/Media/Riff/Chunk/Imed.php create mode 100644 src/Zend/Media/Riff/Chunk/Inam.php create mode 100644 src/Zend/Media/Riff/Chunk/Iplt.php create mode 100644 src/Zend/Media/Riff/Chunk/Iprd.php create mode 100644 src/Zend/Media/Riff/Chunk/Isbj.php create mode 100644 src/Zend/Media/Riff/Chunk/Isft.php create mode 100644 src/Zend/Media/Riff/Chunk/Ishp.php create mode 100644 src/Zend/Media/Riff/Chunk/Isrc.php create mode 100644 src/Zend/Media/Riff/Chunk/Isrf.php create mode 100644 src/Zend/Media/Riff/Chunk/Itch.php create mode 100644 src/Zend/Media/Riff/Chunk/Junk.php create mode 100644 src/Zend/Media/Riff/Chunk/List.php create mode 100644 src/Zend/Media/Riff/ContainerChunk.php create mode 100644 src/Zend/Media/Riff/Exception.php create mode 100644 src/Zend/Media/Riff/StringChunk.php diff --git a/src/Zend/Media/Riff.php b/src/Zend/Media/Riff.php new file mode 100644 index 0000000..e241aa2 --- /dev/null +++ b/src/Zend/Media/Riff.php @@ -0,0 +1,75 @@ + + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff extends Zend_Media_Riff_ContainerChunk +{ + /** @var string */ + private $_filename = null; + + /** + * Constructs the class with given file. + * + * @param string|resource|Zend_Io_Reader $filename The path to the file, file descriptor of an opened file, or a + * {@link Zend_Io_Reader} instance. + * @throws Zend_Media_Riff_Exception if given file descriptor is not valid or an error occurs in stream handling. + */ + public function __construct($filename) + { + if ($filename instanceof Zend_Io_Reader) { + $reader = &$filename; + } else { + $this->_filename = $filename; + require_once('Zend/Io/FileReader.php'); + try { + $reader = new Zend_Io_FileReader($filename); + } catch (Zend_Io_Exception $e) { + require_once 'Zend/Media/Riff/Exception.php'; + throw new Zend_Media_Riff_Exception($e->getMessage()); + } + } + + parent::__construct($reader); + } +} diff --git a/src/Zend/Media/Riff/Chunk.php b/src/Zend/Media/Riff/Chunk.php new file mode 100644 index 0000000..00c018f --- /dev/null +++ b/src/Zend/Media/Riff/Chunk.php @@ -0,0 +1,125 @@ + + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Box.php 177 2010-03-09 13:13:34Z svollbehr $ + */ +abstract class Zend_Media_Riff_Chunk +{ + /** + * The reader object. + * + * @var Reader + */ + protected $_reader; + + /** @var integer */ + protected $_identifier; + + /** @var integer */ + protected $_size; + + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + $this->_reader = $reader; + $this->_identifier = $this->_reader->read(4); + $this->_size = $this->_reader->readUInt32LE(); + } + + /** + * Returns a four-character code that identifies the representation of the chunk data. A program reading a RIFF file + * can skip over any chunk whose chunk ID it doesn't recognize; it simply skips the number of bytes specified by + * size plus the pad byte, if present. + * + * @return string + */ + public final function getIdentifier() + { + return $this->_identifier; + } + + /** + * Sets the four-character code that identifies the representation of the chunk data. + * + * @param string $identifier The chunk identifier. + */ + public final function setIdentifier($identifier) + { + $this->_identifier = $identifier; + } + + /** + * Returns the size of chunk data. This size value does not include the size of the identifier or size fields or the + * pad byte at the end of chunk data. + * + * @return integer + */ + public final function getSize() + { + return $this->_size; + } + + /** + * Sets the size of chunk data. This size value must not include the size of the identifier or size fields or the + * pad byte at the end of chunk data. + * + * @param integer $size The size of chunk data. + */ + public final function setSize($size) + { + $this->_size = $size; + } + + /** + * Magic function so that $obj->value will work. + * + * @param string $name The field name. + * @return mixed + */ + public function __get($name) + { + if (method_exists($this, 'get' . ucfirst(strtolower($name)))) { + return call_user_func(array($this, 'get' . ucfirst(strtolower($name)))); + } else { + require_once('Zend/Media/Riff/Exception.php'); + throw new Zend_Media_Riff_Exception('Unknown field: ' . $name); + } + } + + /** + * Magic function so that assignments with $obj->value will work. + * + * @param string $name The field name. + * @param string $value The field value. + * @return mixed + */ + public function __set($name, $value) + { + if (method_exists($this, 'set' . ucfirst(strtolower($name)))) { + call_user_func(array($this, 'set' . ucfirst(strtolower($name))), $value); + } else { + require_once('Zend/Media/Riff/Exception.php'); + throw new Zend_Media_Riff_Exception('Unknown field: ' . $name); + } + } +} diff --git a/src/Zend/Media/Riff/Chunk/Cgrp.php b/src/Zend/Media/Riff/Chunk/Cgrp.php new file mode 100644 index 0000000..0a2faaf --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Cgrp.php @@ -0,0 +1,47 @@ +Compound File Element Group chunk stores the actual elements of data referenced by the + * {@link Zend_Media_Riff_Chunk_Ctoc CTOC} chunk. The CGRP chunk contains all the compound file elements, concatenated + * together into one contiguous block of data. Some of the elements in the CGRP chunk might be unused, if the element + * was marked for deletion or was altered and stored elsewhere within the CGRP chunk. + * + * Elements within the CGRP chunk are of arbitrary size and can appear in a specific or arbitrary order, depending upon + * the file format definition. Each element is identified by a corresponding {@link Zend_Media_Riff_Chunk_Ctoc CTOC} + * table entry. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @todo Implementation + */ +final class Zend_Media_Riff_Chunk_Cgrp extends Zend_Media_Riff_Chunk +{ + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + require_once('Zend/Media/Riff/Exception.php'); + throw new Zend_Media_Riff_Exception('Not yet implemented'); + } +} diff --git a/src/Zend/Media/Riff/Chunk/Cset.php b/src/Zend/Media/Riff/Chunk/Cset.php new file mode 100644 index 0000000..e611b36 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Cset.php @@ -0,0 +1,172 @@ +Character Set chunk defines the code page and country, language, and dialect codes for the file. These + * values can be overridden for specific file elements. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Cset extends Zend_Media_Riff_Chunk +{ + /** @var integer */ + private $_codePage; + + /** @var integer */ + private $_countryCode; + + /** @var integer */ + private $_language; + + /** @var integer */ + private $_dialect; + + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->_codePage = $this->_reader->readUInt16LE(); + $this->_countryCode = $this->_reader->readUInt16LE(); + $this->_language = $this->_reader->readUInt16LE(); + $this->_dialect = $this->_reader->readUInt16LE(); + } + + /** + * Returns the code page used for file elements. If the CSET chunk is not present, or if this field has value zero, + * assume standard ISO-8859-1 code page (identical to code page 1004 without code points defined in hex columns 0, + * 1, 8, and 9). + * + * @return integer + */ + public final function getCodePage() + { + return $this->_codePage; + } + + /** + * Sets the code page used for file elements. Value can be one of the following. + * o 000 None (ignore this field) + * o 001 USA + * o 002 Canada + * o 003 Latin America + * o 030 Greece + * o 031 Netherlands + * o 032 Belgium + * o 033 France + * o 034 Spain + * o 039 Italy + * o 041 Switzerland + * o 043 Austria + * o 044 United Kingdom + * o 045 Denmark + * o 046 Sweden + * o 047 Norway + * o 049 West Germany + * o 052 Mexico + * o 055 Brazil + * o 061 Australia + * o 064 New Zealand + * o 081 Japan + * o 082 Korea + * o 086 People’s Republic of China + * o 088 Taiwan + * o 090 Turkey + * o 351 Portugal + * o 352 Luxembourg + * o 354 Iceland + * o 358 Finland + * + * @param string $type The code page used for file elements. + */ + public final function setCodePage($codePage) + { + $this->_codePage = $codePage; + } + + /** + * Returns the country code used for file elements. See the file format specification for a list of currently + * defined country codes. If the CSET chunk is not present, or if this field has value zero, assume USA (country + * code 001). + * + * @return integer + */ + public final function getCountryCode() + { + return $this->_countryCode; + } + + /** + * Sets the country code used for file elements. + * + * @param string $type The country code used for file elements. + */ + public final function setCountryCode($countryCode) + { + $this->_countryCode = $countryCode; + } + + /** + * Returns the language used for file elements. See the file format specification for a list of language codes. + * If the CSET chunk is not present, or if these fields have value zero, assume US English (language code 9, + * dialect code 1). + * + * @return integer + */ + public final function getLanguage() + { + return $this->_language; + } + + /** + * Sets the language used for file elements. + * + * @param string $type The language used for file elements. + */ + public final function setLanguage($language) + { + $this->_language = $language; + } + + /** + * Returns the dialect used for file elements. See the file format specification for a list of dialect codes. + * If the CSET chunk is not present, or if these fields have value zero, assume US English (language code 9, + * dialect code 1). + * + * @return integer + */ + public final function getDialect() + { + return $this->_dialect; + } + + /** + * Sets the dialect used for file elements. + * + * @param string $type The dialect used for file elements. + */ + public final function setDialect($dialect) + { + $this->_dialect = $dialect; + } +} diff --git a/src/Zend/Media/Riff/Chunk/Ctoc.php b/src/Zend/Media/Riff/Chunk/Ctoc.php new file mode 100644 index 0000000..1fd138b --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ctoc.php @@ -0,0 +1,47 @@ +Compound File Table of Contents chunk functions mainly as an index, allowing direct access to elements + * within a compound file. The CTOC chunk also contains information about the attributes of the entire file and of each + * media element within the file. + * + * To provide the maximum flexibility for defining compound file formats, the CTOC chunk can be customized at several + * levels. The CTOC chunk contains fields whose length and usage is defined by other CTOC fields. This parameterization + * adds complexity, but it provides flexibility to file format designers and allows applications to correctly read data + * without necessarily knowing the specific file format definition. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @todo Implementation + */ +final class Zend_Media_Riff_Chunk_Ctoc extends Zend_Media_Riff_Chunk +{ + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + require_once('Zend/Media/Riff/Exception.php'); + throw new Zend_Media_Riff_Exception('Not yet implemented'); + } +} diff --git a/src/Zend/Media/Riff/Chunk/Iarl.php b/src/Zend/Media/Riff/Chunk/Iarl.php new file mode 100644 index 0000000..85e849e --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Iarl.php @@ -0,0 +1,28 @@ +Archival Location chunk indicates where the subject of the file is archived. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Iarl extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Iart.php b/src/Zend/Media/Riff/Chunk/Iart.php new file mode 100644 index 0000000..0fbffc3 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Iart.php @@ -0,0 +1,28 @@ +Artist chunk lists the artist of the original subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Iart extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Icms.php b/src/Zend/Media/Riff/Chunk/Icms.php new file mode 100644 index 0000000..0239203 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Icms.php @@ -0,0 +1,28 @@ +Commissioned chunk lists the name of the person or organization that commissioned the subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Icms extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Icmt.php b/src/Zend/Media/Riff/Chunk/Icmt.php new file mode 100644 index 0000000..896750b --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Icmt.php @@ -0,0 +1,29 @@ +Comments chunk provides general comments about the file or the subject of the file. If the comment is + * several sentences long, end each sentence with a period. Do not include newline characters. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Icmt extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Icop.php b/src/Zend/Media/Riff/Chunk/Icop.php new file mode 100644 index 0000000..353778a --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Icop.php @@ -0,0 +1,29 @@ +Copyright chunk records the copyright information for the file. If there are multiple copyrights, separate + * them by a semicolon followed by a space. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Icop extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Icrd.php b/src/Zend/Media/Riff/Chunk/Icrd.php new file mode 100644 index 0000000..6a22867 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Icrd.php @@ -0,0 +1,29 @@ +Creation date chunk specifies the date the subject of the file was created. List dates in year-month-day + * format, padding one-digit months and days with a zero on the left. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Icrd extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Icrp.php b/src/Zend/Media/Riff/Chunk/Icrp.php new file mode 100644 index 0000000..e06fffb --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Icrp.php @@ -0,0 +1,28 @@ +Cropped chunk describes whether an image has been cropped and, if so, how it was cropped. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Icrp extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Idim.php b/src/Zend/Media/Riff/Chunk/Idim.php new file mode 100644 index 0000000..d18e419 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Idim.php @@ -0,0 +1,28 @@ +Dimensions chunk specifies the size of the original subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Idim extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Idpi.php b/src/Zend/Media/Riff/Chunk/Idpi.php new file mode 100644 index 0000000..fb114ed --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Idpi.php @@ -0,0 +1,28 @@ +Dots Per Inch chunk stores dots per inch setting of the digitizer used to produce the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Idpi extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Ieng.php b/src/Zend/Media/Riff/Chunk/Ieng.php new file mode 100644 index 0000000..6fc813b --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ieng.php @@ -0,0 +1,29 @@ +Engineer stores the name of the engineer who worked on the file. If there are multiple engineers, separate + * the names by a semicolon and a blank. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Ieng extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Ignr.php b/src/Zend/Media/Riff/Chunk/Ignr.php new file mode 100644 index 0000000..38d663a --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ignr.php @@ -0,0 +1,28 @@ +Genre chunk describes the original work, such as, landscape, portrait, still life, etc. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Ignr extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Ikey.php b/src/Zend/Media/Riff/Chunk/Ikey.php new file mode 100644 index 0000000..6ed5650 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ikey.php @@ -0,0 +1,29 @@ +Keywords provides a list of keywords that refer to the file or subject of the file. Separate multiple + * keywords with a semicolon and a blank. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Ikey extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Ilgt.php b/src/Zend/Media/Riff/Chunk/Ilgt.php new file mode 100644 index 0000000..37b5dd6 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ilgt.php @@ -0,0 +1,29 @@ +Lightness chunk describes the changes in lightness settings on the digitizer required to produce the file. + * Note that the format of this information depends on hardware used. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Ilgt extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Imed.php b/src/Zend/Media/Riff/Chunk/Imed.php new file mode 100644 index 0000000..d7bf5ee --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Imed.php @@ -0,0 +1,28 @@ +Medium describes the original subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Imed extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Inam.php b/src/Zend/Media/Riff/Chunk/Inam.php new file mode 100644 index 0000000..bb8a7f0 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Inam.php @@ -0,0 +1,28 @@ +Name chunk stores the title of the subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Inam extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Iplt.php b/src/Zend/Media/Riff/Chunk/Iplt.php new file mode 100644 index 0000000..ec10e26 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Iplt.php @@ -0,0 +1,28 @@ +Palette Setting specifies the number of colors requested when digitizing an image. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Iplt extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Iprd.php b/src/Zend/Media/Riff/Chunk/Iprd.php new file mode 100644 index 0000000..0a250fb --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Iprd.php @@ -0,0 +1,28 @@ +Product chunk specifies the name of the title the file was originally intended for. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Iprd extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Isbj.php b/src/Zend/Media/Riff/Chunk/Isbj.php new file mode 100644 index 0000000..fdf51d0 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Isbj.php @@ -0,0 +1,28 @@ +Subject describes the conbittents of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Isbj extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Isft.php b/src/Zend/Media/Riff/Chunk/Isft.php new file mode 100644 index 0000000..437262b --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Isft.php @@ -0,0 +1,28 @@ +Software identifies the name of the software package used to create the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Isft extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Ishp.php b/src/Zend/Media/Riff/Chunk/Ishp.php new file mode 100644 index 0000000..bf218a1 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Ishp.php @@ -0,0 +1,29 @@ +Sharpness chunk identifies the changes in sharpness for the digitizer required to produce the file (the + * format depends on the hardware used). + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Ishp extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Isrc.php b/src/Zend/Media/Riff/Chunk/Isrc.php new file mode 100644 index 0000000..b044b05 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Isrc.php @@ -0,0 +1,28 @@ +Source chunk identifies the name of the person or organization who supplied the original subject of the file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Isrc extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Isrf.php b/src/Zend/Media/Riff/Chunk/Isrf.php new file mode 100644 index 0000000..a992602 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Isrf.php @@ -0,0 +1,29 @@ +Source Form chunk identifies the original form of the material that was digitized, such as slide, paper, map, + * and so forth. This is not necessarily the same as {@link Zend_Media_Riff_Chunk_Imed IMED}. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Isrf extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Itch.php b/src/Zend/Media/Riff/Chunk/Itch.php new file mode 100644 index 0000000..3a55401 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Itch.php @@ -0,0 +1,28 @@ +Technician chunk identifies the technician who digitized the subject file. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Itch extends Zend_Media_Riff_StringChunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/Junk.php b/src/Zend/Media/Riff/Chunk/Junk.php new file mode 100644 index 0000000..58b23d5 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/Junk.php @@ -0,0 +1,29 @@ +Filler chunk represents padding, filler or outdated information. It contains no relevant data; it is a + * space filler of arbitrary size. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_Junk extends Zend_Media_Riff_Chunk +{ +} diff --git a/src/Zend/Media/Riff/Chunk/List.php b/src/Zend/Media/Riff/Chunk/List.php new file mode 100644 index 0000000..a060347 --- /dev/null +++ b/src/Zend/Media/Riff/Chunk/List.php @@ -0,0 +1,28 @@ +LIST chunk contains a list, or ordered sequence, of subchunks. + * + * @category Zend + * @package Zend_Media + * @subpackage Riff + * @author Sven Vollbehr + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +final class Zend_Media_Riff_Chunk_List extends Zend_Media_Riff_ContainerChunk +{ +} diff --git a/src/Zend/Media/Riff/ContainerChunk.php b/src/Zend/Media/Riff/ContainerChunk.php new file mode 100644 index 0000000..52ebbab --- /dev/null +++ b/src/Zend/Media/Riff/ContainerChunk.php @@ -0,0 +1,142 @@ + + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Box.php 177 2010-03-09 13:13:34Z svollbehr $ + */ +abstract class Zend_Media_Riff_ContainerChunk extends Zend_Media_Riff_Chunk +{ + /** @var string */ + protected $_type; + + /** @var Array */ + private $_chunks = array(); + + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $startOffset = $this->_reader->getOffset(); + $this->_type = $this->_reader->read(4); + while (($this->_reader->getOffset() - $startOffset) < $this->_size) { + $offset = $this->_reader->getOffset(); + + $identifier = $this->_reader->read(4); + $size = $this->_reader->readUInt32LE(); + + $this->_reader->setOffset($offset); + if (@fopen + ($file = 'Zend/Media/Riff/Chunk/' . + ucfirst(strtolower(rtrim($identifier, ' '))) . '.php', 'r', true) !== false) { + require_once($file); + } + if (class_exists($classname = 'Zend_Media_Riff_Chunk_' . ucfirst(strtolower(rtrim($identifier, ' '))))) { + $this->_chunks[] = new $classname($this->_reader); + + $this->_reader->setOffset($offset + 8 + $size); + } else { + trigger_error('Unknown RIFF chunk: \'' . $identifier . '\' skipped', E_USER_WARNING); + $this->_reader->skip(8 + $size); + } + } + } + + /** + * Returns a four-character code that identifies the contents of the container chunk. + * + * @return string + */ + public final function getType() + { + return $this->_type; + } + + /** + * Sets the four-character code that identifies the contents of the container chunk. + * + * @param string $type The chunk container type. + */ + public final function setType($type) + { + $this->_type = $type; + } + + /** + * Returns all the chunks this chunk contains as an array. + * + * @return Array + */ + public final function getChunks() + { + return $this->_chunks; + } + + /** + * Returns an array of chunks matching the given identifier or an empty array if no chunks matched the identifier. + * + * The identifier may contain wildcard characters '*' and '?'. The asterisk matches against zero or more characters, + * and the question mark matches any single character. + * + * Please note that one may also use the shorthand $obj->identifier to access the first chunk with the identifier + * given. Wildcards cannot be used with the shorthand. + * + * @param string $identifier The chunk identifier. + * @return Array + */ + public final function getChunksByIdentifier($identifier) + { + $matches = array(); + $searchPattern = "/^" . str_replace(array("*", "?"), array(".*", "."), $identifier) . "$/i"; + foreach ($this->_chunks as $chunk) { + if (preg_match($searchPattern, rtrim($chunk->getIdentifier(), ' '))) { + $matches[] = $chunk; + } + } + return $matches; + } + + /** + * Magic function so that $obj->value will work. The method will first attempt to return the first contained chunk + * whose identifier matches the given name, and if not found, invoke a getter method. + * + * If there are no chunks or getter methods with the given name, an exception is thrown. + * + * @param string $name The chunk or field name. + * @return mixed + */ + public function __get($name) + { + $chunks = $this->getChunksByIdentifier($name); + if (count($chunks) > 0) { + return $chunks[0]; + } + if (method_exists($this, 'get' . ucfirst($name))) { + return call_user_func(array($this, 'get' . ucfirst($name))); + } + require_once 'Zend/Media/Riff/Exception.php'; + throw new Zend_Media_Riff_Exception('Unknown chunk/field: ' . $name); + } +} diff --git a/src/Zend/Media/Riff/Exception.php b/src/Zend/Media/Riff/Exception.php new file mode 100644 index 0000000..da0fd0d --- /dev/null +++ b/src/Zend/Media/Riff/Exception.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Media_Riff_Exception extends Zend_Media_Exception +{} diff --git a/src/Zend/Media/Riff/StringChunk.php b/src/Zend/Media/Riff/StringChunk.php new file mode 100644 index 0000000..0e7105f --- /dev/null +++ b/src/Zend/Media/Riff/StringChunk.php @@ -0,0 +1,67 @@ + + * @copyright Copyright (c) 2011 Sven Vollbehr + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Box.php 177 2010-03-09 13:13:34Z svollbehr $ + */ +abstract class Zend_Media_Riff_StringChunk extends Zend_Media_Riff_Chunk +{ + /** @var string */ + protected $_value; + + /** + * Constructs the class with given parameters and options. + * + * @param Zend_Io_Reader $reader The reader object. + */ + public function __construct($reader) + { + parent::__construct($reader); + $this->_value = rtrim($this->_reader->read($this->_size), "\0"); + } + + /** + * Returns the text string value. + * + * @return string + */ + public final function getValue() + { + return $this->_value; + } + + /** + * Sets the text string value. + * + * @param string $type The text string value. + */ + public final function setValue($value) + { + $this->_value = $value; + } +}