diff e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.png.php @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.graphic.png.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,556 @@
     1.4 +<?php
     1.5 +// +----------------------------------------------------------------------+
     1.6 +// | PHP version 5                                                        |
     1.7 +// +----------------------------------------------------------------------+
     1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
     1.9 +// +----------------------------------------------------------------------+
    1.10 +// | This source file is subject to version 2 of the GPL license,         |
    1.11 +// | that is bundled with this package in the file license.txt and is     |
    1.12 +// | available through the world-wide-web at the following url:           |
    1.13 +// | http://www.gnu.org/copyleft/gpl.html                                 |
    1.14 +// +----------------------------------------------------------------------+
    1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
    1.16 +// +----------------------------------------------------------------------+
    1.17 +// | Authors: James Heinrich <infoØgetid3*org>                            |
    1.18 +// |          Allan Hansen <ahØartemis*dk>                                |
    1.19 +// +----------------------------------------------------------------------+
    1.20 +// | module.graphic.png.php                                               |
    1.21 +// | Module for analyzing PNG graphic files.                              |
    1.22 +// | dependencies: zlib support in PHP (optional)                         |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.graphic.png.php,v 1.4 2006/11/02 10:48:02 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_png extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +
    1.34 +        $getid3 = $this->getid3;
    1.35 +
    1.36 +        $getid3->info['png'] = array ();
    1.37 +        $info_png = &$getid3->info['png'];
    1.38 +
    1.39 +        $getid3->info['fileformat']          = 'png';
    1.40 +        $getid3->info['video']['dataformat'] = 'png';
    1.41 +        $getid3->info['video']['lossless']   = false;
    1.42 +
    1.43 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.44 +        $png_filedata = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
    1.45 +
    1.46 +        // Magic bytes  "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
    1.47 +
    1.48 +        $offset = 8;
    1.49 +
    1.50 +        while (((ftell($getid3->fp) - (strlen($png_filedata) - $offset)) < $getid3->info['filesize'])) {
    1.51 +            
    1.52 +            $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4));
    1.53 +            $offset += 4;
    1.54 +            while (((strlen($png_filedata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($getid3->fp) < $getid3->info['filesize'])) {
    1.55 +                $png_filedata .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
    1.56 +            }
    1.57 +            
    1.58 +            $chunk['type_text'] = substr($png_filedata, $offset, 4);
    1.59 +            $chunk['type_raw']  = getid3_lib::BigEndian2Int($chunk['type_text']);
    1.60 +            $offset += 4;
    1.61 +            
    1.62 +            $chunk['data'] = substr($png_filedata, $offset, $chunk['data_length']);
    1.63 +            $offset += $chunk['data_length'];
    1.64 +            
    1.65 +            $chunk['crc'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4));
    1.66 +            $offset += 4;
    1.67 +
    1.68 +            $chunk['flags']['ancilliary']   = (bool)($chunk['type_raw'] & 0x20000000);
    1.69 +            $chunk['flags']['private']      = (bool)($chunk['type_raw'] & 0x00200000);
    1.70 +            $chunk['flags']['reserved']     = (bool)($chunk['type_raw'] & 0x00002000);
    1.71 +            $chunk['flags']['safe_to_copy'] = (bool)($chunk['type_raw'] & 0x00000020);
    1.72 +
    1.73 +            // shortcut
    1.74 +            $info_png[$chunk['type_text']] = array ();
    1.75 +            $info_png_chunk_type_text = &$info_png[$chunk['type_text']];
    1.76 +
    1.77 +            switch ($chunk['type_text']) {
    1.78 +
    1.79 +                case 'IHDR': // Image Header
    1.80 +                    $info_png_chunk_type_text['header'] = $chunk;
    1.81 +                    $info_png_chunk_type_text['width']  = getid3_lib::BigEndian2Int(substr($chunk['data'],  0, 4));
    1.82 +                    $info_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'],  4, 4));
    1.83 +                    
    1.84 +                    getid3_lib::ReadSequence('BigEndian2Int', $info_png_chunk_type_text['raw'], $chunk['data'], 8, 
    1.85 +                        array (
    1.86 +                            'bit_depth'          => 1,
    1.87 +                            'color_type'         => 1,
    1.88 +                            'compression_method' => 1,
    1.89 +                            'filter_method'      => 1,
    1.90 +                            'interlace_method'   => 1
    1.91 +                        )
    1.92 +                    );
    1.93 +
    1.94 +                    $info_png_chunk_type_text['compression_method_text']  = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['raw']['compression_method']);
    1.95 +                    $info_png_chunk_type_text['color_type']['palette']    = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x01);
    1.96 +                    $info_png_chunk_type_text['color_type']['true_color'] = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x02);
    1.97 +                    $info_png_chunk_type_text['color_type']['alpha']      = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x04);
    1.98 +
    1.99 +                    $getid3->info['video']['resolution_x'] = $info_png_chunk_type_text['width'];
   1.100 +                    $getid3->info['video']['resolution_y'] = $info_png_chunk_type_text['height'];
   1.101 +
   1.102 +                    $getid3->info['video']['bits_per_sample'] = getid3_png::IHDRcalculateBitsPerSample($info_png_chunk_type_text['raw']['color_type'], $info_png_chunk_type_text['raw']['bit_depth']);
   1.103 +                    break;
   1.104 +
   1.105 +
   1.106 +                case 'PLTE': // Palette
   1.107 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.108 +                    $palette_offset = 0;
   1.109 +                    for ($i = 0; $i <= 255; $i++) {
   1.110 +                        $red   = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
   1.111 +                        $green = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
   1.112 +                        $blue  = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
   1.113 +                        $info_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue));
   1.114 +                    }
   1.115 +                    break;
   1.116 +
   1.117 +
   1.118 +                case 'tRNS': // Transparency
   1.119 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.120 +                    switch ($info_png['IHDR']['raw']['color_type']) {
   1.121 +                        case 0:
   1.122 +                            $info_png_chunk_type_text['transparent_color_gray']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
   1.123 +                            break;
   1.124 +
   1.125 +                        case 2:
   1.126 +                            $info_png_chunk_type_text['transparent_color_red']   = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
   1.127 +                            $info_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2));
   1.128 +                            $info_png_chunk_type_text['transparent_color_blue']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 2));
   1.129 +                            break;
   1.130 +
   1.131 +                        case 3:
   1.132 +                            for ($i = 0; $i < strlen($chunk['data']); $i++) {
   1.133 +                                $info_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int($chunk['data'][$i]);
   1.134 +                            }
   1.135 +                            break;
   1.136 +
   1.137 +                        case 4:
   1.138 +                        case 6:
   1.139 +                            throw new getid3_exception('Invalid color_type in tRNS chunk: '.$info_png['IHDR']['raw']['color_type']);
   1.140 +
   1.141 +                        default:
   1.142 +                            $getid3->warning('Unhandled color_type in tRNS chunk: '.$info_png['IHDR']['raw']['color_type']);
   1.143 +                            break;
   1.144 +                    }
   1.145 +                    break;
   1.146 +
   1.147 +
   1.148 +                case 'gAMA': // Image Gamma
   1.149 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.150 +                    $info_png_chunk_type_text['gamma']  = getid3_lib::BigEndian2Int($chunk['data']) / 100000;
   1.151 +                    break;
   1.152 +
   1.153 +
   1.154 +                case 'cHRM': // Primary Chromaticities
   1.155 +                    $info_png_chunk_type_text['header']  = $chunk;
   1.156 +                    $info_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'],  0, 4)) / 100000;
   1.157 +                    $info_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'],  4, 4)) / 100000;
   1.158 +                    $info_png_chunk_type_text['red_y']   = getid3_lib::BigEndian2Int(substr($chunk['data'],  8, 4)) / 100000;
   1.159 +                    $info_png_chunk_type_text['red_y']   = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
   1.160 +                    $info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
   1.161 +                    $info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
   1.162 +                    $info_png_chunk_type_text['blue_y']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
   1.163 +                    $info_png_chunk_type_text['blue_y']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
   1.164 +                    break;
   1.165 +
   1.166 +
   1.167 +                case 'sRGB': // Standard RGB Color Space
   1.168 +                    $info_png_chunk_type_text['header']                 = $chunk;
   1.169 +                    $info_png_chunk_type_text['reindering_intent']      = getid3_lib::BigEndian2Int($chunk['data']);
   1.170 +                    $info_png_chunk_type_text['reindering_intent_text'] = getid3_png::PNGsRGBintentLookup($info_png_chunk_type_text['reindering_intent']);
   1.171 +                    break;
   1.172 +
   1.173 +
   1.174 +                case 'iCCP': // Embedded ICC Profile
   1.175 +                    $info_png_chunk_type_text['header']                  = $chunk;
   1.176 +                    list($profilename, $compressiondata)                 = explode("\x00", $chunk['data'], 2);
   1.177 +                    $info_png_chunk_type_text['profile_name']            = $profilename;
   1.178 +                    $info_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int($compressiondata[0]);
   1.179 +                    $info_png_chunk_type_text['compression_profile']     = substr($compressiondata, 1);
   1.180 +                    $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
   1.181 +                    break;
   1.182 +
   1.183 +
   1.184 +                case 'tEXt': // Textual Data
   1.185 +                    $info_png_chunk_type_text['header']  = $chunk;
   1.186 +                    list($keyword, $text)                                = explode("\x00", $chunk['data'], 2);
   1.187 +                    $info_png_chunk_type_text['keyword'] = $keyword;
   1.188 +                    $info_png_chunk_type_text['text']    = $text;
   1.189 +
   1.190 +                    $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
   1.191 +                    break;
   1.192 +
   1.193 +
   1.194 +                case 'zTXt': // Compressed Textual Data
   1.195 +                    $info_png_chunk_type_text['header']                  = $chunk;
   1.196 +                    list($keyword, $otherdata)                           = explode("\x00", $chunk['data'], 2);
   1.197 +                    $info_png_chunk_type_text['keyword']                 = $keyword;
   1.198 +                    $info_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
   1.199 +                    $info_png_chunk_type_text['compressed_text']         = substr($otherdata, 1);
   1.200 +                    $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
   1.201 +                    
   1.202 +                    if ($info_png_chunk_type_text['compression_method'] != 0) {
   1.203 +                        // unknown compression method
   1.204 +                        break;
   1.205 +                    }
   1.206 +                    
   1.207 +                    if (function_exists('gzuncompress')) {
   1.208 +                        $info_png_chunk_type_text['text']  = gzuncompress($info_png_chunk_type_text['compressed_text']);
   1.209 +                    }
   1.210 +                    else {
   1.211 +                        if (!@$this->zlib_warning) {
   1.212 +                            $getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
   1.213 +                        }
   1.214 +                        $this->zlib_warning = true;
   1.215 +                    }
   1.216 +                    
   1.217 +
   1.218 +                    if (isset($info_png_chunk_type_text['text'])) {
   1.219 +                        $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
   1.220 +                    }
   1.221 +                    break;
   1.222 +
   1.223 +
   1.224 +                case 'iTXt': // International Textual Data
   1.225 +                    $info_png_chunk_type_text['header']                  = $chunk;
   1.226 +                    list($keyword, $otherdata)                           = explode("\x00", $chunk['data'], 2);
   1.227 +                    $info_png_chunk_type_text['keyword']                 = $keyword;
   1.228 +                    $info_png_chunk_type_text['compression']             = (bool)getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
   1.229 +                    $info_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int($otherdata[1]);
   1.230 +                    $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
   1.231 +                    list($languagetag, $translatedkeyword, $text)        = explode("\x00", substr($otherdata, 2), 3);
   1.232 +                    $info_png_chunk_type_text['language_tag']            = $languagetag;
   1.233 +                    $info_png_chunk_type_text['translated_keyword']      = $translatedkeyword;
   1.234 +
   1.235 +                    if ($info_png_chunk_type_text['compression']) {
   1.236 +
   1.237 +                        switch ($info_png_chunk_type_text['compression_method']) {
   1.238 +                            case 0:
   1.239 +                                if (function_exists('gzuncompress')) {
   1.240 +                                    $info_png_chunk_type_text['text'] = gzuncompress($text);
   1.241 +                                }
   1.242 +                                else {
   1.243 +                                    if (!@$this->zlib_warning) {
   1.244 +                                        $getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
   1.245 +                                    }
   1.246 +                                    $this->zlib_warning = true;
   1.247 +                                }
   1.248 +                                break;
   1.249 +
   1.250 +                            default:
   1.251 +                                // unknown compression method
   1.252 +                                break;
   1.253 +                        }
   1.254 +
   1.255 +                    } else {
   1.256 +
   1.257 +                        $info_png_chunk_type_text['text']                = $text;
   1.258 +
   1.259 +                    }
   1.260 +
   1.261 +                    if (isset($info_png_chunk_type_text['text'])) {
   1.262 +                        $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
   1.263 +                    }
   1.264 +                    break;
   1.265 +
   1.266 +
   1.267 +                case 'bKGD': // Background Color
   1.268 +                    $info_png_chunk_type_text['header']                   = $chunk;
   1.269 +                    switch ($info_png['IHDR']['raw']['color_type']) {
   1.270 +                        case 0:
   1.271 +                        case 4:
   1.272 +                            $info_png_chunk_type_text['background_gray']  = getid3_lib::BigEndian2Int($chunk['data']);
   1.273 +                            break;
   1.274 +
   1.275 +                        case 2:
   1.276 +                        case 6:
   1.277 +                            $info_png_chunk_type_text['background_red']   = getid3_lib::BigEndian2Int(substr($chunk['data'], 0 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
   1.278 +                            $info_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
   1.279 +                            $info_png_chunk_type_text['background_blue']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 2 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
   1.280 +                            break;
   1.281 +
   1.282 +                        case 3:
   1.283 +                            $info_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($chunk['data']);
   1.284 +                            break;
   1.285 +
   1.286 +                        default:
   1.287 +                            break;
   1.288 +                    }
   1.289 +                    break;
   1.290 +
   1.291 +
   1.292 +                case 'pHYs': // Physical Pixel Dimensions
   1.293 +                    $info_png_chunk_type_text['header']                 = $chunk;
   1.294 +                    $info_png_chunk_type_text['pixels_per_unit_x']      = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4));
   1.295 +                    $info_png_chunk_type_text['pixels_per_unit_y']      = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4));
   1.296 +                    $info_png_chunk_type_text['unit_specifier']         = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1));
   1.297 +                    $info_png_chunk_type_text['unit']                   = getid3_png::PNGpHYsUnitLookup($info_png_chunk_type_text['unit_specifier']);
   1.298 +                    break;
   1.299 +
   1.300 +
   1.301 +                case 'sBIT': // Significant Bits
   1.302 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.303 +                    switch ($info_png['IHDR']['raw']['color_type']) {
   1.304 +                        case 0:
   1.305 +                            $info_png_chunk_type_text['significant_bits_gray']  = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
   1.306 +                            break;
   1.307 +
   1.308 +                        case 2:
   1.309 +                        case 3:
   1.310 +                            $info_png_chunk_type_text['significant_bits_red']   = getid3_lib::BigEndian2Int($chunk['data'][0]);
   1.311 +                            $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
   1.312 +                            $info_png_chunk_type_text['significant_bits_blue']  = getid3_lib::BigEndian2Int($chunk['data'][2]);
   1.313 +                            break;                                                                                                                     
   1.314 +                                                                                                                                                       
   1.315 +                        case 4:                                                                                                                        
   1.316 +                            $info_png_chunk_type_text['significant_bits_gray']  = getid3_lib::BigEndian2Int($chunk['data'][0]);
   1.317 +                            $info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
   1.318 +                            break;                                                                                                                     
   1.319 +                                                                                                                                                       
   1.320 +                        case 6:                                                                                                                        
   1.321 +                            $info_png_chunk_type_text['significant_bits_red']   = getid3_lib::BigEndian2Int($chunk['data'][0]);
   1.322 +                            $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
   1.323 +                            $info_png_chunk_type_text['significant_bits_blue']  = getid3_lib::BigEndian2Int($chunk['data'][2]);
   1.324 +                            $info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][3]);
   1.325 +                            break;
   1.326 +
   1.327 +                        default:
   1.328 +                            break;
   1.329 +                    }
   1.330 +                    break;
   1.331 +
   1.332 +
   1.333 +                case 'sPLT': // Suggested Palette
   1.334 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.335 +                    
   1.336 +                    list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2);
   1.337 +                    $info_png_chunk_type_text['palette_name'] = $palettename;
   1.338 +                    
   1.339 +                    $info_png_chunk_type_text['sample_depth_bits']  = getid3_lib::BigEndian2Int($otherdata[0]);
   1.340 +                    $info_png_chunk_type_text['sample_depth_bytes'] = $info_png_chunk_type_text['sample_depth_bits'] / 8;
   1.341 +                    
   1.342 +                    $s_plt_offset = 1;
   1.343 +                    $paletteCounter = 0;
   1.344 +                    while ($s_plt_offset < strlen($otherdata)) {
   1.345 +                        
   1.346 +                        $info_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
   1.347 +                        $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
   1.348 +                        
   1.349 +                        $info_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
   1.350 +                        $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
   1.351 +                        
   1.352 +                        $info_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
   1.353 +                        $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
   1.354 +                        
   1.355 +                        $info_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
   1.356 +                        $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
   1.357 +                        
   1.358 +                        $info_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, 2));
   1.359 +                        $s_plt_offset += 2;
   1.360 +                        
   1.361 +                        $paletteCounter++;
   1.362 +                    }
   1.363 +                    break;
   1.364 +
   1.365 +
   1.366 +                case 'hIST': // Palette Histogram
   1.367 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.368 +                    $h_ist_counter = 0;
   1.369 +                    while ($h_ist_counter < strlen($chunk['data'])) {
   1.370 +                        $info_png_chunk_type_text[$h_ist_counter] = getid3_lib::BigEndian2Int(substr($chunk['data'], $h_ist_counter / 2, 2));
   1.371 +                        $h_ist_counter += 2;
   1.372 +                    }
   1.373 +                    break;
   1.374 +
   1.375 +
   1.376 +                case 'tIME': // Image Last-Modification Time
   1.377 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.378 +                    $info_png_chunk_type_text['year']   = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
   1.379 +                    $info_png_chunk_type_text['month']  = getid3_lib::BigEndian2Int($chunk['data']{2});
   1.380 +                    $info_png_chunk_type_text['day']    = getid3_lib::BigEndian2Int($chunk['data']{3});
   1.381 +                    $info_png_chunk_type_text['hour']   = getid3_lib::BigEndian2Int($chunk['data']{4});
   1.382 +                    $info_png_chunk_type_text['minute'] = getid3_lib::BigEndian2Int($chunk['data']{5});
   1.383 +                    $info_png_chunk_type_text['second'] = getid3_lib::BigEndian2Int($chunk['data']{6});
   1.384 +                    $info_png_chunk_type_text['unix']   = gmmktime($info_png_chunk_type_text['hour'], $info_png_chunk_type_text['minute'], $info_png_chunk_type_text['second'], $info_png_chunk_type_text['month'], $info_png_chunk_type_text['day'], $info_png_chunk_type_text['year']);
   1.385 +                    break;
   1.386 +
   1.387 +
   1.388 +                case 'oFFs': // Image Offset
   1.389 +                    $info_png_chunk_type_text['header']         = $chunk;
   1.390 +                    $info_png_chunk_type_text['position_x']     = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
   1.391 +                    $info_png_chunk_type_text['position_y']     = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
   1.392 +                    $info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int($chunk['data'][8]);
   1.393 +                    $info_png_chunk_type_text['unit']           = getid3_png::PNGoFFsUnitLookup($info_png_chunk_type_text['unit_specifier']);
   1.394 +                    break;
   1.395 +
   1.396 +
   1.397 +                case 'pCAL': // Calibration Of Pixel Values
   1.398 +                    $info_png_chunk_type_text['header']             = $chunk;
   1.399 +                    list($calibrationname, $otherdata)              = explode("\x00", $chunk['data'], 2);
   1.400 +                    $info_png_chunk_type_text['calibration_name']   = $calibrationname;
   1.401 +                    $info_png_chunk_type_text['original_zero']      = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
   1.402 +                    $info_png_chunk_type_text['original_max']       = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
   1.403 +                    $info_png_chunk_type_text['equation_type']      = getid3_lib::BigEndian2Int($chunk['data'][8]);
   1.404 +                    $info_png_chunk_type_text['equation_type_text'] = getid3_png::PNGpCALequationTypeLookup($info_png_chunk_type_text['equation_type']);
   1.405 +                    $info_png_chunk_type_text['parameter_count']    = getid3_lib::BigEndian2Int($chunk['data'][9]);
   1.406 +                    $info_png_chunk_type_text['parameters']         = explode("\x00", substr($chunk['data'], 10));
   1.407 +                    break;
   1.408 +
   1.409 +
   1.410 +                case 'sCAL': // Physical Scale Of Image Subject
   1.411 +                    $info_png_chunk_type_text['header']         = $chunk;
   1.412 +                    $info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
   1.413 +                    $info_png_chunk_type_text['unit']           = getid3_png::PNGsCALUnitLookup($info_png_chunk_type_text['unit_specifier']);
   1.414 +                    list($info_png_chunk_type_text['pixel_width'], $info_png_chunk_type_text['pixel_height']) = explode("\x00", substr($chunk['data'], 1));
   1.415 +                    break;
   1.416 +
   1.417 +
   1.418 +                case 'gIFg': // GIF Graphic Control Extension
   1.419 +                    $gIFg_counter = 0;
   1.420 +                    if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
   1.421 +                        $gIFg_counter = count($info_png_chunk_type_text);
   1.422 +                    }
   1.423 +                    $info_png_chunk_type_text[$gIFg_counter]['header']          = $chunk;
   1.424 +                    $info_png_chunk_type_text[$gIFg_counter]['disposal_method'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
   1.425 +                    $info_png_chunk_type_text[$gIFg_counter]['user_input_flag'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
   1.426 +                    $info_png_chunk_type_text[$gIFg_counter]['delay_time']      = getid3_lib::BigEndian2Int($chunk['data'][2]);
   1.427 +                    break;
   1.428 +
   1.429 +
   1.430 +                case 'gIFx': // GIF Application Extension
   1.431 +                    $gIFx_counter = 0;
   1.432 +                    if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
   1.433 +                        $gIFx_counter = count($info_png_chunk_type_text);
   1.434 +                    }
   1.435 +                    $info_png_chunk_type_text[$gIFx_counter]['header']                 = $chunk;
   1.436 +                    $info_png_chunk_type_text[$gIFx_counter]['application_identifier'] = substr($chunk['data'],  0, 8);
   1.437 +                    $info_png_chunk_type_text[$gIFx_counter]['authentication_code']    = substr($chunk['data'],  8, 3);
   1.438 +                    $info_png_chunk_type_text[$gIFx_counter]['application_data']       = substr($chunk['data'], 11);
   1.439 +                    break;
   1.440 +
   1.441 +
   1.442 +                case 'IDAT': // Image Data
   1.443 +                    $idat_information_field_index = 0;
   1.444 +                    if (isset($info_png['IDAT']) && is_array($info_png['IDAT'])) {
   1.445 +                        $idat_information_field_index = count($info_png['IDAT']);
   1.446 +                    }
   1.447 +                    unset($chunk['data']);
   1.448 +                    $info_png_chunk_type_text[$idat_information_field_index]['header'] = $chunk;
   1.449 +                    break;
   1.450 +
   1.451 +
   1.452 +                case 'IEND': // Image Trailer
   1.453 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.454 +                    break;
   1.455 +
   1.456 +
   1.457 +                default:
   1.458 +                    $info_png_chunk_type_text['header'] = $chunk;
   1.459 +                    $getid3->warning('Unhandled chunk type: '.$chunk['type_text']);
   1.460 +                    break;
   1.461 +            }
   1.462 +        }
   1.463 +
   1.464 +        return true;
   1.465 +    }
   1.466 +
   1.467 +
   1.468 +
   1.469 +    public static function PNGsRGBintentLookup($sRGB) {
   1.470 +        
   1.471 +        static $lookup = array (
   1.472 +            0 => 'Perceptual',
   1.473 +            1 => 'Relative colorimetric',
   1.474 +            2 => 'Saturation',
   1.475 +            3 => 'Absolute colorimetric'
   1.476 +        );
   1.477 +        return (isset($lookup[$sRGB]) ? $lookup[$sRGB] : 'invalid');
   1.478 +    }
   1.479 +
   1.480 +
   1.481 +
   1.482 +    public static function PNGcompressionMethodLookup($compression_method) {
   1.483 +    
   1.484 +        return ($compression_method == 0 ?  'deflate/inflate' : 'invalid');
   1.485 +    }
   1.486 +
   1.487 +    
   1.488 +    
   1.489 +    public static function PNGpHYsUnitLookup($unit_id) {
   1.490 +    
   1.491 +        static $lookup = array (
   1.492 +            0 => 'unknown',
   1.493 +            1 => 'meter'
   1.494 +        );
   1.495 +        return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
   1.496 +    }
   1.497 +
   1.498 +    
   1.499 +    
   1.500 +    public static function PNGoFFsUnitLookup($unit_id) {
   1.501 +    
   1.502 +        static $lookup = array (
   1.503 +            0 => 'pixel',
   1.504 +            1 => 'micrometer'
   1.505 +        );
   1.506 +        return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
   1.507 +    }
   1.508 +
   1.509 +    
   1.510 +    
   1.511 +    public static function PNGpCALequationTypeLookup($equation_type) {
   1.512 +        
   1.513 +        static $lookup = array (
   1.514 +            0 => 'Linear mapping',
   1.515 +            1 => 'Base-e exponential mapping',
   1.516 +            2 => 'Arbitrary-base exponential mapping',
   1.517 +            3 => 'Hyperbolic mapping'
   1.518 +        );
   1.519 +        return (isset($lookup[$equation_type]) ? $lookup[$equation_type] : 'invalid');
   1.520 +    }
   1.521 +
   1.522 +
   1.523 +
   1.524 +    public static function PNGsCALUnitLookup($unit_id) {
   1.525 +
   1.526 +        static $lookup = array (
   1.527 +            0 => 'meter',
   1.528 +            1 => 'radian'
   1.529 +        );
   1.530 +        return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
   1.531 +    }
   1.532 +
   1.533 +    
   1.534 +    
   1.535 +    public static function IHDRcalculateBitsPerSample($color_type, $bit_depth) {
   1.536 +    
   1.537 +        switch ($color_type) {
   1.538 +            case 0: // Each pixel is a grayscale sample.
   1.539 +                return $bit_depth;
   1.540 +
   1.541 +            case 2: // Each pixel is an R,G,B triple
   1.542 +                return 3 * $bit_depth;
   1.543 +
   1.544 +            case 3: // Each pixel is a palette index; a PLTE chunk must appear.
   1.545 +                return $bit_depth;
   1.546 +
   1.547 +            case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
   1.548 +                return 2 * $bit_depth;
   1.549 +
   1.550 +            case 6: // Each pixel is an R,G,B triple, followed by an alpha sample.
   1.551 +                return 4 * $bit_depth;
   1.552 +        }
   1.553 +        return false;
   1.554 +    }
   1.555 +
   1.556 +}
   1.557 +
   1.558 +
   1.559 +?>
   1.560 \ No newline at end of file