From c751ae168ce6602063c59ad377e5784fea35edda Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sun, 10 Jun 2018 13:36:47 +1000 Subject: [PATCH 1/6] improve test coverage --- test/unit/Codec/PngCodecTest.php | 93 +++++++++++++++++++++ test/unit/PngCodecTest.php | 34 -------- test/unit/{ => Util}/LzwCompressionTest.php | 0 3 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 test/unit/Codec/PngCodecTest.php delete mode 100644 test/unit/PngCodecTest.php rename test/unit/{ => Util}/LzwCompressionTest.php (100%) diff --git a/test/unit/Codec/PngCodecTest.php b/test/unit/Codec/PngCodecTest.php new file mode 100644 index 0000000..dc00bf5 --- /dev/null +++ b/test/unit/Codec/PngCodecTest.php @@ -0,0 +1,93 @@ + encode($img, "png"); + // Compare to known-good PNG + $this -> assertEquals(self::SMALL_FILE, $pngStr); + } + + public function testDecode() { + $codec = new PngCodec(); + $img = $codec -> decode(self::SMALL_FILE); + $this -> assertTrue($img instanceof RgbRasterImage); + $this -> assertEquals(1, $img -> getWidth()); + $this -> assertEquals(1, $img -> getHeight()); + } + + public function testBlackAndWhiteImageLoad() { + // Simple test of a black-and-white, interlaced & non-interlaced image, since + // we can do a text-based assertion on the actual image content. + $expected = " ▄█\n" . + " ▄███\n" . + " ██ ██ ▄█████\n" . + " ██ ▄▄ ██ ▄███████\n" . + " ██ ██ ██ ▄█████████\n" . + " ████████ ▄███████████\n" . + " ██ ██ ▄█████████████\n" . + " ▄███████████████\n" . + " ▄█████████████████\n" . + " ▄███████ █████\n" . + " ▄█████████ ████ ████\n" . + " ▄███████████ █████\n" . + " ▄█████████████ ████ ████\n" . + " ▄███████████████ █████\n" . + " ▄█████████████████████████████\n" . + "▄███████████████████████████████\n"; + // Load interlaced & non-interlaced + $interlacedImage = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basi0g01.png"); + $interlacedResult = $interlacedImage -> toString(); + $nonInterlacedImage = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basn0g01.png"); + $nonInterlacedResult = $interlacedImage -> toString(); + // These should both match the expected output + $this -> assertEquals($expected, $interlacedResult); + $this -> assertEquals($expected, $nonInterlacedResult); + } + + public function testIndexedImageLoad() { + // Load an interlaced 8-bit image, which follows a very different code path to + // lower bit depths. + $img = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basi3p08.png") -> toIndexed(); + $this -> assertEquals(255, $img -> getMaxVal()); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + public function testFiltering() { + // Expected value is sensitive to the grayscale -> B&W conversion + $expected = "████████████████████████████████\n" . + "███████████▀▀▀▀▀▀▀▀▀▀███████████\n" . + "████████▀ ▀████████\n" . + "██████▀ ▀██████\n" . + "████▀ ▀████\n" . + "███▀ ▀███\n" . + "███ ███\n" . + "███ ███\n" . + "███ ███\n" . + "███ ███\n" . + "███▄ ▄███\n" . + "████▄ ▄████\n" . + "██████▄ ▄██████\n" . + "████████▄ ▄████████\n" . + "███████████▄▄▄▄▄▄▄▄▄▄███████████\n" . + "████████████████████████████████\n"; + // Image with different filters on each scanline + $img = Image::fromFile(__DIR__ . "/../../resources/pngsuite/f99n0g04.png") -> toBlackAndWhite(); + $result = $img -> toString(); + $this -> assertEquals($expected, $result); + } +} \ No newline at end of file diff --git a/test/unit/PngCodecTest.php b/test/unit/PngCodecTest.php deleted file mode 100644 index f26e6f4..0000000 --- a/test/unit/PngCodecTest.php +++ /dev/null @@ -1,34 +0,0 @@ - toString(); - $expected = " ▄█\n" . - " ▄███\n" . - " ██ ██ ▄█████\n" . - " ██ ▄▄ ██ ▄███████\n" . - " ██ ██ ██ ▄█████████\n" . - " ████████ ▄███████████\n" . - " ██ ██ ▄█████████████\n" . - " ▄███████████████\n" . - " ▄█████████████████\n" . - " ▄███████ █████\n" . - " ▄█████████ ████ ████\n" . - " ▄███████████ █████\n" . - " ▄█████████████ ████ ████\n" . - " ▄███████████████ █████\n" . - " ▄█████████████████████████████\n" . - "▄███████████████████████████████\n"; - $this -> assertEquals($expected, $result); - } -} - diff --git a/test/unit/LzwCompressionTest.php b/test/unit/Util/LzwCompressionTest.php similarity index 100% rename from test/unit/LzwCompressionTest.php rename to test/unit/Util/LzwCompressionTest.php From 0a75d777891f3ce104b6feff500f5fc2e0699604 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sun, 10 Jun 2018 17:47:12 +1000 Subject: [PATCH 2/6] More test coverage improvements, related bug fixes --- .../GfxPhp/Codec/Png/InterlaceDecoder.php | 3 +- src/Mike42/GfxPhp/Codec/Png/PngHeader.php | 32 +- src/Mike42/GfxPhp/Image.php | 6 +- test/integration/PngsuiteTest.php | 1216 +++++++++++++++++ test/unit/Codec/PnmCodecTest.php | 98 ++ 5 files changed, 1343 insertions(+), 12 deletions(-) create mode 100644 test/integration/PngsuiteTest.php create mode 100644 test/unit/Codec/PnmCodecTest.php diff --git a/src/Mike42/GfxPhp/Codec/Png/InterlaceDecoder.php b/src/Mike42/GfxPhp/Codec/Png/InterlaceDecoder.php index b95f013..f0a3bd3 100644 --- a/src/Mike42/GfxPhp/Codec/Png/InterlaceDecoder.php +++ b/src/Mike42/GfxPhp/Codec/Png/InterlaceDecoder.php @@ -80,7 +80,8 @@ private function decodeAdam7Interlace(PngHeader $header, string $binData) foreach ($passes as $passId => $pass) { $passWidth = $pass['width']; $passHeight = $pass['height']; - if ($passWidth == 0) { + if ($passWidth == 0 || $passHeight == 0) { + // No data in this scanline, proceed. continue; } $passScanlineWidth = intdiv($passWidth * $bitDepth + 7, 8) * $channels; diff --git a/src/Mike42/GfxPhp/Codec/Png/PngHeader.php b/src/Mike42/GfxPhp/Codec/Png/PngHeader.php index 0044982..e995492 100644 --- a/src/Mike42/GfxPhp/Codec/Png/PngHeader.php +++ b/src/Mike42/GfxPhp/Codec/Png/PngHeader.php @@ -11,12 +11,12 @@ class PngHeader const COLOR_TYPE_INDEXED = 3; const COLOR_TYPE_MONOCHROME_ALPHA = 4; const COLOR_TYPE_RGBA = 6; - + const COMPRESSION_DEFLATE = 0; - + const INTERLACE_NONE = 0; const INTERLACE_ADAM7 = 1; - + private $width; private $height; private $bitDepth; @@ -32,13 +32,29 @@ public function __construct(int $width, int $height, int $bitDepth, int $colorTy $height < 1 || $height > 2147483647) { throw new \Exception("Invalid image dimensions"); } - $this -> width = $width; - $this -> height = $height; - // Color type & bit depth - // - Only some combinations of bit depth and colorType are valid + $this -> width = $width; + $this -> height = $height; + // Color type & bit depth - Only some combinations of bit depth and colorType are valid. + // I'm sure you could abbreviate this code, but it's written for comparison with the PNG standard. + if ($colorType === 0 && ($bitDepth === 1 || $bitDepth === 2 || $bitDepth === 4 || $bitDepth === 8 || $bitDepth === 16)) { + $this -> bitDepth = $bitDepth; + $this -> colorType = $colorType; + } else if ($colorType === 2 && ($bitDepth === 8 || $bitDepth === 16)) { $this -> bitDepth = $bitDepth; $this -> colorType = $colorType; - // Compression + } else if ($colorType === 3 && ($bitDepth === 1 || $bitDepth === 2 || $bitDepth === 4 || $bitDepth === 8)) { + $this -> bitDepth = $bitDepth; + $this -> colorType = $colorType; + } else if ($colorType === 4 && ($bitDepth === 8 || $bitDepth === 16)) { + $this -> bitDepth = $bitDepth; + $this -> colorType = $colorType; + } else if ($colorType === 6 && ($bitDepth === 8 || $bitDepth === 16)) { + $this -> bitDepth = $bitDepth; + $this -> colorType = $colorType; + } else { + throw new \Exception("Invalid color type / bit depth combination."); + } + // Compression if ($compression != PngHeader::COMPRESSION_DEFLATE) { throw new \Exception("Compression type not supported"); } diff --git a/src/Mike42/GfxPhp/Image.php b/src/Mike42/GfxPhp/Image.php index 1c5591e..9360810 100644 --- a/src/Mike42/GfxPhp/Image.php +++ b/src/Mike42/GfxPhp/Image.php @@ -20,7 +20,7 @@ public static function fromFile(string $filename) : RasterImage if ($blob === false) { throw new \Exception("Could not retrieve image data from '$filename'. Check that the file exists and can be read."); } - return self::fromBlob($blob); + return self::fromBlob($blob, $filename); } public static function fromBlob(string $blob, string $filename = null) : RasterImage @@ -29,11 +29,11 @@ public static function fromBlob(string $blob, string $filename = null) : RasterI self::$codecs = ImageCodec::getInstance(); } $format = self::$codecs -> identify($blob); - if ($format == null) { + if ($format === null) { throw new \Exception("Unknown format for image '$filename'."); } $decoder = self::$codecs ->getDecoderForFormat($format); - if ($decoder == null) { + if ($decoder === null) { throw new \Exception("Format $format not supported, reading '$filename'."); } return $decoder -> decode($blob); diff --git a/test/integration/PngsuiteTest.php b/test/integration/PngsuiteTest.php new file mode 100644 index 0000000..f9104dd --- /dev/null +++ b/test/integration/PngsuiteTest.php @@ -0,0 +1,1216 @@ + loadImage("basi0g01.png"); + $this -> assertTrue($img instanceOf BlackAndWhiteRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi0g02() { + $img = $this -> loadImage("basi0g02.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi0g04() { + $img = $this -> loadImage("basi0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi0g08() { + $img = $this -> loadImage("basi0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi0g16() { + $img = $this -> loadImage("basi0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi2c08() { + $img = $this -> loadImage("basi2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi2c16() { + $img = $this -> loadImage("basi2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi3p01() { + $img = $this -> loadImage("basi3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi3p02() { + $img = $this -> loadImage("basi3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi3p04() { + $img = $this -> loadImage("basi3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi3p08() { + $img = $this -> loadImage("basi3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi4a08() { + $img = $this -> loadImage("basi4a08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi4a16() { + $img = $this -> loadImage("basi4a16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi6a08() { + $img = $this -> loadImage("basi6a08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basi6a16() { + $img = $this -> loadImage("basi6a16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn0g01() { + $img = $this -> loadImage("basn0g01.png"); + $this -> assertTrue($img instanceOf BlackAndWhiteRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn0g02() { + $img = $this -> loadImage("basn0g02.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn0g04() { + $img = $this -> loadImage("basn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn0g08() { + $img = $this -> loadImage("basn0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn0g16() { + $img = $this -> loadImage("basn0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn2c08() { + $img = $this -> loadImage("basn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn2c16() { + $img = $this -> loadImage("basn2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn3p01() { + $img = $this -> loadImage("basn3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn3p02() { + $img = $this -> loadImage("basn3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn3p04() { + $img = $this -> loadImage("basn3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn3p08() { + $img = $this -> loadImage("basn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn4a08() { + $img = $this -> loadImage("basn4a08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn4a16() { + $img = $this -> loadImage("basn4a16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn6a08() { + $img = $this -> loadImage("basn6a08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_basn6a16() { + $img = $this -> loadImage("basn6a16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgai4a08() { + $img = $this -> loadImage("bgai4a08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgai4a16() { + $img = $this -> loadImage("bgai4a16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgan6a08() { + $img = $this -> loadImage("bgan6a08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgan6a16() { + $img = $this -> loadImage("bgan6a16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgbn4a08() { + $img = $this -> loadImage("bgbn4a08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bggn4a16() { + $img = $this -> loadImage("bggn4a16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgwn6a08() { + $img = $this -> loadImage("bgwn6a08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_bgyn6a16() { + $img = $this -> loadImage("bgyn6a16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ccwn2c08() { + $img = $this -> loadImage("ccwn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ccwn3p08() { + $img = $this -> loadImage("ccwn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cdfn2c08() { + $img = $this -> loadImage("cdfn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(8, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cdhn2c08() { + $img = $this -> loadImage("cdhn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(8, $img -> getHeight()); + } + + function test_cdsn2c08() { + $img = $this -> loadImage("cdsn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(8, $img -> getWidth()); + $this -> assertEquals(8, $img -> getHeight()); + } + + function test_cdun2c08() { + $img = $this -> loadImage("cdun2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ch1n3p04() { + $img = $this -> loadImage("ch1n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ch2n3p08() { + $img = $this -> loadImage("ch2n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cm0n0g04() { + $img = $this -> loadImage("cm0n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cm7n0g04() { + $img = $this -> loadImage("cm7n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cm9n0g04() { + $img = $this -> loadImage("cm9n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs3n2c16() { + $img = $this -> loadImage("cs3n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs3n3p08() { + $img = $this -> loadImage("cs3n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs5n2c08() { + $img = $this -> loadImage("cs5n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs5n3p08() { + $img = $this -> loadImage("cs5n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs8n2c08() { + $img = $this -> loadImage("cs8n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cs8n3p08() { + $img = $this -> loadImage("cs8n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ct0n0g04() { + $img = $this -> loadImage("ct0n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ct1n0g04() { + $img = $this -> loadImage("ct1n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cten0g04() { + $img = $this -> loadImage("cten0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ctfn0g04() { + $img = $this -> loadImage("ctfn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ctgn0g04() { + $img = $this -> loadImage("ctgn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_cthn0g04() { + $img = $this -> loadImage("cthn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ctjn0g04() { + $img = $this -> loadImage("ctjn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ctzn0g04() { + $img = $this -> loadImage("ctzn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_exif2c08() { + $img = $this -> loadImage("exif2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f00n0g08() { + $img = $this -> loadImage("f00n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f00n2c08() { + $img = $this -> loadImage("f00n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f01n0g08() { + $img = $this -> loadImage("f01n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f01n2c08() { + $img = $this -> loadImage("f01n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f02n0g08() { + $img = $this -> loadImage("f02n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f02n2c08() { + $img = $this -> loadImage("f02n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f03n0g08() { + $img = $this -> loadImage("f03n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f03n2c08() { + $img = $this -> loadImage("f03n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f04n0g08() { + $img = $this -> loadImage("f04n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f04n2c08() { + $img = $this -> loadImage("f04n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_f99n0g04() { + $img = $this -> loadImage("f99n0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g03n0g16() { + $img = $this -> loadImage("g03n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g03n2c08() { + $img = $this -> loadImage("g03n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g03n3p04() { + $img = $this -> loadImage("g03n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g04n0g16() { + $img = $this -> loadImage("g04n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g04n2c08() { + $img = $this -> loadImage("g04n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g04n3p04() { + $img = $this -> loadImage("g04n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g05n0g16() { + $img = $this -> loadImage("g05n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g05n2c08() { + $img = $this -> loadImage("g05n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g05n3p04() { + $img = $this -> loadImage("g05n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g07n0g16() { + $img = $this -> loadImage("g07n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g07n2c08() { + $img = $this -> loadImage("g07n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g07n3p04() { + $img = $this -> loadImage("g07n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g10n0g16() { + $img = $this -> loadImage("g10n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g10n2c08() { + $img = $this -> loadImage("g10n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g10n3p04() { + $img = $this -> loadImage("g10n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g25n0g16() { + $img = $this -> loadImage("g25n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g25n2c08() { + $img = $this -> loadImage("g25n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_g25n3p04() { + $img = $this -> loadImage("g25n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi1n0g16() { + $img = $this -> loadImage("oi1n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi1n2c16() { + $img = $this -> loadImage("oi1n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi2n0g16() { + $img = $this -> loadImage("oi2n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi2n2c16() { + $img = $this -> loadImage("oi2n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi4n0g16() { + $img = $this -> loadImage("oi4n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi4n2c16() { + $img = $this -> loadImage("oi4n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi9n0g16() { + $img = $this -> loadImage("oi9n0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_oi9n2c16() { + $img = $this -> loadImage("oi9n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_pp0n2c16() { + $img = $this -> loadImage("pp0n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_pp0n6a08() { + $img = $this -> loadImage("pp0n6a08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ps1n0g08() { + $img = $this -> loadImage("ps1n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ps1n2c16() { + $img = $this -> loadImage("ps1n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ps2n0g08() { + $img = $this -> loadImage("ps2n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_ps2n2c16() { + $img = $this -> loadImage("ps2n2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_s01i3p01() { + $img = $this -> loadImage("s01i3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(1, $img -> getWidth()); + $this -> assertEquals(1, $img -> getHeight()); + } + + function test_s01n3p01() { + $img = $this -> loadImage("s01n3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(1, $img -> getWidth()); + $this -> assertEquals(1, $img -> getHeight()); + } + + function test_s02i3p01() { + $img = $this -> loadImage("s02i3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(2, $img -> getWidth()); + $this -> assertEquals(2, $img -> getHeight()); + } + + function test_s02n3p01() { + $img = $this -> loadImage("s02n3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(2, $img -> getWidth()); + $this -> assertEquals(2, $img -> getHeight()); + } + + function test_s03i3p01() { + $img = $this -> loadImage("s03i3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(3, $img -> getWidth()); + $this -> assertEquals(3, $img -> getHeight()); + } + + function test_s03n3p01() { + $img = $this -> loadImage("s03n3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(3, $img -> getWidth()); + $this -> assertEquals(3, $img -> getHeight()); + } + + function test_s04i3p01() { + $img = $this -> loadImage("s04i3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(4, $img -> getWidth()); + $this -> assertEquals(4, $img -> getHeight()); + } + + function test_s04n3p01() { + $img = $this -> loadImage("s04n3p01.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(4, $img -> getWidth()); + $this -> assertEquals(4, $img -> getHeight()); + } + + function test_s05i3p02() { + $img = $this -> loadImage("s05i3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(5, $img -> getWidth()); + $this -> assertEquals(5, $img -> getHeight()); + } + + function test_s05n3p02() { + $img = $this -> loadImage("s05n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(5, $img -> getWidth()); + $this -> assertEquals(5, $img -> getHeight()); + } + + function test_s06i3p02() { + $img = $this -> loadImage("s06i3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(6, $img -> getWidth()); + $this -> assertEquals(6, $img -> getHeight()); + } + + function test_s06n3p02() { + $img = $this -> loadImage("s06n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(6, $img -> getWidth()); + $this -> assertEquals(6, $img -> getHeight()); + } + + function test_s07i3p02() { + $img = $this -> loadImage("s07i3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(7, $img -> getWidth()); + $this -> assertEquals(7, $img -> getHeight()); + } + + function test_s07n3p02() { + $img = $this -> loadImage("s07n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(7, $img -> getWidth()); + $this -> assertEquals(7, $img -> getHeight()); + } + + function test_s08i3p02() { + $img = $this -> loadImage("s08i3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(8, $img -> getWidth()); + $this -> assertEquals(8, $img -> getHeight()); + } + + function test_s08n3p02() { + $img = $this -> loadImage("s08n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(8, $img -> getWidth()); + $this -> assertEquals(8, $img -> getHeight()); + } + + function test_s09i3p02() { + $img = $this -> loadImage("s09i3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(9, $img -> getWidth()); + $this -> assertEquals(9, $img -> getHeight()); + } + + function test_s09n3p02() { + $img = $this -> loadImage("s09n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(9, $img -> getWidth()); + $this -> assertEquals(9, $img -> getHeight()); + } + + function test_s32i3p04() { + $img = $this -> loadImage("s32i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_s32n3p04() { + $img = $this -> loadImage("s32n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_s33i3p04() { + $img = $this -> loadImage("s33i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(33, $img -> getWidth()); + $this -> assertEquals(33, $img -> getHeight()); + } + + function test_s33n3p04() { + $img = $this -> loadImage("s33n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(33, $img -> getWidth()); + $this -> assertEquals(33, $img -> getHeight()); + } + + function test_s34i3p04() { + $img = $this -> loadImage("s34i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(34, $img -> getWidth()); + $this -> assertEquals(34, $img -> getHeight()); + } + + function test_s34n3p04() { + $img = $this -> loadImage("s34n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(34, $img -> getWidth()); + $this -> assertEquals(34, $img -> getHeight()); + } + + function test_s35i3p04() { + $img = $this -> loadImage("s35i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(35, $img -> getWidth()); + $this -> assertEquals(35, $img -> getHeight()); + } + + function test_s35n3p04() { + $img = $this -> loadImage("s35n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(35, $img -> getWidth()); + $this -> assertEquals(35, $img -> getHeight()); + } + + function test_s36i3p04() { + $img = $this -> loadImage("s36i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(36, $img -> getWidth()); + $this -> assertEquals(36, $img -> getHeight()); + } + + function test_s36n3p04() { + $img = $this -> loadImage("s36n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(36, $img -> getWidth()); + $this -> assertEquals(36, $img -> getHeight()); + } + + function test_s37i3p04() { + $img = $this -> loadImage("s37i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(37, $img -> getWidth()); + $this -> assertEquals(37, $img -> getHeight()); + } + + function test_s37n3p04() { + $img = $this -> loadImage("s37n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(37, $img -> getWidth()); + $this -> assertEquals(37, $img -> getHeight()); + } + + function test_s38i3p04() { + $img = $this -> loadImage("s38i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(38, $img -> getWidth()); + $this -> assertEquals(38, $img -> getHeight()); + } + + function test_s38n3p04() { + $img = $this -> loadImage("s38n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(38, $img -> getWidth()); + $this -> assertEquals(38, $img -> getHeight()); + } + + function test_s39i3p04() { + $img = $this -> loadImage("s39i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(39, $img -> getWidth()); + $this -> assertEquals(39, $img -> getHeight()); + } + + function test_s39n3p04() { + $img = $this -> loadImage("s39n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(39, $img -> getWidth()); + $this -> assertEquals(39, $img -> getHeight()); + } + + function test_s40i3p04() { + $img = $this -> loadImage("s40i3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(40, $img -> getWidth()); + $this -> assertEquals(40, $img -> getHeight()); + } + + function test_s40n3p04() { + $img = $this -> loadImage("s40n3p04.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(40, $img -> getWidth()); + $this -> assertEquals(40, $img -> getHeight()); + } + + function test_tbbn0g04() { + $img = $this -> loadImage("tbbn0g04.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbbn2c16() { + $img = $this -> loadImage("tbbn2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbbn3p08() { + $img = $this -> loadImage("tbbn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbgn2c16() { + $img = $this -> loadImage("tbgn2c16.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbgn3p08() { + $img = $this -> loadImage("tbgn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbrn2c08() { + $img = $this -> loadImage("tbrn2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbwn0g16() { + $img = $this -> loadImage("tbwn0g16.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbwn3p08() { + $img = $this -> loadImage("tbwn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tbyn3p08() { + $img = $this -> loadImage("tbyn3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tm3n3p02() { + $img = $this -> loadImage("tm3n3p02.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tp0n0g08() { + $img = $this -> loadImage("tp0n0g08.png"); + $this -> assertTrue($img instanceOf GrayscaleRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tp0n2c08() { + $img = $this -> loadImage("tp0n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tp0n3p08() { + $img = $this -> loadImage("tp0n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_tp1n3p08() { + $img = $this -> loadImage("tp1n3p08.png"); + $this -> assertTrue($img instanceOf IndexedRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_xc1n0g08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xc1n0g08.png"); + } + + function test_xc9n2c08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xc9n2c08.png"); + } + + function test_xcrn0g04() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xcrn0g04.png"); + } + + function test_xcsn0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xcsn0g01.png"); + } + + function test_xd0n2c08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xd0n2c08.png"); + } + + function test_xd3n2c08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xd3n2c08.png"); + } + + function test_xd9n2c08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xd9n2c08.png"); + } + + function test_xdtn0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xdtn0g01.png"); + } + + function test_xhdn0g08() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xhdn0g08.png"); + } + + function test_xlfn0g04() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xlfn0g04.png"); + } + + function test_xs1n0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xs1n0g01.png"); + } + + function test_xs2n0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xs2n0g01.png"); + } + + function test_xs4n0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xs4n0g01.png"); + } + + function test_xs7n0g01() { + $this -> expectException(Exception::class); + $img = $this -> loadImage("xs7n0g01.png"); + } + + function test_z00n2c08() { + $img = $this -> loadImage("z00n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_z03n2c08() { + $img = $this -> loadImage("z03n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_z06n2c08() { + $img = $this -> loadImage("z06n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } + + function test_z09n2c08() { + $img = $this -> loadImage("z09n2c08.png"); + $this -> assertTrue($img instanceOf RgbRasterImage); + $this -> assertEquals(32, $img -> getWidth()); + $this -> assertEquals(32, $img -> getHeight()); + } +} + diff --git a/test/unit/Codec/PnmCodecTest.php b/test/unit/Codec/PnmCodecTest.php new file mode 100644 index 0000000..8720c96 --- /dev/null +++ b/test/unit/Codec/PnmCodecTest.php @@ -0,0 +1,98 @@ + rgbToInt(0, 0, 0); + $white = $image -> rgbToInt(255, 255, 255); + $image -> setPixel(0, 0, $black); + $image -> setPixel(1, 0, $white); + $image -> setPixel(0, 1, $white); + $image -> setPixel(1, 1, $black); + return $image; + } + + public function testPnmEncodeRgb() { + // Test image as RGB + $encoder = new PnmCodec(); + $image = $this -> createRgbTestImage(); + // Encode + $blob = $encoder -> encode($image, 'pnm'); + // Should have auto-selected PPM based on RgbTestImage input + $this -> assertEquals(self::PPM_EXAMPLE, $blob); + } + + public function testPbmEncodeRgb() { + // Test image as RGB + $encoder = new PnmCodec(); + $image = $this -> createRgbTestImage(); + // Encode + $blob = $encoder -> encode($image, 'pbm'); + // Check against known-good encoding of PBM + $this -> assertEquals(self::PBM_EXAMPLE, $blob); + } + + public function testPbmDecode() { + $decoder = new PnmCodec(); + $image = $decoder -> decode(self::PBM_EXAMPLE); + $this -> assertTrue($image instanceof BlackAndWhiteRasterImage); + $this -> assertEquals(self::IMAGE_TEXT, $image -> toString()); + + } + + public function testPgmEncodeRgb() { + // Test image as RGB + $encoder = new PnmCodec(); + $image = $this -> createRgbTestImage(); + // Encode + $blob = $encoder -> encode($image, 'pgm'); + // Check against known-good encoding of PGM + $this -> assertEquals(self::PGM_EXAMPLE, $blob); + } + + public function testPgmDecode() { + $decoder = new PnmCodec(); + $image = $decoder -> decode(self::PGM_EXAMPLE); + $this -> assertTrue($image instanceof GrayscaleRasterImage); + $this -> assertEquals(self::IMAGE_TEXT, $image -> toBlackAndWhite() -> toString()); + } + + public function testPpmEncodeRgb() { + // Test image as RGB + $encoder = new PnmCodec(); + $image = $this -> createRgbTestImage(); + // Encode + $blob = $encoder -> encode($image, 'ppm'); + // Check against known-good encoding of PPM + $this -> assertEquals(self::PPM_EXAMPLE, $blob); + } + + public function testPpmDecode() { + $decoder = new PnmCodec(); + $image = $decoder -> decode(self::PPM_EXAMPLE); + $this -> assertTrue($image instanceof RgbRasterImage); + $this -> assertEquals(self::IMAGE_TEXT, $image -> toBlackAndWhite() -> toString()); + } +} From d0e69a054519dc952591387e42493302eb37c1c5 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sun, 10 Jun 2018 19:56:57 +1000 Subject: [PATCH 3/6] add code coverage link, update README --- README.md | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ae2f39f..f9a8693 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/mike42/gfx-php.svg?branch=master)](https://travis-ci.org/mike42/gfx-php) [![Latest Stable Version](https://poser.pugx.org/mike42/gfx-php/v/stable)](https://packagist.org/packages/mike42/gfx-php) [![Total Downloads](https://poser.pugx.org/mike42/gfx-php/downloads)](https://packagist.org/packages/mike42/gfx-php) -[![License](https://poser.pugx.org/mike42/gfx-php/license)](https://packagist.org/packages/mike42/gfx-php) +[![License](https://poser.pugx.org/mike42/gfx-php/license)](https://packagist.org/packages/mike42/gfx-php) [![Coverage Status](https://coveralls.io/repos/github/mike42/gfx-php/badge.svg?branch=master)](https://coveralls.io/github/mike42/gfx-php?branch=master) This library implements input, output and processing of raster images in pure PHP, so that image processing extensions (Gd, Imagick) are not required. @@ -11,46 +11,51 @@ This allows developers to eliminate some portability issues from their applicati ## Requirements -- PHP 7.0 or newer +- PHP 7.0 or newer. +- zlib extension, for reading PNG files. -## Examples +## Get started -- See the `examples/` sub-folder. +- Have a read of the documentation at [gfx-php.readthedocs.io](https://gfx-php.readthedocs.io/) +- See the `examples/` sub-folder for snippets. -## Status & Scope +## Status & scope -Currently, we are implementing basic raster operations on select file formats. If you're interested in image processing algorithms, then please consider contributing an implementation. +Currently, we are implementing basic raster operations on select file formats. + +See related documentation for: + +- [Available input file formats](https://gfx-php.readthedocs.io/en/latest/user/formats.html#input-formats). +- [Available output file formats](https://gfx-php.readthedocs.io/en/latest/user/formats.html#output-formats). +- [Available image operations](https://gfx-php.readthedocs.io/en/latest/user/operations.html). + +If you're interested in image processing algorithms, then please consider contributing an implementation. For algorithms, it appears feasable to implement: -- Color conversions -- Scale -- Crop -- Blur -- Composite -- Mask +- Rotate +- Layered operations - Affine transformations - Lines, arcs, circles, and rectangles. -And the roadmap for format support: +And sill on the roadmap for format support: -- The full suite of Netpbm binary and text formats (PNM, PBM, PGM, PPM). -- BMP, which involves RLE (de)compression -- PNG, which involves DEFLATE (de)compression -- GIF and TIFF, which involve LZW (de)compression +- BMP input, which involves RLE decompression (BMP output is already available). +- GIF input, which involves LZW decompression (GIF output is already available). +- TIFF input and output, which also involves LZW (de)compression. -In the interests of getting the basic features working first, I'm not currently planning to attempt lossy compression, or formats that are not common on either the web or for printing: +In the interests of getting the basic features working first, there is no current plan to attempt lossy compression, or formats that are not common on either the web or for printing, eg: - JPEG - MNG - PAM format - XPM -- More advanced transformations +- .. etc. Also, as we don't have the luxury of pulling in dependencies, I'm considering anything that is not a raster operation out-of-scope: - All vector image formats (PDF, SVG, EPS, etc). -- Anything involving fonts +- Anything involving vector fonts ### Test data sets From 75b79406618f18d4746c9b0fdfafe3435bb11aab Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sun, 10 Jun 2018 22:17:38 +1000 Subject: [PATCH 4/6] remove erroneous namespaces, fix default when no palette is provided --- src/Mike42/GfxPhp/IndexedRasterImage.php | 2 +- test/unit/Codec/PngCodecTest.php | 2 -- test/unit/Codec/PnmCodecTest.php | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Mike42/GfxPhp/IndexedRasterImage.php b/src/Mike42/GfxPhp/IndexedRasterImage.php index 168ac27..c70d3ae 100644 --- a/src/Mike42/GfxPhp/IndexedRasterImage.php +++ b/src/Mike42/GfxPhp/IndexedRasterImage.php @@ -228,7 +228,7 @@ public function deallocateColor(array $color) throw new \Exception("Not implemented"); } - public static function create(int $width, int $height, array $data = null, array $palette = null, int $maxVal = 255) + public static function create(int $width, int $height, array $data = null, array $palette = [], int $maxVal = 255) { $expectedSize = $width * $height; if ($data == null) { diff --git a/test/unit/Codec/PngCodecTest.php b/test/unit/Codec/PngCodecTest.php index dc00bf5..ef25554 100644 --- a/test/unit/Codec/PngCodecTest.php +++ b/test/unit/Codec/PngCodecTest.php @@ -1,6 +1,4 @@ Date: Sun, 10 Jun 2018 23:03:48 +1000 Subject: [PATCH 5/6] Fix quantization off-by-one error, more tests. --- src/Mike42/GfxPhp/IndexedRasterImage.php | 4 +- test/unit/BlackAndWhiteRasterImageTest.php | 75 ++++++++++++++++- test/unit/Codec/BmpCodecTest.php | 22 +++++ test/unit/Codec/GifCodecTest.php | 65 +++++++++++++++ test/unit/IndexedRasterImageTest.php | 95 ++++++++++++++++++++++ 5 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 test/unit/Codec/BmpCodecTest.php create mode 100644 test/unit/Codec/GifCodecTest.php create mode 100644 test/unit/IndexedRasterImageTest.php diff --git a/src/Mike42/GfxPhp/IndexedRasterImage.php b/src/Mike42/GfxPhp/IndexedRasterImage.php index c70d3ae..585d9a7 100644 --- a/src/Mike42/GfxPhp/IndexedRasterImage.php +++ b/src/Mike42/GfxPhp/IndexedRasterImage.php @@ -200,11 +200,11 @@ public function setMaxVal(int $maxVal) $this -> maxVal = $maxVal; $this -> setPalette(PaletteGenerator::colorPalette()); return; - } else if ($maxVal >= 2) { + } else if ($maxVal >= 1) { $this -> maxVal = $maxVal; $this -> setPalette(PaletteGenerator::blackAndWhitePalette()); return; - } else if ($maxVal >= 1) { + } else if ($maxVal >= 0) { $this -> maxVal = $maxVal; $this -> setPalette(PaletteGenerator::whitePalette()); return; diff --git a/test/unit/BlackAndWhiteRasterImageTest.php b/test/unit/BlackAndWhiteRasterImageTest.php index c9d1d3c..dd4ff89 100644 --- a/test/unit/BlackAndWhiteRasterImageTest.php +++ b/test/unit/BlackAndWhiteRasterImageTest.php @@ -3,11 +3,84 @@ use PHPUnit\Framework\TestCase; +/* + * Many of these tests use an example image like this- + *╭────╮ + *│████│ ██ = 1 + *│░░██│ ░░ = 0 + *╰────╯ + */ class BlackAndWhiteRasterImageTest extends TestCase { + protected function createBlackAndWhiteTestImage() { + $image = BlackAndWhiteRasterImage::create(2, 2); + $image -> setPixel(0, 0, 1); + $image -> setPixel(1, 0, 1); + $image -> setPixel(0, 1, 0); + $image -> setPixel(1, 1, 1); + return $image; + } public function testCreate() { - $foo = BlackAndWhiteRasterImage::create(1, 1); + $img = $this -> createBlackAndWhiteTestImage(); + $this -> assertEquals("▀█\n", $img -> toString()); + } + + public function testInvert() { + $img = $this -> createBlackAndWhiteTestImage(); + $img -> invert(); + $this -> assertEquals("▄ \n", $img -> toString()); + } + + public function testToRgb() + { + $img = $this -> createBlackAndWhiteTestImage() -> toRgb() -> toBlackAndWhite(); + $this -> assertEquals("▀█\n", $img -> toString()); + } + + public function testToIndexed() + { + $img = $this -> createBlackAndWhiteTestImage() -> toIndexed() -> toBlackAndWhite(); + $this -> assertEquals("▀█\n", $img -> toString()); + } + + public function testToGrayscale() + { + $img = $this -> createBlackAndWhiteTestImage() -> toGrayscale() -> toBlackAndWhite(); + $this -> assertEquals("▀█\n", $img -> toString()); + } + + public function testClear() + { + $img = $this -> createBlackAndWhiteTestImage(); + $img -> clear(); + $this -> assertEquals(" \n", $img -> toString()); + } + + public function testScale() + { + $img = $this -> createBlackAndWhiteTestImage() -> scale(4, 2); + $this -> assertEquals("▀▀██\n", $img -> toString()); + } + + public function testRectEmpty() + { + $img = BlackAndWhiteRasterImage::create(5, 5); + $img -> rect(1, 1, 3, 3); + $expected = " ▄▄▄ \n" . + " █▄█ \n" . + " \n"; + $this -> assertEquals($expected, $img -> toString()); + } + + public function testRectFilled() + { + $img = BlackAndWhiteRasterImage::create(5, 5); + $img -> rect(1, 1, 3, 3, true); + $expected = " ▄▄▄ \n" . + " ███ \n" . + " \n"; + $this -> assertEquals($expected, $img -> toString()); } } \ No newline at end of file diff --git a/test/unit/Codec/BmpCodecTest.php b/test/unit/Codec/BmpCodecTest.php new file mode 100644 index 0000000..dbb5f67 --- /dev/null +++ b/test/unit/Codec/BmpCodecTest.php @@ -0,0 +1,22 @@ + encode($image, 'bmp'); + $this -> assertEquals(self::BMP_IMAGE, $imageStr); + } +} + diff --git a/test/unit/Codec/GifCodecTest.php b/test/unit/Codec/GifCodecTest.php new file mode 100644 index 0000000..3593786 --- /dev/null +++ b/test/unit/Codec/GifCodecTest.php @@ -0,0 +1,65 @@ + setTransparentColor(255); + $imageStr = $encoder -> encode($image, 'gif'); + $this -> assertEquals(self::GIF_IMAGE, $imageStr); + } + +} + diff --git a/test/unit/IndexedRasterImageTest.php b/test/unit/IndexedRasterImageTest.php new file mode 100644 index 0000000..0bbcd88 --- /dev/null +++ b/test/unit/IndexedRasterImageTest.php @@ -0,0 +1,95 @@ + setPixel(0, 0, 0); + $image -> setPixel(1, 0, 1); + $image -> setPixel(0, 1, 2); + $image -> setPixel(1, 1, 3); + return $image; + } + + public function testCreate() + { + $img = $this -> createIndexedTestImage(); + $this -> assertEquals(2, $img -> getWidth()); + $this -> assertEquals(2, $img -> getHeight()); + $this -> assertEquals(255, $img -> getMaxVal()); + $this -> assertEquals("▄▄\n", $img -> toBlackAndWhite() -> toString()); + } + + public function testReduceDepthTo1Bit() + { + $img = $this -> createIndexedTestImage(); + $img -> setMaxVal(1); + $this -> assertEquals(0, $img -> getPixel(0, 0)); + $this -> assertEquals(0, $img -> getPixel(1, 0)); + $this -> assertEquals(1, $img -> getPixel(0, 1)); + $this -> assertEquals(1, $img -> getPixel(1, 1)); + } + + public function testToGrayscale() { + $img = $this -> createIndexedTestImage() -> toGrayscale(); + $this -> assertEquals(255, $img -> getPixel(0, 0)); + $this -> assertEquals(160, $img -> getPixel(1, 0)); + $this -> assertEquals(80, $img -> getPixel(0, 1)); + $this -> assertEquals(0, $img -> getPixel(1, 1)); + } + + public function testToRgb() { + $white = RgbRasterImage::rgbToInt(255, 255, 255); + $lightGray = RgbRasterImage::rgbToInt(160, 160, 160); + $darkGray = RgbRasterImage::rgbToInt(80, 80, 80); + $black = RgbRasterImage::rgbToInt(0, 0, 0); + $img = $this -> createIndexedTestImage() -> toRgb(); + $this -> assertEquals($white, $img -> getPixel(0, 0)); + $this -> assertEquals($lightGray, $img -> getPixel(1, 0)); + $this -> assertEquals($darkGray, $img -> getPixel(0, 1)); + $this -> assertEquals($black, $img -> getPixel(1, 1)); + } + + public function testRgbToIndexExists() { + $img = $this -> createIndexedTestImage(); + $idx = $img -> rgbToIndex([80, 80, 80]); + $this -> assertEquals(2, $idx); + } + + public function testQuantizeGrayscale() { + // Produce 8-bit grayscale image via high color-count RGBA + $img = Image::fromFile(__DIR__ . "/../resources/pngsuite/basn2c08.png") -> toIndexed() -> toGrayscale(); + $this -> assertEquals(255, $img -> getMaxVal()); + $this -> assertEquals(255, $img -> getPixel(0, 0)); // White + $this -> assertEquals(0, $img -> getPixel(31, 31)); // Black + } + + public function testQuantizeRgb() { + // Reduce depth of image with more than 16 colors. + $img = Image::fromFile(__DIR__ . "/../resources/pngsuite/basn2c08.png") -> toIndexed(); + $this -> assertEquals(16777215, $img -> getMaxVal()); + $img -> setMaxVal(255); + // Check new range. + $this -> assertEquals(255, $img -> getMaxVal()); + $this -> assertEquals(255, $img -> getPixel(0, 0)); // White + $this -> assertEquals(0, $img -> getPixel(31, 31)); // Black + } +} + From 1526729b398efe9af14820790e965fee71fc4dea Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sun, 10 Jun 2018 23:15:30 +1000 Subject: [PATCH 6/6] more tests, subImage and GrayscaleRasterImage this time --- test/unit/BlackAndWhiteRasterImageTest.php | 10 ++++ test/unit/GrayscaleRasterImageTest.php | 56 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/unit/GrayscaleRasterImageTest.php diff --git a/test/unit/BlackAndWhiteRasterImageTest.php b/test/unit/BlackAndWhiteRasterImageTest.php index dd4ff89..0502fb6 100644 --- a/test/unit/BlackAndWhiteRasterImageTest.php +++ b/test/unit/BlackAndWhiteRasterImageTest.php @@ -74,6 +74,16 @@ public function testRectEmpty() $this -> assertEquals($expected, $img -> toString()); } + public function testSubImageEmpty() + { + $img = BlackAndWhiteRasterImage::create(5, 5); + $img -> rect(1, 1, 3, 3); + $img = $img -> subImage(1, 1, 3, 3); + $expected = "█▀█\n" . + "▀▀▀\n"; + $this -> assertEquals($expected, $img -> toString()); + } + public function testRectFilled() { $img = BlackAndWhiteRasterImage::create(5, 5); diff --git a/test/unit/GrayscaleRasterImageTest.php b/test/unit/GrayscaleRasterImageTest.php new file mode 100644 index 0000000..d4a8fb8 --- /dev/null +++ b/test/unit/GrayscaleRasterImageTest.php @@ -0,0 +1,56 @@ + setPixel(0, 0, 255); + $image -> setPixel(1, 0, 160); + $image -> setPixel(0, 1, 80); + $image -> setPixel(1, 1, 0); + return $image; + } + + public function testCreate() + { + $img = $this -> createGrayscaleTestImage(); + $this -> assertEquals(2, $img -> getWidth()); + $this -> assertEquals(2, $img -> getHeight()); + $this -> assertEquals(255, $img -> getMaxVal()); + $this -> assertEquals("▄▄\n", $img -> toBlackAndWhite() -> toString()); + } + + + public function testToRgb() + { + $white = RgbRasterImage::rgbToInt(255, 255, 255); + $lightGray = RgbRasterImage::rgbToInt(160, 160, 160); + $darkGray = RgbRasterImage::rgbToInt(80, 80, 80); + $black = RgbRasterImage::rgbToInt(0, 0, 0); + $img = $this -> createGrayscaleTestImage() -> toRgb(); + $this -> assertEquals($white, $img -> getPixel(0, 0)); + $this -> assertEquals($lightGray, $img -> getPixel(1, 0)); + $this -> assertEquals($darkGray, $img -> getPixel(0, 1)); + $this -> assertEquals($black, $img -> getPixel(1, 1)); + } + + public function testToIndexed() + { + // Same raster data is used, with grayscale 'palette' + $img = $this -> createGrayscaleTestImage() -> toIndexed(); + $this -> assertEquals(255, $img -> getPixel(0, 0)); + $this -> assertEquals(160, $img -> getPixel(1, 0)); + $this -> assertEquals(80, $img -> getPixel(0, 1)); + $this -> assertEquals(0, $img -> getPixel(1, 1)); + } +} \ No newline at end of file