Skip to content

Commit

Permalink
Merge pull request #83 from usefulness/more_test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Jun 17, 2023
2 parents 6f86df5 + aa5b7a2 commit fb09fa2
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 299 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ max_line_length = 140
indent_size = 4
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_name_count_to_use_star_import = 0
ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_name_count_to_use_star_import_for_members = 999

[*.java]
max_line_length = 140
Expand Down
41 changes: 29 additions & 12 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ name: Build project

on:
pull_request:
push:
branches:
- master
- main

jobs:
cancel-previous-workflows:
name: Cancel previous workflow runs
runs-on: ubuntu-latest
steps:
- uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
build:
runs-on: ubuntu-latest

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -29,14 +32,28 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 20
java-version: |
8
11
17
20
- uses: gradle/gradle-build-action@v2

- uses: gradle/wrapper-validation-action@v1

- run: ./gradlew projectCodestyle --scan

- run: ./gradlew assemble --scan
- run: ./gradlew check --scan

- run: ./gradlew projectCoverage --scan

- run: ./gradlew publishToMavenLocal

- run: git diff --exit-code

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: test-results-${{ matrix.os }}
path: "${{ github.workspace }}/**/build/reports"
55 changes: 31 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
# web-imageio

[![Build](https://github.com/usefulness/webp-imageio/actions/workflows/after_merge.yml/badge.svg?branch=master)](https://github.com/usefulness/webp-imageio/actions/workflows/after_merge.yml)
![Maven Central](https://img.shields.io/maven-central/v/com.github.usefulness/webp-imageio)

# Forked repository
## Description

This contains only pre-compiled binaries

# Supported platforms

See the [full list](https://github.com/usefulness/webp-imageio/tree/master/webp-imageio/src/main/resources/native) of supported platforms

--------------

# Description

[Java Image I/O](http://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html) reader and writer for the
[Java Image I/O](https://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html) reader and writer for the
[Google WebP](https://developers.google.com/speed/webp/) image format.

# License
### Highlights:
- `macos-aarch64` architecture support (ARM chipsets from Apple, M1, M2) ✅
- Sharp YUV option support ✅

### Supported platforms

webp-imageio is distributed under the [Apache Software License](https://www.apache.org/licenses/LICENSE-2.0) version
2.0.
See the [full list](https://github.com/usefulness/webp-imageio/tree/master/webp-imageio/src/main/resources/native) of supported platforms

# Usage
## Usage

- Add dependency `com.github.usefulness:webp-imageio` to your application
- The WebP reader and writer can be used like any other Image I/O reader and writer.
1. Add dependency `com.github.usefulness:webp-imageio` to your application
```groovy
dependencies {
runtimeOnly("com.github.usefulness:webp-imageio:x.y.z")
}
```
2. The WebP reader and writer can be used like any other Image I/O reader and writer.

## Decoding
### Decoding

WebP images can be decoded using default settings as follows.

Expand All @@ -35,7 +36,7 @@ BufferedImage image = ImageIO.read(new File("input.webp"));

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

```
```java
// Obtain a WebP ImageReader instance
ImageReader reader = ImageIO.getImageReadersByMIMEType("image/webp").next();

Expand All @@ -50,13 +51,13 @@ reader.setInput(new FileImageInputStream(new File("input.webp")));
BufferedImage image = reader.read(0, readParam);
```

## Encoding
### 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.

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

Expand All @@ -66,7 +67,7 @@ ImageIO.write(image, "webp", new File("output.webp"));

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

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

Expand All @@ -76,11 +77,17 @@ 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]);
writeParam.setCompressionType(writeParam.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);
```

## License

`webp-imageio` is distributed under the [Apache Software License](https://www.apache.org/licenses/LICENSE-2.0) version
2.0.
`libwebp` binaries is distributed under the [Following License](https://chromium.googlesource.com/webm/libwebp/+/refs/tags/v1.3.0/COPYING)
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ gradle-starter = "0.60.1"
gradle-doctor = "0.8.1"
maven-junit = "5.9.3"
maven-assertj = "3.24.2"
maven-ktlint = "0.48.2"
maven-commons = "2.13.0"

[libraries]
Expand Down
35 changes: 35 additions & 0 deletions webp-imageio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ kotlin {
jvmToolchain(17)
}

tasks.register("generateVersionProperties") {
def projectVersion = version
def propertiesFile = new File(sourceSets.main.output.resourcesDir, "version.properties")
inputs.property("projectVersion", projectVersion)
outputs.file(propertiesFile)

doLast {
propertiesFile.write """
|webp_imageio_version = $projectVersion
|
""".strip().stripMargin()
}
}

[8, 11, 17].forEach { majorVersion ->
def jdkTest = tasks.register("testJdk$majorVersion", Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorVersion)
}

description = "Runs the test suite on JDK $majorVersion"
group = LifecycleBasePlugin.VERIFICATION_GROUP

// Copy inputs from normal Test task.
def testTask = tasks.getByName("test")
classpath = testTask.classpath
testClassesDirs = testTask.testClassesDirs
}
tasks.named("check").configure { dependsOn(jdkTest) }
}

tasks.named("processResources") {
dependsOn("generateVersionProperties")
}

dependencies {
testImplementation(libs.assertj.core)
testRuntimeOnly(libs.junit.jupiter.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,44 +283,24 @@ private static void getNativeLibraryFolderForTheCurrentOS() {
String archName = OSInfo.getArchName();
}

/**
* @return The major version of the library.
*/
public static int getMajorVersion() {
String[] c = getVersion().split("\\.");
return (c.length > 0) ? Integer.parseInt(c[0]) : 1;
}

/**
* @return The minor version of the library.
*/
public static int getMinorVersion() {
String[] c = getVersion().split("\\.");
return (c.length > 1) ? Integer.parseInt(c[1]) : 0;
}

/**
* @return The version of the library.
*/
public static String getVersion() {

URL versionFile = NativeLoader.class.getResource("/META-INF/maven/com.github.gotson/webp-imageio/pom.properties");
if (versionFile == null) {
versionFile = NativeLoader.class.getResource("/META-INF/maven/com.github.gotson/webp-imageio/VERSION");
}
URL versionFile = NativeLoader.class.getClassLoader().getResource("version.properties");

String version = "unknown";
try {
if (versionFile != null) {
Properties versionData = new Properties();
versionData.load(versionFile.openStream());
version = versionData.getProperty("version", version);
version = versionData.getProperty("webp_imageio_version", version);
version = version.trim().replaceAll("[^0-9\\.]", "");
}
} catch (IOException e) {
System.err.println(e);
}
return version;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,14 @@ public static boolean isAlpine() {
Process p = Runtime.getRuntime().exec("cat /etc/os-release | grep ^ID");
p.waitFor();

InputStream in = p.getInputStream();
try {
try (InputStream in = p.getInputStream()) {
int readLen = 0;
ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[32];
while ((readLen = in.read(buf, 0, buf.length)) >= 0) {
b.write(buf, 0, readLen);
}
return b.toString().toLowerCase().contains("alpine");
} finally {
if (in != null) {
in.close();
}
}

} catch (Throwable e) {
Expand All @@ -141,19 +136,14 @@ static String getHardwareName() {
Process p = Runtime.getRuntime().exec("uname -m");
p.waitFor();

InputStream in = p.getInputStream();
try {
int readLen = 0;
try (InputStream in = p.getInputStream()) {
int readLen;
ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[32];
while ((readLen = in.read(buf, 0, buf.length)) >= 0) {
b.write(buf, 0, readLen);
}
return b.toString();
} finally {
if (in != null) {
in.close();
}
}
} catch (Throwable e) {
System.err.println("Error while running uname -m: " + e.getMessage());
Expand Down Expand Up @@ -205,9 +195,7 @@ static String resolveArmArchType() {
System.err.println("WARNING! readelf not found. Cannot check if running on an armhf system, " +
"armel architecture will be presumed.");
}
} catch (IOException e) {
// ignored: fall back to "arm" arch (soft-float ABI)
} catch (InterruptedException e) {
} catch (IOException | InterruptedException e) {
// ignored: fall back to "arm" arch (soft-float ABI)
}
}
Expand Down
Loading

0 comments on commit fb09fa2

Please sign in to comment.