Cenotso 6 Installing the Webplib 0.4.2 Library, using Java Invoke success

Source: Internet
Author: User
Tags webp


1, about webphttp://baike.baidu.com/view/4447461.htm

WEBP is Google's new image technology, which allows Web pages to be effectively compressed, without compromising picture format compatibility and actual clarity, thus allowing the overall page download speed.
As with JPEG, WEBP is a lossy compression utilization predictive coding technique. But Google says the main advantage of this format is efficiency. They found, "in the same quality of the case,
The size of the WEBP format image is 40% smaller than the JPEG format image.
Currently, Google has released the WEBP file Decoder (libvpx) and command-line tools (WEBPCONV), for JPEG and other format pictures and WEBP format between the conversion.

Official website:
https://code.google.com/p/webp/
https://developers.google.com/speed/webp/

The latest version of WEBP is 0.4.2,:

https://chromium.googlesource.com/webm/libwebp/+/0.4.2

Http://downloads.webmproject.org/releases/webp/libwebp-0.4.2.tar.gz

Https://chromium.googlesource.com/webm/libwebp/+archive/0.4.2.tar.gz

2, installation (according to 0.4.0 installation) Unzip:
TAR-ZXVF libwebp-0.4.0.tar.gz

Enter file:
CD LIBWEBP-0.4.2/
Install the compilation environment (requires OPENJDK):
Yum install autoconf gcc make java-1.6.0-openjdk java-1.6.0-openjdk-devel java-1.6.0-openjdk
./configure
Make & make Install
The default installation directory:

/usr/local/lib

3, compiling the Javalib library call WEBP requires the use of swig, which calls the framework across languages. http://www.swig.org/
CD libwebp-0.4.2/swig/

The OPENJDK installation directory is: /USR/LIB/JVM/JAVA-OPENJDK

So the compile command is:
gcc-shared-fpic-fno-strict-aliasing-o2-i/usr/lib/jvm/java-openjdk/include-i/usr/lib/jvm/java-openjdk/include/ Linux  libwebp_java_wrap.c  -lwebp  -o/usr/local/lib/libwebp_jni.so
Install the so file directly into /usr/local/lib

If compile error: (then OPENJDK installation directory is problematic, reinstall)
#include <jni.h>                 ^compilation terminated.
jni.h in the directory:/usr/lib/jvm/java-openjdk/include


#include "jni_md.h"                    ^compilation terminated.
Jni_md.h in the directory:/usr/lib/jvm/java-openjdk/include/linux

Write Java code:
Import Com.google.webp.libwebp;import Java.lang.reflect.method;public class Libwebp_jni_example {  static {    System.out.println ("###################");    System.out.println (System.getproperty ("Java.library.path"));    System.loadlibrary ("Webp_jni");  }  /**   * USAGE:JAVA-CP libwebp.jar:. Libwebp_jni_example   *  /public static void Main (String argv[]) {    Final int version = LIBWEBP. Webpgetdecoderversion ();    System.out.println ("LIBWEBP version:" + integer.tohexstring (version));    System.out.println ("LIBWEBP Methods:");    Final method[] Libwebpmethods = Libwebp.class.getDeclaredMethods ();    for (int i = 0; i < libwebpmethods.length; i++) {      System.out.println (libwebpmethods[i]);}}}  

Compiling Java code: (check if the Libwebp.jar jar is in the current directory)
Javac LIBWEBP_JNI_EXAMPLE.JAVA-CP LIbwebp.jar

Run Java code:

JAVA-CP Libwebp.jar:. -djava.library.path=/usr/local/lib Libwebp_jni_example

If there is a problem:
Exception in thread "main" Java.lang.UnsatisfiedLinkError:no Webp_jni in Java.library.path at        Java.lang.ClassLoader.loadLibrary (classloader.java:1886) at        java.lang.Runtime.loadLibrary0 (runtime.java:849 ) at        java.lang.System.loadLibrary (system.java:1088) at        libwebp_jni_example.<clinit> (libwebp_jni_ Example.java:9)
Description/usr/local/lib There is no libwebp_jni.so, check whether to compile so file, file size is correct.

If there is a problem:
Exception in thread "main" Java.lang.UnsatisfiedLinkError:/usr/local/lib/libwebp_jni.so:libwebp.so.5:cannot Open Shared object File:no such file or directory at        java.lang.classloader$nativelibrary.load (Native Method) at        Java . lang. Classloader.loadlibrary1 (classloader.java:1965) at        java.lang.ClassLoader.loadLibrary0 (classloader.java:1890 ) at        java.lang.ClassLoader.loadLibrary (classloader.java:1880) at        java.lang.Runtime.loadLibrary0 ( runtime.java:849) at        java.lang.System.loadLibrary (system.java:1088) at        Libwebp_jni_example.<clinit > (Libwebp_jni_example.java:9)
indicates that the directory Ld_library_path and Java.library.path directories are inconsistent. Or the libwebp.so file has a problem, such as a size of 0, it is possible to compile a problem, currently in the CENTOS6 compiled successfully.

then set the environment variable: Export Ld_library_path=/usr/local/lib

The following files are listed in the/usr/local/lib directory:

-rw-r--r--.  1 root root 4412068 Feb  3 16:40 libwebp.a-rwxr-xr-x. 1 root root   37138 Feb  3 16:44 libwebp_jni.so-rwxr-xr-x. 1 Root root     952 Feb  3 16:40 libwebp.lalrwxrwxrwx. 1 root root  3 16:40 libwebp.so .0.2lrwxrwxrwx. 1 root root  3 16:40 libwebp.so.5-libwebp.so.5.0.2-rwxr-xr-x. 1 root root 2389782 Feb  3 16:40 l Ibwebp.so.5.0.2drwxr-xr-x. 2 root root  3 16:40 pkgconfig


4, if there are no problems, the successful result is as follows:

###################/usr/local/liblibwebp version:400libwebp methods:public Static int Com.google.webp.libwebp.WebPGetDecoderVersion () public static byte[] Com.google.webp.libwebp.WebPDecodeRGBA (byte[] , long,int[],int[]) public static byte[] Com.google.webp.libwebp.WebPDecodeARGB (byte[],long,int[],int[]) public static int com.google.webp.libwebp.WebPGetInfo (byte[],long,int[],int[]) public static byte[] Com.google.webp.libwebp.WebPDecodeRGB (byte[],long,int[],int[]) public static byte[] Com.google.webp.libwebp.WebPDecodeBGR (byte[],long,int[],int[]) public static byte[] Com.google.webp.libwebp.WebPDecodeBGRA (byte[],long,int[],int[]) public static int Com.google.webp.libwebp.WebPGetEncoderVersion () private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeRGB ( byte[],int,int,int[],int,int,int,float) private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeBGR (byte[], int,int,int[],int,int,int,float) private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeRGBA (Byte[],int,int, Int[],int,int,int,float) private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeBGRA (byte[],int,int,int[],int,int,int,float) private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeLosslessRGB (byte[],int,int,int[],int,int,int) Private Static byte[] Com.google.webp.libwebp.wrap_WebPEncodeLosslessBGR (byte[],int,int,int[],int,int,int) private static Byte[] Com.google.webp.libwebp.wrap_WebPEncodeLosslessRGBA (byte[],int,int,int[],int,int,int) private static byte[] Com.google.webp.libwebp.wrap_WebPEncodeLosslessBGRA (byte[],int,int,int[],int,int,int) public static byte[] Com.google.webp.libwebp.WebPEncodeRGB (byte[],int,int,int,float) public static byte[] Com.google.webp.libwebp.WebPEncodeRGBA (byte[],int,int,int,float) public static byte[] Com.google.webp.libwebp.WebPEncodeBGR (byte[],int,int,int,float) public static byte[] Com.google.webp.libwebp.WebPEncodeBGRA (byte[],int,int,int,float) public static byte[] Com.google.webp.libwebp.WebPEncodeLosslessRGB (byte[],int,int,int) public static byte[] COM.GOOGLE.WEBP.Libwebp. Webpencodelosslessrgba (byte[],int,int,int) public static byte[] Com.google.webp.libwebp.WebPEncodeLosslessBGR (byte [],int,int,int) public static byte[] Com.google.webp.libwebp.WebPEncodeLosslessBGRA (byte[],int,int,int)




Cenotso 6 Installing the Webplib 0.4.2 Library, using Java Invoke success

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.