dead1efe283cc0a7c2abd1b4e3291e81d869da7f
[yaffs-website] / vendor / lsolesen / pel / src / PelEntryLong.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 longs, 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 unsigned longs.
38  *
39  * This class can hold longs, either just a single long or an array of
40  * longs. The class will be used to manipulate any of the Exif tags
41  * which can have format {@link PelFormat::LONG} like in this
42  * example:
43  * <code>
44  * $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
45  * $w->setValue($w->getValue() / 2);
46  * $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
47  * $h->setValue($h->getValue() / 2);
48  * </code>
49  * Here the width and height is updated to 50% of their original
50  * values.
51  *
52  * @author Martin Geisler <mgeisler@users.sourceforge.net>
53  * @package PEL
54  */
55 class PelEntryLong extends PelEntryNumber
56 {
57
58     /**
59      * Make a new entry that can hold an unsigned long.
60      *
61      * The method accept its arguments in two forms: several integer
62      * arguments or a single array argument. The {@link getValue}
63      * method will always return an array except for when a single
64      * integer argument is given here, or when an array with just a
65      * single integer is given.
66      *
67      * This means that one can conveniently use objects like this:
68      * <code>
69      * $a = new PelEntryLong(PelTag::EXIF_IMAGE_WIDTH, 123456);
70      * $b = $a->getValue() - 654321;
71      * </code>
72      * where the call to {@link getValue} will return an integer instead
73      * of an array with one integer element, which would then have to be
74      * extracted.
75      *
76      * @param
77      *            PelTag the tag which this entry represents. This
78      *            should be one of the constants defined in {@link PelTag},
79      *            e.g., {@link PelTag::IMAGE_WIDTH}, or any other tag which can
80      *            have format {@link PelFormat::LONG}.
81      * @param int $value...
82      *            the long(s) that this entry will
83      *            represent or an array of longs. The argument passed must obey
84      *            the same rules as the argument to {@link setValue}, namely that
85      *            it should be within range of an unsigned long (32 bit), that is
86      *            between 0 and 4294967295 (inclusive). If not, then a {@link
87      *            PelExifOverflowException} will be thrown.
88      */
89     public function __construct($tag, $value = null)
90     {
91         $this->tag = $tag;
92         $this->min = 0;
93         $this->max = 4294967295;
94         $this->format = PelFormat::LONG;
95
96         $value = func_get_args();
97         array_shift($value);
98         $this->setValueArray($value);
99     }
100
101     /**
102      * Convert a number into bytes.
103      *
104      * @param
105      *            int the number that should be converted.
106      * @param
107      *            PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
108      *            {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
109      * @return string bytes representing the number given.
110      */
111     public function numberToBytes($number, $order)
112     {
113         return PelConvert::longToBytes($number, $order);
114     }
115 }