Skip to content

Commit 0bf25c5

Browse files
committed
Merge branch 'master' of github.com:libvips/php-vips
2 parents e3aec74 + a9aedf3 commit 0bf25c5

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to `php-vips` will be documented in this file.
77
- suppress autodoc of `composite` and `DemandStyle` [jcupitt]
88
- update docs for 8.17 [jcupitt]
99
- update docs for 8.18 [jcupitt]
10+
- add getGainmap [jcupitt]
1011

1112
## 2.5.0 - 2025-04-04
1213

src/FFI.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,12 @@ private static function init(): void
792792
CPP;
793793
}
794794

795+
if (self::atLeast(8, 18)) {
796+
$vips_decls = $vips_decls . <<<'CPP'
797+
VipsImage* vips_image_get_gainmap(const VipsImage* image);
798+
CPP;
799+
}
800+
795801
Utils::debugLog("init", ["binding ..."]);
796802

797803
/**

src/Image.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,37 @@ public function getFields(): array
12671267
return $fields;
12681268
}
12691269

1270+
/**
1271+
* Get the gainmap attached to an image, or null for no gainmap.
1272+
*
1273+
* After modifying the gainmap, you'll need to use Image::set() to
1274+
* write it back to the image again under the name "gainmap", for example:
1275+
*
1276+
* ```php
1277+
* $gainmap = $image->getGainmap();
1278+
* if ($gainmap != null) {
1279+
* $new_gainmap = $gainmap->crop(0, 0, 10, 10);
1280+
* $image = $image->copy();
1281+
* $image->set("gainmap", $new_gainmap);
1282+
* }
1283+
* ```
1284+
*
1285+
* @return ?Image
1286+
*/
1287+
public function getGainmap(): ?Image
1288+
{
1289+
if (FFI::atLeast(8, 18)) {
1290+
$pointer = FFI::vips()->vips_image_get_gainmap($this->pointer);
1291+
if ($pointer == null) {
1292+
return null;
1293+
} else {
1294+
return new Image($pointer);
1295+
}
1296+
} else {
1297+
return null;
1298+
}
1299+
}
1300+
12701301
/**
12711302
* Set any property on the underlying image.
12721303
*

tests/GainmapTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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::vips()->vips_type_find('VipsOperation', 'uhdrload') == 0) {
26+
$this->markTestSkipped('requires libvips built with Ultra HDR support');
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+
}

tests/images/ultra-hdr.jpg

1.14 MB
Loading

0 commit comments

Comments
 (0)