Skip to content

Commit 999f72c

Browse files
Encode for everyone (#14)
* Create build-libwebp.yml * Update build-libwebp.yml * Update build-libwebp.yml * Update build-libwebp.yml * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Try bundled * Fix tests * Update build-libwebp.yml * Update bundled libwebp v1.6.0 * Update test-webp.yml * Final * Version * Update TestingApp.java * Update renovate.json --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3a1ca3a commit 999f72c

15 files changed

Lines changed: 317 additions & 76 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Build libwebp
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/build-libwebp.yml'
7+
workflow_dispatch:
8+
inputs:
9+
libwebp_version:
10+
description: 'libwebp version tag (e.g. v1.6.0)'
11+
required: false
12+
default: 'v1.6.0'
13+
14+
env:
15+
LIBWEBP_VERSION: ${{ inputs.libwebp_version || 'v1.6.0' }}
16+
17+
jobs:
18+
build:
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- os: ubuntu-latest
24+
target: linux
25+
artifact: libwebp.so
26+
- os: windows-latest
27+
target: windows
28+
artifact: libwebp.dll
29+
- os: macos-latest
30+
target: macos
31+
artifact: libwebp.dylib
32+
33+
name: ${{ matrix.target }}
34+
runs-on: ${{ matrix.os }}
35+
36+
steps:
37+
- uses: actions/checkout@v6
38+
39+
- name: Clone libwebp
40+
run: git clone --depth 1 --branch ${{ env.LIBWEBP_VERSION }} https://chromium.googlesource.com/webm/libwebp
41+
42+
- name: Patch out decoder
43+
shell: bash
44+
run: |
45+
cd libwebp
46+
sed -i.bak 's/\$<TARGET_OBJECTS:webpdecode>//' CMakeLists.txt
47+
sed -i.bak 's/add_library(sharpyuv /add_library(sharpyuv STATIC /' CMakeLists.txt
48+
49+
- name: Create export lists
50+
shell: bash
51+
run: |
52+
cat > libwebp-exports.txt <<'EOF'
53+
{ global: WebPEncodeLosslessBGRA; WebPFree; local: *; };
54+
EOF
55+
cat > libwebp-exports-macos.txt <<'EOF'
56+
_WebPEncodeLosslessBGRA
57+
_WebPFree
58+
EOF
59+
cat > libwebp-exports.def <<'EOF'
60+
EXPORTS
61+
WebPEncodeLosslessBGRA
62+
WebPFree
63+
EOF
64+
65+
- name: Build (Unix)
66+
if: runner.os != 'Windows'
67+
run: |
68+
cd libwebp
69+
mkdir build && cd build
70+
71+
if [ "${{ matrix.target }}" = "macos" ]; then
72+
EXTRA_FLAGS="-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_SHARED_LINKER_FLAGS=-Wl,-exported_symbols_list,${{ github.workspace }}/libwebp-exports-macos.txt,-dead_strip"
73+
else
74+
EXTRA_FLAGS="-DCMAKE_SHARED_LINKER_FLAGS=-Wl,--version-script=${{ github.workspace }}/libwebp-exports.txt,--gc-sections"
75+
fi
76+
77+
cmake .. \
78+
-DCMAKE_BUILD_TYPE=MinSizeRel \
79+
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
80+
-DCMAKE_C_FLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -fno-asynchronous-unwind-tables" \
81+
-DBUILD_SHARED_LIBS=ON \
82+
-DWEBP_BUILD_ANIM_UTILS=OFF \
83+
-DWEBP_BUILD_CWEBP=OFF \
84+
-DWEBP_BUILD_DWEBP=OFF \
85+
-DWEBP_BUILD_GIF2WEBP=OFF \
86+
-DWEBP_BUILD_IMG2WEBP=OFF \
87+
-DWEBP_BUILD_VWEBP=OFF \
88+
-DWEBP_BUILD_WEBPINFO=OFF \
89+
-DWEBP_BUILD_WEBPMUX=OFF \
90+
-DWEBP_BUILD_EXTRAS=OFF \
91+
$EXTRA_FLAGS
92+
cmake --build . --target webp --config MinSizeRel
93+
if [ "${{ matrix.target }}" = "macos" ]; then
94+
strip -x libwebp.* 2>/dev/null || true
95+
else
96+
strip -s libwebp.* 2>/dev/null || true
97+
fi
98+
99+
- name: Build (Windows)
100+
if: runner.os == 'Windows'
101+
run: |
102+
cd libwebp
103+
mkdir build && cd build
104+
cmake .. `
105+
-DCMAKE_BUILD_TYPE=MinSizeRel `
106+
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON `
107+
-DCMAKE_C_FLAGS="/Gw /DWEBP_EXTERN=extern" `
108+
-DBUILD_SHARED_LIBS=ON `
109+
-DCMAKE_SHARED_LINKER_FLAGS="/DEF:${{ github.workspace }}/libwebp-exports.def /OPT:REF,ICF" `
110+
-DWEBP_BUILD_ANIM_UTILS=OFF `
111+
-DWEBP_BUILD_CWEBP=OFF `
112+
-DWEBP_BUILD_DWEBP=OFF `
113+
-DWEBP_BUILD_GIF2WEBP=OFF `
114+
-DWEBP_BUILD_IMG2WEBP=OFF `
115+
-DWEBP_BUILD_VWEBP=OFF `
116+
-DWEBP_BUILD_WEBPINFO=OFF `
117+
-DWEBP_BUILD_WEBPMUX=OFF `
118+
-DWEBP_BUILD_EXTRAS=OFF
119+
cmake --build . --target webp --config MinSizeRel
120+
121+
- name: Copy artifact
122+
shell: bash
123+
run: |
124+
mkdir -p output
125+
if [ "${{ matrix.target }}" = "windows" ]; then
126+
cp libwebp/build/MinSizeRel/${{ matrix.artifact }} output/
127+
else
128+
cp libwebp/build/${{ matrix.artifact }} output/
129+
fi
130+
131+
- name: Upload artifact
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: libwebp-${{ matrix.target }}
135+
path: output/${{ matrix.artifact }}
136+
137+
commit:
138+
needs: build
139+
runs-on: ubuntu-latest
140+
permissions:
141+
contents: write
142+
143+
steps:
144+
- uses: actions/checkout@v6
145+
146+
- name: Download all artifacts
147+
uses: actions/download-artifact@v4
148+
with:
149+
path: artifacts
150+
151+
- name: Place natives
152+
run: |
153+
mkdir -p webp/src/main/resources/natives/{linux,windows,macos}
154+
cp artifacts/libwebp-linux/libwebp.so webp/src/main/resources/natives/linux/
155+
cp artifacts/libwebp-windows/libwebp.dll webp/src/main/resources/natives/windows/
156+
cp artifacts/libwebp-macos/libwebp.dylib webp/src/main/resources/natives/macos/
157+
158+
- name: Commit
159+
run: |
160+
git config user.name "github-actions[bot]"
161+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
162+
git add webp/src/main/resources/natives/
163+
git diff --cached --quiet && echo "No changes" && exit 0
164+
git commit -m "Update bundled libwebp ${{ env.LIBWEBP_VERSION }}"
165+
git push

‎.github/workflows/test-webp.yml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ name: Test WebP
22

33
on:
44
push:
5-
branches:
6-
- 'main'
75
paths:
86
- 'webp/**'
97
- '.github/workflows/test-webp.yml'
10-
pull_request:
8+
workflow_run:
9+
workflows: [Build libwebp]
10+
types: [completed]
1111
workflow_dispatch:
1212

1313
jobs:
@@ -25,13 +25,16 @@ jobs:
2525
name: Linux (NgEngine)
2626
install: sudo find /usr -name 'libwebp*.so*' -exec mv {} {}.disabled \;
2727
expected-decode: Java (ngengine)
28+
expected-encode: libwebp (lossless-only)
2829
- os: macos-latest
2930
name: macOS (ImageIO)
3031
expected-decode: macOS ImageIO
32+
expected-encode: libwebp (lossless-only)
3133
- os: windows-latest
3234
name: Windows (WIC)
3335
install: winget install --id 9PG2DK419DRG --accept-package-agreements --accept-source-agreements --source msstore --silent
3436
expected-decode: Windows WIC
37+
expected-encode: libwebp (lossless-only)
3538

3639
name: ${{ matrix.name }}
3740
runs-on: ${{ matrix.os }}

‎README.MD‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ repositories {
4545
4646
dependencies {
4747
// Include only the modules you need:
48-
implementation "org.redlance.platformtools:accent:4.1.1"
49-
implementation "org.redlance.platformtools:referer:4.1.1"
50-
implementation "org.redlance.platformtools:favorites:4.1.1"
51-
implementation "org.redlance.platformtools:progress:4.1.1"
52-
implementation "org.redlance.platformtools:webp:4.1.1"
48+
implementation "org.redlance.platformtools:accent:4.2.0"
49+
implementation "org.redlance.platformtools:referer:4.2.0"
50+
implementation "org.redlance.platformtools:favorites:4.2.0"
51+
implementation "org.redlance.platformtools:progress:4.2.0"
52+
implementation "org.redlance.platformtools:webp:4.2.0"
5353
5454
// For Java 8 (Downgraded version), add classifier:
55-
// implementation("org.redlance.platformtools:accent:4.1.1:java8")
55+
// implementation("org.redlance.platformtools:accent:4.2.0:java8")
5656
}
5757
```
5858

@@ -69,7 +69,7 @@ dependencies {
6969
<dependency>
7070
<groupId>org.redlance.platformtools</groupId>
7171
<artifactId>accent</artifactId>
72-
<version>4.1.1</version>
72+
<version>4.2.0</version>
7373
</dependency>
7474
```
7575

@@ -205,16 +205,27 @@ Decoder priority (first available wins):
205205
3. **Windows WIC** — Windows Imaging Component via FFM (decode only, requires WebP codec from MS Store)
206206
4. **ngengine** — pure-Java fallback ([image-webp-java](https://github.com/NostrGameEngine/image-webp-java), decode only, ~92 KB bundled)
207207

208-
The `webp` module has two variants:
209-
- **Standard** (`webp`) — uses platform-native APIs or system-installed libwebp. Zero bundled dependencies.
210-
- **Bundled** (`webp` with classifier `bundled`) — includes a shaded and ProGuard-optimized [ngengine image-webp-java](https://github.com/NostrGameEngine/image-webp-java) decoder (~92 KB). Pixel-exact on all platforms without native libraries.
208+
Encoder priority:
209+
1. **libwebp** — system-installed native library (lossy + lossless)
210+
2. **libwebp (lossless-only)** — bundled native encoder (lossless only, included in standard and `bundled` variants)
211+
212+
The `webp` module has three variants:
213+
214+
| Variant | Classifier | Natives | ngengine | Use case |
215+
|---------|------------|---------|----------|----------|
216+
| **Standard** | — | bundled libwebp (lossless encoder) | — | Platform with native decoder (macOS/Windows) or system libwebp |
217+
| **Bundled** | `bundled` | bundled libwebp (lossless encoder) | shaded + ProGuard | Self-contained, works everywhere |
218+
| **Bundled Lite** | `bundled-lite` | — | shaded + ProGuard | Minimal size, no native binaries |
211219

212220
```groovy
213-
// Standard — requires platform support or libwebp on library path
214-
implementation "org.redlance.platformtools:webp:4.1.1"
221+
// Standard — bundled lossless encoder, requires platform decoder or system libwebp for decoding
222+
implementation "org.redlance.platformtools:webp:4.2.0"
223+
224+
// Bundled — self-contained with ngengine decoder + bundled lossless encoder
225+
implementation "org.redlance.platformtools:webp:4.2.0:bundled"
215226
216-
// Bundled — self-contained, works everywhere (decode only)
217-
implementation "org.redlance.platformtools:webp:4.1.1:bundled"
227+
// Bundled Lite — ngengine decoder only, no native binaries
228+
implementation "org.redlance.platformtools:webp:4.2.0:bundled-lite"
218229
```
219230

220231
```java

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414

1515
allprojects {
1616
group = "org.redlance"
17-
version = "4.1.1"
17+
version = "4.2.0"
1818

1919
repositories {
2020
mavenCentral()

‎renovate.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
33
"extends": [
44
"config:recommended"
5+
],
6+
"customManagers": [
7+
{
8+
"customType": "regex",
9+
"fileMatch": ["\\.github/workflows/build-libwebp\\.yml$"],
10+
"matchStrings": ["'(?<currentValue>v\\d+\\.\\d+\\.\\d+)'"],
11+
"depNameTemplate": "webmproject/libwebp",
12+
"datasourceTemplate": "github-tags"
13+
}
514
]
615
}

‎testing/src/main/java/org/redlance/platformtools/testing/TestingApp.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.redlance.platformtools.favorites.PlatformFinderFavorites;
55
import org.redlance.platformtools.progress.PlatformProgressBars;
66
import org.redlance.platformtools.referer.PlatformFileReferer;
7+
import org.redlance.platformtools.webp.WebPDiagnostics;
78
import org.redlance.platformtools.webp.decoder.DecodedImage;
89
import org.redlance.platformtools.webp.decoder.PlatformWebPDecoder;
910
import org.redlance.platformtools.webp.encoder.PlatformWebPEncoder;
@@ -311,6 +312,10 @@ private void showWebPDialog() {
311312
}
312313

313314
log.append("\n");
315+
WebPDiagnostics.summary(s -> {
316+
log.append(s);
317+
log.append("\n");
318+
});
314319
});
315320
buttons.add(probeBtn);
316321

‎webp/build.gradle‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ tasks.register("proguardJar", ProGuardTask) {
7070
configuration(file("proguard.pro"))
7171
}
7272

73-
assemble.dependsOn proguardJar
73+
tasks.register("bundledLiteJar", Jar) {
74+
dependsOn proguardJar
75+
from(zipTree(proguardJar.getOutJarFileCollection().singleFile))
76+
exclude 'natives/**'
77+
archiveClassifier.set("bundled-lite")
78+
}
79+
80+
assemble.dependsOn proguardJar, bundledLiteJar
7481
downgradeJar.enabled = false
7582

7683
shadow {
@@ -82,4 +89,8 @@ publishing.publications.named("mavenJava") {
8289
classifier = "bundled"
8390
builtBy(tasks.named("proguardJar"))
8491
}
92+
artifact(tasks.named("bundledLiteJar")) {
93+
classifier = "bundled-lite"
94+
builtBy(tasks.named("bundledLiteJar"))
95+
}
8596
}

0 commit comments

Comments
 (0)