Test mono / color images (WIP)
This commit is contained in:
@@ -5,3 +5,4 @@
|
|||||||
composer.lock
|
composer.lock
|
||||||
vendor/
|
vendor/
|
||||||
docs/
|
docs/
|
||||||
|
*.svg
|
||||||
|
|||||||
+19
-3
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user