Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / lsolesen / pel / src / PelEntrySRational.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 manipulate rational numbers.
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 rational numbers.
38  *
39  * This class can hold rational numbers, consisting of a numerator and
40  * denominator both of which are of type unsigned long. Each rational
41  * is represented by an array with just two entries: the numerator and
42  * the denominator, in that order.
43  *
44  * The class can hold either just a single rational or an array of
45  * rationals. The class will be used to manipulate any of the Exif
46  * tags which can have format {@link PelFormat::SRATIONAL}.
47  *
48  * @author Martin Geisler <mgeisler@users.sourceforge.net>
49  * @package PEL
50  */
51 class PelEntrySRational extends PelEntrySLong
52 {
53
54     /**
55      * Make a new entry that can hold a signed rational.
56      *
57      * @param
58      *            PelTag the tag which this entry represents. This should
59      *            be one of the constants defined in {@link PelTag}, e.g., {@link
60      *            PelTag::SHUTTER_SPEED_VALUE}, or any other tag which can have
61      *            format {@link PelFormat::SRATIONAL}.
62      *
63      * @param array $value...
64      *            the rational(s) that this entry will
65      *            represent. The arguments passed must obey the same rules as the
66      *            argument to {@link setValue}, namely that each argument should be
67      *            an array with two entries, both of which must be within range of
68      *            a signed long (32 bit), that is between -2147483648 and
69      *            2147483647 (inclusive). If not, then a {@link
70      *            PelOverflowException} will be thrown.
71      */
72     public function __construct($tag, $value = null)
73     {
74         $this->tag = $tag;
75         $this->format = PelFormat::SRATIONAL;
76         $this->dimension = 2;
77         $this->min = - 2147483648;
78         $this->max = 2147483647;
79
80         $value = func_get_args();
81         array_shift($value);
82         $this->setValueArray($value);
83     }
84
85     /**
86      * Format a rational number.
87      *
88      * The rational will be returned as a string with a slash '/'
89      * between the numerator and denominator. Care is taken to display
90      * '-1/2' instead of the ugly but mathematically equivalent '1/-2'.
91      *
92      * @param
93      *            array the rational which will be formatted.
94      *
95      * @param
96      *            boolean not used.
97      *
98      * @return string the rational formatted as a string suitable for
99      *         display.
100      */
101     public function formatNumber($number, $brief = false)
102     {
103         if ($number[1] < 0) {
104             /* Turn output like 1/-2 into -1/2. */
105             return (- $number[0]) . '/' . (- $number[1]);
106         } else {
107             return $number[0] . '/' . $number[1];
108         }
109     }
110
111     /**
112      * Get the value of an entry as text.
113      *
114      * The value will be returned in a format suitable for presentation,
115      * e.g., rationals will be returned as 'x/y', ASCII strings will be
116      * returned as themselves etc.
117      *
118      * @param
119      *            boolean some values can be returned in a long or more
120      *            brief form, and this parameter controls that.
121      *
122      * @return string the value as text.
123      */
124     public function getText($brief = false)
125     {
126         if (isset($this->value[0])) {
127             $v = $this->value[0];
128         }
129
130         switch ($this->tag) {
131             case PelTag::SHUTTER_SPEED_VALUE:
132                 // CC (e->components, 1, v);
133                 // if (!v_srat.denominator) return (NULL);
134                 return Pel::fmt('%.0f/%.0f sec. (APEX: %d)', $v[0], $v[1], pow(sqrt(2), $v[0] / $v[1]));
135
136             case PelTag::BRIGHTNESS_VALUE:
137                 // CC (e->components, 1, v);
138                 //
139                 // TODO: figure out the APEX thing, or remove this so that it is
140                 // handled by the default clause at the bottom.
141                 return sprintf('%d/%d', $v[0], $v[1]);
142             // FIXME: How do I calculate the APEX value?
143
144             case PelTag::EXPOSURE_BIAS_VALUE:
145                 // CC (e->components, 1, v);
146                 // if (!v_srat.denominator) return (NULL);
147                 return sprintf('%s%.01f', $v[0] * $v[1] > 0 ? '+' : '', $v[0] / $v[1]);
148
149             default:
150                 return parent::getText($brief);
151         }
152     }
153 }