24                $info = &$this->getid3->info;
 
   27                $info[
'bmp'][
'header'][
'raw'] = array();
 
   28                $thisfile_bmp                         = &
$info[
'bmp'];
 
   29                $thisfile_bmp_header                  = &$thisfile_bmp[
'header'];
 
   30                $thisfile_bmp_header_raw              = &$thisfile_bmp_header[
'raw'];
 
   42                $BMPheader = $this->
fread(14 + 40);
 
   44                $thisfile_bmp_header_raw[
'identifier']  = substr($BMPheader, $offset, 2);
 
   48                if ($thisfile_bmp_header_raw[
'identifier'] != $magic) {
 
   50                        unset(
$info[
'fileformat']);
 
   70                if (($planes22 == 1) && ($planes26 != 1)) {
 
   71                        $thisfile_bmp[
'type_os']      = 
'OS/2';
 
   72                        $thisfile_bmp[
'type_version'] = 1;
 
   73                } elseif (($planes26 == 1) && ($planes22 != 1)) {
 
   74                        $thisfile_bmp[
'type_os']      = 
'Windows';
 
   75                        $thisfile_bmp[
'type_version'] = 1;
 
   76                } elseif ($thisfile_bmp_header_raw[
'header_size'] == 12) {
 
   77                        $thisfile_bmp[
'type_os']      = 
'OS/2';
 
   78                        $thisfile_bmp[
'type_version'] = 1;
 
   79                } elseif ($thisfile_bmp_header_raw[
'header_size'] == 40) {
 
   80                        $thisfile_bmp[
'type_os']      = 
'Windows';
 
   81                        $thisfile_bmp[
'type_version'] = 1;
 
   82                } elseif ($thisfile_bmp_header_raw[
'header_size'] == 84) {
 
   83                        $thisfile_bmp[
'type_os']      = 
'Windows';
 
   84                        $thisfile_bmp[
'type_version'] = 4;
 
   85                } elseif ($thisfile_bmp_header_raw[
'header_size'] == 100) {
 
   86                        $thisfile_bmp[
'type_os']      = 
'Windows';
 
   87                        $thisfile_bmp[
'type_version'] = 5;
 
   89                        $this->
error(
'Unknown BMP subtype (or not a BMP file)');
 
   90                        unset(
$info[
'fileformat']);
 
   95                $info[
'fileformat']                  = 
'bmp';
 
   96                $info[
'video'][
'dataformat']         = 
'bmp';
 
   97                $info[
'video'][
'lossless']           = 
true;
 
   98                $info[
'video'][
'pixel_aspect_ratio'] = (float) 1;
 
  100                if ($thisfile_bmp[
'type_os'] == 
'OS/2') {
 
  120                        $info[
'video'][
'resolution_x']    = $thisfile_bmp_header_raw[
'width'];
 
  121                        $info[
'video'][
'resolution_y']    = $thisfile_bmp_header_raw[
'height'];
 
  122                        $info[
'video'][
'codec']           = 
'BI_RGB '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
 
  123                        $info[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
 
  125                        if ($thisfile_bmp[
'type_version'] >= 2) {
 
  172                                $info[
'video'][
'codec'] = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
 
  175                } elseif ($thisfile_bmp[
'type_os'] == 
'Windows') {
 
  217                        $info[
'video'][
'resolution_x']    = $thisfile_bmp_header_raw[
'width'];
 
  218                        $info[
'video'][
'resolution_y']    = $thisfile_bmp_header_raw[
'height'];
 
  219                        $info[
'video'][
'codec']           = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
 
  220                        $info[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
 
  222                        if (($thisfile_bmp[
'type_version'] >= 4) || ($thisfile_bmp_header_raw[
'compression'] == 3)) {
 
  224                                $BMPheader .= $this->
fread(44);
 
  247                                $thisfile_bmp_header_raw[
'ciexyz_red']   =                  substr($BMPheader, $offset, 4);
 
  249                                $thisfile_bmp_header_raw[
'ciexyz_green'] =                  substr($BMPheader, $offset, 4);
 
  251                                $thisfile_bmp_header_raw[
'ciexyz_blue']  =                  substr($BMPheader, $offset, 4);
 
  265                        if ($thisfile_bmp[
'type_version'] >= 5) {
 
  266                                $BMPheader .= $this->
fread(16);
 
  286                        $this->
error(
'Unknown BMP format in header.');
 
  292                if ($this->ExtractPalette || $this->ExtractData) {
 
  294                        if ($thisfile_bmp_header_raw[
'bits_per_pixel'] < 16) {
 
  295                                $PaletteEntries = pow(2, $thisfile_bmp_header_raw[
'bits_per_pixel']);
 
  296                        } elseif (isset($thisfile_bmp_header_raw[
'colors_used']) && ($thisfile_bmp_header_raw[
'colors_used'] > 0) && ($thisfile_bmp_header_raw[
'colors_used'] <= 256)) {
 
  297                                $PaletteEntries = $thisfile_bmp_header_raw[
'colors_used'];
 
  299                        if ($PaletteEntries > 0) {
 
  300                                $BMPpalette = $this->
fread(4 * $PaletteEntries);
 
  302                                for (
$i = 0; 
$i < $PaletteEntries; 
$i++) {
 
  311                                        if (($thisfile_bmp[
'type_os'] == 
'OS/2') && ($thisfile_bmp[
'type_version'] == 1)) {
 
  321                if ($this->ExtractData) {
 
  322                        $this->
fseek($thisfile_bmp_header_raw[
'data_offset']);
 
  323                        $RowByteLength = ceil(($thisfile_bmp_header_raw[
'width'] * ($thisfile_bmp_header_raw[
'bits_per_pixel'] / 8)) / 4) * 4; 
 
  324                        $BMPpixelData = $this->
fread($thisfile_bmp_header_raw[
'height'] * $RowByteLength);
 
  325                        $pixeldataoffset = 0;
 
  326                        $thisfile_bmp_header_raw[
'compression'] = (isset($thisfile_bmp_header_raw[
'compression']) ? $thisfile_bmp_header_raw[
'compression'] : 
'');
 
  327                        switch ($thisfile_bmp_header_raw[
'compression']) {
 
  330                                        switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
 
  332                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  333                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
 
  334                                                                        $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
 
  335                                                                        for (
$i = 7; 
$i >= 0; 
$i--) {
 
  336                                                                                $paletteindex = ($paletteindexbyte & (0x01 << 
$i)) >> 
$i;
 
  337                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
 
  341                                                                while (($pixeldataoffset % 4) != 0) {
 
  349                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  350                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
 
  351                                                                        $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
 
  352                                                                        for (
$i = 1; 
$i >= 0; 
$i--) {
 
  353                                                                                $paletteindex = ($paletteindexbyte & (0x0F << (4 * 
$i))) >> (4 * 
$i);
 
  354                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
 
  358                                                                while (($pixeldataoffset % 4) != 0) {
 
  366                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  367                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
 
  368                                                                        $paletteindex = ord($BMPpixelData{$pixeldataoffset++});
 
  369                                                                        $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
 
  371                                                                while (($pixeldataoffset % 4) != 0) {
 
  379                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  380                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
 
  381                                                                        $thisfile_bmp[
'data'][
$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
 
  382                                                                        $pixeldataoffset += 3;
 
  384                                                                while (($pixeldataoffset % 4) != 0) {
 
  392                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  393                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
 
  394                                                                        $thisfile_bmp[
'data'][
$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
 
  395                                                                        $pixeldataoffset += 4;
 
  397                                                                while (($pixeldataoffset % 4) != 0) {
 
  409                                                        $this->
error(
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data');
 
  416                                        switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
 
  419                                                        while ($pixeldataoffset < strlen($BMPpixelData)) {
 
  422                                                                if ($firstbyte == 0) {
 
  427                                                                        switch ($secondbyte) {
 
  435                                                                                        $pixeldataoffset = strlen($BMPpixelData); 
 
  444                                                                                        $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
 
  445                                                                                        $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
 
  446                                                                                        $pixelcounter = (
$row * $thisfile_bmp_header_raw[
'width']) + $col;
 
  454                                                                                        for (
$i = 0; 
$i < $secondbyte; 
$i++) {
 
  456                                                                                                $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
 
  457                                                                                                $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
 
  458                                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
 
  461                                                                                        while (($pixeldataoffset % 2) != 0) {
 
  472                                                                        for (
$i = 0; 
$i < $firstbyte; 
$i++) {
 
  473                                                                                $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
 
  474                                                                                $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
 
  475                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$secondbyte];
 
  484                                                        $this->
error(
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data');
 
  492                                        switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
 
  495                                                        while ($pixeldataoffset < strlen($BMPpixelData)) {
 
  498                                                                if ($firstbyte == 0) {
 
  503                                                                        switch ($secondbyte) {
 
  511                                                                                        $pixeldataoffset = strlen($BMPpixelData); 
 
  520                                                                                        $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
 
  521                                                                                        $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
 
  522                                                                                        $pixelcounter = (
$row * $thisfile_bmp_header_raw[
'width']) + $col;
 
  530                                                                                        unset($paletteindexes);
 
  531                                                                                        for (
$i = 0; 
$i < ceil($secondbyte / 2); 
$i++) {
 
  533                                                                                                $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4;
 
  534                                                                                                $paletteindexes[] = ($paletteindexbyte & 0x0F);
 
  536                                                                                        while (($pixeldataoffset % 2) != 0) {
 
  541                                                                                        foreach ($paletteindexes as $paletteindex) {
 
  542                                                                                                $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
 
  543                                                                                                $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
 
  544                                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
 
  559                                                                        $paletteindexes[0] = ($secondbyte & 0xF0) >> 4;
 
  560                                                                        $paletteindexes[1] = ($secondbyte & 0x0F);
 
  561                                                                        for (
$i = 0; 
$i < $firstbyte; 
$i++) {
 
  562                                                                                $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
 
  563                                                                                $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
 
  564                                                                                $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindexes[(
$i % 2)]];
 
  573                                                        $this->
error(
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data');
 
  580                                        switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
 
  586                                                        while ((($thisfile_bmp_header_raw[
'red_mask'] >> $redshift) & 0x01) == 0) {
 
  589                                                        while ((($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift) & 0x01) == 0) {
 
  592                                                        while ((($thisfile_bmp_header_raw[
'blue_mask'] >> $blueshift) & 0x01) == 0) {
 
  595                                                        for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1); 
$row >= 0; 
$row--) {
 
  596                                                                for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
 
  598                                                                        $pixeldataoffset += $thisfile_bmp_header_raw[
'bits_per_pixel'] / 8;
 
  600                                                                        $red   = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'red_mask'])   >> $redshift)   / ($thisfile_bmp_header_raw[
'red_mask']   >> $redshift))   * 255));
 
  601                                                                        $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift)) * 255));
 
  602                                                                        $blue  = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'blue_mask'])  >> $blueshift)  / ($thisfile_bmp_header_raw[
'blue_mask']  >> $blueshift))  * 255));
 
  605                                                                while (($pixeldataoffset % 4) != 0) {
 
  613                                                        $this->
error(
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data');
 
  620                                        $this->
error(
'Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw[
'compression'].
') - cannot decompress pixel data');
 
  631                if (!isset($BMPinfo[
'bmp'][
'data']) || !is_array($BMPinfo[
'bmp'][
'data'])) {
 
  632                        echo 
'ERROR: no pixel data<BR>';
 
  635                set_time_limit(intval(round($BMPinfo[
'resolution_x'] * $BMPinfo[
'resolution_y'] / 10000)));
 
  636                if ($im = ImageCreateTrueColor($BMPinfo[
'resolution_x'], $BMPinfo[
'resolution_y'])) {
 
  637                        for (
$row = 0; 
$row < $BMPinfo[
'resolution_y']; 
$row++) {
 
  638                                for ($col = 0; $col < $BMPinfo[
'resolution_x']; $col++) {
 
  639                                        if (isset($BMPinfo[
'bmp'][
'data'][
$row][$col])) {
 
  640                                                $red   = ($BMPinfo[
'bmp'][
'data'][
$row][$col] & 0x00FF0000) >> 16;
 
  641                                                $green = ($BMPinfo[
'bmp'][
'data'][
$row][$col] & 0x0000FF00) >> 8;
 
  642                                                $blue  = ($BMPinfo[
'bmp'][
'data'][
$row][$col] & 0x000000FF);
 
  644                                                ImageSetPixel($im, $col, 
$row, $pixelcolor);
 
  651                        if (headers_sent()) {
 
  652                                echo 
'plotted '.($BMPinfo[
'resolution_x'] * $BMPinfo[
'resolution_y']).
' pixels in '.(time() - $starttime).
' seconds<BR>';
 
  656                                header(
'Content-type: image/png');
 
  666                static $BMPcompressionWindowsLookup = array(
 
  674                return (isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] : 
'invalid');
 
  678                static $BMPcompressionOS2Lookup = array(
 
  685                return (isset($BMPcompressionOS2Lookup[$compressionid]) ? $BMPcompressionOS2Lookup[$compressionid] : 
'invalid');
 
An exception for terminatinating execution or to throw for unit testing.
getID3() by James Heinrich info@getid3.org //
BMPcompressionOS2Lookup($compressionid)
BMPcompressionWindowsLookup($compressionid)
fseek($bytes, $whence=SEEK_SET)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
static FixedPoint2_30($rawdata)
static LittleEndian2Int($byteword, $signed=false)