123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- class getid3_gif
- {
- function getid3_gif(&$fd, &$ThisFileInfo) {
- $ThisFileInfo['fileformat'] = 'gif';
- $ThisFileInfo['video']['dataformat'] = 'gif';
- $ThisFileInfo['video']['lossless'] = true;
- $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
- fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
- $GIFheader = fread($fd, 13);
- $offset = 0;
- $ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
- $offset += 3;
- if ($ThisFileInfo['gif']['header']['raw']['identifier'] != 'GIF') {
- $ThisFileInfo['error'][] = 'Expecting "GIF" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['gif']['header']['raw']['identifier'].'"';
- unset($ThisFileInfo['fileformat']);
- unset($ThisFileInfo['gif']);
- return false;
- }
- $ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
- $offset += 3;
- $ThisFileInfo['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
- $offset += 2;
- $ThisFileInfo['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
- $offset += 2;
- $ThisFileInfo['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
- $offset += 1;
- $ThisFileInfo['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
- $offset += 1;
- $ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
- $offset += 1;
- $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width'];
- $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height'];
- $ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version'];
- $ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80);
- if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) {
-
- $ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
- } else {
- $ThisFileInfo['gif']['header']['bits_per_pixel'] = 0;
- }
- $ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40);
- if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
-
-
- $ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1);
- $ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1;
- } else {
- $ThisFileInfo['gif']['header']['global_color_size'] = 0;
- }
- if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) {
-
- $ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
- }
- return true;
- }
- function GetLSBits($fd, $bits) {
- static $bitbuffer = '';
- while (strlen($bitbuffer) < $bits) {
- $bitbuffer = str_pad(decbin(ord(fread($fd, 1))), 8, '0', STR_PAD_LEFT).$bitbuffer;
- }
- $value = bindec(substr($bitbuffer, 0 - $bits));
- $bitbuffer = substr($bitbuffer, 0, 0 - $bits);
- return $value;
- }
- }
- ?>
|