Giter VIP home page Giter VIP logo

webp-imageio-core's Introduction

webp-imageio-core

forked from qwong/j-webp Java Image I/O reader and writer for the Google WebP image format without system lib file.

In source program, coders need to put native lib files like .so/.dll/.dylib into the folder of java.library.path.

For easier to use, qwong/j-webp (bases on webp project of Luciad 0.4.2) import native-lib-loader to load native lib files from project resource folder, instead of java.library.path. (more details to see com.luciad.imageio.webp.WebP.loadNativeLibrary)

However, coders pefer using jar package instead of source java code in personal project. So I fork and edit qwong/j-webp to privide a usable jar. It is a fat jar includes dependencies and native lib file (includes windows/linux/mac both 32&64bit).

Update 20181119: sync from webp project of Luciad 1.0.0

Update 20190912: update win64 dll to libwebp-1.0.3

Update 20191029:

  • prankstrisse provides osx64 dylib file
  • remove x32 .so/.dll/.dylib file

Usage

Because it is not in maven repo, so you have to put the jar file webp-imageio-core-{version}.jar into libs folder of your project manually.

Download jar

if you use gradle, you can put it into src/main/resource/libs, and edit config filebuild.gradle to add local dependencies

dependencies {
    compile fileTree(dir:'src/main/resources/libs',include:['*.jar'])
}

if you use maven, you can put it ${project.basedir}/libs, and edit config file pom.xml to add local dependencies

<dependency>  
    <groupId>com.github.nintha</groupId>  
    <artifactId>webp-imageio-core</artifactId>  
    <version>{version}</version>  
    <scope>system</scope>  
    <systemPath>${project.basedir}/libs/webp-imageio-core-{version}.jar</systemPath>  
</dependency>

The usage of api, you can see example cases in src/main/java/example.

Compiling the native library

download source code of webp project of Luciad , and unzip it.

wget https://bitbucket.org/luciad/webp-imageio/get/873c5677244b.zip -O luciad-webp-imageio-873c5677244b.zip
unzip luciad-webp-imageio-873c5677244b.zip

download source code of google webp project

git clone https://chromium.googlesource.com/webm/libwebp

or use the mirror repo

copy folder libwebp into folder luciad-webp-imageio-873c5677244b, and create a directory called build in the folder luciad-webp-imageio-873c5677244b

folder tree like this:

luciad-webp-imageio-873c5677244b/
	|_ build/	<-- just created 
	|_ gradle/
	|_ src/
	|_ libwebp/  <-- copy from project libwebp 
	|_ .hgignore
	|....
	|.... (other files)

Install CMake 2.8 or newer. CMake can be downloaded from www.cmake.org or installed using your systems package manager. if you use Win10 and VS 2019, it need CMake 3.14 or newer.

Open a terminal and navigate to the newly created 'build' directory.

cd ./build
cmake ..
cmake --build .

The compiled library can be found under the directory build/src/main/c

if you need specific the generator-name, please add -G <generator-name> parameter for cmake, like this

// cmake ..
cmake .. -G "Visual Studio 16 2019"

Compiling the Java library

  • Run mvn install in the root of the project
  • The compiled Java library can be found under the targetdirectory

webp-imageio-core's People

Contributors

jorbits avatar nintha avatar qwang66 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webp-imageio-core's Issues

java.lang.UnsatisfiedLinkError on Win10 system

I learned that I do not need to load webp*.dll by myself to handle webp image by webp-imageio-core. So in my project, I use webp-imageio-core-0.1.3.jar to convert image to webp format, but the error happened.
I tried webp-imageio-core-0.1.2.jar and webp-imageio-core-0.1.1.jar, the error is same. but when I tried webp-imageio-core-0.1.0.jar, it worked. my system is Windows 10 64bit.
So what's the problem, just webp-imageio-core-0.1.0.jar worked for Win10?

Error:

`十月 31, 2019 5:28:51 下午 org.scijava.nativelib.NativeLibraryUtil loadNativeLibrary
警告: Problem with library
java.lang.UnsatisfiedLinkError: C:\Users\zhangdan\AppData\Local\Temp\webp-imageio4585631737438415528.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at org.scijava.nativelib.NativeLibraryUtil.loadNativeLibrary(NativeLibraryUtil.java:291)
at com.luciad.imageio.webp.WebP.loadNativeLibrary(WebP.java:29)
at com.luciad.imageio.webp.WebP.(WebP.java:34)
at com.luciad.imageio.webp.WebPEncoderOptions.(WebPEncoderOptions.java:20)
at com.luciad.imageio.webp.WebPWriteParam.(WebPWriteParam.java:30)
at com.luciad.imageio.webp.WebPWriter.getDefaultWriteParam(WebPWriter.java:38)
at com.luciad.imageio.webp.WebPWriter.write(WebPWriter.java:64)
at javax.imageio.ImageWriter.write(Unknown Source)
at javax.imageio.ImageIO.doWrite(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at com.dancen.util.image.MyImageHelper.writeBufferedImage(MyImageHelper.java:517)
at com.dancen.util.image.MyImageHelper.writeBufferedImage(MyImageHelper.java:481)
at com.dancen.util.image.MyImageFormatUtil.convert(MyImageFormatUtil.java:61)
at com.dancen.util.image.MyImageFormatUtil.convert(MyImageFormatUtil.java:34)
at com.dancen.util.image.MyImageFormatUtil.main(MyImageFormatUtil.java:22)

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.luciad.imageio.webp.WebPEncoderOptions.createConfig()J
at com.luciad.imageio.webp.WebPEncoderOptions.createConfig(Native Method)
at com.luciad.imageio.webp.WebPEncoderOptions.(WebPEncoderOptions.java:26)
at com.luciad.imageio.webp.WebPWriteParam.(WebPWriteParam.java:30)
at com.luciad.imageio.webp.WebPWriter.getDefaultWriteParam(WebPWriter.java:38)
at com.luciad.imageio.webp.WebPWriter.write(WebPWriter.java:64)
at javax.imageio.ImageWriter.write(Unknown Source)
at javax.imageio.ImageIO.doWrite(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at com.dancen.util.image.MyImageHelper.writeBufferedImage(MyImageHelper.java:517)
at com.dancen.util.image.MyImageHelper.writeBufferedImage(MyImageHelper.java:481)
at com.dancen.util.image.MyImageFormatUtil.convert(MyImageFormatUtil.java:61)
at com.dancen.util.image.MyImageFormatUtil.convert(MyImageFormatUtil.java:34)
at com.dancen.util.image.MyImageFormatUtil.main(MyImageFormatUtil.java:22)`

Error while loading : Can't find dependent libraries

While trying to test the library under Windows I have the folowing error. The webp-imageio.dll is in the temporary directory but it seems that there are dependent libraries...

Can someone help me ?

déc. 11, 2020 7:20:51 PM org.scijava.nativelib.NativeLibraryUtil loadNativeLibrary
AVERTISSEMENT: Problem with library
java.lang.UnsatisfiedLinkError: C:\Users\pnv_vmo.ASP\AppData\Local\Temp\webp-imageio3809737815982273834.dll: Can't find dependent libraries
	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:1851)
	at java.lang.Runtime.load0(Runtime.java:795)
	at java.lang.System.load(System.java:1062)
	at org.scijava.nativelib.NativeLibraryUtil.loadNativeLibrary(NativeLibraryUtil.java:291)
	at com.luciad.imageio.webp.WebP.loadNativeLibrary(WebP.java:29)
	at com.luciad.imageio.webp.WebP.<clinit>(WebP.java:34)
	at com.luciad.imageio.webp.WebPEncoderOptions.<clinit>(WebPEncoderOptions.java:20)
	at com.luciad.imageio.webp.WebPWriteParam.<init>(WebPWriteParam.java:30)
	at example.EncodeTest.main(EncodeTest.java:26)

java.lang.UnsatisfiedLinkError

六月 29, 2020 2:11:59 下午 org.scijava.nativelib.NativeLibraryUtil loadNativeLibrary
警告: Problem with library
java.lang.UnsatisfiedLinkError: C:\Users\shuqi\AppData\Local\Temp\webp-imageio5936908501753317424.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at org.scijava.nativelib.NativeLibraryUtil.loadNativeLibrary(NativeLibraryUtil.java:291)
at com.luciad.imageio.webp.WebP.loadNativeLibrary(WebP.java:29)
at com.luciad.imageio.webp.WebP.(WebP.java:34)
at com.luciad.imageio.webp.WebPDecoderOptions.(WebPDecoderOptions.java:20)
at com.luciad.imageio.webp.WebPReadParam.(WebPReadParam.java:24)
at example.DecodeTest.main(DecodeTest.java:23)

system scope is deprecated in maven

There is another way to setup the whole thing when using maven and to avoid using the deprecated "system" scope.
You can install the jar locally on the target system as follows:

mvn install:install-file -Dfile=webp-imageio-core-0.1.0.jar -DgroupId=my.group.id.webp> -DartifactId=webp-imageio -Dversion=0.1.0 -Dpackaging=jar

and then just add to your pom.xml:

<dependency>      
        <groupId>your.group.id.webp</groupId>  
        <artifactId>webp-imageio</artifactId>  
        <version>0.1.0</version> 
    </dependency>

it's clean, simple and it works like a charm !

Decode returned code VP8_STATUS_UNSUPPORTED_FEATURE for .webp animations

I have this task of sending multiple pictures across the network, where the receiver end is Java, So I decided to serialize thoses images into a webp "animation" where each image is a frame. The webp is generated in python using PIL, and it's possible to decode and extract the frames on both python and Ezgif.com.

However when trying decode the same file, I get the following error

java.io.IOException: Decode returned code VP8_STATUS_UNSUPPORTED_FEATURE
at com.luciad.imageio.webp.WebP.decode(WebP.java:61)
at com.luciad.imageio.webp.WebPReader.read(WebPReader.java:158)
at java.desktop/javax.imageio.ImageReader.read(ImageReader.java:938)
at TestFrameGrab.testReadWebpLuciad(TestFrameGrab.java:29)

The test code:

    File inputWebp=new File("input.webp");
    File outputJpeg=new File("output.jpg");

    ImageReader reader = ImageIO.getImageReadersByMIMEType("image/webp").next();
    WebPReadParam readParam = new WebPReadParam();
    readParam.setBypassFiltering(true);

    reader.setInput(new FileImageInputStream(inputWebp));
    BufferedImage image = reader.read(0,readParam);
    ImageIO.write(image,"jpeg",outputJpeg);

The Python code to generate the file:

with open("input.webp","wb") as io:
    img.save(io, format='WebP', save_all=True, append_images=all_imgs, quality=80, lossless=True, allow_mixed=True)

I'm a bit clueless about what could have went wrong, any help or suggestions will be appreciated

A fatal error has been detected by the Java Runtime Environment when WebP.encodeRGBA

Why did the following crash occur? The system call to the native method for generating a WebP thumbnail crashed directly.

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f1eb2a3da7e, pid=15265, tid=0x00007f1eb3983700

JRE version: Java(TM) SE Runtime Environment (8.0_191-b12) (build 1.8.0_191-b12)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops)
Problematic frame:
C [libwebp-imageio468137471292341033.so+0x30a7e] VP8FilterStrengthFromDelta+0x1e

Core dump written.

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 30199 com.luciad.imageio.webp.WebP.encodeRGBA(J[BIII)[B (0 bytes) @ 0x00007f211a80fadf [0x00007f211a80fa80+0x5f]
J 44242 C2 com.luciad.imageio.webp.WebPWriter.write(Ljavax/imageio/metadata/IIOMetadata;Ljavax/imageio/IIOImage;Ljavax/imageio/ImageWriteParam;)V (49 bytes) @ 0x00007f21183f7454 [0x00007f21183f7340+0x114]
J 39077 C2 net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.write(Ljava/awt/image/BufferedImage;)V (67 bytes) @ 0x00007f211bdd1a18 [0x00007f211bdce940+0x30d8]
J 39148 C2 net.coobird.thumbnailator.Thumbnailator.createThumbnail(Lnet/coobird/thumbnailator/tasks/ThumbnailTask;)V (237 bytes) @ 0x00007f211bdbbe0c [0x00007f211bdba2e0+0x1b2c]
J 39154 C2 net.coobird.thumbnailator.Thumbnails$Builder.toOutputStream(Ljava/io/OutputStream;)V (95 bytes) @ 0x00007f211a3b910c [0x00007f211a3b8660+0xaac]

luciad/webp-imageio has disappeared

So, I cannot recompile it under Alpine Linux and cannot follow these instructions:

Download source code of webp project of Luciad , and unzip it.

wget https://bitbucket.org/luciad/webp-imageio/get/873c5677244b.zip -O luciad-webp-imageio-873c5677244b.zip
unzip luciad-webp-imageio-873c5677244b.zip

Where can I find it?

Docker Alpine Linux Container Crashing on Decode

This is using an Alpine Linux image v3.9.

When calling the decode method in the WebP.java is crashing the server when is trying to get the pixels

int[] pixels = decode(aOptions.fPointer, aData, aOffset, aLength, aOut, ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN));

There is no error thrown on the logs, and here is the stacktrace:

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.luciad.imageio.webp.WebP.decode(J[BII[IZ)[I+0
j  com.luciad.imageio.webp.WebP.decode(Lcom/luciad/imageio/webp/WebPDecoderOptions;[BII[I)[I+64
j  com.luciad.imageio.webp.WebPReader.read(ILjavax/imageio/ImageReadParam;)Ljava/awt/image/BufferedImage;+53
j  javax.imageio.ImageIO.read(Ljavax/imageio/stream/ImageInputStream;)Ljava/awt/image/BufferedImage;+55
j  javax.imageio.ImageIO.read(Ljava/io/File;)Ljava/awt/image/BufferedImage;+51
j  com.dotmarketing.image.filter.ThumbnailImageFilter.runFilter(Ljava/io/File;Ljava/util/Map;)Ljava/io/File;+312

On others OS (Win, Ubuntu and MacOs) works without issues.

UnsatisfiedLinkError about WebPDecoderOptions.createDecoderOptions

Hello there I'm using your library on Mulesoft here

And when running the code it gives me this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.luciad.imageio.webp.WebPDecoderOptions.createDecoderOptions()J at com.luciad.imageio.webp.WebPDecoderOptions.createDecoderOptions(Native Method) at com.luciad.imageio.webp.WebPDecoderOptions.<init>(WebPDecoderOptions.java:26) at com.luciad.imageio.webp.WebPReadParam.<init>(WebPReadParam.java:24)

I guess it's because the .dll/.so/.dylib is not suitable for my system, which is

macOS High Sierra version 10.13.6

build the webp-imageio.dll

I clone the webp-imageio by Sourcetree, but the folder "libwebp" clone fail.
When I run cmake .. and it keep throwing error:
CMake Error at CMakeLists.txt:6 (add_subdirectory): add_subdirectory given source "libwebp" which is not an existing directory.

how do you build the webp-imageio.dll?

does this mean animated webp can not convert to gif?

I just try to convert an animated webp file to a animated gif file,when run the demo code something happened,this is the demo:

   `public static void main(String[] args) throws IOException {

	String inputPath = "/demo01.webp";String outputGifPath = "test_pic/test_.gif";

	// Obtain a WebP ImageReader instance
	ImageReader reader = ImageIO.getImageReadersByMIMEType("image/webp").next();
	// Configure decoding parameters
	WebPReadParam readParam = new WebPReadParam();
	readParam.setBypassFiltering(true);

	// Configure the input on the ImageReader
	try {
		reader.setInput(new FileImageInputStream(new File(inputPath)));
	} catch (IOException e) {
		e.printStackTrace();
	}

	// Decode the image
	BufferedImage image = reader.read(0, readParam);
	ImageIO.write(image, "gif", new File(outputGifPath));
}`

and this is the exception
Exception in thread "main" java.io.IOException: Decode returned code VP8_STATUS_UNSUPPORTED_FEATURE at com.luciad.imageio.webp.WebP.decode(WebP.java:61) at com.luciad.imageio.webp.WebPReader.read(WebPReader.java:158) at com.andy.main(Test.java:281)

should I compile the libwebp1.0.0 or the newer?
0.1.0 版本用的库是 libwebp0.4.2,比较老了, 你可以自己编译 mac 环境的 libwebp1.0.0 的动态链接库。我手上没有 mac 机器,无能为力。
https://segmentfault.com/a/1190000016324137

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.