Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.tiff.php @ 3:3f6b44aa6b35 judyates
[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author | rlm |
---|---|
date | Mon, 22 Feb 2010 08:02:39 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.tiff.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,215 @@ 1.4 +<?php 1.5 +// +----------------------------------------------------------------------+ 1.6 +// | PHP version 5 | 1.7 +// +----------------------------------------------------------------------+ 1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | 1.9 +// +----------------------------------------------------------------------+ 1.10 +// | This source file is subject to version 2 of the GPL license, | 1.11 +// | that is bundled with this package in the file license.txt and is | 1.12 +// | available through the world-wide-web at the following url: | 1.13 +// | http://www.gnu.org/copyleft/gpl.html | 1.14 +// +----------------------------------------------------------------------+ 1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | 1.16 +// +----------------------------------------------------------------------+ 1.17 +// | Authors: James Heinrich <infoØgetid3*org> | 1.18 +// | Allan Hansen <ahØartemis*dk> | 1.19 +// +----------------------------------------------------------------------+ 1.20 +// | module.graphic.tiff.php | 1.21 +// | Module for analyzing TIFF graphic files. | 1.22 +// | dependencies: NONE | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// 1.25 +// $Id: module.graphic.tiff.php,v 1.2 2006/11/02 10:48:02 ah Exp $ 1.26 + 1.27 + 1.28 + 1.29 +class getid3_tiff extends getid3_handler 1.30 +{ 1.31 + 1.32 + public function Analyze() { 1.33 + 1.34 + $getid3 = $this->getid3; 1.35 + 1.36 + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); 1.37 + $tiff_header = fread($getid3->fp, 4); 1.38 + 1.39 + $getid3->info['tiff']['byte_order'] = substr($tiff_header, 0, 2) == 'II' ? 'Intel' : 'Motorola'; 1.40 + $endian2int = substr($tiff_header, 0, 2) == 'II' ? 'LittleEndian2Int' : 'BigEndian2Int'; 1.41 + 1.42 + $getid3->info['fileformat'] = 'tiff'; 1.43 + $getid3->info['video']['dataformat'] = 'tiff'; 1.44 + $getid3->info['video']['lossless'] = true; 1.45 + $getid3->info['tiff']['ifd'] = array (); 1.46 + $current_ifd = array (); 1.47 + 1.48 + $field_type_byte_length = array (1=>1, 2=>1, 3=>2, 4=>4, 5=>8); 1.49 + 1.50 + $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4)); 1.51 + 1.52 + while ($next_ifd_offset > 0) { 1.53 + 1.54 + $current_ifd['offset'] = $next_ifd_offset; 1.55 + 1.56 + fseek($getid3->fp, $getid3->info['avdataoffset'] + $next_ifd_offset, SEEK_SET); 1.57 + $current_ifd['fieldcount'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); 1.58 + 1.59 + for ($i = 0; $i < $current_ifd['fieldcount']; $i++) { 1.60 + 1.61 + // shortcut 1.62 + $current_ifd['fields'][$i] = array (); 1.63 + $current_ifd_fields_i = &$current_ifd['fields'][$i]; 1.64 + 1.65 + $current_ifd_fields_i['raw']['tag'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); 1.66 + $current_ifd_fields_i['raw']['type'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); 1.67 + $current_ifd_fields_i['raw']['length'] = getid3_lib::$endian2int(fread($getid3->fp, 4)); 1.68 + $current_ifd_fields_i['raw']['offset'] = fread($getid3->fp, 4); 1.69 + 1.70 + switch ($current_ifd_fields_i['raw']['type']) { 1.71 + case 1: // BYTE An 8-bit unsigned integer. 1.72 + if ($current_ifd_fields_i['raw']['length'] <= 4) { 1.73 + $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 1)); 1.74 + } else { 1.75 + $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']); 1.76 + } 1.77 + break; 1.78 + 1.79 + case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null. 1.80 + if ($current_ifd_fields_i['raw']['length'] <= 4) { 1.81 + $current_ifd_fields_i['value'] = substr($current_ifd_fields_i['raw']['offset'], 3); 1.82 + } else { 1.83 + $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']); 1.84 + } 1.85 + break; 1.86 + 1.87 + case 3: // SHORT A 16-bit (2-byte) unsigned integer. 1.88 + if ($current_ifd_fields_i['raw']['length'] <= 2) { 1.89 + $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 2)); 1.90 + } else { 1.91 + $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']); 1.92 + } 1.93 + break; 1.94 + 1.95 + case 4: // LONG A 32-bit (4-byte) unsigned integer. 1.96 + if ($current_ifd_fields_i['raw']['length'] <= 1) { 1.97 + $current_ifd_fields_i['value'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']); 1.98 + } else { 1.99 + $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']); 1.100 + } 1.101 + break; 1.102 + 1.103 + case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator. 1.104 + break; 1.105 + } 1.106 + } 1.107 + 1.108 + $getid3->info['tiff']['ifd'][] = $current_ifd; 1.109 + $current_ifd = array (); 1.110 + $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4)); 1.111 + 1.112 + } 1.113 + 1.114 + foreach ($getid3->info['tiff']['ifd'] as $ifd_id => $ifd_array) { 1.115 + foreach ($ifd_array['fields'] as $key => $field_array) { 1.116 + switch ($field_array['raw']['tag']) { 1.117 + case 256: // ImageWidth 1.118 + case 257: // ImageLength 1.119 + case 258: // BitsPerSample 1.120 + case 259: // Compression 1.121 + if (!isset($field_array['value'])) { 1.122 + fseek($getid3->fp, $field_array['offset'], SEEK_SET); 1.123 + $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']]); 1.124 + } 1.125 + break; 1.126 + 1.127 + case 270: // ImageDescription 1.128 + case 271: // Make 1.129 + case 272: // Model 1.130 + case 305: // Software 1.131 + case 306: // DateTime 1.132 + case 315: // Artist 1.133 + case 316: // HostComputer 1.134 + if (isset($field_array['value'])) { 1.135 + $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = $field_array['value']; 1.136 + } else { 1.137 + fseek($getid3->fp, $field_array['offset'], SEEK_SET); 1.138 + $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']]); 1.139 + } 1.140 + break; 1.141 + } 1.142 + switch ($field_array['raw']['tag']) { 1.143 + case 256: // ImageWidth 1.144 + $getid3->info['video']['resolution_x'] = $field_array['value']; 1.145 + break; 1.146 + 1.147 + case 257: // ImageLength 1.148 + $getid3->info['video']['resolution_y'] = $field_array['value']; 1.149 + break; 1.150 + 1.151 + case 258: // BitsPerSample 1.152 + if (isset($field_array['value'])) { 1.153 + $getid3->info['video']['bits_per_sample'] = $field_array['value']; 1.154 + } else { 1.155 + $getid3->info['video']['bits_per_sample'] = 0; 1.156 + for ($i = 0; $i < $field_array['raw']['length']; $i++) { 1.157 + $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']])); 1.158 + } 1.159 + } 1.160 + break; 1.161 + 1.162 + case 259: // Compression 1.163 + $getid3->info['video']['codec'] = getid3_tiff::TIFFcompressionMethod($field_array['value']); 1.164 + break; 1.165 + 1.166 + case 270: // ImageDescription 1.167 + case 271: // Make 1.168 + case 272: // Model 1.169 + case 305: // Software 1.170 + case 306: // DateTime 1.171 + case 315: // Artist 1.172 + case 316: // HostComputer 1.173 + @$getid3->info['tiff']['comments'][getid3_tiff::TIFFcommentName($field_array['raw']['tag'])][] = $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data']; 1.174 + break; 1.175 + 1.176 + default: 1.177 + break; 1.178 + } 1.179 + } 1.180 + } 1.181 + 1.182 + return true; 1.183 + } 1.184 + 1.185 + 1.186 + 1.187 + public static function TIFFcompressionMethod($id) { 1.188 + 1.189 + static $lookup = array ( 1.190 + 1 => 'Uncompressed', 1.191 + 2 => 'Huffman', 1.192 + 3 => 'Fax - CCITT 3', 1.193 + 5 => 'LZW', 1.194 + 32773 => 'PackBits', 1.195 + ); 1.196 + return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')'); 1.197 + } 1.198 + 1.199 + 1.200 + 1.201 + public static function TIFFcommentName($id) { 1.202 + 1.203 + static $lookup = array ( 1.204 + 270 => 'imagedescription', 1.205 + 271 => 'make', 1.206 + 272 => 'model', 1.207 + 305 => 'software', 1.208 + 306 => 'datetime', 1.209 + 315 => 'artist', 1.210 + 316 => 'hostcomputer', 1.211 + ); 1.212 + return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')'); 1.213 + } 1.214 + 1.215 +} 1.216 + 1.217 + 1.218 +?> 1.219 \ No newline at end of file