ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_gif Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_gif:
+ Collaboration diagram for getid3_gif:

Public Member Functions

 getid3_gif (&$fd, &$ThisFileInfo)
 
 GetLSBits ($fd, $bits)
 
 Analyze ()
 
 GetLSBits ($bits)
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.graphic.gif.php.

Member Function Documentation

◆ Analyze()

getid3_gif::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 21 of file module.graphic.gif.php.

21 {
22 $info = &$this->getid3->info;
23
24 $info['fileformat'] = 'gif';
25 $info['video']['dataformat'] = 'gif';
26 $info['video']['lossless'] = true;
27 $info['video']['pixel_aspect_ratio'] = (float) 1;
28
29 $this->fseek($info['avdataoffset']);
30 $GIFheader = $this->fread(13);
31 $offset = 0;
32
33 $info['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
34 $offset += 3;
35
36 $magic = 'GIF';
37 if ($info['gif']['header']['raw']['identifier'] != $magic) {
38 $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"';
39 unset($info['fileformat']);
40 unset($info['gif']);
41 return false;
42 }
43
44 $info['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
45 $offset += 3;
46 $info['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
47 $offset += 2;
48 $info['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
49 $offset += 2;
50 $info['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
51 $offset += 1;
52 $info['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
53 $offset += 1;
54 $info['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
55 $offset += 1;
56
57 $info['video']['resolution_x'] = $info['gif']['header']['raw']['width'];
58 $info['video']['resolution_y'] = $info['gif']['header']['raw']['height'];
59 $info['gif']['version'] = $info['gif']['header']['raw']['version'];
60 $info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80);
61 if ($info['gif']['header']['raw']['flags'] & 0x80) {
62 // Number of bits per primary color available to the original image, minus 1
63 $info['gif']['header']['bits_per_pixel'] = 3 * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
64 } else {
65 $info['gif']['header']['bits_per_pixel'] = 0;
66 }
67 $info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40);
68 if ($info['gif']['header']['flags']['global_color_table']) {
69 // the number of bytes contained in the Global Color Table. To determine that
70 // actual size of the color table, raise 2 to [the value of the field + 1]
71 $info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1);
72 $info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1;
73 } else {
74 $info['gif']['header']['global_color_size'] = 0;
75 }
76 if ($info['gif']['header']['raw']['aspect_ratio'] != 0) {
77 // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
78 $info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
79 }
80
81// if ($info['gif']['header']['flags']['global_color_table']) {
82// $GIFcolorTable = $this->fread(3 * $info['gif']['header']['global_color_size']);
83// $offset = 0;
84// for ($i = 0; $i < $info['gif']['header']['global_color_size']; $i++) {
85// $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
86// $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
87// $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
88// $info['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue));
89// }
90// }
91//
92// // Image Descriptor
93// while (!feof($this->getid3->fp)) {
94// $NextBlockTest = $this->fread(1);
95// switch ($NextBlockTest) {
96//
97// case ',': // ',' - Image separator character
98//
99// $ImageDescriptorData = $NextBlockTest.$this->fread(9);
100// $ImageDescriptor = array();
101// $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2));
102// $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2));
103// $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2));
104// $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2));
105// $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1));
106// $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80);
107// $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40);
108// $info['gif']['image_descriptor'][] = $ImageDescriptor;
109//
110// if ($ImageDescriptor['flags']['use_local_color_map']) {
111//
112// $info['warning'][] = 'This version of getID3() cannot parse local color maps for GIFs';
113// return true;
114//
115// }
116//echo 'Start of raster data: '.$this->ftell().'<BR>';
117// $RasterData = array();
118// $RasterData['code_size'] = getid3_lib::LittleEndian2Int($this->fread(1));
119// $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int($this->fread(1));
120// $info['gif']['raster_data'][count($info['gif']['image_descriptor']) - 1] = $RasterData;
121//
122// $CurrentCodeSize = $RasterData['code_size'] + 1;
123// for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) {
124// $DefaultDataLookupTable[$i] = chr($i);
125// }
126// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code
127// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code
128//
129//
130// $NextValue = $this->GetLSBits($CurrentCodeSize);
131// echo 'Clear Code: '.$NextValue.'<BR>';
132//
133// $NextValue = $this->GetLSBits($CurrentCodeSize);
134// echo 'First Color: '.$NextValue.'<BR>';
135//
136// $Prefix = $NextValue;
137//$i = 0;
138// while ($i++ < 20) {
139// $NextValue = $this->GetLSBits($CurrentCodeSize);
140// echo $NextValue.'<BR>';
141// }
142//return true;
143// break;
144//
145// case '!':
146// // GIF Extension Block
147// $ExtensionBlockData = $NextBlockTest.$this->fread(2);
148// $ExtensionBlock = array();
149// $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1));
150// $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1));
151// $ExtensionBlock['data'] = $this->fread($ExtensionBlock['byte_length']);
152// $info['gif']['extension_blocks'][] = $ExtensionBlock;
153// break;
154//
155// case ';':
156// $info['gif']['terminator_offset'] = $this->ftell() - 1;
157// // GIF Terminator
158// break;
159//
160// default:
161// break;
162//
163//
164// }
165// }
166
167 return true;
168 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
$info
Definition: example_052.php:80

References $info, getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\LittleEndian2Int(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ getid3_gif()

getid3_gif::getid3_gif ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.graphic.gif.php.

20 {
21 $ThisFileInfo['fileformat'] = 'gif';
22 $ThisFileInfo['video']['dataformat'] = 'gif';
23 $ThisFileInfo['video']['lossless'] = true;
24 $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
25
26 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
27 $GIFheader = fread($fd, 13);
28 $offset = 0;
29
30 $ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
31 $offset += 3;
32
33 if ($ThisFileInfo['gif']['header']['raw']['identifier'] != 'GIF') {
34 $ThisFileInfo['error'][] = 'Expecting "GIF" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['gif']['header']['raw']['identifier'].'"';
35 unset($ThisFileInfo['fileformat']);
36 unset($ThisFileInfo['gif']);
37 return false;
38 }
39
40 $ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
41 $offset += 3;
42 $ThisFileInfo['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
43 $offset += 2;
44 $ThisFileInfo['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2));
45 $offset += 2;
46 $ThisFileInfo['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
47 $offset += 1;
48 $ThisFileInfo['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
49 $offset += 1;
50 $ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1));
51 $offset += 1;
52
53 $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width'];
54 $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height'];
55 $ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version'];
56 $ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80);
57 if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) {
58 // Number of bits per primary color available to the original image, minus 1
59 $ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
60 } else {
61 $ThisFileInfo['gif']['header']['bits_per_pixel'] = 0;
62 }
63 $ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40);
64 if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
65 // the number of bytes contained in the Global Color Table. To determine that
66 // actual size of the color table, raise 2 to [the value of the field + 1]
67 $ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1);
68 $ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1;
69 } else {
70 $ThisFileInfo['gif']['header']['global_color_size'] = 0;
71 }
72 if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) {
73 // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
74 $ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
75 }
76
77// if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
78// $GIFcolorTable = fread($fd, 3 * $ThisFileInfo['gif']['header']['global_color_size']);
79// $offset = 0;
80// for ($i = 0; $i < $ThisFileInfo['gif']['header']['global_color_size']; $i++) {
81// $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
82// $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
83// $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
84// $ThisFileInfo['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue));
85// }
86// }
87//
88// // Image Descriptor
89// while (!feof($fd)) {
90// $NextBlockTest = fread($fd, 1);
91// switch ($NextBlockTest) {
92//
93// case ',': // ',' - Image separator character
94//
95// $ImageDescriptorData = $NextBlockTest.fread($fd, 9);
96// $ImageDescriptor = array();
97// $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2));
98// $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2));
99// $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2));
100// $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2));
101// $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1));
102// $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80);
103// $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40);
104// $ThisFileInfo['gif']['image_descriptor'][] = $ImageDescriptor;
105//
106// if ($ImageDescriptor['flags']['use_local_color_map']) {
107//
108// $ThisFileInfo['warning'][] = 'This version of getID3() cannot parse local color maps for GIFs';
109// return true;
110//
111// }
112//echo 'Start of raster data: '.ftell($fd).'<BR>';
113// $RasterData = array();
114// $RasterData['code_size'] = getid3_lib::LittleEndian2Int(fread($fd, 1));
115// $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int(fread($fd, 1));
116// $ThisFileInfo['gif']['raster_data'][count($ThisFileInfo['gif']['image_descriptor']) - 1] = $RasterData;
117//
118// $CurrentCodeSize = $RasterData['code_size'] + 1;
119// for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) {
120// $DefaultDataLookupTable[$i] = chr($i);
121// }
122// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code
123// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code
124//
125//
126// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize);
127// echo 'Clear Code: '.$NextValue.'<BR>';
128//
129// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize);
130// echo 'First Color: '.$NextValue.'<BR>';
131//
132// $Prefix = $NextValue;
133//$i = 0;
134// while ($i++ < 20) {
135// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize);
136// echo $NextValue.'<BR>';
137// }
138//return true;
139// break;
140//
141// case '!':
142// // GIF Extension Block
143// $ExtensionBlockData = $NextBlockTest.fread($fd, 2);
144// $ExtensionBlock = array();
145// $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1));
146// $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1));
147// $ExtensionBlock['data'] = fread($fd, $ExtensionBlock['byte_length']);
148// $ThisFileInfo['gif']['extension_blocks'][] = $ExtensionBlock;
149// break;
150//
151// case ';':
152// $ThisFileInfo['gif']['terminator_offset'] = ftell($fd) - 1;
153// // GIF Terminator
154// break;
155//
156// default:
157// break;
158//
159//
160// }
161// }
162
163 return true;
164 }

References getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\LittleEndian2Int().

+ Here is the call graph for this function:

◆ GetLSBits() [1/2]

getid3_gif::GetLSBits (   $bits)

Definition at line 171 of file module.graphic.gif.php.

171 {
172 static $bitbuffer = '';
173 while (strlen($bitbuffer) < $bits) {
174 $bitbuffer = str_pad(decbin(ord($this->fread(1))), 8, '0', STR_PAD_LEFT).$bitbuffer;
175 }
176 $value = bindec(substr($bitbuffer, 0 - $bits));
177 $bitbuffer = substr($bitbuffer, 0, 0 - $bits);
178
179 return $value;
180 }

References getid3_handler\fread().

+ Here is the call graph for this function:

◆ GetLSBits() [2/2]

getid3_gif::GetLSBits (   $fd,
  $bits 
)

Definition at line 167 of file module.graphic.gif.php.

167 {
168 static $bitbuffer = '';
169 while (strlen($bitbuffer) < $bits) {
170//echo 'Read another byte: '.ftell($fd).'<BR>';
171 $bitbuffer = str_pad(decbin(ord(fread($fd, 1))), 8, '0', STR_PAD_LEFT).$bitbuffer;
172 }
173
174 $value = bindec(substr($bitbuffer, 0 - $bits));
175 $bitbuffer = substr($bitbuffer, 0, 0 - $bits);
176
177 return $value;
178 }

References getid3_handler\fread().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: