48 $info = &$this->getid3->info;
52 $thisfile_bmp = &
$info[
'bmp'];
53 $thisfile_bmp_header = &$thisfile_bmp[
'header'];
54 $thisfile_bmp_header_raw = &$thisfile_bmp_header[
'raw'];
64 fseek($this->getid3->fp,
$info[
'avdataoffset'], SEEK_SET);
66 $BMPheader =
fread($this->getid3->fp, 14 + 40);
68 $thisfile_bmp_header_raw[
'identifier'] = substr($BMPheader, $offset, 2);
72 if ($thisfile_bmp_header_raw[
'identifier'] != $magic) {
73 $info[
'error'][] =
'Expecting "'.Helper::PrintHexBytes($magic).
'" at offset '.
$info[
'avdataoffset'].
', found "'.
Helper::PrintHexBytes($thisfile_bmp_header_raw[
'identifier']).
'"';
74 unset(
$info[
'fileformat']);
94 if (($planes22 == 1) && ($planes26 != 1)) {
95 $thisfile_bmp[
'type_os'] =
'OS/2';
96 $thisfile_bmp[
'type_version'] = 1;
97 } elseif (($planes26 == 1) && ($planes22 != 1)) {
98 $thisfile_bmp[
'type_os'] =
'Windows';
99 $thisfile_bmp[
'type_version'] = 1;
100 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 12) {
101 $thisfile_bmp[
'type_os'] =
'OS/2';
102 $thisfile_bmp[
'type_version'] = 1;
103 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 40) {
104 $thisfile_bmp[
'type_os'] =
'Windows';
105 $thisfile_bmp[
'type_version'] = 1;
106 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 84) {
107 $thisfile_bmp[
'type_os'] =
'Windows';
108 $thisfile_bmp[
'type_version'] = 4;
109 } elseif ($thisfile_bmp_header_raw[
'header_size'] == 100) {
110 $thisfile_bmp[
'type_os'] =
'Windows';
111 $thisfile_bmp[
'type_version'] = 5;
113 $info[
'error'][] =
'Unknown BMP subtype (or not a BMP file)';
114 unset(
$info[
'fileformat']);
120 $info[
'fileformat'] =
'bmp';
121 $info[
'video'][
'dataformat'] =
'bmp';
122 $info[
'video'][
'lossless'] =
true;
123 $info[
'video'][
'pixel_aspect_ratio'] = (float) 1;
125 if ($thisfile_bmp[
'type_os'] ==
'OS/2') {
145 $info[
'video'][
'resolution_x'] = $thisfile_bmp_header_raw[
'width'];
146 $info[
'video'][
'resolution_y'] = $thisfile_bmp_header_raw[
'height'];
147 $info[
'video'][
'codec'] =
'BI_RGB '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
148 $info[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
150 if ($thisfile_bmp[
'type_version'] >= 2) {
197 $info[
'video'][
'codec'] = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
200 } elseif ($thisfile_bmp[
'type_os'] ==
'Windows') {
242 $info[
'video'][
'resolution_x'] = $thisfile_bmp_header_raw[
'width'];
243 $info[
'video'][
'resolution_y'] = $thisfile_bmp_header_raw[
'height'];
244 $info[
'video'][
'codec'] = $thisfile_bmp_header[
'compression'].
' '.$thisfile_bmp_header_raw[
'bits_per_pixel'].
'-bit';
245 $info[
'video'][
'bits_per_sample'] = $thisfile_bmp_header_raw[
'bits_per_pixel'];
247 if (($thisfile_bmp[
'type_version'] >= 4) || ($thisfile_bmp_header_raw[
'compression'] == 3)) {
249 $BMPheader .=
fread($this->getid3->fp, 44);
272 $thisfile_bmp_header_raw[
'ciexyz_red'] = substr($BMPheader, $offset, 4);
274 $thisfile_bmp_header_raw[
'ciexyz_green'] = substr($BMPheader, $offset, 4);
276 $thisfile_bmp_header_raw[
'ciexyz_blue'] = substr($BMPheader, $offset, 4);
285 $thisfile_bmp_header[
'ciexyz_red'] =
Helper::FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_red']));
286 $thisfile_bmp_header[
'ciexyz_green'] =
Helper::FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_green']));
287 $thisfile_bmp_header[
'ciexyz_blue'] =
Helper::FixedPoint2_30(strrev($thisfile_bmp_header_raw[
'ciexyz_blue']));
290 if ($thisfile_bmp[
'type_version'] >= 5) {
291 $BMPheader .=
fread($this->getid3->fp, 16);
311 $info[
'error'][] =
'Unknown BMP format in header.';
317 if ($this->ExtractPalette || $this->ExtractData) {
319 if ($thisfile_bmp_header_raw[
'bits_per_pixel'] < 16) {
320 $PaletteEntries = pow(2, $thisfile_bmp_header_raw[
'bits_per_pixel']);
321 } elseif (isset($thisfile_bmp_header_raw[
'colors_used']) && ($thisfile_bmp_header_raw[
'colors_used'] > 0) && ($thisfile_bmp_header_raw[
'colors_used'] <= 256)) {
322 $PaletteEntries = $thisfile_bmp_header_raw[
'colors_used'];
324 if ($PaletteEntries > 0) {
325 $BMPpalette =
fread($this->getid3->fp, 4 * $PaletteEntries);
327 for ($i = 0; $i < $PaletteEntries; $i++) {
336 if (($thisfile_bmp[
'type_os'] ==
'OS/2') && ($thisfile_bmp[
'type_version'] == 1)) {
346 if ($this->ExtractData) {
347 fseek($this->getid3->fp, $thisfile_bmp_header_raw[
'data_offset'], SEEK_SET);
348 $RowByteLength = ceil(($thisfile_bmp_header_raw[
'width'] * ($thisfile_bmp_header_raw[
'bits_per_pixel'] / 8)) / 4) * 4;
349 $BMPpixelData =
fread($this->getid3->fp, $thisfile_bmp_header_raw[
'height'] * $RowByteLength);
350 $pixeldataoffset = 0;
351 $thisfile_bmp_header_raw[
'compression'] = (isset($thisfile_bmp_header_raw[
'compression']) ? $thisfile_bmp_header_raw[
'compression'] :
'');
352 switch ($thisfile_bmp_header_raw[
'compression']) {
355 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
357 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
358 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
359 $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
360 for ($i = 7; $i >= 0; $i--) {
361 $paletteindex = ($paletteindexbyte & (0x01 << $i)) >> $i;
362 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
366 while (($pixeldataoffset % 4) != 0) {
374 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
375 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col = $col) {
376 $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
377 for ($i = 1; $i >= 0; $i--) {
378 $paletteindex = ($paletteindexbyte & (0x0F << (4 * $i))) >> (4 * $i);
379 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
383 while (($pixeldataoffset % 4) != 0) {
391 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
392 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
393 $paletteindex = ord($BMPpixelData{$pixeldataoffset++});
394 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
396 while (($pixeldataoffset % 4) != 0) {
404 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
405 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
406 $thisfile_bmp[
'data'][
$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
407 $pixeldataoffset += 3;
409 while (($pixeldataoffset % 4) != 0) {
417 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
418 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
419 $thisfile_bmp[
'data'][
$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
420 $pixeldataoffset += 4;
422 while (($pixeldataoffset % 4) != 0) {
434 $info[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
440 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
443 while ($pixeldataoffset < strlen($BMPpixelData)) {
446 if ($firstbyte == 0) {
451 switch ($secondbyte) {
459 $pixeldataoffset = strlen($BMPpixelData);
468 $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
469 $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
470 $pixelcounter = (
$row * $thisfile_bmp_header_raw[
'width']) + $col;
478 for ($i = 0; $i < $secondbyte; $i++) {
480 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
481 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
482 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
485 while (($pixeldataoffset % 2) != 0) {
496 for ($i = 0; $i < $firstbyte; $i++) {
497 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
498 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
499 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$secondbyte];
508 $info[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
514 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
517 while ($pixeldataoffset < strlen($BMPpixelData)) {
520 if ($firstbyte == 0) {
525 switch ($secondbyte) {
533 $pixeldataoffset = strlen($BMPpixelData);
542 $col = ($pixelcounter % $thisfile_bmp_header_raw[
'width']) + $colincrement;
543 $row = ($thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width'])) - $rowincrement;
544 $pixelcounter = (
$row * $thisfile_bmp_header_raw[
'width']) + $col;
552 unset($paletteindexes);
553 for ($i = 0; $i < ceil($secondbyte / 2); $i++) {
555 $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4;
556 $paletteindexes[] = ($paletteindexbyte & 0x0F);
558 while (($pixeldataoffset % 2) != 0) {
563 foreach ($paletteindexes as $paletteindex) {
564 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
565 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
566 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindex];
581 $paletteindexes[0] = ($secondbyte & 0xF0) >> 4;
582 $paletteindexes[1] = ($secondbyte & 0x0F);
583 for ($i = 0; $i < $firstbyte; $i++) {
584 $col = $pixelcounter % $thisfile_bmp_header_raw[
'width'];
585 $row = $thisfile_bmp_header_raw[
'height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw[
'width']);
586 $thisfile_bmp[
'data'][
$row][$col] = $thisfile_bmp[
'palette'][$paletteindexes[($i % 2)]];
595 $info[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
601 switch ($thisfile_bmp_header_raw[
'bits_per_pixel']) {
607 while ((($thisfile_bmp_header_raw[
'red_mask'] >> $redshift) & 0x01) == 0) {
610 while ((($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift) & 0x01) == 0) {
613 while ((($thisfile_bmp_header_raw[
'blue_mask'] >> $blueshift) & 0x01) == 0) {
616 for (
$row = ($thisfile_bmp_header_raw[
'height'] - 1);
$row >= 0;
$row--) {
617 for ($col = 0; $col < $thisfile_bmp_header_raw[
'width']; $col++) {
618 $pixelvalue =
Helper::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw[
'bits_per_pixel'] / 8));
619 $pixeldataoffset += $thisfile_bmp_header_raw[
'bits_per_pixel'] / 8;
621 $red = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'red_mask']) >> $redshift) / ($thisfile_bmp_header_raw[
'red_mask'] >> $redshift)) * 255));
622 $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw[
'green_mask'] >> $greenshift)) * 255));
623 $blue = intval(round(((($pixelvalue & $thisfile_bmp_header_raw[
'blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw[
'blue_mask'] >> $blueshift)) * 255));
626 while (($pixeldataoffset % 4) != 0) {
634 $info[
'error'][] =
'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw[
'bits_per_pixel'].
') - cannot read pixel data';
640 $info[
'error'][] =
'Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw[
'compression'].
') - cannot decompress pixel data';
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
static FixedPoint2_30($rawdata)
fseek($bytes, $whence=SEEK_SET)
Create styles array
The data for the language used.
BMPcompressionOS2Lookup($compressionid)
array $BMPcompressionOS2Lookup
static LittleEndian2Int($byteword, $signed=false)
BMPcompressionWindowsLookup($compressionid)
array $BMPcompressionWindowsLookup