Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.bmp.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.bmp.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,319 @@ 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.bmp.php | 1.21 +// | Module for analyzing BMP graphic files. | 1.22 +// | dependencies: NONE | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// 1.25 +// $Id: module.graphic.bmp.php,v 1.4 2006/11/02 10:48:02 ah Exp $ 1.26 + 1.27 + 1.28 + 1.29 +class getid3_bmp extends getid3_handler 1.30 +{ 1.31 + 1.32 + 1.33 + public function Analyze() { 1.34 + 1.35 + $getid3 = $this->getid3; 1.36 + 1.37 + // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp 1.38 + // all versions 1.39 + // WORD bfType; 1.40 + // DWORD bfSize; 1.41 + // WORD bfReserved1; 1.42 + // WORD bfReserved2; 1.43 + // DWORD bfOffBits; 1.44 + 1.45 + // shortcuts 1.46 + $getid3->info['bmp']['header']['raw'] = array (); 1.47 + $info_bmp = &$getid3->info['bmp']; 1.48 + $info_bmp_header = &$info_bmp['header']; 1.49 + $info_bmp_header_raw = &$info_bmp_header['raw']; 1.50 + 1.51 + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); 1.52 + $bmp_header = fread($getid3->fp, 14 + 40); 1.53 + 1.54 + // Magic bytes 1.55 + $info_bmp_header_raw['identifier'] = 'BM'; 1.56 + 1.57 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 2, 1.58 + array ( 1.59 + 'filesize' => 4, 1.60 + 'reserved1' => 2, 1.61 + 'reserved2' => 2, 1.62 + 'data_offset' => 4, 1.63 + 'header_size' => 4 1.64 + ) 1.65 + ); 1.66 + 1.67 + // Check if the hardcoded-to-1 "planes" is at offset 22 or 26 1.68 + $planes22 = getid3_lib::LittleEndian2Int(substr($bmp_header, 22, 2)); 1.69 + $planes26 = getid3_lib::LittleEndian2Int(substr($bmp_header, 26, 2)); 1.70 + if (($planes22 == 1) && ($planes26 != 1)) { 1.71 + $info_bmp['type_os'] = 'OS/2'; 1.72 + $info_bmp['type_version'] = 1; 1.73 + } 1.74 + elseif (($planes26 == 1) && ($planes22 != 1)) { 1.75 + $info_bmp['type_os'] = 'Windows'; 1.76 + $info_bmp['type_version'] = 1; 1.77 + } 1.78 + elseif ($info_bmp_header_raw['header_size'] == 12) { 1.79 + $info_bmp['type_os'] = 'OS/2'; 1.80 + $info_bmp['type_version'] = 1; 1.81 + } 1.82 + elseif ($info_bmp_header_raw['header_size'] == 40) { 1.83 + $info_bmp['type_os'] = 'Windows'; 1.84 + $info_bmp['type_version'] = 1; 1.85 + } 1.86 + elseif ($info_bmp_header_raw['header_size'] == 84) { 1.87 + $info_bmp['type_os'] = 'Windows'; 1.88 + $info_bmp['type_version'] = 4; 1.89 + } 1.90 + elseif ($info_bmp_header_raw['header_size'] == 100) { 1.91 + $info_bmp['type_os'] = 'Windows'; 1.92 + $info_bmp['type_version'] = 5; 1.93 + } 1.94 + else { 1.95 + throw new getid3_exception('Unknown BMP subtype (or not a BMP file)'); 1.96 + } 1.97 + 1.98 + $getid3->info['fileformat'] = 'bmp'; 1.99 + $getid3->info['video']['dataformat'] = 'bmp'; 1.100 + $getid3->info['video']['lossless'] = true; 1.101 + $getid3->info['video']['pixel_aspect_ratio'] = (float)1; 1.102 + 1.103 + if ($info_bmp['type_os'] == 'OS/2') { 1.104 + 1.105 + // OS/2-format BMP 1.106 + // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm 1.107 + 1.108 + // DWORD Size; /* Size of this structure in bytes */ 1.109 + // DWORD Width; /* Bitmap width in pixels */ 1.110 + // DWORD Height; /* Bitmap height in pixel */ 1.111 + // WORD NumPlanes; /* Number of bit planes (color depth) */ 1.112 + // WORD BitsPerPixel; /* Number of bits per pixel per plane */ 1.113 + 1.114 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, 1.115 + array ( 1.116 + 'width' => 2, 1.117 + 'height' => 2, 1.118 + 'planes' => 2, 1.119 + 'bits_per_pixel' => 2 1.120 + ) 1.121 + ); 1.122 + 1.123 + $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; 1.124 + $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; 1.125 + $getid3->info['video']['codec'] = 'BI_RGB '.$info_bmp_header_raw['bits_per_pixel'].'-bit'; 1.126 + $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel']; 1.127 + 1.128 + if ($info_bmp['type_version'] >= 2) { 1.129 + // DWORD Compression; /* Bitmap compression scheme */ 1.130 + // DWORD ImageDataSize; /* Size of bitmap data in bytes */ 1.131 + // DWORD XResolution; /* X resolution of display device */ 1.132 + // DWORD YResolution; /* Y resolution of display device */ 1.133 + // DWORD ColorsUsed; /* Number of color table indices used */ 1.134 + // DWORD ColorsImportant; /* Number of important color indices */ 1.135 + // WORD Units; /* Type of units used to measure resolution */ 1.136 + // WORD Reserved; /* Pad structure to 4-byte boundary */ 1.137 + // WORD Recording; /* Recording algorithm */ 1.138 + // WORD Rendering; /* Halftoning algorithm used */ 1.139 + // DWORD Size1; /* Reserved for halftoning algorithm use */ 1.140 + // DWORD Size2; /* Reserved for halftoning algorithm use */ 1.141 + // DWORD ColorEncoding; /* Color model used in bitmap */ 1.142 + // DWORD Identifier; /* Reserved for application use */ 1.143 + 1.144 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 26, 1.145 + array ( 1.146 + 'compression' => 4, 1.147 + 'bmp_data_size' => 4, 1.148 + 'resolution_h' => 4, 1.149 + 'resolution_v' => 4, 1.150 + 'colors_used' => 4, 1.151 + 'colors_important' => 4, 1.152 + 'resolution_units' => 2, 1.153 + 'reserved1' => 2, 1.154 + 'recording' => 2, 1.155 + 'rendering' => 2, 1.156 + 'size1' => 4, 1.157 + 'size2' => 4, 1.158 + 'color_encoding' => 4, 1.159 + 'identifier' => 4 1.160 + ) 1.161 + ); 1.162 + 1.163 + $info_bmp_header['compression'] = getid3_bmp::BMPcompressionOS2Lookup($info_bmp_header_raw['compression']); 1.164 + $getid3->info['video']['codec'] = $info_bmp_header['compression'].' '.$info_bmp_header_raw['bits_per_pixel'].'-bit'; 1.165 + } 1.166 + 1.167 + return true; 1.168 + } 1.169 + 1.170 + 1.171 + if ($info_bmp['type_os'] == 'Windows') { 1.172 + 1.173 + // Windows-format BMP 1.174 + 1.175 + // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp 1.176 + // all versions 1.177 + // DWORD biSize; 1.178 + // LONG biWidth; 1.179 + // LONG biHeight; 1.180 + // WORD biPlanes; 1.181 + // WORD biBitCount; 1.182 + // DWORD biCompression; 1.183 + // DWORD biSizeImage; 1.184 + // LONG biXPelsPerMeter; 1.185 + // LONG biYPelsPerMeter; 1.186 + // DWORD biClrUsed; 1.187 + // DWORD biClrImportant; 1.188 + 1.189 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, 1.190 + array ( 1.191 + 'width' => -4, //signed 1.192 + 'height' => -4, //signed 1.193 + 'planes' => 2, 1.194 + 'bits_per_pixel' => 2, 1.195 + 'compression' => 4, 1.196 + 'bmp_data_size' => 4, 1.197 + 'resolution_h' => -4, //signed 1.198 + 'resolution_v' => -4, //signed 1.199 + 'colors_used' => 4, 1.200 + 'colors_important' => 4 1.201 + ) 1.202 + ); 1.203 + foreach (array ('width', 'height', 'resolution_h', 'resolution_v') as $key) { 1.204 + $info_bmp_header_raw[$key] = getid3_lib::LittleEndian2Int($info_bmp_header_raw[$key], true); 1.205 + } 1.206 + 1.207 + $info_bmp_header['compression'] = getid3_bmp::BMPcompressionWindowsLookup($info_bmp_header_raw['compression']); 1.208 + $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; 1.209 + $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; 1.210 + $getid3->info['video']['codec'] = $info_bmp_header['compression'].' '.$info_bmp_header_raw['bits_per_pixel'].'-bit'; 1.211 + $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel']; 1.212 + 1.213 + // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen 1.214 + if (($info_bmp['type_version'] >= 4) || ($info_bmp_header_raw['compression'] == 3)) { 1.215 + 1.216 + 1.217 + $bmp_header .= fread($getid3->fp, 44); 1.218 + 1.219 + // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp 1.220 + // Win95+, WinNT4.0+ 1.221 + // DWORD bV4RedMask; 1.222 + // DWORD bV4GreenMask; 1.223 + // DWORD bV4BlueMask; 1.224 + // DWORD bV4AlphaMask; 1.225 + // DWORD bV4CSType; 1.226 + // CIEXYZTRIPLE bV4Endpoints; 1.227 + // DWORD bV4GammaRed; 1.228 + // DWORD bV4GammaGreen; 1.229 + // DWORD bV4GammaBlue; 1.230 + 1.231 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 54, 1.232 + array ( 1.233 + 'red_mask' => 4, 1.234 + 'green_mask' => 4, 1.235 + 'blue_mask' => 4, 1.236 + 'alpha_mask' => 4, 1.237 + 'cs_type' => 4, 1.238 + 'ciexyz_red' => -4, //string 1.239 + 'ciexyz_green' => -4, //string 1.240 + 'ciexyz_blue' => -4, //string 1.241 + 'gamma_red' => 4, 1.242 + 'gamma_green' => 4, 1.243 + 'gamma_blue' => 4 1.244 + ) 1.245 + ); 1.246 + 1.247 + $info_bmp_header['ciexyz_red'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_red'])); 1.248 + $info_bmp_header['ciexyz_green'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_green'])); 1.249 + $info_bmp_header['ciexyz_blue'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_blue'])); 1.250 + 1.251 + 1.252 + if ($info_bmp['type_version'] >= 5) { 1.253 + $bmp_header .= fread($getid3->fp, 16); 1.254 + 1.255 + // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp 1.256 + // Win98+, Win2000+ 1.257 + // DWORD bV5Intent; 1.258 + // DWORD bV5ProfileData; 1.259 + // DWORD bV5ProfileSize; 1.260 + // DWORD bV5Reserved; 1.261 + 1.262 + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 98, 1.263 + array ( 1.264 + 'intent' => 4, 1.265 + 'profile_data_offset' => 4, 1.266 + 'profile_data_size' => 4, 1.267 + 'reserved3' => 4 1.268 + ) 1.269 + ); 1.270 + 1.271 + } 1.272 + } 1.273 + 1.274 + return true; 1.275 + } 1.276 + 1.277 + 1.278 + throw new getid3_exception('Unknown BMP format in header.'); 1.279 + 1.280 + } 1.281 + 1.282 + 1.283 + 1.284 + public static function BMPcompressionWindowsLookup($compression_id) { 1.285 + 1.286 + static $lookup = array ( 1.287 + 0 => 'BI_RGB', 1.288 + 1 => 'BI_RLE8', 1.289 + 2 => 'BI_RLE4', 1.290 + 3 => 'BI_BITFIELDS', 1.291 + 4 => 'BI_JPEG', 1.292 + 5 => 'BI_PNG' 1.293 + ); 1.294 + return (isset($lookup[$compression_id]) ? $lookup[$compression_id] : 'invalid'); 1.295 + } 1.296 + 1.297 + 1.298 + 1.299 + public static function BMPcompressionOS2Lookup($compression_id) { 1.300 + 1.301 + static $lookup = array ( 1.302 + 0 => 'BI_RGB', 1.303 + 1 => 'BI_RLE8', 1.304 + 2 => 'BI_RLE4', 1.305 + 3 => 'Huffman 1D', 1.306 + 4 => 'BI_RLE24', 1.307 + ); 1.308 + return (isset($lookup[$compression_id]) ? $lookup[$compression_id] : 'invalid'); 1.309 + } 1.310 + 1.311 + 1.312 + public static function FixedPoint2_30($raw_data) { 1.313 + 1.314 + $binary_string = getid3_lib::BigEndian2Bin($raw_data); 1.315 + return bindec(substr($binary_string, 0, 2)) + (float)(bindec(substr($binary_string, 2, 30)) / 1073741824); // pow(2, 30) = 1073741824 1.316 + } 1.317 + 1.318 + 1.319 +} 1.320 + 1.321 + 1.322 +?> 1.323 \ No newline at end of file