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 <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. /* PelJpegMarker.php,v 1.7 2004/07/20 16:09:25 gimpster Exp */
  25.  
  26.  
  27. /**
  28. * Classes for dealing with JPEG markers.
  29. *
  30. * @author Martin Geisler <gimpster@users.sourceforge.net>
  31. * @version 1.7
  32. * @date 2004/07/20 16:09:25
  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. /** Application segment 1 */
  152.  
  153. const APP1 = 0xE1;
  154. /** Application segment 2 */
  155.  
  156. const APP2 = 0xE2;
  157. /** Application segment 3 */
  158.  
  159. const APP3 = 0xE3;
  160. /** Application segment 4 */
  161.  
  162. const APP4 = 0xE4;
  163. /** Application segment 5 */
  164.  
  165. const APP5 = 0xE5;
  166. /** Application segment 6 */
  167.  
  168. const APP6 = 0xE6;
  169. /** Application segment 7 */
  170.  
  171. const APP7 = 0xE7;
  172. /** Application segment 8 */
  173.  
  174. const APP8 = 0xE8;
  175. /** Application segment 9 */
  176.  
  177. const APP9 = 0xE9;
  178. /** Application segment 10 */
  179.  
  180. const APP10 = 0xEA;
  181. /** Application segment 11 */
  182.  
  183. const APP11 = 0xEB;
  184. /** Application segment 12 */
  185.  
  186. const APP12 = 0xEC;
  187. /** Application segment 13 */
  188.  
  189. const APP13 = 0xED;
  190. /** Application segment 14 */
  191.  
  192. const APP14 = 0xEE;
  193. /** Application segment 15 */
  194.  
  195. const APP15 = 0xEF;
  196. /** Extension 0 */
  197.  
  198. const JPG0 = 0xF0;
  199. /** Extension 1 */
  200.  
  201. const JPG1 = 0xF1;
  202. /** Extension 2 */
  203.  
  204. const JPG2 = 0xF2;
  205. /** Extension 3 */
  206.  
  207. const JPG3 = 0xF3;
  208. /** Extension 4 */
  209.  
  210. const JPG4 = 0xF4;
  211. /** Extension 5 */
  212.  
  213. const JPG5 = 0xF5;
  214. /** Extension 6 */
  215.  
  216. const JPG6 = 0xF6;
  217. /** Extension 7 */
  218.  
  219. const JPG7 = 0xF7;
  220. /** Extension 8 */
  221.  
  222. const JPG8 = 0xF8;
  223. /** Extension 9 */
  224.  
  225. const JPG9 = 0xF9;
  226. /** Extension 10 */
  227.  
  228. const JPG10 = 0xFA;
  229. /** Extension 11 */
  230.  
  231. const JPG11 = 0xFB;
  232. /** Extension 12 */
  233.  
  234. const JPG12 = 0xFC;
  235. /** Extension 13 */
  236.  
  237. const JPG13 = 0xFD;
  238. /** Comment */
  239.  
  240. const COM = 0xFE;
  241.  
  242. /**
  243. * Check if a byte is a valid JPEG marker.
  244. *
  245. * @param PelJpegMarker the byte that will be checked.
  246. *
  247. * @return boolean if the byte is recognized true is returned,
  248. * otherwise false will be returned.
  249. */
  250. static function isValid($m) {
  251. return ($m >= self::SOF0 && $m <= self::COM);
  252. }
  253. /**
  254. * Turn a JPEG marker into bytes.
  255. *
  256. * @param PelJpegMarker the marker.
  257. *
  258. * @return string the marker as a string. This will be a string
  259. * with just a single byte since all JPEG markers are simply single
  260. * bytes.
  261. */
  262. static function getBytes($m) {
  263. return chr($m);
  264. }
  265.  
  266. /**
  267. * Return the short name for a marker.
  268. *
  269. * @param PelJpegMarker the marker.
  270. *
  271. * @return string the name of the marker, e.g., 'SOI' for the Start
  272. * of Image marker.
  273. */
  274. static function getName($m) {
  275. switch ($m) {
  276. case self::SOF0: return 'SOF0';
  277. case self::SOF1: return 'SOF1';
  278. case self::SOF2: return 'SOF2';
  279. case self::SOF3: return 'SOF3';
  280. case self::SOF5: return 'SOF5';
  281. case self::SOF6: return 'SOF6';
  282. case self::SOF7: return 'SOF7';
  283. case self::SOF9: return 'SOF9';
  284. case self::SOF10: return 'SOF10';
  285. case self::SOF11: return 'SOF11';
  286. case self::SOF13: return 'SOF13';
  287. case self::SOF14: return 'SOF14';
  288. case self::SOF15: return 'SOF15';
  289. case self::SOI: return 'SOI';
  290. case self::EOI: return 'EOI';
  291. case self::SOS: return 'SOS';
  292. case self::COM: return 'COM';
  293. case self::DHT: return 'DHT';
  294. case self::JPG: return 'JPG';
  295. case self::DAC: return 'DAC';
  296. case self::RST0: return 'RST0';
  297. case self::RST1: return 'RST1';
  298. case self::RST2: return 'RST2';
  299. case self::RST3: return 'RST3';
  300. case self::RST4: return 'RST4';
  301. case self::RST5: return 'RST5';
  302. case self::RST6: return 'RST6';
  303. case self::RST7: return 'RST7';
  304. case self::DQT: return 'DQT';
  305. case self::DNL: return 'DNL';
  306. case self::DRI: return 'DRI';
  307. case self::DHP: return 'DHP';
  308. case self::EXP: return 'EXP';
  309. case self::APP0: return 'APP0';
  310. case self::APP1: return 'APP1';
  311. case self::APP2: return 'APP2';
  312. case self::APP3: return 'APP3';
  313. case self::APP4: return 'APP4';
  314. case self::APP5: return 'APP5';
  315. case self::APP6: return 'APP6';
  316. case self::APP7: return 'APP7';
  317. case self::APP8: return 'APP8';
  318. case self::APP9: return 'APP9';
  319. case self::APP10: return 'APP10';
  320. case self::APP11: return 'APP11';
  321. case self::APP12: return 'APP12';
  322. case self::APP13: return 'APP13';
  323. case self::APP14: return 'APP14';
  324. case self::APP15: return 'APP15';
  325. case self::JPG0: return 'JPG0';
  326. case self::JPG1: return 'JPG1';
  327. case self::JPG2: return 'JPG2';
  328. case self::JPG3: return 'JPG3';
  329. case self::JPG4: return 'JPG4';
  330. case self::JPG5: return 'JPG5';
  331. case self::JPG6: return 'JPG6';
  332. case self::JPG7: return 'JPG7';
  333. case self::JPG8: return 'JPG8';
  334. case self::JPG9: return 'JPG9';
  335. case self::JPG10: return 'JPG10';
  336. case self::JPG11: return 'JPG11';
  337. case self::JPG12: return 'JPG12';
  338. case self::JPG13: return 'JPG13';
  339. case self::COM: return 'COM';
  340. default: return Pel::fmt('Unknown marker: 0x%02X', $m);
  341. }
  342. }
  343.  
  344. /**
  345. * Returns a description of a JPEG marker.
  346. *
  347. * @param PelJpegMarker the marker.
  348. *
  349. * @return string the description of the marker.
  350. */
  351. static function getDescription($m) {
  352. switch ($m) {
  353. case self::SOF0:
  354. return Pel::tra('Encoding (baseline)');
  355. case self::SOF1:
  356. return Pel::tra('Encoding (extended sequential)');
  357. case self::SOF2:
  358. return Pel::tra('Encoding (progressive)');
  359. case self::SOF3:
  360. return Pel::tra('Encoding (lossless)');
  361. case self::SOF5:
  362. return Pel::tra('Encoding (differential sequential)');
  363. case self::SOF6:
  364. return Pel::tra('Encoding (differential progressive)');
  365. case self::SOF7:
  366. return Pel::tra('Encoding (differential lossless)');
  367. case self::SOF9:
  368. return Pel::tra('Encoding (extended sequential, arithmetic)');
  369. case self::SOF10:
  370. return Pel::tra('Encoding (progressive, arithmetic)');
  371. case self::SOF11:
  372. return Pel::tra('Encoding (lossless, arithmetic)');
  373. case self::SOF13:
  374. return Pel::tra('Encoding (differential sequential, arithmetic)');
  375. case self::SOF14:
  376. return Pel::tra('Encoding (differential progressive, arithmetic)');
  377. case self::SOF15:
  378. return Pel::tra('Encoding (differential lossless, arithmetic)');
  379. case self::SOI:
  380. return Pel::tra('Start of image');
  381. case self::EOI:
  382. return Pel::tra('End of image');
  383. case self::SOS:
  384. return Pel::tra('Start of scan');
  385. case self::COM:
  386. return Pel::tra('Comment');
  387. case self::DHT:
  388. return Pel::tra('Define Huffman table');
  389. case self::JPG:
  390. return Pel::tra('Extension');
  391. case self::DAC:
  392. return Pel::tra('Define arithmetic coding conditioning');
  393. case self::RST0:
  394. return Pel::tra('Restart 0');
  395. case self::RST1:
  396. return Pel::tra('Restart 1');
  397. case self::RST2:
  398. return Pel::tra('Restart 2');
  399. case self::RST3:
  400. return Pel::tra('Restart 3');
  401. case self::RST4:
  402. return Pel::tra('Restart 4');
  403. case self::RST5:
  404. return Pel::tra('Restart 5');
  405. case self::RST6:
  406. return Pel::tra('Restart 6');
  407. case self::RST7:
  408. return Pel::tra('Restart 7');
  409. case self::DQT:
  410. return Pel::tra('Define quantization table');
  411. case self::DNL:
  412. return Pel::tra('Define number of lines');
  413. case self::DRI:
  414. return Pel::tra('Define restart interval');
  415. case self::DHP:
  416. return Pel::tra('Define hierarchical progression');
  417. case self::EXP:
  418. return Pel::tra('Expand reference component');
  419. case self::APP0:
  420. return Pel::tra('Application segment 0');
  421. case self::APP1:
  422. return Pel::tra('Application segment 1');
  423. case self::APP2:
  424. return Pel::tra('Application segment 2');
  425. case self::APP3:
  426. return Pel::tra('Application segment 3');
  427. case self::APP4:
  428. return Pel::tra('Application segment 4');
  429. case self::APP5:
  430. return Pel::tra('Application segment 5');
  431. case self::APP6:
  432. return Pel::tra('Application segment 6');
  433. case self::APP7:
  434. return Pel::tra('Application segment 7');
  435. case self::APP8:
  436. return Pel::tra('Application segment 8');
  437. case self::APP9:
  438. return Pel::tra('Application segment 9');
  439. case self::APP10:
  440. return Pel::tra('Application segment 10');
  441. case self::APP11:
  442. return Pel::tra('Application segment 11');
  443. case self::APP12:
  444. return Pel::tra('Application segment 12');
  445. case self::APP13:
  446. return Pel::tra('Application segment 13');
  447. case self::APP14:
  448. return Pel::tra('Application segment 14');
  449. case self::APP15:
  450. return Pel::tra('Application segment 15');
  451. case self::JPG0:
  452. return Pel::tra('Extension 0');
  453. case self::JPG1:
  454. return Pel::tra('Extension 1');
  455. case self::JPG2:
  456. return Pel::tra('Extension 2');
  457. case self::JPG3:
  458. return Pel::tra('Extension 3');
  459. case self::JPG4:
  460. return Pel::tra('Extension 4');
  461. case self::JPG5:
  462. return Pel::tra('Extension 5');
  463. case self::JPG6:
  464. return Pel::tra('Extension 6');
  465. case self::JPG7:
  466. return Pel::tra('Extension 7');
  467. case self::JPG8:
  468. return Pel::tra('Extension 8');
  469. case self::JPG9:
  470. return Pel::tra('Extension 9');
  471. case self::JPG10:
  472. return Pel::tra('Extension 10');
  473. case self::JPG11:
  474. return Pel::tra('Extension 11');
  475. case self::JPG12:
  476. return Pel::tra('Extension 12');
  477. case self::JPG13:
  478. return Pel::tra('Extension 13');
  479. case self::COM:
  480. return Pel::tra('Comment');
  481. default:
  482. return Pel::fmt('Unknown marker: 0x%02X', $m);
  483. }
  484. }
  485. }
  486.  
  487. ?>

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