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.
8 * Copyright (C) 2004, 2005, 2006 Martin Geisler.
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.
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.
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
25 namespace lsolesen\pel;
28 * Classes used to hold shorts, both signed and unsigned.
30 * @author Martin Geisler <mgeisler@users.sourceforge.net>
31 * @license http://www.gnu.org/licenses/gpl.html GNU General Public
37 * Class for holding signed shorts.
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
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);
51 * Here the width and height is updated to 50% of their original
54 * @author Martin Geisler <mgeisler@users.sourceforge.net>
57 class PelEntryShort extends PelEntryNumber
61 * Make a new entry that can hold an unsigned short.
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.
67 * This means that one can conveniently use objects like this:
69 * $a = new PelEntryShort(PelTag::EXIF_IMAGE_HEIGHT, 42);
70 * $b = $a->getValue() + 314;
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.
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}.
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
90 public function __construct($tag, $value = null)
95 $this->format = PelFormat::SHORT;
97 $value = func_get_args();
99 $this->setValueArray($value);
103 * Convert a number into bytes.
106 * the number that should be converted.
108 * @param PelByteOrder $order
109 * one of {@link PelConvert::LITTLE_ENDIAN} and
110 * {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
112 * @return string bytes representing the number given.
114 public function numberToBytes($number, $order)
116 return PelConvert::shortToBytes($number, $order);
120 * Get the value of an entry as text.
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
128 * boolean some values can be returned in a long or more
129 * brief form, and this parameter controls that.
131 * @return string the value as text.
133 public function getText($brief = false)
135 switch ($this->tag) {
136 case PelTag::METERING_MODE:
137 // CC (e->components, 1, v);
138 switch ($this->value[0]) {
140 return Pel::tra('Unknown');
142 return Pel::tra('Average');
144 return Pel::tra('Center-Weighted Average');
146 return Pel::tra('Spot');
148 return Pel::tra('Multi Spot');
150 return Pel::tra('Pattern');
152 return Pel::tra('Partial');
154 return Pel::tra('Other');
156 return $this->value[0];
159 case PelTag::COMPRESSION:
160 // CC (e->components, 1, v);
161 switch ($this->value[0]) {
163 return Pel::tra('Uncompressed');
165 return Pel::tra('JPEG compression');
167 return $this->value[0];
170 case PelTag::PLANAR_CONFIGURATION:
171 // CC (e->components, 1, v);
172 switch ($this->value[0]) {
174 return Pel::tra('chunky format');
176 return Pel::tra('planar format');
178 return $this->value[0];
181 case PelTag::SENSING_METHOD:
182 // CC (e->components, 1, v);
183 switch ($this->value[0]) {
185 return Pel::tra('Not defined');
187 return Pel::tra('One-chip color area sensor');
189 return Pel::tra('Two-chip color area sensor');
191 return Pel::tra('Three-chip color area sensor');
193 return Pel::tra('Color sequential area sensor');
195 return Pel::tra('Trilinear sensor');
197 return Pel::tra('Color sequential linear sensor');
199 return $this->value[0];
202 case PelTag::LIGHT_SOURCE:
203 // CC (e->components, 1, v);
204 switch ($this->value[0]) {
206 return Pel::tra('Unknown');
208 return Pel::tra('Daylight');
210 return Pel::tra('Fluorescent');
212 return Pel::tra('Tungsten (incandescent light)');
214 return Pel::tra('Flash');
216 return Pel::tra('Fine weather');
218 return Pel::tra('Cloudy weather');
220 return Pel::tra('Shade');
222 return Pel::tra('Daylight fluorescent');
224 return Pel::tra('Day white fluorescent');
226 return Pel::tra('Cool white fluorescent');
228 return Pel::tra('White fluorescent');
230 return Pel::tra('Standard light A');
232 return Pel::tra('Standard light B');
234 return Pel::tra('Standard light C');
236 return Pel::tra('D55');
238 return Pel::tra('D65');
240 return Pel::tra('D75');
242 return Pel::tra('ISO studio tungsten');
244 return Pel::tra('Other');
246 return $this->value[0];
249 case PelTag::FOCAL_PLANE_RESOLUTION_UNIT:
250 case PelTag::RESOLUTION_UNIT:
251 // CC (e->components, 1, v);
252 switch ($this->value[0]) {
254 return Pel::tra('Inch');
256 return Pel::tra('Centimeter');
258 return $this->value[0];
261 case PelTag::EXPOSURE_PROGRAM:
262 // CC (e->components, 1, v);
263 switch ($this->value[0]) {
265 return Pel::tra('Not defined');
267 return Pel::tra('Manual');
269 return Pel::tra('Normal program');
271 return Pel::tra('Aperture priority');
273 return Pel::tra('Shutter priority');
275 return Pel::tra('Creative program (biased toward depth of field)');
277 return Pel::tra('Action program (biased toward fast shutter speed)');
279 return Pel::tra('Portrait mode (for closeup photos with the background out of focus');
281 return Pel::tra('Landscape mode (for landscape photos with the background in focus');
283 return $this->value[0];
286 case PelTag::ORIENTATION:
287 // CC (e->components, 1, v);
288 switch ($this->value[0]) {
290 return Pel::tra('top - left');
292 return Pel::tra('top - right');
294 return Pel::tra('bottom - right');
296 return Pel::tra('bottom - left');
298 return Pel::tra('left - top');
300 return Pel::tra('right - top');
302 return Pel::tra('right - bottom');
304 return Pel::tra('left - bottom');
306 return $this->value[0];
309 case PelTag::YCBCR_POSITIONING:
310 // CC (e->components, 1, v);
311 switch ($this->value[0]) {
313 return Pel::tra('centered');
315 return Pel::tra('co-sited');
317 return $this->value[0];
320 case PelTag::YCBCR_SUB_SAMPLING:
321 // CC (e->components, 2, v);
322 if ($this->value[0] == 2 && $this->value[1] == 1) {
325 if ($this->value[0] == 2 && $this->value[1] == 2) {
329 return $this->value[0] . ', ' . $this->value[1];
331 case PelTag::PHOTOMETRIC_INTERPRETATION:
332 // CC (e->components, 1, v);
333 switch ($this->value[0]) {
339 return $this->value[0];
342 case PelTag::COLOR_SPACE:
343 // CC (e->components, 1, v);
344 switch ($this->value[0]) {
350 return Pel::tra('Uncalibrated');
352 return $this->value[0];
356 // CC (e->components, 1, v);
357 switch ($this->value[0]) {
359 return Pel::tra('Flash did not fire.');
361 return Pel::tra('Flash fired.');
363 return Pel::tra('Strobe return light not detected.');
365 return Pel::tra('Strobe return light detected.');
367 return Pel::tra('Flash fired, compulsory flash mode.');
369 return Pel::tra('Flash fired, compulsory flash mode, return light not detected.');
371 return Pel::tra('Flash fired, compulsory flash mode, return light detected.');
373 return Pel::tra('Flash did not fire, compulsory flash mode.');
375 return Pel::tra('Flash did not fire, auto mode.');
377 return Pel::tra('Flash fired, auto mode.');
379 return Pel::tra('Flash fired, auto mode, return light not detected.');
381 return Pel::tra('Flash fired, auto mode, return light detected.');
383 return Pel::tra('No flash function.');
385 return Pel::tra('Flash fired, red-eye reduction mode.');
387 return Pel::tra('Flash fired, red-eye reduction mode, return light not detected.');
389 return Pel::tra('Flash fired, red-eye reduction mode, return light detected.');
391 return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode.');
393 return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected.');
395 return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light detected.');
397 return Pel::tra('Flash did not fire, auto mode, red-eye reduction mode.');
399 return Pel::tra('Flash fired, auto mode, red-eye reduction mode.');
401 return Pel::tra('Flash fired, auto mode, return light not detected, red-eye reduction mode.');
403 return Pel::tra('Flash fired, auto mode, return light detected, red-eye reduction mode.');
405 return $this->value[0];
408 case PelTag::CUSTOM_RENDERED:
409 // CC (e->components, 1, v);
410 switch ($this->value[0]) {
412 return Pel::tra('Normal process');
414 return Pel::tra('Custom process');
416 return $this->value[0];
419 case PelTag::EXPOSURE_MODE:
420 // CC (e->components, 1, v);
421 switch ($this->value[0]) {
423 return Pel::tra('Auto exposure');
425 return Pel::tra('Manual exposure');
427 return Pel::tra('Auto bracket');
429 return $this->value[0];
432 case PelTag::WHITE_BALANCE:
433 // CC (e->components, 1, v);
434 switch ($this->value[0]) {
436 return Pel::tra('Auto white balance');
438 return Pel::tra('Manual white balance');
440 return $this->value[0];
443 case PelTag::SCENE_CAPTURE_TYPE:
444 // CC (e->components, 1, v);
445 switch ($this->value[0]) {
447 return Pel::tra('Standard');
449 return Pel::tra('Landscape');
451 return Pel::tra('Portrait');
453 return Pel::tra('Night scene');
455 return $this->value[0];
458 case PelTag::GAIN_CONTROL:
459 // CC (e->components, 1, v);
460 switch ($this->value[0]) {
462 return Pel::tra('Normal');
464 return Pel::tra('Low gain up');
466 return Pel::tra('High gain up');
468 return Pel::tra('Low gain down');
470 return Pel::tra('High gain down');
472 return $this->value[0];
475 case PelTag::SATURATION:
476 // CC (e->components, 1, v);
477 switch ($this->value[0]) {
479 return Pel::tra('Normal');
481 return Pel::tra('Low saturation');
483 return Pel::tra('High saturation');
485 return $this->value[0];
488 case PelTag::CONTRAST:
489 case PelTag::SHARPNESS:
490 // CC (e->components, 1, v);
491 switch ($this->value[0]) {
493 return Pel::tra('Normal');
495 return Pel::tra('Soft');
497 return Pel::tra('Hard');
499 return $this->value[0];
502 case PelTag::SUBJECT_DISTANCE_RANGE:
503 // CC (e->components, 1, v);
504 switch ($this->value[0]) {
506 return Pel::tra('Unknown');
508 return Pel::tra('Macro');
510 return Pel::tra('Close view');
512 return Pel::tra('Distant view');
514 return $this->value[0];
517 case PelTag::SUBJECT_AREA:
518 switch ($this->components) {
520 return Pel::fmt('(x,y) = (%d,%d)', $this->value[0], $this->value[1]);
522 return Pel::fmt('Within distance %d of (x,y) = (%d,%d)', $this->value[0], $this->value[1], $this->value[2]);
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]);
527 return Pel::fmt('Unexpected number of components (%d, expected 2, 3, or 4).', $this->components);
531 return parent::getText($brief);