8ef5cffc7a566f5a184cd4f49f1e132baec99c29
[yaffs-website] / lsolesen / pel / src / PelEntryShort.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::SHORT} like in this
42  * example:
43  *
44  * <code>
45  * $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
46  * $w->setValue($w->getValue() / 2);
47  * $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
48  * $h->setValue($h->getValue() / 2);
49  * </code>
50  *
51  * Here the width and height is updated to 50% of their original
52  * values.
53  *
54  * @author Martin Geisler <mgeisler@users.sourceforge.net>
55  * @package PEL
56  */
57 class PelEntryShort extends PelEntryNumber
58 {
59
60     /**
61      * Make a new entry that can hold an unsigned short.
62      *
63      * The method accept several integer arguments. The {@link
64      * getValue} method will always return an array except for when a
65      * single integer argument is given here.
66      *
67      * This means that one can conveniently use objects like this:
68      * <code>
69      * $a = new PelEntryShort(PelTag::EXIF_IMAGE_HEIGHT, 42);
70      * $b = $a->getValue() + 314;
71      * </code>
72      * where the call to {@link getValue} will return an integer
73      * instead of an array with one integer element, which would then
74      * have to be extracted.
75      *
76      * @param PelTag $tag
77      *            the tag which this entry represents. This should be
78      *            one of the constants defined in {@link PelTag}, e.g., {@link
79      *            PelTag::IMAGE_WIDTH}, {@link PelTag::ISO_SPEED_RATINGS},
80      *            or any other tag with format {@link PelFormat::SHORT}.
81      *
82      * @param int $value...
83      *            the short(s) that this entry will
84      *            represent. The argument passed must obey the same rules as the
85      *            argument to {@link setValue}, namely that it should be within
86      *            range of an unsigned short, that is between 0 and 65535
87      *            (inclusive). If not, then a {@link PelOverFlowException} will be
88      *            thrown.
89      */
90     public function __construct($tag, $value = null)
91     {
92         $this->tag = $tag;
93         $this->min = 0;
94         $this->max = 65535;
95         $this->format = PelFormat::SHORT;
96
97         $value = func_get_args();
98         array_shift($value);
99         $this->setValueArray($value);
100     }
101
102     /**
103      * Convert a number into bytes.
104      *
105      * @param int $number
106      *            the number that should be converted.
107      *
108      * @param PelByteOrder $order
109      *            one of {@link PelConvert::LITTLE_ENDIAN} and
110      *            {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
111      *
112      * @return string bytes representing the number given.
113      */
114     public function numberToBytes($number, $order)
115     {
116         return PelConvert::shortToBytes($number, $order);
117     }
118
119     /**
120      * Get the value of an entry as text.
121      *
122      * The value will be returned in a format suitable for presentation,
123      * e.g., instead of returning '2' for a {@link
124      * PelTag::METERING_MODE} tag, 'Center-Weighted Average' is
125      * returned.
126      *
127      * @param
128      *            boolean some values can be returned in a long or more
129      *            brief form, and this parameter controls that.
130      *
131      * @return string the value as text.
132      */
133     public function getText($brief = false)
134     {
135         switch ($this->tag) {
136             case PelTag::METERING_MODE:
137                 // CC (e->components, 1, v);
138                 switch ($this->value[0]) {
139                     case 0:
140                         return Pel::tra('Unknown');
141                     case 1:
142                         return Pel::tra('Average');
143                     case 2:
144                         return Pel::tra('Center-Weighted Average');
145                     case 3:
146                         return Pel::tra('Spot');
147                     case 4:
148                         return Pel::tra('Multi Spot');
149                     case 5:
150                         return Pel::tra('Pattern');
151                     case 6:
152                         return Pel::tra('Partial');
153                     case 255:
154                         return Pel::tra('Other');
155                     default:
156                         return $this->value[0];
157                 }
158                 break;
159             case PelTag::COMPRESSION:
160                 // CC (e->components, 1, v);
161                 switch ($this->value[0]) {
162                     case 1:
163                         return Pel::tra('Uncompressed');
164                     case 6:
165                         return Pel::tra('JPEG compression');
166                     default:
167                         return $this->value[0];
168                 }
169                 break;
170             case PelTag::PLANAR_CONFIGURATION:
171                 // CC (e->components, 1, v);
172                 switch ($this->value[0]) {
173                     case 1:
174                         return Pel::tra('chunky format');
175                     case 2:
176                         return Pel::tra('planar format');
177                     default:
178                         return $this->value[0];
179                 }
180                 break;
181             case PelTag::SENSING_METHOD:
182                 // CC (e->components, 1, v);
183                 switch ($this->value[0]) {
184                     case 1:
185                         return Pel::tra('Not defined');
186                     case 2:
187                         return Pel::tra('One-chip color area sensor');
188                     case 3:
189                         return Pel::tra('Two-chip color area sensor');
190                     case 4:
191                         return Pel::tra('Three-chip color area sensor');
192                     case 5:
193                         return Pel::tra('Color sequential area sensor');
194                     case 7:
195                         return Pel::tra('Trilinear sensor');
196                     case 8:
197                         return Pel::tra('Color sequential linear sensor');
198                     default:
199                         return $this->value[0];
200                 }
201                 break;
202             case PelTag::LIGHT_SOURCE:
203                 // CC (e->components, 1, v);
204                 switch ($this->value[0]) {
205                     case 0:
206                         return Pel::tra('Unknown');
207                     case 1:
208                         return Pel::tra('Daylight');
209                     case 2:
210                         return Pel::tra('Fluorescent');
211                     case 3:
212                         return Pel::tra('Tungsten (incandescent light)');
213                     case 4:
214                         return Pel::tra('Flash');
215                     case 9:
216                         return Pel::tra('Fine weather');
217                     case 10:
218                         return Pel::tra('Cloudy weather');
219                     case 11:
220                         return Pel::tra('Shade');
221                     case 12:
222                         return Pel::tra('Daylight fluorescent');
223                     case 13:
224                         return Pel::tra('Day white fluorescent');
225                     case 14:
226                         return Pel::tra('Cool white fluorescent');
227                     case 15:
228                         return Pel::tra('White fluorescent');
229                     case 17:
230                         return Pel::tra('Standard light A');
231                     case 18:
232                         return Pel::tra('Standard light B');
233                     case 19:
234                         return Pel::tra('Standard light C');
235                     case 20:
236                         return Pel::tra('D55');
237                     case 21:
238                         return Pel::tra('D65');
239                     case 22:
240                         return Pel::tra('D75');
241                     case 24:
242                         return Pel::tra('ISO studio tungsten');
243                     case 255:
244                         return Pel::tra('Other');
245                     default:
246                         return $this->value[0];
247                 }
248                 break;
249             case PelTag::FOCAL_PLANE_RESOLUTION_UNIT:
250             case PelTag::RESOLUTION_UNIT:
251                 // CC (e->components, 1, v);
252                 switch ($this->value[0]) {
253                     case 2:
254                         return Pel::tra('Inch');
255                     case 3:
256                         return Pel::tra('Centimeter');
257                     default:
258                         return $this->value[0];
259                 }
260                 break;
261             case PelTag::EXPOSURE_PROGRAM:
262                 // CC (e->components, 1, v);
263                 switch ($this->value[0]) {
264                     case 0:
265                         return Pel::tra('Not defined');
266                     case 1:
267                         return Pel::tra('Manual');
268                     case 2:
269                         return Pel::tra('Normal program');
270                     case 3:
271                         return Pel::tra('Aperture priority');
272                     case 4:
273                         return Pel::tra('Shutter priority');
274                     case 5:
275                         return Pel::tra('Creative program (biased toward depth of field)');
276                     case 6:
277                         return Pel::tra('Action program (biased toward fast shutter speed)');
278                     case 7:
279                         return Pel::tra('Portrait mode (for closeup photos with the background out of focus');
280                     case 8:
281                         return Pel::tra('Landscape mode (for landscape photos with the background in focus');
282                     default:
283                         return $this->value[0];
284                 }
285                 break;
286             case PelTag::ORIENTATION:
287                 // CC (e->components, 1, v);
288                 switch ($this->value[0]) {
289                     case 1:
290                         return Pel::tra('top - left');
291                     case 2:
292                         return Pel::tra('top - right');
293                     case 3:
294                         return Pel::tra('bottom - right');
295                     case 4:
296                         return Pel::tra('bottom - left');
297                     case 5:
298                         return Pel::tra('left - top');
299                     case 6:
300                         return Pel::tra('right - top');
301                     case 7:
302                         return Pel::tra('right - bottom');
303                     case 8:
304                         return Pel::tra('left - bottom');
305                     default:
306                         return $this->value[0];
307                 }
308                 break;
309             case PelTag::YCBCR_POSITIONING:
310                 // CC (e->components, 1, v);
311                 switch ($this->value[0]) {
312                     case 1:
313                         return Pel::tra('centered');
314                     case 2:
315                         return Pel::tra('co-sited');
316                     default:
317                         return $this->value[0];
318                 }
319                 break;
320             case PelTag::YCBCR_SUB_SAMPLING:
321                 // CC (e->components, 2, v);
322                 if ($this->value[0] == 2 && $this->value[1] == 1) {
323                     return 'YCbCr4:2:2';
324                 }
325                 if ($this->value[0] == 2 && $this->value[1] == 2) {
326                     return 'YCbCr4:2:0';
327                 }
328
329                 return $this->value[0] . ', ' . $this->value[1];
330                 break;
331             case PelTag::PHOTOMETRIC_INTERPRETATION:
332                 // CC (e->components, 1, v);
333                 switch ($this->value[0]) {
334                     case 2:
335                         return 'RGB';
336                     case 6:
337                         return 'YCbCr';
338                     default:
339                         return $this->value[0];
340                 }
341                 break;
342             case PelTag::COLOR_SPACE:
343                 // CC (e->components, 1, v);
344                 switch ($this->value[0]) {
345                     case 1:
346                         return 'sRGB';
347                     case 2:
348                         return 'Adobe RGB';
349                     case 0xffff:
350                         return Pel::tra('Uncalibrated');
351                     default:
352                         return $this->value[0];
353                 }
354                 break;
355             case PelTag::FLASH:
356                 // CC (e->components, 1, v);
357                 switch ($this->value[0]) {
358                     case 0x0000:
359                         return Pel::tra('Flash did not fire.');
360                     case 0x0001:
361                         return Pel::tra('Flash fired.');
362                     case 0x0005:
363                         return Pel::tra('Strobe return light not detected.');
364                     case 0x0007:
365                         return Pel::tra('Strobe return light detected.');
366                     case 0x0009:
367                         return Pel::tra('Flash fired, compulsory flash mode.');
368                     case 0x000d:
369                         return Pel::tra('Flash fired, compulsory flash mode, return light not detected.');
370                     case 0x000f:
371                         return Pel::tra('Flash fired, compulsory flash mode, return light detected.');
372                     case 0x0010:
373                         return Pel::tra('Flash did not fire, compulsory flash mode.');
374                     case 0x0018:
375                         return Pel::tra('Flash did not fire, auto mode.');
376                     case 0x0019:
377                         return Pel::tra('Flash fired, auto mode.');
378                     case 0x001d:
379                         return Pel::tra('Flash fired, auto mode, return light not detected.');
380                     case 0x001f:
381                         return Pel::tra('Flash fired, auto mode, return light detected.');
382                     case 0x0020:
383                         return Pel::tra('No flash function.');
384                     case 0x0041:
385                         return Pel::tra('Flash fired, red-eye reduction mode.');
386                     case 0x0045:
387                         return Pel::tra('Flash fired, red-eye reduction mode, return light not detected.');
388                     case 0x0047:
389                         return Pel::tra('Flash fired, red-eye reduction mode, return light detected.');
390                     case 0x0049:
391                         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode.');
392                     case 0x004d:
393                         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected.');
394                     case 0x004f:
395                         return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light detected.');
396                     case 0x0058:
397                         return Pel::tra('Flash did not fire, auto mode, red-eye reduction mode.');
398                     case 0x0059:
399                         return Pel::tra('Flash fired, auto mode, red-eye reduction mode.');
400                     case 0x005d:
401                         return Pel::tra('Flash fired, auto mode, return light not detected, red-eye reduction mode.');
402                     case 0x005f:
403                         return Pel::tra('Flash fired, auto mode, return light detected, red-eye reduction mode.');
404                     default:
405                         return $this->value[0];
406                 }
407                 break;
408             case PelTag::CUSTOM_RENDERED:
409                 // CC (e->components, 1, v);
410                 switch ($this->value[0]) {
411                     case 0:
412                         return Pel::tra('Normal process');
413                     case 1:
414                         return Pel::tra('Custom process');
415                     default:
416                         return $this->value[0];
417                 }
418                 break;
419             case PelTag::EXPOSURE_MODE:
420                 // CC (e->components, 1, v);
421                 switch ($this->value[0]) {
422                     case 0:
423                         return Pel::tra('Auto exposure');
424                     case 1:
425                         return Pel::tra('Manual exposure');
426                     case 2:
427                         return Pel::tra('Auto bracket');
428                     default:
429                         return $this->value[0];
430                 }
431                 break;
432             case PelTag::WHITE_BALANCE:
433                 // CC (e->components, 1, v);
434                 switch ($this->value[0]) {
435                     case 0:
436                         return Pel::tra('Auto white balance');
437                     case 1:
438                         return Pel::tra('Manual white balance');
439                     default:
440                         return $this->value[0];
441                 }
442                 break;
443             case PelTag::SCENE_CAPTURE_TYPE:
444                 // CC (e->components, 1, v);
445                 switch ($this->value[0]) {
446                     case 0:
447                         return Pel::tra('Standard');
448                     case 1:
449                         return Pel::tra('Landscape');
450                     case 2:
451                         return Pel::tra('Portrait');
452                     case 3:
453                         return Pel::tra('Night scene');
454                     default:
455                         return $this->value[0];
456                 }
457                 break;
458             case PelTag::GAIN_CONTROL:
459                 // CC (e->components, 1, v);
460                 switch ($this->value[0]) {
461                     case 0:
462                         return Pel::tra('Normal');
463                     case 1:
464                         return Pel::tra('Low gain up');
465                     case 2:
466                         return Pel::tra('High gain up');
467                     case 3:
468                         return Pel::tra('Low gain down');
469                     case 4:
470                         return Pel::tra('High gain down');
471                     default:
472                         return $this->value[0];
473                 }
474                 break;
475             case PelTag::SATURATION:
476                 // CC (e->components, 1, v);
477                 switch ($this->value[0]) {
478                     case 0:
479                         return Pel::tra('Normal');
480                     case 1:
481                         return Pel::tra('Low saturation');
482                     case 2:
483                         return Pel::tra('High saturation');
484                     default:
485                         return $this->value[0];
486                 }
487                 break;
488             case PelTag::CONTRAST:
489             case PelTag::SHARPNESS:
490                 // CC (e->components, 1, v);
491                 switch ($this->value[0]) {
492                     case 0:
493                         return Pel::tra('Normal');
494                     case 1:
495                         return Pel::tra('Soft');
496                     case 2:
497                         return Pel::tra('Hard');
498                     default:
499                         return $this->value[0];
500                 }
501                 break;
502             case PelTag::SUBJECT_DISTANCE_RANGE:
503                 // CC (e->components, 1, v);
504                 switch ($this->value[0]) {
505                     case 0:
506                         return Pel::tra('Unknown');
507                     case 1:
508                         return Pel::tra('Macro');
509                     case 2:
510                         return Pel::tra('Close view');
511                     case 3:
512                         return Pel::tra('Distant view');
513                     default:
514                         return $this->value[0];
515                 }
516                 break;
517             case PelTag::SUBJECT_AREA:
518                 switch ($this->components) {
519                     case 2:
520                         return Pel::fmt('(x,y) = (%d,%d)', $this->value[0], $this->value[1]);
521                     case 3:
522                         return Pel::fmt('Within distance %d of (x,y) = (%d,%d)', $this->value[0], $this->value[1], $this->value[2]);
523                     case 4:
524                         return Pel::fmt('Within rectangle (width %d, height %d) around (x,y) = (%d,%d)', $this->value[0], $this->value[1], $this->value[2], $this->value[3]);
525
526                     default:
527                         return Pel::fmt('Unexpected number of components (%d, expected 2, 3, or 4).', $this->components);
528                 }
529                 break;
530             default:
531                 return parent::getText($brief);
532         }
533     }
534 }