Skip to content

Commit 2813560

Browse files
authored
feat(image): support decode avif and webp (#18)
1 parent 7e0c1cf commit 2813560

File tree

20 files changed

+80
-33
lines changed

20 files changed

+80
-33
lines changed

.github/workflows/CI.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ env:
33
DEBUG: napi:*
44
APP_NAME: image
55
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
SYSTEM_DEPS_DAV1D_BUILD_INTERNAL: 'always'
67
'on':
78
push:
89
branches:
@@ -27,10 +28,12 @@ jobs:
2728
- host: macos-latest
2829
target: x86_64-apple-darwin
2930
build: |
31+
brew install meson
3032
yarn workspace @napi-rs/image build --features with_simd
3133
strip -x packages/*/*.node
3234
- host: windows-latest
3335
build: |
36+
choco install meson -y
3437
yarn workspace @napi-rs/image build --features with_simd
3538
target: x86_64-pc-windows-msvc
3639
- host: windows-2022-xl
@@ -47,7 +50,7 @@ jobs:
4750
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
4851
build: |
4952
set -e && \
50-
apt install libaom-dev -y && \
53+
apt install meson -y && \
5154
yarn workspace @napi-rs/image build --features with_simd --target x86_64-unknown-linux-gnu && \
5255
strip packages/*/*.node
5356
- host: ubuntu-latest
@@ -58,7 +61,7 @@ jobs:
5861
unset RUSTFLAGS &&
5962
unset CC &&
6063
unset CXX &&
61-
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache perl nasm aom-dev &&
64+
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache perl nasm aom-dev meson &&
6265
export LIB_AOM_STATIC_LIB_PATH=/usr/lib &&
6366
export LIB_AOM_INCLUDE_PATH=/usr/include/aom/aom &&
6467
export LIB_AOM_PKG_CONFIG_PATH=/usr/lib/pkgconfig &&
@@ -67,14 +70,15 @@ jobs:
6770
- host: macos-latest
6871
target: aarch64-apple-darwin
6972
build: |
73+
brew install meson
7074
yarn workspace @napi-rs/image build --features with_simd
7175
strip -x packages/*/*.node
7276
- host: ubuntu-18.04
7377
architecture: x64
7478
target: aarch64-unknown-linux-gnu
7579
setup: |
7680
sudo apt-get update
77-
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
81+
sudo apt-get install meson g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
7882
build: |
7983
yarn workspace @napi-rs/image build --features with_simd
8084
aarch64-linux-gnu-strip packages/*/*.node
@@ -83,14 +87,16 @@ jobs:
8387
target: armv7-unknown-linux-gnueabihf
8488
setup: |
8589
sudo apt-get update
86-
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
90+
sudo apt-get install meson gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
8791
build: |
8892
yarn workspace @napi-rs/image build --features oxipng_libdeflater
8993
arm-linux-gnueabihf-strip packages/*/*.node
9094
- host: ubuntu-latest
9195
architecture: x64
9296
target: aarch64-linux-android
9397
build: |
98+
sudo apt update
99+
sudo apt install meson -y
94100
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
95101
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
96102
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"
@@ -101,6 +107,8 @@ jobs:
101107
architecture: x64
102108
target: armv7-linux-androideabi
103109
build: |
110+
sudo apt update
111+
sudo apt install meson -y
104112
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
105113
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
106114
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"
@@ -118,7 +126,7 @@ jobs:
118126
unset RUSTFLAGS &&
119127
unset CC &&
120128
unset CXX &&
121-
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache aom-dev perl &&
129+
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache aom-dev perl meson &&
122130
yarn workspace @napi-rs/image build --target aarch64-unknown-linux-musl --features with_simd &&
123131
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip packages/*/*.node
124132
name: stable - ${{ matrix.settings.target }} - node@16

packages/binding/CHANGELOG.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
55

66
## [1.1.2](https://github.com/Brooooooklyn/Image/compare/@napi-rs/image@1.1.1...@napi-rs/image@1.1.2) (2022-04-22)
77

8-
98
### Bug Fixes
109

11-
* **image:** manipulate image has no effect ([e224c25](https://github.com/Brooooooklyn/Image/commit/e224c259d709bba704549ca34fa7851da41a6a3d))
12-
* **image:** webp encode LumaA8 and Luma8 ([2473680](https://github.com/Brooooooklyn/Image/commit/24736809eaa38237bd618b5860b12ae0ebe91bd6))
13-
14-
15-
16-
10+
- **image:** manipulate image has no effect ([e224c25](https://github.com/Brooooooklyn/Image/commit/e224c259d709bba704549ca34fa7851da41a6a3d))
11+
- **image:** webp encode LumaA8 and Luma8 ([2473680](https://github.com/Brooooooklyn/Image/commit/24736809eaa38237bd618b5860b12ae0ebe91bd6))
1712

1813
## [1.1.1](https://github.com/Brooooooklyn/Image/compare/@napi-rs/image@1.1.0...@napi-rs/image@1.1.1) (2022-04-21)
1914

packages/binding/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ image = { version = "0.24", default-features = false, features = [
2525
"tga",
2626
"tiff",
2727
"bmp",
28+
"webp",
2829
"hdr",
2930
"dxt",
3031
"dds",

packages/binding/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ This library support encode/decode these formats:
1919
| BMP || Rgb8, Rgba8, Gray8, GrayA8 |
2020
| ICO |||
2121
| TIFF | Baseline(no fax support) + LZW + PackBits | Rgb8, Rgba8, Gray8 |
22-
| WebP | No ||
23-
| AVIF | No ||
22+
| WebP | ||
23+
| AVIF | ||
2424
| PNM | PBM, PGM, PPM, standard PAM ||
2525
| DDS | DXT1, DXT3, DXT5 | No |
2626
| TGA || Rgb8, Rgba8, Bgr8, Bgra8, Gray8, GrayA8 |

packages/binding/__test__/transformer.spec.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ test('should be able to encode into webp', async (t) => {
4141
await t.notThrowsAsync(() => decoder.webp(75))
4242
})
4343

44+
test('should be able to decode from avif', async (t) => {
45+
const decoder = new Transformer(PNG)
46+
const AVIF = await decoder.avif()
47+
const avifDecoder = new Transformer(AVIF)
48+
await t.notThrowsAsync(() => avifDecoder.png())
49+
})
50+
51+
test('should be able to decode from webp', async (t) => {
52+
const decoder = new Transformer(PNG)
53+
const WEBP = await decoder.webpLossless()
54+
const webpDecoder = new Transformer(WEBP)
55+
await t.notThrowsAsync(() => webpDecoder.png())
56+
})
57+
4458
test('should be able to create transformer from raw rgba pixels', async (t) => {
4559
const pixels = decode('LEHV6nWB2yk8pyo0adR*.7kCMdnj', 32, 32)
4660
await t.notThrowsAsync(() => Transformer.fromRgbaPixels(pixels, 32, 32).webpLossless())

packages/binding/npm/android-arm-eabi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"access": "public"
3535
},
3636
"repository": "git@github.com:Brooooooklyn/imgquant.git"
37-
}
37+
}

packages/binding/npm/android-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"access": "public"
3535
},
3636
"repository": "git@github.com:Brooooooklyn/imgquant.git"
37-
}
37+
}

packages/binding/npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"access": "public"
3535
},
3636
"repository": "git@github.com:Brooooooklyn/imgquant.git"
37-
}
37+
}

packages/binding/npm/darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"access": "public"
3535
},
3636
"repository": "git@github.com:Brooooooklyn/imgquant.git"
37-
}
37+
}

packages/binding/npm/freebsd-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"access": "public"
3535
},
3636
"repository": "git@github.com:Brooooooklyn/imgquant.git"
37-
}
37+
}

0 commit comments

Comments
 (0)