22 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
23 $TIFFheader = fread($fd, 4);
25 switch (substr($TIFFheader, 0, 2)) {
27 $ThisFileInfo[
'tiff'][
'byte_order'] =
'Intel';
30 $ThisFileInfo[
'tiff'][
'byte_order'] =
'Motorola';
33 $ThisFileInfo[
'error'][] =
'Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).
') at offset '.$ThisFileInfo[
'avdataoffset'];
38 $ThisFileInfo[
'fileformat'] =
'tiff';
39 $ThisFileInfo[
'video'][
'dataformat'] =
'tiff';
40 $ThisFileInfo[
'video'][
'lossless'] =
true;
41 $ThisFileInfo[
'tiff'][
'ifd'] = array();
42 $CurrentIFD = array();
44 $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
46 $nextIFDoffset = $this->
TIFFendian2Int(fread($fd, 4), $ThisFileInfo[
'tiff'][
'byte_order']);
48 while ($nextIFDoffset > 0) {
50 $CurrentIFD[
'offset'] = $nextIFDoffset;
52 fseek($fd, $ThisFileInfo[
'avdataoffset'] + $nextIFDoffset, SEEK_SET);
53 $CurrentIFD[
'fieldcount'] = $this->
TIFFendian2Int(fread($fd, 2), $ThisFileInfo[
'tiff'][
'byte_order']);
55 for ($i = 0; $i < $CurrentIFD[
'fieldcount']; $i++) {
56 $CurrentIFD[
'fields'][$i][
'raw'][
'tag'] = $this->
TIFFendian2Int(fread($fd, 2), $ThisFileInfo[
'tiff'][
'byte_order']);
57 $CurrentIFD[
'fields'][$i][
'raw'][
'type'] = $this->
TIFFendian2Int(fread($fd, 2), $ThisFileInfo[
'tiff'][
'byte_order']);
58 $CurrentIFD[
'fields'][$i][
'raw'][
'length'] = $this->
TIFFendian2Int(fread($fd, 4), $ThisFileInfo[
'tiff'][
'byte_order']);
59 $CurrentIFD[
'fields'][$i][
'raw'][
'offset'] = fread($fd, 4);
61 switch ($CurrentIFD[
'fields'][$i][
'raw'][
'type']) {
63 if ($CurrentIFD[
'fields'][$i][
'raw'][
'length'] <= 4) {
64 $CurrentIFD[
'fields'][$i][
'value'] = $this->
TIFFendian2Int(substr($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], 0, 1), $ThisFileInfo[
'tiff'][
'byte_order']);
66 $CurrentIFD[
'fields'][$i][
'offset'] = $this->
TIFFendian2Int($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], $ThisFileInfo[
'tiff'][
'byte_order']);
71 if ($CurrentIFD[
'fields'][$i][
'raw'][
'length'] <= 4) {
72 $CurrentIFD[
'fields'][$i][
'value'] = substr($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], 3);
74 $CurrentIFD[
'fields'][$i][
'offset'] = $this->
TIFFendian2Int($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], $ThisFileInfo[
'tiff'][
'byte_order']);
79 if ($CurrentIFD[
'fields'][$i][
'raw'][
'length'] <= 2) {
80 $CurrentIFD[
'fields'][$i][
'value'] = $this->
TIFFendian2Int(substr($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], 0, 2), $ThisFileInfo[
'tiff'][
'byte_order']);
82 $CurrentIFD[
'fields'][$i][
'offset'] = $this->
TIFFendian2Int($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], $ThisFileInfo[
'tiff'][
'byte_order']);
87 if ($CurrentIFD[
'fields'][$i][
'raw'][
'length'] <= 1) {
88 $CurrentIFD[
'fields'][$i][
'value'] = $this->
TIFFendian2Int($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], $ThisFileInfo[
'tiff'][
'byte_order']);
90 $CurrentIFD[
'fields'][$i][
'offset'] = $this->
TIFFendian2Int($CurrentIFD[
'fields'][$i][
'raw'][
'offset'], $ThisFileInfo[
'tiff'][
'byte_order']);
99 $ThisFileInfo[
'tiff'][
'ifd'][] = $CurrentIFD;
100 $CurrentIFD = array();
101 $nextIFDoffset = $this->
TIFFendian2Int(fread($fd, 4), $ThisFileInfo[
'tiff'][
'byte_order']);
105 foreach ($ThisFileInfo[
'tiff'][
'ifd'] as $IFDid => $IFDarray) {
106 foreach ($IFDarray[
'fields'] as $key => $fieldarray) {
107 switch ($fieldarray[
'raw'][
'tag']) {
112 if (!isset($fieldarray[
'value'])) {
113 fseek($fd, $fieldarray[
'offset'], SEEK_SET);
114 $ThisFileInfo[
'tiff'][
'ifd'][$IFDid][
'fields'][$key][
'raw'][
'data'] = fread($fd, $fieldarray[
'raw'][
'length'] * $FieldTypeByteLength[$fieldarray[
'raw'][
'type']]);
126 if (isset($fieldarray[
'value'])) {
127 $ThisFileInfo[
'tiff'][
'ifd'][$IFDid][
'fields'][$key][
'raw'][
'data'] = $fieldarray[
'value'];
129 fseek($fd, $fieldarray[
'offset'], SEEK_SET);
130 $ThisFileInfo[
'tiff'][
'ifd'][$IFDid][
'fields'][$key][
'raw'][
'data'] = fread($fd, $fieldarray[
'raw'][
'length'] * $FieldTypeByteLength[$fieldarray[
'raw'][
'type']]);
135 switch ($fieldarray[
'raw'][
'tag']) {
137 $ThisFileInfo[
'video'][
'resolution_x'] = $fieldarray[
'value'];
141 $ThisFileInfo[
'video'][
'resolution_y'] = $fieldarray[
'value'];
145 if (isset($fieldarray[
'value'])) {
146 $ThisFileInfo[
'video'][
'bits_per_sample'] = $fieldarray[
'value'];
148 $ThisFileInfo[
'video'][
'bits_per_sample'] = 0;
149 for ($i = 0; $i < $fieldarray[
'raw'][
'length']; $i++) {
150 $ThisFileInfo[
'video'][
'bits_per_sample'] += $this->
TIFFendian2Int(substr($ThisFileInfo[
'tiff'][
'ifd'][$IFDid][
'fields'][$key][
'raw'][
'data'], $i * $FieldTypeByteLength[$fieldarray[
'raw'][
'type']], $FieldTypeByteLength[$fieldarray[
'raw'][
'type']]), $ThisFileInfo[
'tiff'][
'byte_order']);
166 @$ThisFileInfo[
'tiff'][
'comments'][$this->
TIFFcommentName($fieldarray[
'raw'][
'tag'])][] = $ThisFileInfo[
'tiff'][
'ifd'][$IFDid][
'fields'][$key][
'raw'][
'data'];
180 if ($byteorder ==
'Intel') {
182 } elseif ($byteorder ==
'Motorola') {
189 static $TIFFcompressionMethod = array();
190 if (empty($TIFFcompressionMethod)) {
191 $TIFFcompressionMethod = array(
194 3 =>
'Fax - CCITT 3',
199 return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] :
'unknown/invalid ('.$id.
')');
203 static $TIFFcommentName = array();
204 if (empty($TIFFcommentName)) {
205 $TIFFcommentName = array(
206 270 =>
'imagedescription',
212 316 =>
'hostcomputer',
215 return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] :
'unknown/invalid ('.$id.
')');