Skip to content

Commit

Permalink
add 2bpp indexed BMP support
Browse files Browse the repository at this point in the history
  • Loading branch information
mike42 committed Jul 9, 2019
1 parent 4b8cf7d commit 23aec3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Mike42/GfxPhp/Codec/Bmp/BmpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static function fromBinary(DataInputStream $data) : BmpFile
$infoHeader = BmpInfoHeader::fromBinary($data);
if ($infoHeader -> bpp != 0 &&
$infoHeader -> bpp != 1 &&
$infoHeader -> bpp != 2 &&
$infoHeader -> bpp != 4 &&
$infoHeader -> bpp != 8 &&
$infoHeader -> bpp != 16 &&
Expand Down Expand Up @@ -109,8 +110,11 @@ public static function fromBinary(DataInputStream $data) : BmpFile
public function toRasterImage() : RasterImage
{
if ($this -> infoHeader -> bpp == 1) {
$expandedData = PngImage::expandBytes1Bpp($this->uncompressedData, $this->infoHeader->width);
return IndexedRasterImage::create($this->infoHeader->width, $this->infoHeader->height, $expandedData, $this->palette);
$expandedData = PngImage::expandBytes1Bpp($this -> uncompressedData, $this -> infoHeader -> width);
return IndexedRasterImage::create($this -> infoHeader -> width, $this -> infoHeader -> height, $expandedData, $this -> palette);
} else if ($this -> infoHeader -> bpp == 2) {
$expandedData = PngImage::expandBytes2Bpp($this -> uncompressedData, $this -> infoHeader -> width);
return IndexedRasterImage::create($this->infoHeader -> width, $this -> infoHeader -> height, $expandedData, $this -> palette);
} else if ($this -> infoHeader -> bpp == 4) {
$expandedData = PngImage::expandBytes4Bpp($this -> uncompressedData, $this -> infoHeader -> width);
return IndexedRasterImage::create($this -> infoHeader -> width, $this -> infoHeader -> height, $expandedData, $this -> palette);
Expand Down
2 changes: 0 additions & 2 deletions test/integration/BmpsuiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,12 @@ function test_pal1p1() {
}

function test_pal2() {
$this -> markTestSkipped("Not implemented");
$img = $this -> loadImage("q/pal2.bmp");
$this -> assertEquals(127, $img -> getWidth());
$this -> assertEquals(64, $img -> getHeight());
}

function test_pal2color() {
$this -> markTestSkipped("Not implemented");
$img = $this -> loadImage("q/pal2color.bmp");
$this -> assertEquals(127, $img -> getWidth());
$this -> assertEquals(64, $img -> getHeight());
Expand Down

0 comments on commit 23aec3f

Please sign in to comment.