Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.tiff.php @ 20:1038db2374ec judyates
change address
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 08 Sep 2013 00:47:09 -0400 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+3 // | PHP version 5 |4 // +----------------------------------------------------------------------+5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |6 // +----------------------------------------------------------------------+7 // | This source file is subject to version 2 of the GPL license, |8 // | that is bundled with this package in the file license.txt and is |9 // | available through the world-wide-web at the following url: |10 // | http://www.gnu.org/copyleft/gpl.html |11 // +----------------------------------------------------------------------+12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |13 // +----------------------------------------------------------------------+14 // | Authors: James Heinrich <infoØgetid3*org> |15 // | Allan Hansen <ahØartemis*dk> |16 // +----------------------------------------------------------------------+17 // | module.graphic.tiff.php |18 // | Module for analyzing TIFF graphic files. |19 // | dependencies: NONE |20 // +----------------------------------------------------------------------+21 //22 // $Id: module.graphic.tiff.php,v 1.2 2006/11/02 10:48:02 ah Exp $26 class getid3_tiff extends getid3_handler27 {29 public function Analyze() {31 $getid3 = $this->getid3;33 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);34 $tiff_header = fread($getid3->fp, 4);36 $getid3->info['tiff']['byte_order'] = substr($tiff_header, 0, 2) == 'II' ? 'Intel' : 'Motorola';37 $endian2int = substr($tiff_header, 0, 2) == 'II' ? 'LittleEndian2Int' : 'BigEndian2Int';39 $getid3->info['fileformat'] = 'tiff';40 $getid3->info['video']['dataformat'] = 'tiff';41 $getid3->info['video']['lossless'] = true;42 $getid3->info['tiff']['ifd'] = array ();43 $current_ifd = array ();45 $field_type_byte_length = array (1=>1, 2=>1, 3=>2, 4=>4, 5=>8);47 $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));49 while ($next_ifd_offset > 0) {51 $current_ifd['offset'] = $next_ifd_offset;53 fseek($getid3->fp, $getid3->info['avdataoffset'] + $next_ifd_offset, SEEK_SET);54 $current_ifd['fieldcount'] = getid3_lib::$endian2int(fread($getid3->fp, 2));56 for ($i = 0; $i < $current_ifd['fieldcount']; $i++) {58 // shortcut59 $current_ifd['fields'][$i] = array ();60 $current_ifd_fields_i = &$current_ifd['fields'][$i];62 $current_ifd_fields_i['raw']['tag'] = getid3_lib::$endian2int(fread($getid3->fp, 2));63 $current_ifd_fields_i['raw']['type'] = getid3_lib::$endian2int(fread($getid3->fp, 2));64 $current_ifd_fields_i['raw']['length'] = getid3_lib::$endian2int(fread($getid3->fp, 4));65 $current_ifd_fields_i['raw']['offset'] = fread($getid3->fp, 4);67 switch ($current_ifd_fields_i['raw']['type']) {68 case 1: // BYTE An 8-bit unsigned integer.69 if ($current_ifd_fields_i['raw']['length'] <= 4) {70 $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 1));71 } else {72 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);73 }74 break;76 case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.77 if ($current_ifd_fields_i['raw']['length'] <= 4) {78 $current_ifd_fields_i['value'] = substr($current_ifd_fields_i['raw']['offset'], 3);79 } else {80 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);81 }82 break;84 case 3: // SHORT A 16-bit (2-byte) unsigned integer.85 if ($current_ifd_fields_i['raw']['length'] <= 2) {86 $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 2));87 } else {88 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);89 }90 break;92 case 4: // LONG A 32-bit (4-byte) unsigned integer.93 if ($current_ifd_fields_i['raw']['length'] <= 1) {94 $current_ifd_fields_i['value'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);95 } else {96 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);97 }98 break;100 case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.101 break;102 }103 }105 $getid3->info['tiff']['ifd'][] = $current_ifd;106 $current_ifd = array ();107 $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));109 }111 foreach ($getid3->info['tiff']['ifd'] as $ifd_id => $ifd_array) {112 foreach ($ifd_array['fields'] as $key => $field_array) {113 switch ($field_array['raw']['tag']) {114 case 256: // ImageWidth115 case 257: // ImageLength116 case 258: // BitsPerSample117 case 259: // Compression118 if (!isset($field_array['value'])) {119 fseek($getid3->fp, $field_array['offset'], SEEK_SET);120 $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = fread($getid3->fp, $field_array['raw']['length'] * $field_type_byte_length[$field_array['raw']['type']]);121 }122 break;124 case 270: // ImageDescription125 case 271: // Make126 case 272: // Model127 case 305: // Software128 case 306: // DateTime129 case 315: // Artist130 case 316: // HostComputer131 if (isset($field_array['value'])) {132 $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = $field_array['value'];133 } else {134 fseek($getid3->fp, $field_array['offset'], SEEK_SET);135 $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = fread($getid3->fp, $field_array['raw']['length'] * $field_type_byte_length[$field_array['raw']['type']]);136 }137 break;138 }139 switch ($field_array['raw']['tag']) {140 case 256: // ImageWidth141 $getid3->info['video']['resolution_x'] = $field_array['value'];142 break;144 case 257: // ImageLength145 $getid3->info['video']['resolution_y'] = $field_array['value'];146 break;148 case 258: // BitsPerSample149 if (isset($field_array['value'])) {150 $getid3->info['video']['bits_per_sample'] = $field_array['value'];151 } else {152 $getid3->info['video']['bits_per_sample'] = 0;153 for ($i = 0; $i < $field_array['raw']['length']; $i++) {154 $getid3->info['video']['bits_per_sample'] += getid3_lib::$endian2int(substr($getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'], $i * $field_type_byte_length[$field_array['raw']['type']], $field_type_byte_length[$field_array['raw']['type']]));155 }156 }157 break;159 case 259: // Compression160 $getid3->info['video']['codec'] = getid3_tiff::TIFFcompressionMethod($field_array['value']);161 break;163 case 270: // ImageDescription164 case 271: // Make165 case 272: // Model166 case 305: // Software167 case 306: // DateTime168 case 315: // Artist169 case 316: // HostComputer170 @$getid3->info['tiff']['comments'][getid3_tiff::TIFFcommentName($field_array['raw']['tag'])][] = $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'];171 break;173 default:174 break;175 }176 }177 }179 return true;180 }184 public static function TIFFcompressionMethod($id) {186 static $lookup = array (187 1 => 'Uncompressed',188 2 => 'Huffman',189 3 => 'Fax - CCITT 3',190 5 => 'LZW',191 32773 => 'PackBits',192 );193 return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');194 }198 public static function TIFFcommentName($id) {200 static $lookup = array (201 270 => 'imagedescription',202 271 => 'make',203 272 => 'model',204 305 => 'software',205 306 => 'datetime',206 315 => 'artist',207 316 => 'hostcomputer',208 );209 return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');210 }212 }215 ?>