2022-02-14 12:19:52 +01:00
|
|
|
# SWIG bindings
|
2011-05-07 03:03:02 +02:00
|
|
|
|
2022-02-14 12:19:52 +01:00
|
|
|
## Building
|
|
|
|
|
|
|
|
### JNI SWIG bindings
|
|
|
|
|
|
|
|
```shell
|
2011-05-07 03:03:02 +02:00
|
|
|
$ gcc -shared -fPIC -fno-strict-aliasing -O2 \
|
|
|
|
-I/path/to/your/jdk/includes \
|
|
|
|
libwebp_java_wrap.c \
|
|
|
|
-lwebp \
|
|
|
|
-o libwebp_jni.so
|
2022-02-14 12:19:52 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Example usage:
|
2011-05-07 03:03:02 +02:00
|
|
|
|
2022-02-14 12:19:52 +01:00
|
|
|
```java
|
2011-06-10 20:48:48 +02:00
|
|
|
import com.google.webp.libwebp;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2011-05-07 03:03:02 +02:00
|
|
|
|
|
|
|
public class libwebp_jni_example {
|
|
|
|
static {
|
|
|
|
System.loadLibrary("webp_jni");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-10 20:48:48 +02:00
|
|
|
* usage: java -cp libwebp.jar:. libwebp_jni_example
|
2011-05-07 03:03:02 +02:00
|
|
|
*/
|
|
|
|
public static void main(String argv[]) {
|
|
|
|
final int version = libwebp.WebPGetDecoderVersion();
|
|
|
|
System.out.println("libwebp version: " + Integer.toHexString(version));
|
2011-06-10 20:48:48 +02:00
|
|
|
|
|
|
|
System.out.println("libwebp methods:");
|
|
|
|
final Method[] libwebpMethods = libwebp.class.getDeclaredMethods();
|
|
|
|
for (int i = 0; i < libwebpMethods.length; i++) {
|
|
|
|
System.out.println(libwebpMethods[i]);
|
|
|
|
}
|
2011-05-07 03:03:02 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-14 12:19:52 +01:00
|
|
|
```
|
2011-05-07 03:03:02 +02:00
|
|
|
|
2022-02-14 12:19:52 +01:00
|
|
|
```shell
|
2011-05-07 03:03:02 +02:00
|
|
|
$ javac -cp libwebp.jar libwebp_jni_example.java
|
|
|
|
$ java -Djava.library.path=. -cp libwebp.jar:. libwebp_jni_example
|
2022-02-14 12:19:52 +01:00
|
|
|
```
|
2013-05-10 08:27:54 +02:00
|
|
|
|
2022-02-14 12:19:52 +01:00
|
|
|
### Python SWIG bindings:
|
|
|
|
|
|
|
|
```shell
|
2013-05-10 08:27:54 +02:00
|
|
|
$ python setup.py build_ext
|
|
|
|
$ python setup.py install --prefix=pylocal
|
2022-02-14 12:19:52 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Example usage:
|
2013-05-10 08:27:54 +02:00
|
|
|
|
2022-02-14 12:19:52 +01:00
|
|
|
```python
|
2013-05-10 08:27:54 +02:00
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
sys.path.append(glob.glob('pylocal/lib/python*/site-packages')[0])
|
|
|
|
|
|
|
|
from com.google.webp import libwebp
|
|
|
|
print "libwebp decoder version: %x" % libwebp.WebPGetDecoderVersion()
|
|
|
|
|
|
|
|
print "libwebp attributes:"
|
|
|
|
for attr in dir(libwebp): print attr
|
2022-02-14 12:19:52 +01:00
|
|
|
```
|