• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SWIG bindings
2
3## Building
4
5### JNI SWIG bindings
6
7```shell
8 $ gcc -shared -fPIC -fno-strict-aliasing -O2 \
9       -I/path/to/your/jdk/includes \
10       libwebp_java_wrap.c \
11       -lwebp \
12       -o libwebp_jni.so
13```
14
15Example usage:
16
17```java
18import com.google.webp.libwebp;
19
20import java.lang.reflect.Method;
21
22public class libwebp_jni_example {
23  static {
24    System.loadLibrary("webp_jni");
25  }
26
27  /**
28   * usage: java -cp libwebp.jar:. libwebp_jni_example
29   */
30  public static void main(String argv[]) {
31    final int version = libwebp.WebPGetDecoderVersion();
32    System.out.println("libwebp version: " + Integer.toHexString(version));
33
34    System.out.println("libwebp methods:");
35    final Method[] libwebpMethods = libwebp.class.getDeclaredMethods();
36    for (int i = 0; i < libwebpMethods.length; i++) {
37      System.out.println(libwebpMethods[i]);
38    }
39  }
40}
41```
42
43```shell
44 $ javac -cp libwebp.jar libwebp_jni_example.java
45 $ java -Djava.library.path=. -cp libwebp.jar:. libwebp_jni_example
46```
47
48### Python SWIG bindings:
49
50```shell
51 $ python setup.py build_ext
52 $ python setup.py install --prefix=pylocal
53```
54
55Example usage:
56
57```python
58import glob
59import sys
60sys.path.append(glob.glob('pylocal/lib/python*/site-packages')[0])
61
62from com.google.webp import libwebp
63print "libwebp decoder version: %x" % libwebp.WebPGetDecoderVersion()
64
65print "libwebp attributes:"
66for attr in dir(libwebp): print attr
67```
68