28 $ThisFileInfo = array();
29 if ($this->
getid3_bmp($BMPdata, $ThisFileInfo,
true,
true)) {
30 $gd = $this->
PlotPixelsGD($ThisFileInfo[
'bmp'], $truecolor);
37 if ($fp = @fopen($filename,
'rb')) {
38 $BMPdata = fread($fp, filesize($filename));
46 $imageX = ImageSX($gd_image);
47 $imageY = ImageSY($gd_image);
50 for ($y = ($imageY - 1); $y >= 0; $y--) {
52 for ($x = 0; $x < $imageX; $x++) {
54 $thisline .= chr($argb[
'blue']).chr($argb[
'green']).chr($argb[
'red']);
56 while (strlen($thisline) % 4) {
62 $bmpSize = strlen($BMP) + 14 + 40;
64 $BITMAPFILEHEADER =
'BM';
83 return $BITMAPFILEHEADER.$BITMAPINFOHEADER.$BMP;
86 function getid3_bmp(&$BMPdata, &$ThisFileInfo, $ExtractPalette=
false, $ExtractData=
false) {
89 $ThisFileInfo[
'bmp'][
'header'][
'raw'] = array();
90 $thisfile_bmp = &$ThisFileInfo[
'bmp'];
91 $thisfile_bmp_header = &$thisfile_bmp[
'header'];
92 $thisfile_bmp_header_raw = &$thisfile_bmp_header[
'raw'];
104 $BMPheader = substr($BMPdata, $overalloffset, 14 + 40);
105 $overalloffset += (14 + 40);
107 $thisfile_bmp_header_raw[
'identifier'] = substr($BMPheader, $offset, 2);
110 if ($thisfile_bmp_header_raw[
'identifier'] !=
'BM') {
111 $ThisFileInfo[
'error'][] =
'Expecting "BM" at offset '.intval(@$ThisFileInfo[
'avdataoffset']).
', found "'.$thisfile_bmp_header_raw[
'identifier'].
'"';
112 unset($ThisFileInfo[
'fileformat']);
113 unset($ThisFileInfo[
'bmp']);
117 $thisfile_bmp_header_raw[
'filesize'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
119 $thisfile_bmp_header_raw[
'reserved1'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
121 $thisfile_bmp_header_raw[
'reserved2'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
123 $thisfile_bmp_header_raw[
'data_offset'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
125 $thisfile_bmp_header_raw[
'header_size'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
132 if (($planes22 == 1) && ($planes26 != 1)) {
133 $thisfile_bmp[
'type_os'] =
'OS/2';
134 $thisfile_bmp[
'type_version'] = 1;
135 } elseif (($planes26 == 1) && ($planes22 != 1)) {
136 $thisfile_bmp[
'type_os'] =
'Windows';
137 $thisfile_bmp[
'type_version'] = 1;
138 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 12) {
139 $thisfile_bmp[
'type_os'] =
'OS/2';
140 $thisfile_bmp[
'type_version'] = 1;
141 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 40) {
142 $thisfile_bmp[
'type_os'] =
'Windows';
143 $thisfile_bmp[
'type_version'] = 1;
144 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 84) {
145 $thisfile_bmp[
'type_os'] =
'Windows';
146 $thisfile_bmp[
'type_version'] = 4;
147 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 100) {
148 $thisfile_bmp[
'type_os'] =
'Windows';
149 $thisfile_bmp[
'type_version'] = 5;
151 $ThisFileInfo[
'error'][] =
'Unknown BMP subtype (or not a BMP file)';
152 unset($ThisFileInfo[
'fileformat']);
153 unset($ThisFileInfo[
'bmp']);
157 $ThisFileInfo[
'fileformat'] =
'bmp';
158 $ThisFileInfo[
'video'][
'dataformat'] =
'bmp';
159 $ThisFileInfo[
'video'][
'lossless'] =
true;
160 $ThisFileInfo[
'video'][
'pixel_aspect_ratio'] = (float) 1;
162 if ($thisfile_bmp[
'type_os'] ==
'OS/2') {
173 $thisfile_bmp_header_raw[
'width'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
175 $thisfile_bmp_header_raw[
'height'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
177 $thisfile_bmp_header_raw[
'planes'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
179 $thisfile_bmp_header_raw[
'bits_per_pixel'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
182 $ThisFileInfo[
'video'][
'resolution_x'] = $thisfile_bmp_header_raw[
'width'];
183 $ThisFileInfo[
'video'][
'resolution_y'] = $thisfile_bmp_header_raw[
'height'];
184 $ThisFileInfo[
'video'][
'codec'] =
'BI_RGB '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
185 $ThisFileInfo[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
187 if ($thisfile_bmp[
'type_version'] >= 2) {
203 $thisfile_bmp_header_raw[
'compression'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
205 $thisfile_bmp_header_raw[
'bmp_data_size'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
207 $thisfile_bmp_header_raw[
'resolution_h'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
209 $thisfile_bmp_header_raw[
'resolution_v'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
211 $thisfile_bmp_header_raw[
'colors_used'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
213 $thisfile_bmp_header_raw[
'colors_important'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
215 $thisfile_bmp_header_raw[
'resolution_units'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
217 $thisfile_bmp_header_raw[
'reserved1'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
219 $thisfile_bmp_header_raw[
'recording'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
221 $thisfile_bmp_header_raw[
'rendering'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
223 $thisfile_bmp_header_raw[
'size1'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
225 $thisfile_bmp_header_raw[
'size2'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
227 $thisfile_bmp_header_raw[
'color_encoding'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
229 $thisfile_bmp_header_raw[
'identifier'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
234 $ThisFileInfo[
'video'][
'codec'] = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
237 } elseif ($thisfile_bmp[
'type_os'] ==
'Windows') {
255 $thisfile_bmp_header_raw[
'width'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4),
true);
257 $thisfile_bmp_header_raw[
'height'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4),
true);
259 $thisfile_bmp_header_raw[
'planes'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
261 $thisfile_bmp_header_raw[
'bits_per_pixel'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 2));
263 $thisfile_bmp_header_raw[
'compression'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
265 $thisfile_bmp_header_raw[
'bmp_data_size'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
267 $thisfile_bmp_header_raw[
'resolution_h'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4),
true);
269 $thisfile_bmp_header_raw[
'resolution_v'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4),
true);
271 $thisfile_bmp_header_raw[
'colors_used'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
273 $thisfile_bmp_header_raw[
'colors_important'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
277 $ThisFileInfo[
'video'][
'resolution_x'] = $thisfile_bmp_header_raw[
'width'];
278 $ThisFileInfo[
'video'][
'resolution_y'] = $thisfile_bmp_header_raw[
'height'];
279 $ThisFileInfo[
'video'][
'codec'] = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
280 $ThisFileInfo[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
282 if (($thisfile_bmp[
'type_version'] >= 4) || ($thisfile_bmp_header_raw[
'compression'] == 3)) {
284 $BMPheader .= substr($BMPdata, $overalloffset, 44);
285 $overalloffset += 44;
298 $thisfile_bmp_header_raw[
'red_mask'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
300 $thisfile_bmp_header_raw[
'green_mask'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
302 $thisfile_bmp_header_raw[
'blue_mask'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
304 $thisfile_bmp_header_raw[
'alpha_mask'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
306 $thisfile_bmp_header_raw[
'cs_type'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
308 $thisfile_bmp_header_raw[
'ciexyz_red'] = substr($BMPheader, $offset, 4);
310 $thisfile_bmp_header_raw[
'ciexyz_green'] = substr($BMPheader, $offset, 4);
312 $thisfile_bmp_header_raw[
'ciexyz_blue'] = substr($BMPheader, $offset, 4);
314 $thisfile_bmp_header_raw[
'gamma_red'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
316 $thisfile_bmp_header_raw[
'gamma_green'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
318 $thisfile_bmp_header_raw[
'gamma_blue'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
321 $thisfile_bmp_header[
'ciexyz_red'] = $this->
FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_red']));
322 $thisfile_bmp_header[
'ciexyz_green'] = $this->
FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_green']));
323 $thisfile_bmp_header[
'ciexyz_blue'] = $this->
FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_blue']));
326 if ($thisfile_bmp[
'type_version'] >= 5) {
327 $BMPheader .= substr($BMPdata, $overalloffset, 16);
328 $overalloffset += 16;
336 $thisfile_bmp_header_raw[
'intent'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
338 $thisfile_bmp_header_raw[
'profile_data_offset'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
340 $thisfile_bmp_header_raw[
'profile_data_size'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
342 $thisfile_bmp_header_raw[
'reserved3'] = $this->
LittleEndian2Int(substr($BMPheader, $offset, 4));
348 $ThisFileInfo[
'error'][] =
'Unknown BMP format in header.';
353 if ($ExtractPalette || $ExtractData) {
355 if ($thisfile_bmp_header_raw[
'bits_per_pixel'] < 16) {
356 $PaletteEntries = pow(2, $thisfile_bmp_header_raw[
'bits_per_pixel']);
357 } elseif (isset($thisfile_bmp_header_raw[
'colors_used']) && ($thisfile_bmp_header_raw[
'colors_used'] > 0) && ($thisfile_bmp_header_raw[
'colors_used'] <= 256)) {
358 $PaletteEntries = $thisfile_bmp_header_raw[
'colors_used'];
360 if ($PaletteEntries > 0) {
361 $BMPpalette = substr($BMPdata, $overalloffset, 4 * $PaletteEntries);
362 $overalloffset += 4 * $PaletteEntries;
365 for (
$i = 0;
$i < $PaletteEntries;
$i++) {
374 if (($thisfile_bmp[
'type_os'] ==
'OS/2') && ($thisfile_bmp[
'type_version'] == 1)) {
379 $thisfile_bmp[
'palette'][
$i] = (($red << 16) | ($green << 8) | ($blue));
385 $RowByteLength = ceil(($thisfile_bmp_header_raw[
'width'] * ($thisfile_bmp_header_raw[
'bits_per_pixel'] / 8)) / 4) * 4;
387 $BMPpixelData = substr($BMPdata, $thisfile_bmp_header_raw[
'data_offset'], $thisfile_bmp_header_raw[
'height'] * $RowByteLength);
388 $overalloffset = $thisfile_bmp_header_raw[
'data_offset'] + ($thisfile_bmp_header_raw[
'height'] * $RowByteLength);
390 $pixeldataoffset = 0;
391 switch (@$thisfile_bmp_header_raw[
'compression']) {
394 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
396 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
397 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
398 $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
399 for (
$i = 7;
$i >= 0;
$i--) {
400 $paletteindex = ($paletteindexbyte & (0x01 <<
$i)) >>
$i;
401 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
405 while (($pixeldataoffset % 4) != 0) {
413 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
414 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
415 $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
416 for (
$i = 1;
$i >= 0;
$i--) {
417 $paletteindex = ($paletteindexbyte & (0x0F << (4 *
$i))) >> (4 *
$i);
418 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
422 while (($pixeldataoffset % 4) != 0) {
430 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
431 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
432 $paletteindex = ord($BMPpixelData{$pixeldataoffset++});
433 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
435 while (($pixeldataoffset % 4) != 0) {
443 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
444 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
445 $thisfile_bmp[
'data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
446 $pixeldataoffset += 3;
448 while (($pixeldataoffset % 4) != 0) {
456 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
457 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
458 $thisfile_bmp[
'data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
459 $pixeldataoffset += 4;
461 while (($pixeldataoffset % 4) != 0) {
473 $ThisFileInfo[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
480 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
483 while ($pixeldataoffset < strlen($BMPpixelData)) {
484 $firstbyte = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
485 $secondbyte = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
486 if ($firstbyte == 0) {
491 switch ($secondbyte) {
499 $pixeldataoffset = strlen($BMPpixelData);
506 $colincrement = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
507 $rowincrement = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
508 $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
509 $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
510 $pixelcounter = ($row * $thisfile_bmp_header_raw[
'width']) + $col;
518 for (
$i = 0;
$i < $secondbyte;
$i++) {
519 $paletteindex = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
520 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
521 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
522 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
525 while (($pixeldataoffset % 2) != 0) {
536 for (
$i = 0;
$i < $firstbyte;
$i++) {
537 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
538 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
539 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$secondbyte];
548 $ThisFileInfo[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
556 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
559 while ($pixeldataoffset < strlen($BMPpixelData)) {
560 $firstbyte = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
561 $secondbyte = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
562 if ($firstbyte == 0) {
567 switch ($secondbyte) {
575 $pixeldataoffset = strlen($BMPpixelData);
582 $colincrement = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
583 $rowincrement = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
584 $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
585 $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
586 $pixelcounter = ($row * $thisfile_bmp_header_raw[
'width']) + $col;
594 unset($paletteindexes);
595 for (
$i = 0;
$i < ceil($secondbyte / 2);
$i++) {
596 $paletteindexbyte = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
597 $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4;
598 $paletteindexes[] = ($paletteindexbyte & 0x0F);
600 while (($pixeldataoffset % 2) != 0) {
605 foreach ($paletteindexes as $dummy => $paletteindex) {
606 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
607 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
608 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
623 $paletteindexes[0] = ($secondbyte & 0xF0) >> 4;
624 $paletteindexes[1] = ($secondbyte & 0x0F);
625 for (
$i = 0;
$i < $firstbyte;
$i++) {
626 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
627 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
628 $thisfile_bmp[
'data'][$row][$col] = $thisfile_bmp[
'palette'][$paletteindexes[(
$i % 2)]];
637 $ThisFileInfo[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
644 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
650 if (!$thisfile_bmp_header_raw[
'red_mask'] || !$thisfile_bmp_header_raw[
'green_mask'] || !$thisfile_bmp_header_raw[
'blue_mask']) {
651 $ThisFileInfo[
'error'][] =
'missing $thisfile_bmp_header_raw[(red|green|blue)_mask]';
654 while ((($thisfile_bmp_header_raw[
'red_mask'] >> $redshift) & 0x01) == 0) {
657 while ((($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift) & 0x01) == 0) {
660 while ((($thisfile_bmp_header_raw[
'blue_mask'] >> $blueshift) & 0x01) == 0) {
663 for ($row = ($thisfile_bmp_header_raw[
'height'] - 1); $row >= 0; $row--) {
664 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
665 $pixelvalue = $this->
LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw[
'bits_per_pixel'] / 8));
666 $pixeldataoffset += $thisfile_bmp_header_raw[
'bits_per_pixel'] / 8;
668 $red = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'red_mask']) >> $redshift) / ($thisfile_bmp_header_raw[
'red_mask'] >> $redshift)) * 255));
669 $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift)) * 255));
670 $blue = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw[
'blue_mask'] >> $blueshift)) * 255));
671 $thisfile_bmp[
'data'][$row][$col] = (($red << 16) | ($green << 8) | ($blue));
673 while (($pixeldataoffset % 4) != 0) {
681 $ThisFileInfo[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
688 $ThisFileInfo[
'error'][] =
'Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw[
'compression'].
') - cannot decompress pixel data';
697 $red = ($color & 0x00FF0000) >> 16;
698 $green = ($color & 0x0000FF00) >> 8;
699 $blue = ($color & 0x000000FF);
700 return array($red, $green, $blue);
704 $imagewidth = $BMPdata[
'header'][
'raw'][
'width'];
705 $imageheight = $BMPdata[
'header'][
'raw'][
'height'];
709 $gd = @ImageCreateTrueColor($imagewidth, $imageheight);
713 $gd = @ImageCreate($imagewidth, $imageheight);
714 if (!empty($BMPdata[
'palette'])) {
716 foreach ($BMPdata[
'palette'] as $dummy => $color) {
718 ImageColorAllocate($gd, $r, $g, $b);
722 for ($r = 0x00; $r <= 0xFF; $r += 0x33) {
723 for ($g = 0x00; $g <= 0xFF; $g += 0x33) {
724 for ($b = 0x00; $b <= 0xFF; $b += 0x33) {
725 ImageColorAllocate($gd, $r, $g, $b);
732 if (!is_resource($gd)) {
736 foreach ($BMPdata[
'data'] as $row => $colarray) {
740 foreach ($colarray as $col => $color) {
741 list($red, $green, $blue) = $this->
IntColor2RGB($color);
743 $pixelcolor = ImageColorAllocate($gd, $red, $green, $blue);
745 $pixelcolor = ImageColorClosest($gd, $red, $green, $blue);
747 ImageSetPixel($gd, $col, $row, $pixelcolor);
755 if (!isset($BMPinfo[
'bmp'][
'data']) || !is_array($BMPinfo[
'bmp'][
'data'])) {
756 echo
'ERROR: no pixel data<BR>';
760 set_time_limit(intval(round($BMPinfo[
'resolution_x'] * $BMPinfo[
'resolution_y'] / 10000)));
763 if (headers_sent()) {
764 echo
'plotted '.($BMPinfo[
'resolution_x'] * $BMPinfo[
'resolution_y']).
' pixels in '.(time() -
$starttime).
' seconds<BR>';
768 header(
'Content-Type: image/png');
777 static $BMPcompressionWindowsLookup = array(
785 return (isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] :
'invalid');
789 static $BMPcompressionOS2Lookup = array(
796 return (isset($BMPcompressionOS2Lookup[$compressionid]) ? $BMPcompressionOS2Lookup[$compressionid] :
'invalid');
805 if ($floatnumber >= 1) {
806 $truncatednumber = floor($floatnumber);
807 } elseif ($floatnumber <= -1) {
808 $truncatednumber = ceil($floatnumber);
810 $truncatednumber = 0;
812 if ($truncatednumber <= 1073741824) {
813 $truncatednumber = (int) $truncatednumber;
815 return $truncatednumber;
820 $byteword = strrev($byteword);
821 $bytewordlen = strlen($byteword);
822 for (
$i = 0;
$i < $bytewordlen;
$i++) {
823 $intvalue += ord($byteword{
$i}) * pow(256, ($bytewordlen - 1 -
$i));
834 $bytewordlen = strlen($byteword);
835 for (
$i = 0;
$i < $bytewordlen;
$i++) {
836 $binvalue .= str_pad(decbin(ord($byteword{
$i})), 8,
'0', STR_PAD_LEFT);
843 return $this->
Bin2Dec(substr($binarystring, 0, 2)) + (float) ($this->
Bin2Dec(substr($binarystring, 2, 30)) / 1073741824);
849 if ($binstring{0} ==
'1') {
852 $binstring = substr($binstring, 1);
855 for (
$i = 0;
$i < strlen($binstring);
$i++) {
856 $decvalue += ((int) substr($binstring, strlen($binstring) -
$i - 1, 1)) * pow(2,
$i);
858 return $this->
CastAsInt($decvalue * $signmult);
863 $floatnum = (float) $floatnum;
866 if ($this->
trunc($floatnum) == $floatnum) {
868 if ($floatnum <= 1073741824) {
870 $floatnum = (int) $floatnum;