Source for file PelEntryShort.php

Documentation is available at PelEntryShort.php

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

SourceForge.net Logo Documentation generated on Wed, 21 Jul 2004 19:13:06 +0200 by phpDocumentor 1.3.0RC3