886b530e53103d74c9a0efe0dcb37b81cefba844
[yaffs-website] / lsolesen / pel / src / PelEntrySShort.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2005, 2006 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25 namespace lsolesen\pel;
26
27 /**
28  * Classes used to hold shorts, both signed and unsigned.
29  *
30  * @author Martin Geisler <mgeisler@users.sourceforge.net>
31  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
32  *          License (GPL)
33  * @package PEL
34  */
35
36 /**
37  * Class for holding signed shorts.
38  *
39  * This class can hold shorts, either just a single short or an array
40  * of shorts. The class will be used to manipulate any of the Exif
41  * tags which has format {@link PelFormat::SSHORT}.
42  *
43  * @author Martin Geisler <mgeisler@users.sourceforge.net>
44  * @package PEL
45  */
46 class PelEntrySShort extends PelEntryNumber
47 {
48
49     /**
50      * Make a new entry that can hold a signed short.
51      *
52      * The method accept several integer arguments. The {@link
53      * getValue} method will always return an array except for when a
54      * single integer argument is given here.
55      *
56      * @param PelTag $tag
57      *            the tag which this entry represents. This
58      *            should be one of the constants defined in {@link PelTag}
59      *            which has format {@link PelFormat::SSHORT}.
60      *
61      * @param int $value...
62      *            the signed short(s) that this entry will
63      *            represent. The argument passed must obey the same rules as the
64      *            argument to {@link setValue}, namely that it should be within
65      *            range of a signed short, that is between -32768 to 32767
66      *            (inclusive). If not, then a {@link PelOverFlowException} will be
67      *            thrown.
68      */
69     public function __construct($tag, $value = null)
70     {
71         $this->tag = $tag;
72         $this->min = - 32768;
73         $this->max = 32767;
74         $this->format = PelFormat::SSHORT;
75
76         $value = func_get_args();
77         array_shift($value);
78         $this->setValueArray($value);
79     }
80
81     /**
82      * Convert a number into bytes.
83      *
84      * @param int $number
85      *            the number that should be converted.
86      *
87      * @param PelByteOrder $order
88      *            one of {@link PelConvert::LITTLE_ENDIAN} and
89      *            {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
90      *
91      * @return string bytes representing the number given.
92      */
93     public function numberToBytes($number, $order)
94     {
95         return PelConvert::sShortToBytes($number, $order);
96     }
97 }