<Website>

getID3

PHK Home

File: /lib/module.graphic.gif.php

Size:3026
Storage flags:strip

<?php
















class getid3_gif extends getid3_handler
{

public function 
Analyze() {
$info = &$this->getid3->info;

$info['fileformat'] = 'gif';
$info['video']['dataformat'] = 'gif';
$info['video']['lossless'] = true;
$info['video']['pixel_aspect_ratio'] = (float) 1;

$this->fseek($info['avdataoffset']);
$GIFheader $this->fread(13);
$offset 0;

$info['gif']['header']['raw']['identifier'] = substr($GIFheader$offset3);
$offset += 3;

$magic 'GIF';
if (
$info['gif']['header']['raw']['identifier'] != $magic) {
$info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"';
unset(
$info['fileformat']);
unset(
$info['gif']);
return 
false;
}

$info['gif']['header']['raw']['version'] = substr($GIFheader$offset3);
$offset += 3;
$info['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader$offset2));
$offset += 2;
$info['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader$offset2));
$offset += 2;
$info['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader$offset1));
$offset += 1;
$info['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader$offset1));
$offset += 1;
$info['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader$offset1));
$offset += 1;

$info['video']['resolution_x'] = $info['gif']['header']['raw']['width'];
$info['video']['resolution_y'] = $info['gif']['header']['raw']['height'];
$info['gif']['version'] = $info['gif']['header']['raw']['version'];
$info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80);
if (
$info['gif']['header']['raw']['flags'] & 0x80) {

 
$info['gif']['header']['bits_per_pixel'] = * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
} else {
$info['gif']['header']['bits_per_pixel'] = 0;
}
$info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40);
if (
$info['gif']['header']['flags']['global_color_table']) {

 
 
$info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1);
$info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1;
} else {
$info['gif']['header']['global_color_size'] = 0;
}
if (
$info['gif']['header']['raw']['aspect_ratio'] != 0) {

 
$info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
}























































































return 
true;
}


public function 
GetLSBits($bits) {
static 
$bitbuffer '';
while (
strlen($bitbuffer) < $bits) {
$bitbuffer str_pad(decbin(ord($this->fread(1))), 8'0'STR_PAD_LEFT).$bitbuffer;
}
$value bindec(substr($bitbuffer$bits));
$bitbuffer substr($bitbuffer0$bits);

return 
$value;
}

}

For more information about the PHK package format: http://phk.tekwire.net