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.
Binary file
package/dist/esm/index.js CHANGED
@@ -37,19 +37,20 @@ export const encode = (data, width, height, hasAlpha, config) => __awaiter(void
37
37
  });
38
38
  export const encodeAnimation = (width, height, hasAlpha, frames) => __awaiter(void 0, void 0, void 0, function* () {
39
39
  const module = yield Module();
40
- const durations = [];
41
- const dataLength = frames.reduce((acc, frame) => {
42
- acc += frame.data.length;
43
- return acc;
44
- }, 0);
45
- const data = new Uint8Array(dataLength);
46
- let offset = 0;
40
+ const frameVector = new module.VectorWebPAnimationFrame();
47
41
  frames.forEach((frame) => {
48
- data.set(frame.data, offset);
49
- offset += frame.data.length;
50
- durations.push(frame.duration);
42
+ const hasConfig = frame.config !== undefined;
43
+ const config = Object.assign(Object.assign({}, defaultWebpConfig), frame.config);
44
+ config.lossless = Math.min(1, Math.max(0, config.lossless));
45
+ config.quality = Math.min(100, Math.max(0, config.quality));
46
+ frameVector.push_back({
47
+ duration: frame.duration,
48
+ data: frame.data,
49
+ config,
50
+ has_config: hasConfig,
51
+ });
51
52
  });
52
- return module.encodeAnimation(width, height, hasAlpha, durations, data);
53
+ return module.encodeAnimation(width, height, hasAlpha, frameVector);
53
54
  });
54
55
  export const decoderVersion = () => __awaiter(void 0, void 0, void 0, function* () {
55
56
  const module = yield Module();