Skip to content

Commit 9e6066d

Browse files
committed
Dependency update.
Scripts update.
1 parent 07e15a0 commit 9e6066d

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "avif"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2021"
55

66
[lib]

avif.mjs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
const url=new URL('avif.wasm',import.meta.url);
2+
let wasm;
23
const imports={
34
wbg: {
4-
__wbg_log_12edb8942696c207: (p,n)=>{
5+
__wbg_log_aa11a1e72555df69: (p,n)=>{
56
console.log(new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n)));
7+
},
8+
__wbindgen_init_externref_table:function(){
9+
const table=wasm.__wbindgen_export_0;
10+
const offset=table.grow(4);
11+
table.set(0);
12+
table.set(offset);
13+
table.set(offset+1,null);
14+
table.set(offset+2,true);
15+
table.set(offset+3,false);
616
}
717
}
818
};
9-
const {instance: {exports: wasm}}=await WebAssembly.instantiateStreaming(await fetch(url,{cache: 'force-cache'}),imports);
19+
const {instance}=await WebAssembly.instantiateStreaming(await fetch(url,{cache: 'force-cache'}),imports);
20+
wasm=instance.exports;
1021
const malloc=wasm.__wbindgen_malloc;
1122
const free=wasm.__wbindgen_free;
12-
const pointer=wasm.__wbindgen_add_to_stack_pointer;
1323
/**
1424
* Encodes the supplied ImageData rgba array.
1525
* @param {Uint8Array} bytes
@@ -22,19 +32,11 @@ const pointer=wasm.__wbindgen_add_to_stack_pointer;
2232
const avif=(bytes,width,height,quality=50,speed=6)=>{
2333
const n1=bytes.length;
2434
const p1=malloc(n1,1);
25-
const r=pointer(-16);
26-
try{
27-
new Uint8Array(wasm.memory.buffer).set(bytes,p1);
28-
wasm.avif_from_imagedata(r,p1,n1,width,height,quality,speed);
29-
const arr=new Int32Array(wasm.memory.buffer);
30-
const p2=arr[r/4];
31-
const n2=arr[r/4+1];
32-
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
33-
free(p2,n2);
34-
return res;
35-
}finally{
36-
pointer(16)
37-
}
35+
new Uint8Array(wasm.memory.buffer).set(bytes,p1);
36+
const [p2,n2]=wasm.avif_from_imagedata(p1,n1,width,height,quality,speed);
37+
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
38+
free(p2,n2);
39+
return res;
3840
};
3941
export {avif};
4042
export default avif;

avif.wasm

-3.92 KB
Binary file not shown.

avif.wasm.br

594 Bytes
Binary file not shown.

avif_for_importScripts.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
const avif=(async()=>{
2+
let wasm;
23
const imports={
34
wbg: {
4-
__wbg_log_12edb8942696c207: (p,n)=>{
5+
__wbg_log_aa11a1e72555df69: (p,n)=>{
56
console.log(new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n)));
7+
},
8+
__wbindgen_init_externref_table:function(){
9+
const table=wasm.__wbindgen_export_0;
10+
const offset=table.grow(4);
11+
table.set(0);
12+
table.set(offset);
13+
table.set(offset+1,null);
14+
table.set(offset+2,true);
15+
table.set(offset+3,false);
616
}
717
}
818
};
9-
const {instance: {exports: wasm}}=await WebAssembly.instantiateStreaming(await fetch('./avif.wasm',{cache: 'force-cache'}),imports);
19+
const {instance}=await WebAssembly.instantiateStreaming(await fetch('./avif.wasm',{cache: 'force-cache'}),imports);
20+
wasm=instance.exports;
1021
const malloc=wasm.__wbindgen_malloc;
1122
const free=wasm.__wbindgen_free;
12-
const pointer=wasm.__wbindgen_add_to_stack_pointer;
1323
return (it,width,height,quality=50,speed=6)=>{
1424
const n1=it.length;
1525
const p1=malloc(n1,1);
16-
const r=pointer(-16);
17-
try{
18-
new Uint8Array(wasm.memory.buffer).set(data,p1);
19-
wasm.avif_from_imagedata(r,p1,n1,width,height,quality,speed);
20-
const arr=new Int32Array(wasm.memory.buffer);
21-
const p2=arr[r/4];
22-
const n2=arr[r/4+1];
23-
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
24-
free(p2,n2);
25-
return res;
26-
}finally{
27-
pointer(16)
28-
}
26+
new Uint8Array(wasm.memory.buffer).set(data,p1);
27+
const [p2,n2]=wasm.avif_from_imagedata(p1,n1,width,height,quality,speed);
28+
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
29+
free(p2,n2);
30+
return res;
2931
};
3032
})();

0 commit comments

Comments
 (0)