<?php
+
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
-// available at http://getid3.sourceforge.net //
-// or http://www.getid3.org //
-// also https://github.com/JamesHeinrich/getID3 //
-/////////////////////////////////////////////////////////////////
-// See readme.txt for more details //
+// available at https://github.com/JamesHeinrich/getID3 //
+// or https://www.getid3.org //
+// or http://getid3.sourceforge.net //
+// see readme.txt for more details //
/////////////////////////////////////////////////////////////////
// //
// module.graphic.png.php //
class getid3_png extends getid3_handler
{
- public $max_data_bytes = 10000000; // if data chunk is larger than this do not read it completely (getID3 only needs the first few dozen bytes for parsing)
-
+ /**
+ * If data chunk is larger than this do not read it completely (getID3 only needs the first
+ * few dozen bytes for parsing).
+ *
+ * @var int
+ */
+ public $max_data_bytes = 10000000;
+
+ /**
+ * @return bool
+ */
public function Analyze() {
$info = &$this->getid3->info;
case 4:
case 6:
$this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
+ break;
default:
$this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
$thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk;
break;
-
case 'IEND': // Image Trailer
$thisfile_png_chunk_type_text['header'] = $chunk;
break;
+ case 'acTL': // Animation Control chunk
+ // https://wiki.mozilla.org/APNG_Specification#.60acTL.60:_The_Animation_Control_Chunk
+ $thisfile_png['animation']['num_frames'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); // Number of frames
+ $thisfile_png['animation']['num_plays'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); // Number of times to loop this APNG. 0 indicates infinite looping.
+
+ unset($chunk['data']);
+ $thisfile_png_chunk_type_text['header'] = $chunk;
+ break;
+
+ case 'fcTL': // Frame Control chunk
+ // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
+ $fcTL = array();
+ $fcTL['sequence_number'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); // Sequence number of the animation chunk, starting from 0
+ $fcTL['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); // Width of the following frame
+ $fcTL['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)); // Height of the following frame
+ $fcTL['x_offset'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)); // X position at which to render the following frame
+ $fcTL['y_offset'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)); // Y position at which to render the following frame
+ $fcTL['delay_num'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 2)); // Frame delay fraction numerator
+ $fcTL['delay_den'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 22, 2)); // Frame delay fraction numerator
+ $fcTL['dispose_op'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area disposal to be done after rendering this frame
+ $fcTL['blend_op'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area rendering for this frame
+ if ($fcTL['delay_den']) {
+ $fcTL['delay'] = $fcTL['delay_num'] / $fcTL['delay_den'];
+ }
+ $thisfile_png['animation']['fcTL'][$fcTL['sequence_number']] = $fcTL;
+
+ unset($chunk['data']);
+ $thisfile_png_chunk_type_text['header'] = $chunk;
+ break;
+
+ case 'fdAT': // Frame Data chunk
+ // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
+ // "The `fdAT` chunk has the same purpose as an `IDAT` chunk. It has the same structure as an `IDAT` chunk, except preceded by a sequence number."
+ unset($chunk['data']);
+ $thisfile_png_chunk_type_text['header'] = $chunk;
+ break;
default:
//unset($chunk['data']);
break;
}
}
-
+ if (!empty($thisfile_png['animation']['num_frames']) && !empty($thisfile_png['animation']['fcTL'])) {
+ $info['video']['dataformat'] = 'apng';
+ $info['playtime_seconds'] = 0;
+ foreach ($thisfile_png['animation']['fcTL'] as $seqno => $fcTL) {
+ $info['playtime_seconds'] += $fcTL['delay'];
+ }
+ }
return true;
}
+ /**
+ * @param int $sRGB
+ *
+ * @return string
+ */
public function PNGsRGBintentLookup($sRGB) {
static $PNGsRGBintentLookup = array(
0 => 'Perceptual',
return (isset($PNGsRGBintentLookup[$sRGB]) ? $PNGsRGBintentLookup[$sRGB] : 'invalid');
}
+ /**
+ * @param int $compressionmethod
+ *
+ * @return string
+ */
public function PNGcompressionMethodLookup($compressionmethod) {
static $PNGcompressionMethodLookup = array(
0 => 'deflate/inflate'
return (isset($PNGcompressionMethodLookup[$compressionmethod]) ? $PNGcompressionMethodLookup[$compressionmethod] : 'invalid');
}
+ /**
+ * @param int $unitid
+ *
+ * @return string
+ */
public function PNGpHYsUnitLookup($unitid) {
static $PNGpHYsUnitLookup = array(
0 => 'unknown',
return (isset($PNGpHYsUnitLookup[$unitid]) ? $PNGpHYsUnitLookup[$unitid] : 'invalid');
}
+ /**
+ * @param int $unitid
+ *
+ * @return string
+ */
public function PNGoFFsUnitLookup($unitid) {
static $PNGoFFsUnitLookup = array(
0 => 'pixel',
return (isset($PNGoFFsUnitLookup[$unitid]) ? $PNGoFFsUnitLookup[$unitid] : 'invalid');
}
+ /**
+ * @param int $equationtype
+ *
+ * @return string
+ */
public function PNGpCALequationTypeLookup($equationtype) {
static $PNGpCALequationTypeLookup = array(
0 => 'Linear mapping',
return (isset($PNGpCALequationTypeLookup[$equationtype]) ? $PNGpCALequationTypeLookup[$equationtype] : 'invalid');
}
+ /**
+ * @param int $unitid
+ *
+ * @return string
+ */
public function PNGsCALUnitLookup($unitid) {
static $PNGsCALUnitLookup = array(
0 => 'meter',
return (isset($PNGsCALUnitLookup[$unitid]) ? $PNGsCALUnitLookup[$unitid] : 'invalid');
}
+ /**
+ * @param int $color_type
+ * @param int $bit_depth
+ *
+ * @return int|false
+ */
public function IHDRcalculateBitsPerSample($color_type, $bit_depth) {
switch ($color_type) {
case 0: // Each pixel is a grayscale sample.