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