Skip to content

Commit

Permalink
Merge pull request #3 from umjammer/0.2.3
Browse files Browse the repository at this point in the history
0.2.3
  • Loading branch information
umjammer authored Oct 8, 2022
2 parents d94dcd8 + 0881075 commit 8e87594
Show file tree
Hide file tree
Showing 23 changed files with 533 additions and 433 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Java CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: |
mvn -B package --file pom.xml
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[![Release](https://jitpack.io/v/umjammer/javavp8decoder.svg)](https://jitpack.io/#umjammer/javavp8decoder)
[![Parent](https://img.shields.io/badge/Parent-vavi--image--sandbox-pink)](https://github.com/umjammer/vavi-image-sandbox)

[![Java CI](https://github.com/umjammer/javavp8decoder/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/javavp8decoder/actions/workflows/maven.yml)
[![CodeQL](https://github.com/umjammer/javavp8decoder/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/javavp8decoder/actions/workflows/codeql-analysis.yml)
![Java](https://img.shields.io/badge/Java-8-b07219)
[![Parent](https://img.shields.io/badge/Parent-vavi--image--sandbox-pink)](https://github.com/umjammer/vavi-image-sandbox)

# javavp8decoder

Java VP8 Decoder
An implementation of the VP8 image/video codec in _**pure Java**_.

## Install

https://jitpack.io/#umjammer/javavp8decoder

## Usage

```java
BufferedImage image = ImageIO.read(Paths.get("/foo/bar.webp").toFile());
```
83 changes: 65 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,93 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.sf.javavp8decoder</groupId>
<artifactId>javavp8decoder</artifactId>
<version>0.2.2</version>
<name>Java VP8 Decoder</name>
<description>An implementation of the VP8 image/video codec in pure Java.

0.2.2
<version>0.2.3</version>

bug fix about lost service file

0.2.1
<name>Java VP8 Decoder</name>
<scm>
<url>https://github.com/umjammer/javavp8decoder/</url>
</scm>
<url>https://sourceforge.net/projects/javavp8decoder/</url>
<issueManagement>
<url>https://github.com/umjammer/javavp8decoder/issues</url>
</issueManagement>
<description>pure Java webp Decoder</description>

mavenize</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.10.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<argLine>
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>jebml</artifactId>
<version>0.0.2</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.umjammer</groupId>
<artifactId>vavi-commons</artifactId>
<version>1.1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<scm>
<url>https://github.com/umjammer/javavp8decoder/</url>
</scm>
<url>https://sourceforge.net/projects/javavp8decoder/</url>
<issueManagement>
<url>https://github.com/umjammer/javavp8decoder/issues</url>
</issueManagement>
</project>
12 changes: 10 additions & 2 deletions src/main/java/net/sf/javavp8decoder/imageio/WebPImageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.IIOException;
import javax.imageio.ImageReadParam;
Expand All @@ -38,6 +40,8 @@

public class WebPImageReader extends ImageReader implements IIOReadProgressListener {

private static final Logger logger = Logger.getLogger(WebPImageReader.class.getName());

// Constants enumerating the values of colorType
static final int COLOR_TYPE_GRAY = 0;

Expand Down Expand Up @@ -209,10 +213,14 @@ public void readHeader() throws IIOException {
}
decoder.decodeFrame(false);
} catch (IOException e) {
e.printStackTrace();
if (logger.isLoggable(Level.FINE)) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
if (logger.isLoggable(Level.FINE)) {
e.printStackTrace();
}
}
this.width = decoder.getWidth();
this.height = decoder.getHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public WebPImageReaderSpi() {
suffixes,
MIMETypes,
readerClassName,
STANDARD_INPUT_TYPE, // Accept ImageInputStreams
new Class[] { ImageInputStream.class },
writerSpiNames,
supportsStandardStreamMetadataFormat,
nativeStreamMetadataFormatName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

public class WebPMetadataFormat extends IIOMetadataFormatImpl {

// Create a single instance of this class (singleton pattern)
/** Create a single instance of this class (singleton pattern) */
private static WebPMetadataFormat defaultInstance = new WebPMetadataFormat();

// Return the singleton instance
/** Return the singleton instance */
public static WebPMetadataFormat getDefaultInstance() {
return defaultInstance;
}

// Make constructor private to enforce the singleton pattern
/** Make constructor private to enforce the singleton pattern */
private WebPMetadataFormat() {
// Set the name of the root node
// The root node has a single child node type that may repeat
Expand All @@ -47,7 +47,7 @@ private WebPMetadataFormat() {
addAttribute("KeywordValuePair", "value", DATATYPE_STRING, true, null);
}

// Check for legal element name
/** Check for legal element name */
public boolean canNodeAppear(String elementName, ImageTypeSpecifier imageType) {
return elementName.equals("KeywordValuePair");
}
Expand Down
40 changes: 25 additions & 15 deletions src/main/java/net/sf/javavp8decoder/vp8Decoder/BoolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@


public class BoolDecoder {
int bit_count; /* # of bits shifted out of value, at most 7 */
/** # of bits shifted out of value, at most 7 */
int bit_count;

ImageInputStream data;

private long offset; /* pointer to next compressed data byte */
/** pointer to next compressed data byte */
private long offset;

private int range; /* always identical to encoder's range */
/** always identical to encoder's range */
private int range;

private int value; /* contains at least 24 significant bits */
/** contains at least 24 significant bits */
private int value;

BoolDecoder(ImageInputStream frame, long offset) throws IOException {
this.data = frame;
Expand All @@ -40,15 +44,15 @@ public class BoolDecoder {

private void initBoolDecoder() throws IOException {

value = 0; /* value = first 16 input bits */
value = 0; // value = first 16 input bits

data.seek(offset);
value = data.readUnsignedByte() << 8;
// value = (data[offset]) << 8;
offset++;

range = 255; /* initial range is full */
bit_count = 0; /* have not yet shifted out any bits */
range = 255; // initial range is full
bit_count = 0; // have not yet shifted out any bits
}

public int readBit() throws IOException {
Expand Down Expand Up @@ -94,19 +98,23 @@ public int readBool(int probability) throws IOException {
return bit;
}

/* Convenience function reads a "literal", that is, a "num_bits" wide
/**
* Convenience function reads a "literal", that is, a "num_bits" wide
* unsigned value whose bits come high- to low-order, with each bit encoded
* at probability 128 (i.e., 1/2). */
* at probability 128 (i.e., 1/2).
*/
public int readLiteral(int num_bits) throws IOException {
int v = 0;
while (num_bits-- > 0)
v = (v << 1) + readBool(128);
return v;
}

int readTree(int t[], /* tree specification */
int p[] /* corresponding interior node probabilities */
) throws IOException {
/**
* @param t tree specification
* @param p corresponding interior node probabilities
*/
int readTree(int[] t, int[] p) throws IOException {
int i = 0; /* begin at root */

/* Descend tree until leaf is reached */
Expand All @@ -116,9 +124,11 @@ int readTree(int t[], /* tree specification */

}

int readTreeSkip(int t[], /* tree specification */
int p[], /* corresponding interior node probabilities */
int skip_branches) throws IOException {
/**
* @param t tree specification
* @param p corresponding interior node probabilities
*/
int readTreeSkip(int[] t, int[] p, int skip_branches) throws IOException {
int i = skip_branches * 2; /* begin at root */

/* Descend tree until leaf is reached */
Expand Down
Loading

0 comments on commit 8e87594

Please sign in to comment.