Skip to content

Commit bbedf8d

Browse files
committed
add setProgress
And an example program to demo it. Uses signalConnect, see #191
1 parent a38b72c commit bbedf8d

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

examples/progress.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/../vendor/autoload.php';
5+
use Jcupitt\Vips;
6+
7+
# Vips\Config::setLogger(new Vips\DebugLogger());
8+
9+
$image = Vips\Image::black(1, 1000000);
10+
$image->setProgress(true);
11+
12+
$image->signalConnect("preeval", function($image, $progress) {
13+
echo "preeval:\n";
14+
});
15+
$image->signalConnect("eval", function($image, $progress) {
16+
echo "eval: $progress->percent % complete\r";
17+
});
18+
19+
$image->signalConnect("posteval", function($image, $progress) {
20+
echo "\nposteval:\n";
21+
});
22+
23+
// trigger evaluation
24+
$image->avg();
25+
26+
$image = null;
27+
28+
Vips\FFI::shutDown();

src/FFI.php

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ private static function init(): void
808808
"VipsSourceCustom" => self::$vips->type("VipsSourceCustom*"),
809809
"VipsTarget" => self::$vips->type("VipsTarget*"),
810810
"VipsTargetCustom" => self::$vips->type("VipsTargetCustom*"),
811+
"VipsProgress" => self::$vips->type("VipsProgress*"),
811812
];
812813

813814
self::$gtypes = [

src/GObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static function getMarshaler(string $name, callable $callback): ?Closure
128128
CData $hint,
129129
?CData $data
130130
) use (&$callback) {
131-
assert($numberOfParams === 3);
131+
assert($numberOfParams === 2);
132132
/**
133133
* Signature: void(VipsImage* image, void* progress, void* handle)
134134
*/

src/Image.php

+17
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,23 @@ public function remove(string $name): void
12961296
}
12971297
}
12981298

1299+
/**
1300+
* Enable progress reporting on an image.
1301+
*
1302+
* The preeval, eval and posteval signals will be emitted on the
1303+
* most-downstream image for which setProgress() was enabled. @see
1304+
* GObject::signalConnect().
1305+
*
1306+
* @param bool $progress TRUE to enable progress reporting.
1307+
*
1308+
* @return void
1309+
*/
1310+
public function setProgress(bool $progress): void
1311+
{
1312+
FFI::vips()->vips_image_set_progress($this->pointer, $progress);
1313+
1314+
}
1315+
12991316
/**
13001317
* Makes a string-ified version of the Image.
13011318
*

0 commit comments

Comments
 (0)