Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

- name: Run samples
run: |
vips --version || brew install vips
vips --version || ((brew install pkgconf || brew link --overwrite pkgconf) && brew install vips)
./run_samples.sh

windows-sense-check:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
}

dependencies {
implementation("app.photofox.vips-ffm:vips-ffm-core:1.2.2")
implementation("app.photofox.vips-ffm:vips-ffm-core:1.3.0")
}
```
When running your project you must add `--enable-native-access=ALL-UNNAMED` to your JVM runtime arguments. If you
Expand Down Expand Up @@ -172,6 +172,12 @@ yet (which could manifest as crashes/segfaults):
* `vipsffm.abinumber.glib.override`, default: `0`
* `vipsffm.abinumber.gobject.override`, default: `0`

If you want to manually override the library lookup path for any of the above (for example, if you're using a platform
like Android where it's hard to set the system library path), you can do so using these system properties:
* libvips: `vipsffm.libpath.vips.override` (eg `/opt/homebrew/lib/libvips.dylib`)
* glib: `vipsffm.libpath.glib.override`
* gobject: `vipsffm.libpath.gobject.override`

## Project goals

Ideas and suggestions are welcome, but please make sure they fit in to these goals, or you have a good argument about
Expand Down
35 changes: 35 additions & 0 deletions core/src/main/java/app/photofox/vipsffm/VipsLibLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.foreign.Arena;
import java.lang.foreign.SymbolLookup;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

Expand All @@ -25,6 +26,10 @@ public static SymbolLookup buildSymbolLoader(Arena arena) {
}

private static SymbolLookup findVipsLoader(Arena arena) {
var overrideLookup = makeOptionalLibraryLookup("vips", arena);
if (overrideLookup.isPresent()) {
return overrideLookup.get();
}
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.vips.override"))
.orElse("42");
var names = List.of(
Expand All @@ -36,6 +41,10 @@ private static SymbolLookup findVipsLoader(Arena arena) {
}

private static SymbolLookup findGlibLoader(Arena arena) {
var overrideLookup = makeOptionalLibraryLookup("glib", arena);
if (overrideLookup.isPresent()) {
return overrideLookup.get();
}
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.glib.override"))
.orElse("0");
var names = List.of(
Expand All @@ -47,6 +56,10 @@ private static SymbolLookup findGlibLoader(Arena arena) {
}

private static SymbolLookup findGObjectLoader(Arena arena) {
var overrideLookup = makeOptionalLibraryLookup("gobject", arena);
if (overrideLookup.isPresent()) {
return overrideLookup.get();
}
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.gobject.override"))
.orElse("0");
var names = List.of(
Expand Down Expand Up @@ -79,4 +92,26 @@ static Optional<SymbolLookup> attemptLibraryLookup(String name, Arena arena) {
return Optional.empty();
}
}

private static Optional<SymbolLookup> makeOptionalLibraryLookup(String libraryName, Arena arena) {
var propertyPath = "vipsffm.libpath.%s.override".formatted(libraryName);
var overridePath = Optional.ofNullable(System.getProperty(propertyPath));
return overridePath.map(path -> {
SymbolLookup symbolLookup;
try {
symbolLookup = SymbolLookup.libraryLookup(Path.of(path), arena);
} catch (IllegalArgumentException exception) {
throw makeOverriddenPathMissingException(libraryName, path);
}
return symbolLookup;
});
}

private static IllegalArgumentException makeOverriddenPathMissingException(
String libraryName,
String overridePath
) {
var message = "path override requested for %s, but library not found at path: %s".formatted(libraryName, overridePath);
return new IllegalArgumentException(message);
}
}
18 changes: 12 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h2 id="usage-heading">Usage</h2>
}

dependencies {
implementation(&quot;app.photofox.vips-ffm:vips-ffm-core:1.2.2&quot;)
implementation(&quot;app.photofox.vips-ffm:vips-ffm-core:1.3.0&quot;)
}
</code></pre>
<p>When running your project you must add <code>--enable-native-access=ALL-UNNAMED</code> to your JVM runtime arguments. If you
Expand Down Expand Up @@ -122,8 +122,7 @@ <h3 id="thumbnail-sample-heading">Thumbnail sample</h3>
Vips.run { arena -&gt;
val sourceImage = VImage.newFromFile(
arena,
&quot;sample/src/main/resources/sample_images/rabbit.jpg&quot;,
VipsOption.Enum(&quot;access&quot;, VipsAccess.ACCESS_SEQUENTIAL) // example of an option
&quot;sample/src/main/resources/sample_images/rabbit.jpg&quot;
)
val sourceWidth = sourceImage.width
val sourceHeight = sourceImage.height
Expand All @@ -132,9 +131,9 @@ <h3 id="thumbnail-sample-heading">Thumbnail sample</h3>
val outputPath = workingDirectory.resolve(&quot;rabbit_copy.jpg&quot;)
sourceImage.writeToFile(outputPath.absolutePathString())

val thumbnail = sourceImage.thumbnail(
&quot;sample/src/main/resources/sample_images/rabbit.jpg&quot;,
400
val thumbnail = sourceImage.thumbnailImage(
400,
VipsOption.Boolean(&quot;auto-rotate&quot;, true) // example of an option
)
val thumbnailWidth = thumbnail.width
val thumbnailHeight = thumbnail.height
Expand Down Expand Up @@ -218,6 +217,13 @@ <h2 id="native-library-loading-heading">Native library loading</h2>
<li><code>vipsffm.abinumber.glib.override</code>, default: <code>0</code></li>
<li><code>vipsffm.abinumber.gobject.override</code>, default: <code>0</code></li>
</ul>
<p>If you want to manually override the library lookup path for any of the above (for example, if you're using a platform
like Android where it's hard to set the system library path), you can do so using these system properties:</p>
<ul>
<li>libvips: <code>vipsffm.libpath.vips.override</code> (eg <code>/opt/homebrew/lib/libvips.dylib</code>)</li>
<li>glib: <code>vipsffm.libpath.glib.override</code></li>
<li>gobject: <code>vipsffm.libpath.gobject.override</code></li>
</ul>
<h2 id="project-goals-heading">Project goals</h2>
<p>Ideas and suggestions are welcome, but please make sure they fit in to these goals, or you have a good argument about
why a goal should change!</p>
Expand Down
5 changes: 4 additions & 1 deletion run_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ set -eou pipefail
echo "building samples..."
./gradlew sample:clean sample:shadowJar

export JAVA_PATH_OPTS=""
if [[ "$OSTYPE" == "darwin"* ]]; then
export DYLD_LIBRARY_PATH=/opt/homebrew/lib
# this tests the library path override feature
export JAVA_PATH_OPTS="-Dvipsffm.libpath.vips.override=/opt/homebrew/lib/libvips.dylib"
fi

echo "running samples..."
java -jar sample/build/libs/sample-all.jar 2>&1 | tee sample_output.log
java $JAVA_PATH_OPTS -jar sample/build/libs/sample-all.jar 2>&1 | tee sample_output.log

echo "checking for leaks..."
if grep --quiet "objects alive:" sample_output.log; then
Expand Down
Loading