Test mono / color images (WIP)

This commit is contained in:
Nicolò P 2024-12-27 16:26:52 +01:00
parent 19df4cc926
commit 5e4180a4a2
6 changed files with 19640 additions and 3 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
composer.lock composer.lock
vendor/ vendor/
docs/ docs/
*.svg

View File

@ -15,7 +15,8 @@ class ImageBlob
public readonly int $dataBits; public readonly int $dataBits;
public readonly int $width; public readonly int $width;
public readonly int $height; public readonly int $height;
public readonly int $naxis3; public readonly ?int $naxis3;
public readonly bool $isColor;
/** /**
* @throws InvalidBitpixValue * @throws InvalidBitpixValue
@ -29,12 +30,27 @@ class ImageBlob
$this->bitpix = Bitpix::tryFrom($bitpix) ?? throw new InvalidBitpixValue($bitpix); $this->bitpix = Bitpix::tryFrom($bitpix) ?? throw new InvalidBitpixValue($bitpix);
$this->width = (int) trim($this->header->keyword('NAXIS1')->value); $this->width = (int) trim($this->header->keyword('NAXIS1')->value);
$this->height = (int) trim($this->header->keyword('NAXIS2')->value); $this->height = (int) trim($this->header->keyword('NAXIS2')->value);
$this->naxis3 = (int) trim($this->header->keyword('NAXIS3')->value); $naxis3 = null;
$this->dataBits = abs($this->bitpix->value) * $this->width * $this->height * $this->naxis3; $dataBits = abs($this->bitpix->value) * $this->width * $this->height;
$naxis = (int) trim($this->header->keyword('NAXIS')->value);
// Color image (right?)
if ($naxis === 3) {
$naxis3 = (int) trim($this->header->keyword('NAXIS3')->value);
$dataBits *= $naxis3;
}
$this->naxis3 = $naxis3 ?? 1;
$this->dataBits = $dataBits;
$this->isColor = $this->naxis3 === 3;
} }
/** /**
* Returns a generator that yields image data * Returns a generator that yields image data
* pixel by pixel * pixel by pixel
*@todo Conversion from 16 to 8-bit?
* This won't work with mono images...
*/ */
public function pixels(): \Generator public function pixels(): \Generator
{ {

View File

@ -28,6 +28,17 @@ final class ImageBlobTest extends TestCase
{ {
$this->assertSame($this->imageBlob->dataBits, 16*2448*1669*3); $this->assertSame($this->imageBlob->dataBits, 16*2448*1669*3);
} }
public function testIsColor(): void
{
$mono = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_mono.fit');
$imageBlob = new Dumbastro\FitsPhp\ImageBlob($mono->header(), $mono->imageBlob);
$this->assertFalse($imageBlob->isColor);
$this->assertTrue($this->imageBlob->isColor);
$this->assertEquals($imageBlob->naxis3, 1);
}
} }

2
tests/test_m52.fit Normal file

File diff suppressed because one or more lines are too long

BIN
tests/test_mono.fit Normal file

Binary file not shown.

19607
tests/test_orion_8bit.fit Normal file

File diff suppressed because one or more lines are too long