2011-07-22 08:30:52 +04:00
|
|
|
<?php
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
/// getID3() by James Heinrich <info@getid3.org> //
|
|
|
|
// available at http://getid3.sourceforge.net //
|
|
|
|
// or http://www.getid3.org //
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
// See readme.txt for more details //
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// module.archive.tiff.php //
|
|
|
|
// module for analyzing TIFF files //
|
|
|
|
// dependencies: NONE //
|
|
|
|
// ///
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
class getid3_tiff extends getid3_handler
|
2011-07-22 08:30:52 +04:00
|
|
|
{
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
function Analyze() {
|
|
|
|
$info = &$this->getid3->info;
|
2011-07-22 08:30:52 +04:00
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
|
|
|
|
$TIFFheader = fread($this->getid3->fp, 4);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
switch (substr($TIFFheader, 0, 2)) {
|
|
|
|
case 'II':
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['tiff']['byte_order'] = 'Intel';
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
case 'MM':
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['tiff']['byte_order'] = 'Motorola';
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
default:
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['error'][] = 'Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset'];
|
2011-07-22 08:30:52 +04:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['fileformat'] = 'tiff';
|
|
|
|
$info['video']['dataformat'] = 'tiff';
|
|
|
|
$info['video']['lossless'] = true;
|
|
|
|
$info['tiff']['ifd'] = array();
|
2011-07-22 08:30:52 +04:00
|
|
|
$CurrentIFD = array();
|
|
|
|
|
|
|
|
$FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
$nextIFDoffset = $this->TIFFendian2Int(fread($this->getid3->fp, 4), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
while ($nextIFDoffset > 0) {
|
|
|
|
|
|
|
|
$CurrentIFD['offset'] = $nextIFDoffset;
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
fseek($this->getid3->fp, $info['avdataoffset'] + $nextIFDoffset, SEEK_SET);
|
|
|
|
$CurrentIFD['fieldcount'] = $this->TIFFendian2Int(fread($this->getid3->fp, 2), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int(fread($this->getid3->fp, 2), $info['tiff']['byte_order']);
|
|
|
|
$CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int(fread($this->getid3->fp, 2), $info['tiff']['byte_order']);
|
|
|
|
$CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int(fread($this->getid3->fp, 4), $info['tiff']['byte_order']);
|
|
|
|
$CurrentIFD['fields'][$i]['raw']['offset'] = fread($this->getid3->fp, 4);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
switch ($CurrentIFD['fields'][$i]['raw']['type']) {
|
|
|
|
case 1: // BYTE An 8-bit unsigned integer.
|
|
|
|
if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
|
|
|
|
if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
|
|
|
|
$CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3);
|
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // SHORT A 16-bit (2-byte) unsigned integer.
|
|
|
|
if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: // LONG A 32-bit (4-byte) unsigned integer.
|
|
|
|
if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
$CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['tiff']['ifd'][] = $CurrentIFD;
|
2011-07-22 08:30:52 +04:00
|
|
|
$CurrentIFD = array();
|
2012-04-03 01:33:18 +04:00
|
|
|
$nextIFDoffset = $this->TIFFendian2Int(fread($this->getid3->fp, 4), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:33:18 +04:00
|
|
|
foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) {
|
2011-07-22 08:30:52 +04:00
|
|
|
foreach ($IFDarray['fields'] as $key => $fieldarray) {
|
|
|
|
switch ($fieldarray['raw']['tag']) {
|
|
|
|
case 256: // ImageWidth
|
|
|
|
case 257: // ImageLength
|
|
|
|
case 258: // BitsPerSample
|
|
|
|
case 259: // Compression
|
|
|
|
if (!isset($fieldarray['value'])) {
|
2012-04-03 01:33:18 +04:00
|
|
|
fseek($this->getid3->fp, $fieldarray['offset'], SEEK_SET);
|
|
|
|
$info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($this->getid3->fp, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 270: // ImageDescription
|
|
|
|
case 271: // Make
|
|
|
|
case 272: // Model
|
|
|
|
case 305: // Software
|
|
|
|
case 306: // DateTime
|
|
|
|
case 315: // Artist
|
|
|
|
case 316: // HostComputer
|
|
|
|
if (isset($fieldarray['value'])) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value'];
|
2011-07-22 08:30:52 +04:00
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
fseek($this->getid3->fp, $fieldarray['offset'], SEEK_SET);
|
|
|
|
$info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($this->getid3->fp, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch ($fieldarray['raw']['tag']) {
|
|
|
|
case 256: // ImageWidth
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['resolution_x'] = $fieldarray['value'];
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 257: // ImageLength
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['resolution_y'] = $fieldarray['value'];
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 258: // BitsPerSample
|
|
|
|
if (isset($fieldarray['value'])) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['bits_per_sample'] = $fieldarray['value'];
|
2011-07-22 08:30:52 +04:00
|
|
|
} else {
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['bits_per_sample'] = 0;
|
2011-07-22 08:30:52 +04:00
|
|
|
for ($i = 0; $i < $fieldarray['raw']['length']; $i++) {
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $info['tiff']['byte_order']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 259: // Compression
|
2012-04-03 01:33:18 +04:00
|
|
|
$info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']);
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 270: // ImageDescription
|
|
|
|
case 271: // Make
|
|
|
|
case 272: // Model
|
|
|
|
case 305: // Software
|
|
|
|
case 306: // DateTime
|
|
|
|
case 315: // Artist
|
|
|
|
case 316: // HostComputer
|
2012-04-03 01:33:18 +04:00
|
|
|
$TIFFcommentName = $this->TIFFcommentName($fieldarray['raw']['tag']);
|
|
|
|
if (isset($info['tiff']['comments'][$TIFFcommentName])) {
|
|
|
|
$info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'];
|
|
|
|
} else {
|
|
|
|
$info['tiff']['comments'][$TIFFcommentName] = array($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']);
|
|
|
|
}
|
2011-07-22 08:30:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TIFFendian2Int($bytestring, $byteorder) {
|
|
|
|
if ($byteorder == 'Intel') {
|
|
|
|
return getid3_lib::LittleEndian2Int($bytestring);
|
|
|
|
} elseif ($byteorder == 'Motorola') {
|
|
|
|
return getid3_lib::BigEndian2Int($bytestring);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function TIFFcompressionMethod($id) {
|
|
|
|
static $TIFFcompressionMethod = array();
|
|
|
|
if (empty($TIFFcompressionMethod)) {
|
|
|
|
$TIFFcompressionMethod = array(
|
|
|
|
1 => 'Uncompressed',
|
|
|
|
2 => 'Huffman',
|
|
|
|
3 => 'Fax - CCITT 3',
|
|
|
|
5 => 'LZW',
|
|
|
|
32773 => 'PackBits',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')');
|
|
|
|
}
|
|
|
|
|
|
|
|
function TIFFcommentName($id) {
|
|
|
|
static $TIFFcommentName = array();
|
|
|
|
if (empty($TIFFcommentName)) {
|
|
|
|
$TIFFcommentName = array(
|
|
|
|
270 => 'imagedescription',
|
|
|
|
271 => 'make',
|
|
|
|
272 => 'model',
|
|
|
|
305 => 'software',
|
|
|
|
306 => 'datetime',
|
|
|
|
315 => 'artist',
|
|
|
|
316 => 'hostcomputer',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|