1 | <?php |
---|
2 | // +----------------------------------------------------------------------+ |
---|
3 | // | PHP version 5 | |
---|
4 | // +----------------------------------------------------------------------+ |
---|
5 | // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | |
---|
6 | // +----------------------------------------------------------------------+ |
---|
7 | // | This source file is subject to version 2 of the GPL license, | |
---|
8 | // | that is bundled with this package in the file license.txt and is | |
---|
9 | // | available through the world-wide-web at the following url: | |
---|
10 | // | http://www.gnu.org/copyleft/gpl.html | |
---|
11 | // +----------------------------------------------------------------------+ |
---|
12 | // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | |
---|
13 | // +----------------------------------------------------------------------+ |
---|
14 | // | Authors: James Heinrich <infoØgetid3*org> | |
---|
15 | // | Allan Hansen <ahØartemis*dk> | |
---|
16 | // +----------------------------------------------------------------------+ |
---|
17 | // | module.graphic.gif.php | |
---|
18 | // | Module for analyzing CompuServe GIF graphic files. | |
---|
19 | // | dependencies: NONE | |
---|
20 | // +----------------------------------------------------------------------+ |
---|
21 | // |
---|
22 | // $Id: module.graphic.gif.php 3318 2009-05-20 21:54:10Z vdigital $ |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | class getid3_gif extends getid3_handler |
---|
27 | { |
---|
28 | |
---|
29 | public function Analyze() { |
---|
30 | |
---|
31 | $getid3 = $this->getid3; |
---|
32 | |
---|
33 | $getid3->info['fileformat'] = 'gif'; |
---|
34 | $getid3->info['video']['dataformat'] = 'gif'; |
---|
35 | $getid3->info['video']['lossless'] = true; |
---|
36 | $getid3->info['video']['pixel_aspect_ratio'] = (float)1; |
---|
37 | |
---|
38 | $getid3->info['gif']['header'] = array (); |
---|
39 | $info_gif_header = &$getid3->info['gif']['header']; |
---|
40 | |
---|
41 | fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
---|
42 | $gif_header = fread($getid3->fp, 13); |
---|
43 | |
---|
44 | // Magic bytes |
---|
45 | $info_gif_header['raw']['identifier'] = 'GIF'; |
---|
46 | |
---|
47 | getid3_lib::ReadSequence('LittleEndian2Int', $info_gif_header['raw'], $gif_header, 3, |
---|
48 | array ( |
---|
49 | 'version' => -3, // string |
---|
50 | 'width' => 2, |
---|
51 | 'height' => 2, |
---|
52 | 'flags' => 1, |
---|
53 | 'bg_color_index' => 1, |
---|
54 | 'aspect_ratio' => 1 |
---|
55 | ) |
---|
56 | ); |
---|
57 | |
---|
58 | $getid3->info['video']['resolution_x'] = $info_gif_header['raw']['width']; |
---|
59 | $getid3->info['video']['resolution_y'] = $info_gif_header['raw']['height']; |
---|
60 | $getid3->info['gif']['version'] = $info_gif_header['raw']['version']; |
---|
61 | |
---|
62 | $info_gif_header['flags']['global_color_table'] = (bool)($info_gif_header['raw']['flags'] & 0x80); |
---|
63 | |
---|
64 | if ($info_gif_header['raw']['flags'] & 0x80) { |
---|
65 | // Number of bits per primary color available to the original image, minus 1 |
---|
66 | $info_gif_header['bits_per_pixel'] = 3 * ((($info_gif_header['raw']['flags'] & 0x70) >> 4) + 1); |
---|
67 | } else { |
---|
68 | $info_gif_header['bits_per_pixel'] = 0; |
---|
69 | } |
---|
70 | |
---|
71 | $info_gif_header['flags']['global_color_sorted'] = (bool)($info_gif_header['raw']['flags'] & 0x40); |
---|
72 | if ($info_gif_header['flags']['global_color_table']) { |
---|
73 | // the number of bytes contained in the Global Color Table. To determine that |
---|
74 | // actual size of the color table, raise 2 to [the value of the field + 1] |
---|
75 | $info_gif_header['global_color_size'] = pow(2, ($info_gif_header['raw']['flags'] & 0x07) + 1); |
---|
76 | $getid3->info['video']['bits_per_sample'] = ($info_gif_header['raw']['flags'] & 0x07) + 1; |
---|
77 | } else { |
---|
78 | $info_gif_header['global_color_size'] = 0; |
---|
79 | } |
---|
80 | |
---|
81 | if ($info_gif_header['raw']['aspect_ratio'] != 0) { |
---|
82 | // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 |
---|
83 | $info_gif_header['aspect_ratio'] = ($info_gif_header['raw']['aspect_ratio'] + 15) / 64; |
---|
84 | } |
---|
85 | |
---|
86 | return true; |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | ?> |
---|