wasm-webp 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -6
- package/dist/cjs/index.js +19 -13
- package/dist/cjs/webp-wasm.js +1133 -325
- package/dist/cjs/webp-wasm.wasm +0 -0
- package/dist/esm/index.js +12 -11
- package/dist/esm/webp-wasm.js +1128 -324
- package/dist/esm/webp-wasm.wasm +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,13 @@ webp.wasm is a pure Webassembly / Javascript port of libwebp. The library suppor
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
npm i wasm-webp
|
|
13
|
+
```
|
|
7
14
|
|
|
8
15
|
## APIs
|
|
9
16
|
|
|
@@ -79,15 +86,15 @@ A more advanced API is based on the WebPConfig. <b>Only the lossless and quality
|
|
|
79
86
|
|
|
80
87
|
`function encodeRGBA(data: Uint8Array, width: number, height: number, hasAlpha: boolean,config: Partial<WebPConfig>): Promise<Nullable<Uint8Array>>`
|
|
81
88
|
|
|
82
|
-
- hasAlpha: boolean
|
|
89
|
+
- hasAlpha: `boolean`
|
|
83
90
|
|
|
84
91
|
Whether to include alpha chanel.
|
|
85
92
|
|
|
86
|
-
- WebPConfig.lossless: number
|
|
93
|
+
- WebPConfig.lossless: `number`
|
|
87
94
|
|
|
88
95
|
Lossless encoding (0=lossy(default), 1=lossless).
|
|
89
96
|
|
|
90
|
-
- WebPConfig.quality: number
|
|
97
|
+
- WebPConfig.quality: `number`
|
|
91
98
|
|
|
92
99
|
Between 0 and 100. Default value is 100.
|
|
93
100
|
|
|
@@ -108,20 +115,24 @@ Returns animated WebP like `GIF`.
|
|
|
108
115
|
|
|
109
116
|
`function encodeAnimation(width: number, height: number, hasAlpha: boolean, frames: WebPAnimationFrame[]): Promise<Nullable<Uint8Array>>`
|
|
110
117
|
|
|
111
|
-
- hasAlpha: boolean
|
|
118
|
+
- hasAlpha: `boolean`
|
|
112
119
|
|
|
113
120
|
Whether to include alpha chanel.
|
|
114
121
|
|
|
115
122
|
The WebPAnimationFrame has follow properties:
|
|
116
123
|
|
|
117
|
-
- WebPAnimationFrame.data: Uint8Array
|
|
124
|
+
- WebPAnimationFrame.data: `Uint8Array`
|
|
118
125
|
|
|
119
126
|
Frame bitmap.
|
|
120
127
|
|
|
121
|
-
- WebPAnimationFrame.duration: number
|
|
128
|
+
- WebPAnimationFrame.duration: `number`
|
|
122
129
|
|
|
123
130
|
Duration of frame.
|
|
124
131
|
|
|
132
|
+
- WebPAnimationFrame.config: `WebPConfig` (optional)
|
|
133
|
+
|
|
134
|
+
Per-frame encoding configuration. If not provided, default config is used (lossless: 0, quality: 100).
|
|
135
|
+
|
|
125
136
|
##### Example
|
|
126
137
|
|
|
127
138
|
```javascript
|
|
@@ -131,6 +142,12 @@ frames.push({
|
|
|
131
142
|
data: ctx.getImageData(0, 0, 100, 100).data,
|
|
132
143
|
duration: 20
|
|
133
144
|
})
|
|
145
|
+
// with per-frame config
|
|
146
|
+
frames.push({
|
|
147
|
+
data: ctx.getImageData(0, 0, 100, 100).data,
|
|
148
|
+
duration: 20,
|
|
149
|
+
config: { lossless: 0, quality: 80 }
|
|
150
|
+
})
|
|
134
151
|
const webpData = await encodeAnimation(100, 100, true, frames)
|
|
135
152
|
...
|
|
136
153
|
// download webp
|
package/dist/cjs/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.decodeRGBA = exports.decodeRGB = exports.decoderVersion = exports.encodeAnimation = exports.encode = exports.encodeRGBA = exports.encodeRGB = exports.encoderVersion = void 0;
|
|
15
|
+
exports.decodeAnimation = exports.decodeRGBA = exports.decodeRGB = exports.decoderVersion = exports.encodeAnimation = exports.encode = exports.encodeRGBA = exports.encodeRGB = exports.encoderVersion = void 0;
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const webp_wasm_1 = __importDefault(require("./webp-wasm"));
|
|
18
18
|
// default webp config
|
|
@@ -47,19 +47,20 @@ const encode = (data, width, height, hasAlpha, config) => __awaiter(void 0, void
|
|
|
47
47
|
exports.encode = encode;
|
|
48
48
|
const encodeAnimation = (width, height, hasAlpha, frames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
49
|
const module = yield (0, webp_wasm_1.default)();
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
const frameVector = new module.VectorWebPAnimationFrame();
|
|
51
|
+
frames.forEach((frame) => {
|
|
52
|
+
const hasConfig = frame.config !== undefined;
|
|
53
|
+
const config = Object.assign(Object.assign({}, defaultWebpConfig), frame.config);
|
|
54
|
+
config.lossless = Math.min(1, Math.max(0, config.lossless));
|
|
55
|
+
config.quality = Math.min(100, Math.max(0, config.quality));
|
|
56
|
+
frameVector.push_back({
|
|
57
|
+
duration: frame.duration,
|
|
58
|
+
data: frame.data,
|
|
59
|
+
config,
|
|
60
|
+
has_config: hasConfig,
|
|
61
|
+
});
|
|
61
62
|
});
|
|
62
|
-
return module.encodeAnimation(width, height, hasAlpha,
|
|
63
|
+
return module.encodeAnimation(width, height, hasAlpha, frameVector);
|
|
63
64
|
});
|
|
64
65
|
exports.encodeAnimation = encodeAnimation;
|
|
65
66
|
const decoderVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -82,3 +83,8 @@ exports.decodeRGBA = decodeRGBA;
|
|
|
82
83
|
// const module = await Module()
|
|
83
84
|
// return module.decode(data, hasAlpha)
|
|
84
85
|
// }
|
|
86
|
+
const decodeAnimation = (data, hasAlpha) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const module = yield (0, webp_wasm_1.default)();
|
|
88
|
+
return module.decodeAnimation(data, hasAlpha);
|
|
89
|
+
});
|
|
90
|
+
exports.decodeAnimation = decodeAnimation;
|