Skip to content

Commit

Permalink
Add docs, move code to core (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lopcode authored Aug 10, 2024
1 parent 5661d12 commit 47a8e3a
Show file tree
Hide file tree
Showing 85 changed files with 53,611 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ build

jextract*
logo*
libs/lib*
native_libs/lib*
includes.txt
includes_filtered.txt
4 changes: 2 additions & 2 deletions .run/ImFfm.run.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ImFfm" type="Application" factoryName="Application" nameIsGenerated="true">
<envs>
<env name="DYLD_LIBRARY_PATH" value="libs" />
<env name="DYLD_LIBRARY_PATH" value="native_libs" />
</envs>
<option name="MAIN_CLASS_NAME" value="app.photofox.imffm.ImFfm" />
<module name="im-ffm.lib.main" />
<module name="im-ffm.core" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="app.photofox.imffm.*" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A thin wrapper to let Java/JVM projects use [ImageMagick](https://imagemagick.org/), via the
"Foreign Function & Memory API" ([JEP 454](https://openjdk.org/jeps/454)) released in JDK 22.

Incubating in [Photo Fox](https://github.com/lopcode/photo-fox).
Incubating in [Photo Fox](https://github.com/lopcode/photo-fox). Pronounced "imm (like image) eff-eff-emm".

## Project goals

Expand Down
3 changes: 3 additions & 0 deletions build_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

mkdocs build
4 changes: 2 additions & 2 deletions lib/build.gradle.kts → core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tasks.withType<Test> {
exceptionFormat = TestExceptionFormat.FULL
}
jvmArgs("--enable-native-access=ALL-UNNAMED")
environment(mapOf("DYLD_LIBRARY_PATH" to "libs"))
environment(mapOf("DYLD_LIBRARY_PATH" to "native_libs"))
outputs.upToDateWhen { false }
}

Expand All @@ -62,7 +62,7 @@ tasks.named("integrationTest") {

tasks.withType<JavaExec>().configureEach {
jvmArgs("--enable-native-access=ALL-UNNAMED")
environment(mapOf("DYLD_LIBRARY_PATH" to "libs"))
environment(mapOf("DYLD_LIBRARY_PATH" to "native_libs"))
javaLauncher.set(project.javaToolchains.launcherFor(java.toolchain))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Generated by jextract

package app.photofox.imffm.generated;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* typedef void *(*AcquireAlignedMemoryHandler)(const size_t, const size_t)
* }
*/
public class AcquireAlignedMemoryHandler {

AcquireAlignedMemoryHandler() {
// Should not be called directly
}

/**
* The function pointer signature, expressed as a functional interface
*/
public interface Function {
MemorySegment apply(long _x0, long _x1);
}

private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
MagickWand_h.C_POINTER,
MagickWand_h.C_LONG,
MagickWand_h.C_LONG
);

/**
* The descriptor of this function pointer
*/
public static FunctionDescriptor descriptor() {
return $DESC;
}

private static final MethodHandle UP$MH = MagickWand_h.upcallHandle(AcquireAlignedMemoryHandler.Function.class, "apply", $DESC);

/**
* Allocates a new upcall stub, whose implementation is defined by {@code fi}.
* The lifetime of the returned segment is managed by {@code arena}
*/
public static MemorySegment allocate(AcquireAlignedMemoryHandler.Function fi, Arena arena) {
return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
}

private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

/**
* Invoke the upcall stub {@code funcPtr}, with given parameters
*/
public static MemorySegment invoke(MemorySegment funcPtr,long _x0, long _x1) {
try {
return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Generated by jextract

package app.photofox.imffm.generated;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* typedef void *(*AcquireMemoryHandler)(size_t)
* }
*/
public class AcquireMemoryHandler {

AcquireMemoryHandler() {
// Should not be called directly
}

/**
* The function pointer signature, expressed as a functional interface
*/
public interface Function {
MemorySegment apply(long _x0);
}

private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
MagickWand_h.C_POINTER,
MagickWand_h.C_LONG
);

/**
* The descriptor of this function pointer
*/
public static FunctionDescriptor descriptor() {
return $DESC;
}

private static final MethodHandle UP$MH = MagickWand_h.upcallHandle(AcquireMemoryHandler.Function.class, "apply", $DESC);

/**
* Allocates a new upcall stub, whose implementation is defined by {@code fi}.
* The lifetime of the returned segment is managed by {@code arena}
*/
public static MemorySegment allocate(AcquireMemoryHandler.Function fi, Arena arena) {
return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
}

private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

/**
* Invoke the upcall stub {@code funcPtr}, with given parameters
*/
public static MemorySegment invoke(MemorySegment funcPtr,long _x0) {
try {
return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Generated by jextract

package app.photofox.imffm.generated;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* typedef ssize_t (*CustomStreamHandler)(unsigned char *, const size_t, void *)
* }
*/
public class CustomStreamHandler {

CustomStreamHandler() {
// Should not be called directly
}

/**
* The function pointer signature, expressed as a functional interface
*/
public interface Function {
long apply(MemorySegment _x0, long _x1, MemorySegment _x2);
}

private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
MagickWand_h.C_LONG,
MagickWand_h.C_POINTER,
MagickWand_h.C_LONG,
MagickWand_h.C_POINTER
);

/**
* The descriptor of this function pointer
*/
public static FunctionDescriptor descriptor() {
return $DESC;
}

private static final MethodHandle UP$MH = MagickWand_h.upcallHandle(CustomStreamHandler.Function.class, "apply", $DESC);

/**
* Allocates a new upcall stub, whose implementation is defined by {@code fi}.
* The lifetime of the returned segment is managed by {@code arena}
*/
public static MemorySegment allocate(CustomStreamHandler.Function fi, Arena arena) {
return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
}

private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

/**
* Invoke the upcall stub {@code funcPtr}, with given parameters
*/
public static long invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1, MemorySegment _x2) {
try {
return (long) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Generated by jextract

package app.photofox.imffm.generated;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* typedef Image *(DecodeImageHandler)(const ImageInfo *, ExceptionInfo *)
* }
*/
public class DecodeImageHandler {

DecodeImageHandler() {
// Should not be called directly
}

/**
* The function pointer signature, expressed as a functional interface
*/
public interface Function {
MemorySegment apply(MemorySegment _x0, MemorySegment _x1);
}

private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
MagickWand_h.C_POINTER,
MagickWand_h.C_POINTER,
MagickWand_h.C_POINTER
);

/**
* The descriptor of this function pointer
*/
public static FunctionDescriptor descriptor() {
return $DESC;
}

private static final MethodHandle UP$MH = MagickWand_h.upcallHandle(DecodeImageHandler.Function.class, "apply", $DESC);

/**
* Allocates a new upcall stub, whose implementation is defined by {@code fi}.
* The lifetime of the returned segment is managed by {@code arena}
*/
public static MemorySegment allocate(DecodeImageHandler.Function fi, Arena arena) {
return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
}

private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

/**
* Invoke the upcall stub {@code funcPtr}, with given parameters
*/
public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) {
try {
return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
}
}

Loading

0 comments on commit 47a8e3a

Please sign in to comment.