Ignore:
Timestamp:
Jul 7, 2009, 10:27:37 PM (15 years ago)
Author:
vdigital
Message:

Change: getid3 upgraded to -> 1.7.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/charlies_content/getid3/getid3/module.graphic.gif.php

    r3318 r3544  
    11<?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$
     2/////////////////////////////////////////////////////////////////
     3/// getID3() by James Heinrich <info@getid3.org>               //
     4//  available at http://getid3.sourceforge.net                 //
     5//            or http://www.getid3.org                         //
     6/////////////////////////////////////////////////////////////////
     7// See readme.txt for more details                             //
     8/////////////////////////////////////////////////////////////////
     9//                                                             //
     10// module.graphic.gif.php                                      //
     11// module for analyzing GIF Image files                        //
     12// dependencies: NONE                                          //
     13//                                                            ///
     14/////////////////////////////////////////////////////////////////
    2315
    24        
    25        
    26 class getid3_gif extends getid3_handler
     16
     17class getid3_gif
    2718{
    2819
    29     public function Analyze() {
    30        
    31         $getid3 = $this->getid3;
     20        function getid3_gif(&$fd, &$ThisFileInfo) {
     21                $ThisFileInfo['fileformat']                  = 'gif';
     22                $ThisFileInfo['video']['dataformat']         = 'gif';
     23                $ThisFileInfo['video']['lossless']           = true;
     24                $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
    3225
    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'];
     26                fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     27                $GIFheader = fread($fd, 13);
     28                $offset = 0;
    4029
    41         fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    42         $gif_header = fread($getid3->fp, 13);
     30                $ThisFileInfo['gif']['header']['raw']['identifier']            =                              substr($GIFheader, $offset, 3);
     31                $offset += 3;
    4332
    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         );
     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                }
    5739
    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         }
     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;
    8552
    86         return true;
    87     }
     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        }
     165
     166
     167        function GetLSBits($fd, $bits) {
     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        }
    88179
    89180}
Note: See TracChangeset for help on using the changeset viewer.