Skip to content

Commit

Permalink
Merge pull request #1 from umjammer/0.0.2
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
umjammer authored Sep 7, 2022
2 parents 4e84cce + fb641d1 commit 3ab79ba
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

# vavi-image-avif

Java AVIF decoder
Java AVIF decoder<br/>
wrapped libavif by jna<br/>
based on https://github.com/AOMediaCodec/libavif/tree/main/android_jni

<img src="https://upload.wikimedia.org/wikipedia/commons/4/45/Avif-logo-rgb.svg" width="256"/>

## Install

https://jitpack.io/#umjammer/vavi-image-avif
* install `libavif` e.g `brew libavif`
* https://jitpack.io/#umjammer/vavi-image-avif
* add `-Djna.library.path=/usr/local/lib` for jvm args

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-image-avif</artifactId>
<version>0.0.1</version>
<version>0.0.2-SNAPSHOT</version>

<name>Java AVIF Decoder</name>
<scm>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/vavi/awt/image/avif/jna/Avif.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ private avifDecoder createDecoderAndParse(final Pointer buffer, int length) {
* @param encoded The encoded AVIF image. encoded.position() must be 0.
* @param length Length of the encoded buffer.
* @param bitmap The decoded pixels will be copied into the bitmap.
* @return true on success and false on failure. A few possible reasons for failure are: 1) Input
* was not valid AVIF. 2) Bitmap was not large enough to store the decoded image.
* @return the decoded image.
*/
public BufferedImage decode(ByteBuffer encoded, int length, BufferedImage bitmap) {
Pointer buffer = Native.getDirectBufferPointer(encoded);
Expand Down
34 changes: 20 additions & 14 deletions src/test/java/Test1.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
Expand All @@ -18,6 +19,9 @@
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import vavi.awt.image.avif.jna.Avif;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;


/**
* Test1.
Expand All @@ -32,7 +36,7 @@ void test0() throws Exception {
String file = "/kimono.avif";
InputStream is = Test1.class.getResourceAsStream(file);
ByteBuffer bb = ByteBuffer.allocateDirect(is.available());
System.err.println("size: " + bb.capacity());
System.err.println("size: " + bb.capacity());
int l = 0;
while (l < bb.capacity()) {
int r = Channels.newChannel(is).read(bb);
Expand All @@ -42,10 +46,10 @@ void test0() throws Exception {

Avif avif = Avif.getInstance();
boolean r = avif.isAvifImage(bb, bb.capacity());
System.err.println("image is avif: " + r);
System.err.println("image is avif: " + r);

BufferedImage image = avif.getCompatibleImage(bb, bb.capacity());
System.err.printf("image: %dx%d%n", image.getWidth(), image.getHeight());
System.err.printf("image: %dx%d%n", image.getWidth(), image.getHeight());
avif.decode(bb, bb.capacity(), image);
}

Expand All @@ -58,7 +62,7 @@ void test1() throws Exception {
// String file = "/data/io/kodim23_yuv420_8bpc.avif";
InputStream is = Test1.class.getResourceAsStream(file);
ByteBuffer bb = ByteBuffer.allocateDirect(is.available());
System.err.println("size: " + bb.capacity());
System.err.println("size: " + bb.capacity());
int l = 0;
while (l < bb.capacity()) {
int r = Channels.newChannel(is).read(bb);
Expand All @@ -68,10 +72,10 @@ void test1() throws Exception {

Avif avif = Avif.getInstance();
boolean r = avif.isAvifImage(bb, bb.capacity());
System.err.println("image is avif: " + r);
System.err.println("image is avif: " + r);

BufferedImage image = avif.getCompatibleImage(bb, bb.capacity());
System.err.printf("image: %dx%d%n", image.getWidth(), image.getHeight());
System.err.printf("image: %dx%d%n", image.getWidth(), image.getHeight());
show(avif.decode(bb, bb.capacity(), image));
while (true) Thread.yield();
}
Expand All @@ -95,15 +99,17 @@ public void paint(Graphics g) {
@Test
void test00() throws Exception {
String[] rs = ImageIO.getReaderFormatNames();
System.err.println("-- reader --");
for (String r : rs) {
System.err.println(r);
}
System.err.println("-- writer --");
System.err.println("-- reader --");
for (String r : rs) {
System.err.println(r);
}
assertTrue(Arrays.asList(rs).contains("AVIF"));
String[] ws = ImageIO.getWriterFormatNames();
for (String w : ws) {
System.err.println(w);
}
System.err.println("-- writer --");
for (String w : ws) {
System.err.println(w);
}
assertFalse(Arrays.asList(ws).contains("AVIF"));
}

@Test
Expand Down

0 comments on commit 3ab79ba

Please sign in to comment.