Source for file PelJpegMarker.php

Documentation is available at PelJpegMarker.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.
  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. /* PelJpegMarker.php,v 1.9 2005/02/10 21:22:44 gimpster Exp */
  25.  
  26.  
  27. /**
  28. * Classes for dealing with JPEG markers.
  29. *
  30. * @author Martin Geisler <gimpster@users.sourceforge.net>
  31. * @version 1.9
  32. * @date 2005/02/10 21:22:44
  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. ('Pel.php');
  40. /**#@-*/ * Class with static methods for JPEG markers.
  41. *
  42. * This class defines the constants to be used whenever one refers to
  43. * a JPEG marker. All the methods defined are static, and they all
  44. * operate on one argument which should be one of the class constants.
  45. * They will all be denoted by PelJpegMarker in the documentation.
  46. *
  47. * @author Martin Geisler <gimpster@users.sourceforge.net>
  48. * @package PEL
  49. */
  50. class PelJpegMarker {
  51.  
  52. /** Encoding (baseline) */
  53.  
  54. const SOF0 = 0xC0;
  55. /** Encoding (extended sequential) */
  56.  
  57. const SOF1 = 0xC1;
  58. /** Encoding (progressive) */
  59.  
  60. const SOF2 = 0xC2;
  61. /** Encoding (lossless) */
  62.  
  63. const SOF3 = 0xC3;
  64. /** Define Huffman table */
  65.  
  66. const DHT = 0xC4;
  67. /** Encoding (differential sequential) */
  68.  
  69. const SOF5 = 0xC5;
  70. /** Encoding (differential progressive) */
  71.  
  72. const SOF6 = 0xC6;
  73. /** Encoding (differential lossless) */
  74.  
  75. const SOF7 = 0xC7;
  76. /** Extension */
  77.  
  78. const JPG = 0xC8;
  79. /** Encoding (extended sequential, arithmetic) */
  80.  
  81. const SOF9 = 0xC9;
  82. /** Encoding (progressive, arithmetic) */
  83.  
  84. const SOF10 = 0xCA;
  85. /** Encoding (lossless, arithmetic) */
  86.  
  87. const SOF11 = 0xCB;
  88. /** Define arithmetic coding conditioning */
  89.  
  90. const DAC = 0xCC;
  91. /** Encoding (differential sequential, arithmetic) */
  92.  
  93. const SOF13 = 0xCD;
  94. /** Encoding (differential progressive, arithmetic) */
  95.  
  96. const SOF14 = 0xCE;
  97. /** Encoding (differential lossless, arithmetic) */
  98.  
  99. const SOF15 = 0xCF;
  100. /** Restart 0 */
  101.  
  102. const RST0 = 0xD0;
  103. /** Restart 1 */
  104.  
  105. const RST1 = 0xD1;
  106. /** Restart 2 */
  107.  
  108. const RST2 = 0xD2;
  109. /** Restart 3 */
  110.  
  111. const RST3 = 0xD3;
  112. /** Restart 4 */
  113.  
  114. const RST4 = 0xD4;
  115. /** Restart 5 */
  116.  
  117. const RST5 = 0xD5;
  118. /** Restart 6 */
  119.  
  120. const RST6 = 0xD6;
  121. /** Restart 7 */
  122.  
  123. const RST7 = 0xD7;
  124. /** Start of image */
  125.  
  126. const SOI = 0xD8;
  127. /** End of image */
  128.  
  129. const EOI = 0xD9;
  130. /** Start of scan */
  131.  
  132. const SOS = 0xDA;
  133. /** Define quantization table */
  134.  
  135. const DQT = 0xDB;
  136. /** Define number of lines */
  137.  
  138. const DNL = 0xDC;
  139. /** Define restart interval */
  140.  
  141. const DRI = 0xDD;
  142. /** Define hierarchical progression */
  143.  
  144. const DHP = 0xDE;
  145. /** Expand reference component */
  146.  
  147. const EXP = 0xDF;
  148. /** Application segment 0 */
  149.  
  150. const APP0 = 0xE0;
  151. /**
  152. * Application segment 1
  153. *
  154. * When a JPEG image contains EXIF data, the data will normally be
  155. * stored in this section. A call to {@link PelJpeg::getSection()}
  156. * with this marker as argument will then return a {@link PelExif}
  157. * object.
  158. */
  159. const APP1 = 0xE1;
  160. /** Application segment 2 */
  161.  
  162. const APP2 = 0xE2;
  163. /** Application segment 3 */
  164.  
  165. const APP3 = 0xE3;
  166. /** Application segment 4 */
  167.  
  168. const APP4 = 0xE4;
  169. /** Application segment 5 */
  170.  
  171. const APP5 = 0xE5;
  172. /** Application segment 6 */
  173.  
  174. const APP6 = 0xE6;
  175. /** Application segment 7 */
  176.  
  177. const APP7 = 0xE7;
  178. /** Application segment 8 */
  179.  
  180. const APP8 = 0xE8;
  181. /** Application segment 9 */
  182.  
  183. const APP9 = 0xE9;
  184. /** Application segment 10 */
  185.  
  186. const APP10 = 0xEA;
  187. /** Application segment 11 */
  188.  
  189. const APP11 = 0xEB;
  190. /** Application segment 12 */
  191.  
  192. const APP12 = 0xEC;
  193. /** Application segment 13 */
  194.  
  195. const APP13 = 0xED;
  196. /** Application segment 14 */
  197.  
  198. const APP14 = 0xEE;
  199. /** Application segment 15 */
  200.  
  201. const APP15 = 0xEF;
  202. /** Extension 0 */
  203.  
  204. const JPG0 = 0xF0;
  205. /** Extension 1 */
  206.  
  207. const JPG1 = 0xF1;
  208. /** Extension 2 */
  209.  
  210. const JPG2 = 0xF2;
  211. /** Extension 3 */
  212.  
  213. const JPG3 = 0xF3;
  214. /** Extension 4 */
  215.  
  216. const JPG4 = 0xF4;
  217. /** Extension 5 */
  218.  
  219. const JPG5 = 0xF5;
  220. /** Extension 6 */
  221.  
  222. const JPG6 = 0xF6;
  223. /** Extension 7 */
  224.  
  225. const JPG7 = 0xF7;
  226. /** Extension 8 */
  227.  
  228. const JPG8 = 0xF8;
  229. /** Extension 9 */
  230.  
  231. const JPG9 = 0xF9;
  232. /** Extension 10 */
  233.  
  234. const JPG10 = 0xFA;
  235. /** Extension 11 */
  236.  
  237. const JPG11 = 0xFB;
  238. /** Extension 12 */
  239.  
  240. const JPG12 = 0xFC;
  241. /** Extension 13 */
  242.  
  243. const JPG13 = 0xFD;
  244. /** Comment */
  245.  
  246. const COM = 0xFE;
  247.  
  248. /**
  249. * Check if a byte is a valid JPEG marker.
  250. *
  251. * @param PelJpegMarker the byte that will be checked.
  252. *
  253. * @return boolean if the byte is recognized true is returned,
  254. * otherwise false will be returned.
  255. */
  256. static function isValid($m) {
  257. return ($m >= self::SOF0 && $m <= self::COM);
  258. }
  259. /**
  260. * Turn a JPEG marker into bytes.
  261. *
  262. * @param PelJpegMarker the marker.
  263. *
  264. * @return string the marker as a string. This will be a string
  265. * with just a single byte since all JPEG markers are simply single
  266. * bytes.
  267. */
  268. static function getBytes($m) {
  269. return chr($m);
  270. }
  271.  
  272. /**
  273. * Return the short name for a marker.
  274. *
  275. * @param PelJpegMarker the marker.
  276. *
  277. * @return string the name of the marker, e.g., 'SOI' for the Start
  278. * of Image marker.
  279. */
  280. static function getName($m) {
  281. switch ($m) {
  282. case self::SOF0: return 'SOF0';
  283. case self::SOF1: return 'SOF1';
  284. case self::SOF2: return 'SOF2';
  285. case self::SOF3: return 'SOF3';
  286. case self::SOF5: return 'SOF5';
  287. case self::SOF6: return 'SOF6';
  288. case self::SOF7: return 'SOF7';
  289. case self::SOF9: return 'SOF9';
  290. case self::SOF10: return 'SOF10';
  291. case self::SOF11: return 'SOF11';
  292. case self::SOF13: return 'SOF13';
  293. case self::SOF14: return 'SOF14';
  294. case self::SOF15: return 'SOF15';
  295. case self::SOI: return 'SOI';
  296. case self::EOI: return 'EOI';
  297. case self::SOS: return 'SOS';
  298. case self::COM: return 'COM';
  299. case self::DHT: return 'DHT';
  300. case self::JPG: return 'JPG';
  301. case self::DAC: return 'DAC';
  302. case self::RST0: return 'RST0';
  303. case self::RST1: return 'RST1';
  304. case self::RST2: return 'RST2';
  305. case self::RST3: return 'RST3';
  306. case self::RST4: return 'RST4';
  307. case self::RST5: return 'RST5';
  308. case self::RST6: return 'RST6';
  309. case self::RST7: return 'RST7';
  310. case self::DQT: return 'DQT';
  311. case self::DNL: return 'DNL';
  312. case self::DRI: return 'DRI';
  313. case self::DHP: return 'DHP';
  314. case self::EXP: return 'EXP';
  315. case self::APP0: return 'APP0';
  316. case self::APP1: return 'APP1';
  317. case self::APP2: return 'APP2';
  318. case self::APP3: return 'APP3';
  319. case self::APP4: return 'APP4';
  320. case self::APP5: return 'APP5';
  321. case self::APP6: return 'APP6';
  322. case self::APP7: return 'APP7';
  323. case self::APP8: return 'APP8';
  324. case self::APP9: return 'APP9';
  325. case self::APP10: return 'APP10';
  326. case self::APP11: return 'APP11';
  327. case self::APP12: return 'APP12';
  328. case self::APP13: return 'APP13';
  329. case self::APP14: return 'APP14';
  330. case self::APP15: return 'APP15';
  331. case self::JPG0: return 'JPG0';
  332. case self::JPG1: return 'JPG1';
  333. case self::JPG2: return 'JPG2';
  334. case self::JPG3: return 'JPG3';
  335. case self::JPG4: return 'JPG4';
  336. case self::JPG5: return 'JPG5';
  337. case self::JPG6: return 'JPG6';
  338. case self::JPG7: return 'JPG7';
  339. case self::JPG8: return 'JPG8';
  340. case self::JPG9: return 'JPG9';
  341. case self::JPG10: return 'JPG10';
  342. case self::JPG11: return 'JPG11';
  343. case self::JPG12: return 'JPG12';
  344. case self::JPG13: return 'JPG13';
  345. case self::COM: return 'COM';
  346. default: return Pel::fmt('Unknown marker: 0x%02X', $m);
  347. }
  348. }
  349.  
  350. /**
  351. * Returns a description of a JPEG marker.
  352. *
  353. * @param PelJpegMarker the marker.
  354. *
  355. * @return string the description of the marker.
  356. */
  357. static function getDescription($m) {
  358. switch ($m) {
  359. case self::SOF0:
  360. return Pel::tra('Encoding (baseline)');
  361. case self::SOF1:
  362. return Pel::tra('Encoding (extended sequential)');
  363. case self::SOF2:
  364. return Pel::tra('Encoding (progressive)');
  365. case self::SOF3:
  366. return Pel::tra('Encoding (lossless)');
  367. case self::SOF5:
  368. return Pel::tra('Encoding (differential sequential)');
  369. case self::SOF6:
  370. return Pel::tra('Encoding (differential progressive)');
  371. case self::SOF7:
  372. return Pel::tra('Encoding (differential lossless)');
  373. case self::SOF9:
  374. return Pel::tra('Encoding (extended sequential, arithmetic)');
  375. case self::SOF10:
  376. return Pel::tra('Encoding (progressive, arithmetic)');
  377. case self::SOF11:
  378. return Pel::tra('Encoding (lossless, arithmetic)');
  379. case self::SOF13:
  380. return Pel::tra('Encoding (differential sequential, arithmetic)');
  381. case self::SOF14:
  382. return Pel::tra('Encoding (differential progressive, arithmetic)');
  383. case self::SOF15:
  384. return Pel::tra('Encoding (differential lossless, arithmetic)');
  385. case self::SOI:
  386. return Pel::tra('Start of image');
  387. case self::EOI:
  388. return Pel::tra('End of image');
  389. case self::SOS:
  390. return Pel::tra('Start of scan');
  391. case self::COM:
  392. return Pel::tra('Comment');
  393. case self::DHT:
  394. return Pel::tra('Define Huffman table');
  395. case self::JPG:
  396. return Pel::tra('Extension');
  397. case self::DAC:
  398. return Pel::tra('Define arithmetic coding conditioning');
  399. case self::RST0:
  400. return Pel::tra('Restart 0');
  401. case self::RST1:
  402. return Pel::tra('Restart 1');
  403. case self::RST2:
  404. return Pel::tra('Restart 2');
  405. case self::RST3:
  406. return Pel::tra('Restart 3');
  407. case self::RST4:
  408. return Pel::tra('Restart 4');
  409. case self::RST5:
  410. return Pel::tra('Restart 5');
  411. case self::RST6:
  412. return Pel::tra('Restart 6');
  413. case self::RST7:
  414. return Pel::tra('Restart 7');
  415. case self::DQT:
  416. return Pel::tra('Define quantization table');
  417. case self::DNL:
  418. return Pel::tra('Define number of lines');
  419. case self::DRI:
  420. return Pel::tra('Define restart interval');
  421. case self::DHP:
  422. return Pel::tra('Define hierarchical progression');
  423. case self::EXP:
  424. return Pel::tra('Expand reference component');
  425. case self::APP0:
  426. return Pel::tra('Application segment 0');
  427. case self::APP1:
  428. return Pel::tra('Application segment 1');
  429. case self::APP2:
  430. return Pel::tra('Application segment 2');
  431. case self::APP3:
  432. return Pel::tra('Application segment 3');
  433. case self::APP4:
  434. return Pel::tra('Application segment 4');
  435. case self::APP5:
  436. return Pel::tra('Application segment 5');
  437. case self::APP6:
  438. return Pel::tra('Application segment 6');
  439. case self::APP7:
  440. return Pel::tra('Application segment 7');
  441. case self::APP8:
  442. return Pel::tra('Application segment 8');
  443. case self::APP9:
  444. return Pel::tra('Application segment 9');
  445. case self::APP10:
  446. return Pel::tra('Application segment 10');
  447. case self::APP11:
  448. return Pel::tra('Application segment 11');
  449. case self::APP12:
  450. return Pel::tra('Application segment 12');
  451. case self::APP13:
  452. return Pel::tra('Application segment 13');
  453. case self::APP14:
  454. return Pel::tra('Application segment 14');
  455. case self::APP15:
  456. return Pel::tra('Application segment 15');
  457. case self::JPG0:
  458. return Pel::tra('Extension 0');
  459. case self::JPG1:
  460. return Pel::tra('Extension 1');
  461. case self::JPG2:
  462. return Pel::tra('Extension 2');
  463. case self::JPG3:
  464. return Pel::tra('Extension 3');
  465. case self::JPG4:
  466. return Pel::tra('Extension 4');
  467. case self::JPG5:
  468. return Pel::tra('Extension 5');
  469. case self::JPG6:
  470. return Pel::tra('Extension 6');
  471. case self::JPG7:
  472. return Pel::tra('Extension 7');
  473. case self::JPG8:
  474. return Pel::tra('Extension 8');
  475. case self::JPG9:
  476. return Pel::tra('Extension 9');
  477. case self::JPG10:
  478. return Pel::tra('Extension 10');
  479. case self::JPG11:
  480. return Pel::tra('Extension 11');
  481. case self::JPG12:
  482. return Pel::tra('Extension 12');
  483. case self::JPG13:
  484. return Pel::tra('Extension 13');
  485. case self::COM:
  486. return Pel::tra('Comment');
  487. default:
  488. return Pel::fmt('Unknown marker: 0x%02X', $m);
  489. }
  490. }
  491. }
  492.  
  493. ?>

SourceForge.net Logo Documentation generated on Fri, 18 Feb 2005 01:43:21 +0100 by phpDocumentor 1.3.0RC3