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, 2006 Martin Geisler.
9 * Copyright (C) 2017 Johannes Weberhofer.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program in the file COPYING; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 * Boston, MA 02110-1301 USA
26 namespace lsolesen\pel;
29 * Classes for dealing with JPEG markers.
31 * This class defines the constants to be used whenever one refers to
32 * a JPEG marker. All the methods defined are static, and they all
33 * operate on one argument which should be one of the class constants.
34 * They will all be denoted by PelJpegMarker in the documentation.
36 * @author Martin Geisler <mgeisler@users.sourceforge.net>
37 * @author Johannes Weberhofer <jweberhofer@weberhofer.at>
39 * @license http://www.gnu.org/licenses/gpl.html GNU General Public
52 * Encoding (extended sequential)
57 * Encoding (progressive)
67 * Define Huffman table
72 * Encoding (differential sequential)
77 * Encoding (differential progressive)
82 * Encoding (differential lossless)
92 * Encoding (extended sequential, arithmetic)
97 * Encoding (progressive, arithmetic)
102 * Encoding (lossless, arithmetic)
107 * Define arithmetic coding conditioning
112 * Encoding (differential sequential, arithmetic)
117 * Encoding (differential progressive, arithmetic)
122 * Encoding (differential lossless, arithmetic)
182 * Define quantization table
187 * Define number of lines
192 * Define restart interval
197 * Define hierarchical progression
202 * Expand reference component
207 * Application segment 0
212 * Application segment 1
214 * When a JPEG image contains Exif data, the data will normally be
215 * stored in this section and a call to {@link PelJpeg::getExif()}
216 * will return a {@link PelExif} object representing it.
221 * Application segment 2
226 * Application segment 3
231 * Application segment 4
236 * Application segment 5
241 * Application segment 6
246 * Application segment 7
251 * Application segment 8
256 * Application segment 9
261 * Application segment 10
266 * Application segment 11
271 * Application segment 12
276 * Application segment 13
281 * Application segment 14
286 * Application segment 15
366 * Values for marker's short names
368 protected static $jpegMarkerShort = array(
369 self::SOF0 => 'SOF0',
370 self::SOF1 => 'SOF1',
371 self::SOF2 => 'SOF2',
372 self::SOF3 => 'SOF3',
373 self::SOF5 => 'SOF5',
374 self::SOF6 => 'SOF6',
375 self::SOF7 => 'SOF7',
376 self::SOF9 => 'SOF9',
377 self::SOF10 => 'SOF10',
378 self::SOF11 => 'SOF11',
379 self::SOF13 => 'SOF13',
380 self::SOF14 => 'SOF14',
381 self::SOF15 => 'SOF15',
389 self::RST0 => 'RST0',
390 self::RST1 => 'RST1',
391 self::RST2 => 'RST2',
392 self::RST3 => 'RST3',
393 self::RST4 => 'RST4',
394 self::RST5 => 'RST5',
395 self::RST6 => 'RST6',
396 self::RST7 => 'RST7',
402 self::APP0 => 'APP0',
403 self::APP1 => 'APP1',
404 self::APP2 => 'APP2',
405 self::APP3 => 'APP3',
406 self::APP4 => 'APP4',
407 self::APP5 => 'APP5',
408 self::APP6 => 'APP6',
409 self::APP7 => 'APP7',
410 self::APP8 => 'APP8',
411 self::APP9 => 'APP9',
412 self::APP10 => 'APP10',
413 self::APP11 => 'APP11',
414 self::APP12 => 'APP12',
415 self::APP13 => 'APP13',
416 self::APP14 => 'APP14',
417 self::APP15 => 'APP15',
418 self::JPG0 => 'JPG0',
419 self::JPG1 => 'JPG1',
420 self::JPG2 => 'JPG2',
421 self::JPG3 => 'JPG3',
422 self::JPG4 => 'JPG4',
423 self::JPG5 => 'JPG5',
424 self::JPG6 => 'JPG6',
425 self::JPG7 => 'JPG7',
426 self::JPG8 => 'JPG8',
427 self::JPG9 => 'JPG9',
428 self::JPG10 => 'JPG10',
429 self::JPG11 => 'JPG11',
430 self::JPG12 => 'JPG12',
431 self::JPG13 => 'JPG13',
436 * Values for marker's descriptions names.
438 protected static $jpegMarkerDescriptions = array(
439 self::SOF0 => 'Encoding (baseline)',
440 self::SOF1 => 'Encoding (extended sequential)',
441 self::SOF2 => 'Encoding (progressive)',
442 self::SOF3 => 'Encoding (lossless)',
443 self::SOF5 => 'Encoding (differential sequential)',
444 self::SOF6 => 'Encoding (differential progressive)',
445 self::SOF7 => 'Encoding (differential lossless)',
446 self::SOF9 => 'Encoding (extended sequential, arithmetic)',
447 self::SOF10 => 'Encoding (progressive, arithmetic)',
448 self::SOF11 => 'Encoding (lossless, arithmetic)',
449 self::SOF13 => 'Encoding (differential sequential, arithmetic)',
450 self::SOF14 => 'Encoding (differential progressive, arithmetic)',
451 self::SOF15 => 'Encoding (differential lossless, arithmetic)',
452 self::SOI => 'Start of image',
453 self::EOI => 'End of image',
454 self::SOS => 'Start of scan',
455 self::COM => 'Comment',
456 self::DHT => 'Define Huffman table',
457 self::JPG => 'Extension',
458 self::DAC => 'Define arithmetic coding conditioning',
459 'RST' => 'Restart %d',
460 self::DQT => 'Define quantization table',
461 self::DNL => 'Define number of lines',
462 self::DRI => 'Define restart interval',
463 self::DHP => 'Define hierarchical progression',
464 self::EXP => 'Expand reference component',
465 'APP' => 'Application segment %d',
466 'JPG' => 'Extension %d',
467 self::COM => 'Comment'
471 * Check if a byte is a valid JPEG marker.
472 * If the byte is recognized true is returned, otherwise false will be returned.
474 * @param integer $marker
475 * the marker as defined in {@link PelJpegMarker}
479 public static function isValid($marker)
481 return ($marker >= self::SOF0 && $marker <= self::COM);
485 * Turn a JPEG marker into bytes.
486 * This will be a string with just a single byte since all JPEG markers are simply single bytes.
488 * @param integer $marker
489 * the marker as defined in {@link PelJpegMarker}
493 public static function getBytes($marker)
499 * Return the short name for a marker, e.g., 'SOI' for the Start
502 * @param integer $marker
503 * the marker as defined in {@link PelJpegMarker}
507 public static function getName($marker)
509 if (array_key_exists($marker, self::$jpegMarkerShort)) {
510 return self::$jpegMarkerShort[$marker];
512 return Pel::fmt('Unknown marker: 0x%02X', $marker);
517 * Returns a description of a JPEG marker.
519 * @param integer $marker
520 * the marker as defined in {@link PelJpegMarker}
524 public static function getDescription($marker)
526 if (array_key_exists($marker, self::$jpegMarkerShort)) {
527 if (array_key_exists($marker, self::$jpegMarkerDescriptions)) {
528 return self::$jpegMarkerDescriptions[$marker];
530 $splitted = preg_split(
532 self::$jpegMarkerShort[$marker],
534 PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
535 if ((count($splitted) == 2) && array_key_exists($splitted[0], self::$jpegMarkerDescriptions)) {
536 return Pel::fmt(self::$jpegMarkerDescriptions[$splitted[0]], $splitted[1]);
540 return Pel::fmt('Unknown marker: 0x%02X', $marker);