|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Jcupitt\Vips\Test; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use Jcupitt\Vips; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +class GainmapTest extends TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var Vips\Image |
| 13 | + */ |
| 14 | + private $image; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var Vips\Image |
| 18 | + */ |
| 19 | + private $no_gainmap_image; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + parent::setUp(); |
| 24 | + |
| 25 | + if (!Vips\FFI::atLeast(8, 18)) { |
| 26 | + $this->markTestSkipped('libvips too old for gainmap test'); |
| 27 | + } |
| 28 | + |
| 29 | + $filename = __DIR__ . '/images/ultra-hdr.jpg'; |
| 30 | + $this->image = Vips\Image::newFromFile($filename); |
| 31 | + |
| 32 | + $filename = __DIR__ . '/images/img_0076.jpg'; |
| 33 | + $this->no_gainmap_image = Vips\Image::newFromFile($filename); |
| 34 | + } |
| 35 | + |
| 36 | + protected function tearDown(): void |
| 37 | + { |
| 38 | + unset($this->image); |
| 39 | + unset($this->no_gainmap_image); |
| 40 | + } |
| 41 | + |
| 42 | + public function testVipsGetGainmap() |
| 43 | + { |
| 44 | + $gainmap = $this->image->getGainmap(); |
| 45 | + $this->assertEquals($gainmap->width, 960); |
| 46 | + |
| 47 | + $gainmap = $this->no_gainmap_image->getGainmap(); |
| 48 | + $this->assertEquals($gainmap, null); |
| 49 | + } |
| 50 | + |
| 51 | + public function testVipsSetGainmap() |
| 52 | + { |
| 53 | + $gainmap = $this->image->getGainmap(); |
| 54 | + $new_gainmap = $gainmap->crop(0, 0, 10, 10); |
| 55 | + $image = $this->image->copy(); |
| 56 | + $image->set("gainmap", $new_gainmap); |
| 57 | + |
| 58 | + $gainmap = $image->getGainmap(); |
| 59 | + $this->assertEquals($gainmap->width, 10); |
| 60 | + } |
| 61 | +} |
0 commit comments