annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.tiff.php @ 18:903b91a97990 judyates

updated site to use google analytics
author Robert McIntyre <rlm@mit.edu>
date Mon, 11 Jul 2011 03:06:13 -0400
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.graphic.tiff.php |
rlm@3 18 // | Module for analyzing TIFF graphic files. |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.graphic.tiff.php,v 1.2 2006/11/02 10:48:02 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_tiff extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 34 $tiff_header = fread($getid3->fp, 4);
rlm@3 35
rlm@3 36 $getid3->info['tiff']['byte_order'] = substr($tiff_header, 0, 2) == 'II' ? 'Intel' : 'Motorola';
rlm@3 37 $endian2int = substr($tiff_header, 0, 2) == 'II' ? 'LittleEndian2Int' : 'BigEndian2Int';
rlm@3 38
rlm@3 39 $getid3->info['fileformat'] = 'tiff';
rlm@3 40 $getid3->info['video']['dataformat'] = 'tiff';
rlm@3 41 $getid3->info['video']['lossless'] = true;
rlm@3 42 $getid3->info['tiff']['ifd'] = array ();
rlm@3 43 $current_ifd = array ();
rlm@3 44
rlm@3 45 $field_type_byte_length = array (1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
rlm@3 46
rlm@3 47 $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));
rlm@3 48
rlm@3 49 while ($next_ifd_offset > 0) {
rlm@3 50
rlm@3 51 $current_ifd['offset'] = $next_ifd_offset;
rlm@3 52
rlm@3 53 fseek($getid3->fp, $getid3->info['avdataoffset'] + $next_ifd_offset, SEEK_SET);
rlm@3 54 $current_ifd['fieldcount'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
rlm@3 55
rlm@3 56 for ($i = 0; $i < $current_ifd['fieldcount']; $i++) {
rlm@3 57
rlm@3 58 // shortcut
rlm@3 59 $current_ifd['fields'][$i] = array ();
rlm@3 60 $current_ifd_fields_i = &$current_ifd['fields'][$i];
rlm@3 61
rlm@3 62 $current_ifd_fields_i['raw']['tag'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
rlm@3 63 $current_ifd_fields_i['raw']['type'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
rlm@3 64 $current_ifd_fields_i['raw']['length'] = getid3_lib::$endian2int(fread($getid3->fp, 4));
rlm@3 65 $current_ifd_fields_i['raw']['offset'] = fread($getid3->fp, 4);
rlm@3 66
rlm@3 67 switch ($current_ifd_fields_i['raw']['type']) {
rlm@3 68 case 1: // BYTE An 8-bit unsigned integer.
rlm@3 69 if ($current_ifd_fields_i['raw']['length'] <= 4) {
rlm@3 70 $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 1));
rlm@3 71 } else {
rlm@3 72 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
rlm@3 73 }
rlm@3 74 break;
rlm@3 75
rlm@3 76 case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
rlm@3 77 if ($current_ifd_fields_i['raw']['length'] <= 4) {
rlm@3 78 $current_ifd_fields_i['value'] = substr($current_ifd_fields_i['raw']['offset'], 3);
rlm@3 79 } else {
rlm@3 80 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
rlm@3 81 }
rlm@3 82 break;
rlm@3 83
rlm@3 84 case 3: // SHORT A 16-bit (2-byte) unsigned integer.
rlm@3 85 if ($current_ifd_fields_i['raw']['length'] <= 2) {
rlm@3 86 $current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 2));
rlm@3 87 } else {
rlm@3 88 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
rlm@3 89 }
rlm@3 90 break;
rlm@3 91
rlm@3 92 case 4: // LONG A 32-bit (4-byte) unsigned integer.
rlm@3 93 if ($current_ifd_fields_i['raw']['length'] <= 1) {
rlm@3 94 $current_ifd_fields_i['value'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
rlm@3 95 } else {
rlm@3 96 $current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
rlm@3 97 }
rlm@3 98 break;
rlm@3 99
rlm@3 100 case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
rlm@3 101 break;
rlm@3 102 }
rlm@3 103 }
rlm@3 104
rlm@3 105 $getid3->info['tiff']['ifd'][] = $current_ifd;
rlm@3 106 $current_ifd = array ();
rlm@3 107 $next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));
rlm@3 108
rlm@3 109 }
rlm@3 110
rlm@3 111 foreach ($getid3->info['tiff']['ifd'] as $ifd_id => $ifd_array) {
rlm@3 112 foreach ($ifd_array['fields'] as $key => $field_array) {
rlm@3 113 switch ($field_array['raw']['tag']) {
rlm@3 114 case 256: // ImageWidth
rlm@3 115 case 257: // ImageLength
rlm@3 116 case 258: // BitsPerSample
rlm@3 117 case 259: // Compression
rlm@3 118 if (!isset($field_array['value'])) {
rlm@3 119 fseek($getid3->fp, $field_array['offset'], SEEK_SET);
rlm@3 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']]);
rlm@3 121 }
rlm@3 122 break;
rlm@3 123
rlm@3 124 case 270: // ImageDescription
rlm@3 125 case 271: // Make
rlm@3 126 case 272: // Model
rlm@3 127 case 305: // Software
rlm@3 128 case 306: // DateTime
rlm@3 129 case 315: // Artist
rlm@3 130 case 316: // HostComputer
rlm@3 131 if (isset($field_array['value'])) {
rlm@3 132 $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = $field_array['value'];
rlm@3 133 } else {
rlm@3 134 fseek($getid3->fp, $field_array['offset'], SEEK_SET);
rlm@3 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']]);
rlm@3 136 }
rlm@3 137 break;
rlm@3 138 }
rlm@3 139 switch ($field_array['raw']['tag']) {
rlm@3 140 case 256: // ImageWidth
rlm@3 141 $getid3->info['video']['resolution_x'] = $field_array['value'];
rlm@3 142 break;
rlm@3 143
rlm@3 144 case 257: // ImageLength
rlm@3 145 $getid3->info['video']['resolution_y'] = $field_array['value'];
rlm@3 146 break;
rlm@3 147
rlm@3 148 case 258: // BitsPerSample
rlm@3 149 if (isset($field_array['value'])) {
rlm@3 150 $getid3->info['video']['bits_per_sample'] = $field_array['value'];
rlm@3 151 } else {
rlm@3 152 $getid3->info['video']['bits_per_sample'] = 0;
rlm@3 153 for ($i = 0; $i < $field_array['raw']['length']; $i++) {
rlm@3 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']]));
rlm@3 155 }
rlm@3 156 }
rlm@3 157 break;
rlm@3 158
rlm@3 159 case 259: // Compression
rlm@3 160 $getid3->info['video']['codec'] = getid3_tiff::TIFFcompressionMethod($field_array['value']);
rlm@3 161 break;
rlm@3 162
rlm@3 163 case 270: // ImageDescription
rlm@3 164 case 271: // Make
rlm@3 165 case 272: // Model
rlm@3 166 case 305: // Software
rlm@3 167 case 306: // DateTime
rlm@3 168 case 315: // Artist
rlm@3 169 case 316: // HostComputer
rlm@3 170 @$getid3->info['tiff']['comments'][getid3_tiff::TIFFcommentName($field_array['raw']['tag'])][] = $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'];
rlm@3 171 break;
rlm@3 172
rlm@3 173 default:
rlm@3 174 break;
rlm@3 175 }
rlm@3 176 }
rlm@3 177 }
rlm@3 178
rlm@3 179 return true;
rlm@3 180 }
rlm@3 181
rlm@3 182
rlm@3 183
rlm@3 184 public static function TIFFcompressionMethod($id) {
rlm@3 185
rlm@3 186 static $lookup = array (
rlm@3 187 1 => 'Uncompressed',
rlm@3 188 2 => 'Huffman',
rlm@3 189 3 => 'Fax - CCITT 3',
rlm@3 190 5 => 'LZW',
rlm@3 191 32773 => 'PackBits',
rlm@3 192 );
rlm@3 193 return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');
rlm@3 194 }
rlm@3 195
rlm@3 196
rlm@3 197
rlm@3 198 public static function TIFFcommentName($id) {
rlm@3 199
rlm@3 200 static $lookup = array (
rlm@3 201 270 => 'imagedescription',
rlm@3 202 271 => 'make',
rlm@3 203 272 => 'model',
rlm@3 204 305 => 'software',
rlm@3 205 306 => 'datetime',
rlm@3 206 315 => 'artist',
rlm@3 207 316 => 'hostcomputer',
rlm@3 208 );
rlm@3 209 return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');
rlm@3 210 }
rlm@3 211
rlm@3 212 }
rlm@3 213
rlm@3 214
rlm@3 215 ?>