Giter VIP home page Giter VIP logo

webp-imageio's Introduction

Travis build status

Forked repository

This is a fork from luciad/webp-imageio

Changes

  • Native libs are bundled in the jar
  • Published to Maven Central (org.sejda.imageio:webp-imageio artifact)
  • Android support unknown (have not tested)

Supported platforms

  • windows (32, 64 bit)
  • linux (64 bit)
  • mac (64 bit)

Description

Java Image I/O reader and writer for the Google WebP image format.

License

webp-imageio is distributed under the Apache Software License version 2.0.

Usage

  • Add Maven dependency org.sejda.imageio:webp-imageio to your application
  • The WebP reader and writer can be used like any other Image I/O reader and writer.

Decoding

WebP images can be decoded using default settings as follows.

BufferedImage image = ImageIO.read(new File("input.webp"));

To customize the WebP decoder settings you need to create instances of ImageReader and WebPReadParam.

// 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
reader.setInput(new FileImageInputStream(new File("input.webp")));

// Decode the image
BufferedImage image = reader.read(0, readParam);

Encoding

Encoding is done in a similar way to decoding.

You can either use the Image I/O convenience methods to encode using default settings.

// Obtain an image to encode from somewhere
BufferedImage image = ImageIO.read(new File("input.png"));

// Encode it as webp using default settings
ImageIO.write(image, "webp", new File("output.webp"));

Or you can create an instance of ImageWriter and WebPWriteParam to use custom settings.

// Obtain an image to encode from somewhere
BufferedImage image = ImageIO.read(new File("input.png"));

// Obtain a WebP ImageWriter instance
ImageWriter writer = ImageIO.getImageWritersByMIMEType("image/webp").next();

// Configure encoding parameters
WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType(p.getCompressionTypes()[WebPWriteParam.LOSSLESS_COMPRESSION]);

// Configure the output on the ImageWriter
writer.setOutput(new FileImageOutputStream(new File("output.webp")));

// Encode
writer.write(null, new IIOImage(image, null, null), writeParam);

Compiling

Compiling the native library for Java SE

  • Install CMake 2.8 or newer. CMake can be downloaded from www.cmake.org or installed using your systems package manager.
  • Install VS 2017 Community and make sure the C++/Cmake dev tools modules are installed
  • Create a directory called build in the root of the project
  • Open a terminal and navigate to the newly created 'build' directory
  • Run cmake .. in the 'build' directory to generate the build scripts for your system. On Windows 64 bit run cmake -DCMAKE_GENERATOR_PLATFORM=x64 .. to get a 64 bit dll.
  • cmake --build . --config Release to compile the library
  • The compiled library can be found under the directory build/src/main/c
  • Copy the compiled library to src/main/resources/native/$platform/$bits

Compiling the native library for Android

  • Install the Android NDK.
  • Run ndk-build in the src/android directory
  • After completion libwebp-imageio.so can be found under src/android/libs/<abi>

Compiling the Java library

Using Maven

  • Run mvn clean test in the root of the project
  • The compiled Java library can be found under the build directory
  • Run mvn release:prepare release:perform -Prelease -Darguments="-Dgpg.passphrase=secret123 -DstagingDescription=sambox" to upload to OSS Nexus, then login and publish to Maven Central

webp-imageio's People

Contributors

ediweissmann avatar pepijnve 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's Issues

java.lang.ArrayIndexOutOfBoundsException: 1

Hi

When trying to convert an emissive map (glow map) from jpg to webp using ImageIO and this plugin, I am getting this error:


SEVERE: Uncaught exception thrown in Thread[main,5,main]
java.lang.ArrayIndexOutOfBoundsException: 1
	at com.luciad.imageio.webp.WebPWriter.extractComponentRGBByte(WebPWriter.java:216)
	at com.luciad.imageio.webp.WebPWriter.getRGB(WebPWriter.java:129)
	at com.luciad.imageio.webp.WebPWriter.encode(WebPWriter.java:99)
	at com.luciad.imageio.webp.WebPWriter.write(WebPWriter.java:72)
	at app.Main.convertTexturesToWebP(Main.java:706)

this is the texture:

Seeker_emissive

When I am converting it to webp with Gimp it converts Ok.

zero length file written?

Hello! Thank you for this library.

I have a system for reading/writing ImageIO supported formats, already tested with png, tif, bmp, jpg, pio, etc.
Added org.sejda.imageio:webp-imageio:0.1.6 and reading webp files OK. When I try to write out

ImageIO.write(img, "webp", outputStream);

I get a zero length file. No error is generated. No exception thrown. Any ideas?

Compiling in Linux 64 bits

I have installed CMake 2.8.12;2
And I do:

$ mkdir build
$ cd build
$ cmake ..
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:6 (add_subdirectory):
  The source directory

    /home/jenkins/webp-imageio-0.1.6/libwebp

  does not contain a CMakeLists.txt file.


-- Found JNI: /usr/lib/jvm/java/lib/libjawt.so  
-- Configuring incomplete, errors occurred!
See also "/home/jenkins/webp-imageio-0.1.6/build/CMakeFiles/CMakeOutput.log".

Why do I get this error?
I've followed the instructions.

Fix the example code in the README

Fix the example code in the README.
Specifically the code below

- writeParam.setCompressionType(p.getCompressionTypes()[WebPWriteParam.LOSSLESS_COMPRESSION]);
+ writeParam.setCompressionType(writeParam.getCompressionTypes()[WebPWriteParam.LOSSLESS_COMPRESSION]);

I created a pull request because it was minor, but I couldn't create it because I didn't have enough permissions.
So I will contact you with an issue.

VP8_STATUS_UNSUPPORTED_FEATURE

java.io.IOException: Decode returned code VP8_STATUS_UNSUPPORTED_FEATURE
at com.luciad.imageio.webp.WebP.decode(WebP.java:65)
at com.luciad.imageio.webp.WebPReader.read(WebPReader.java:158)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1308)
at com.huya.web.complaygeneral.util.GraphicsUtilTest.drawText(GraphicsUtilTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Animated web files are not supported

Following exception occurs when an animated web file is read

Caused by: java.io.IOException: Decode returned code VP8_STATUS_BITSTREAM_ERROR
at com.luciad.imageio.webp.WebP.decode(WebP.java:65) ~[webp-imageio-0.1.6.jar:?]
at com.luciad.imageio.webp.WebPReader.read(WebPReader.java:158) ~[webp-imageio-0.1.6.jar:?]

Vulnerability !

master brach has vulnerability. also dependabot fixed it. why didn't you merge ? please merge dependabot's pull request

Windows 10 not finding DLL in JAR file.

I'm the project lead for ComiXed.

We're using your library to process WebP encoded comic pages. On Mac no issues have been reported. However some Windows users have reported a bug when working with WebP images (see the thread here for the details - comixed/comixed#159):

Exception in thread "Jarvis-ComiXed" java.lang.UnsatisfiedLinkError: C:\Users\<user>\AppData\Local\Temp\8794223231485648063webp-imageio.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 com.luciad.imageio.webp.NativeLibraryUtils.loadFromJar(WebP.java:131)
        at com.luciad.imageio.webp.WebP.loadNativeLibrary(WebP.java:31)
        at com.luciad.imageio.webp.WebP.<clinit>(WebP.java:38)
        at com.luciad.imageio.webp.WebPDecoderOptions.<clinit>(WebPDecoderOptions.java:20)
        at com.luciad.imageio.webp.WebPReadParam.<init>(WebPReadParam.java:24)
        at com.luciad.imageio.webp.WebPReader.getDefaultReadParam(WebPReader.java:147)
        at javax.imageio.ImageIO.read(Unknown Source)
        at javax.imageio.ImageIO.read(Unknown Source)
        at org.comixed.model.library.Page.getImageMetrics(Page.java:145)
        at org.comixed.model.library.Page.<init>(Page.java:120)
        at org.comixed.loaders.ImageEntryLoader.loadContent(ImageEntryLoader.java:45)
        at org.comixed.adaptors.archive.AbstractArchiveAdaptor.processContent(AbstractArchiveAdaptor.java:211)
        at org.comixed.adaptors.archive.ZipArchiveAdaptor.loadAllFiles(ZipArchiveAdaptor.java:90)
        at org.comixed.adaptors.archive.ZipArchiveAdaptor.loadAllFiles(ZipArchiveAdaptor.java:45)
        at org.comixed.adaptors.archive.AbstractArchiveAdaptor.loadComic(AbstractArchiveAdaptor.java:138)
        at org.comixed.task.model.ProcessComicTask.startTask(ProcessComicTask.java:60)
        at org.comixed.task.runner.Worker.run(Worker.java:187)
        at java.lang.Thread.run(Unknown Source)

We're using the 1.0 release from Maven of webp-imageio.

Library crashes JVM when running on Synology DS1621

Describe The Bug
My project uses imageio-webp to process archives containing WebP images. A user reported to me that, when processing a file containing WebP image while running our app in a Docker container on a Synology DS1621 (1520+ CPU: 2 GHz Intel Celeron J4125 Quad-Core & 8 GB DDR4 1621+ CPU: 2.2 GHz AMD R-Series Ryzen V1500B Quad-Core & base 4 GB EEC DDR4) imageio-webp consistently crashes the JVM.

The same code processes other image types (JPEG, PNG) without a problem.

To Reproduce The Bug
Steps to reproduce the behavior. Please be as complete as possible and describe the exact steps and values used to cause the error:

  1. Launch ComiXed in the Docker container on the Synology platform.
  2. Attempt to import a file containing a WebP image.
  3. The imageio-webp library crashes and brings down the JVM.

Expected Behavior

  1. The library should process the image without crashing.

Additional Context
The WebP code works correctly when run on other platforms, such as MacOS with Intel CPU, Windows and Linux boxes. The problem seems to be an issue on the specified platform.

Retrive webp image metadata

Webp images can contain useful EXIF metadata. Webp reader is not retrieving any metadata and the method is not implemented. This is a rather useful feature and appreciate if you could implement it.

com.luciad.imageio.webp.WebPReader

@OverRide
public IIOMetadata getImageMetadata( int imageIndex ) throws IOException {
return null;
}

It crashes in Alpine Linux 3.13 and 3.14

Alpine Linux is very used in Docker containers because it is very lightweight.
The result is that it always crashes with Java 11:
SIGSEGV (0xb) at pc=0x000000000000b8a6

  com.luciad.imageio.webp.WebP.decode(J[BII[IZ)[I+0
  com.luciad.imageio.webp.WebP.decode(Lcom/luciad/imageio/webp/WebPDecoderOptions;[BII[I)[I+64
  com.luciad.imageio.webp.WebPReader.read(ILjavax/imageio/ImageReadParam;)Ljava/awt/image/BufferedImage;+53
  javax.imageio.ImageIO.read(Ljavax/imageio/stream/ImageInputStream;)Ljava/awt/image/BufferedImage;+55 [email protected]
  javax.imageio.ImageIO.read(Ljava/io/InputStream;)Ljava/awt/image/BufferedImage;+34 [email protected]

Probably it is due to the fact that Alpine uses muslib and the native libray uses glibc.
How can I recompile the native library for Alpine?

TargetSize doesn't work

by using the following code,

ImageWriter writer = ImageIO.getImageWritersByMIMEType("image/webp").next();

// Configure encoding parameters
WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType(writeParam.getCompressionTypes()[WebPWriteParam.LOSSY_COMPRESSION]);
writeParam.setTargetSize(40000);

The output webp file doesn't be changed, by adjusting setTargetSize values.

Compression size

Hi, i'am trying to use the lib to automaticaly convert jpg files to webp to obtain smaller files. My problem is that the output file is the same weight even if it smaller in size (I previously resized the picture).

image

I'am doing this under Windows system with this code :

ImageWriter writer = ImageIO.getImageWritersByMIMEType("image/webp").next();

WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType(writeParam.getCompressionTypes()[WebPWriteParam.LOSSLESS_COMPRESSION]);

writer.setOutput(new FileImageOutputStream(outputFile));

writer.write(null, new IIOImage(bufferedImage, null, null), writeParam);

java.lang.NoClassDefFoundError: javax/imageio/ImageTypeSpecifier

Got an error on

openjdk version "11.0.11" 2021-04-20
Unbuntu 20.04

When

ImageIO.write(myBufferedImage, "webp", myNewFile)

Caused by: java.lang.NoClassDefFoundError: javax/imageio/ImageTypeSpecifier
at com.luciad.imageio.webp.WebPImageWriterSpi.canEncodeImage(WebPImageWriterSpi.java:62)
at java.desktop/javax.imageio.ImageIO$CanEncodeImageAndFormatFilter.filter(ImageIO.java:600)
at java.desktop/javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:876)
at java.desktop/javax.imageio.spi.FilterIterator.(ServiceRegistry.java:870)
at java.desktop/javax.imageio.spi.ServiceRegistry.getServiceProviders(ServiceRegistry.java:518)
at java.desktop/javax.imageio.ImageIO.getImageWriters(ImageIO.java:1172)
at java.desktop/javax.imageio.ImageIO.getWriter(ImageIO.java:1609)
at java.desktop/javax.imageio.ImageIO.write(ImageIO.java:1540)
at eu.utilo.SuperController.saveImg(SuperController.groovy:167)
at eu.utilo.onlineAtelier.myArtPage.MyArtPageSuperController.saveUploadedImage(MyArtPageSuperController.groovy:69)
at eu.utilo.onlineAtelier.myArtPage.MyEventsController.$tt__doChangeEventPic(MyEventsController.groovy:141)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)
at org.grails.core.DefaultGrailsControllerClass$MethodHandleInvoker.invoke(DefaultGrailsControllerClass.java:223)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
... 37 common frames omitted

can't load AMD 64-bit .so on a AARCH64-bit platform

the code work well in windows11

used the latest denpendcy 0.1.6
jdk8

but can't work in linux

error:
Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: /tmp/7424245579060724702libwebp-imageio.so: /tmp/7424245579060724702libwebp-imageio.so: cannot open shared object file: No such file or directory (Possible cause: can't load AMD 64-bit .so on a AARCH64-bit platform), org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: /tmp/7424245579060724702libwebp-imageio.so: /tmp/7424245579060724702libwebp-imageio.so: cannot open shared object file: No such file or directory (Possible cause: can't load AMD 64-bit .so on a AARCH64-bit platform)

linux-core version:
Linux version 4.18.0-147.5.1.el8_1.aarch64 ([email protected]) (gcc version 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC)) #1 SMP Tue Feb 4 23:44:08 UTC 2020

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.