Skip to content

Commit 07e15a0

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

13 files changed

+46
-35
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target/
22
**/*.rs.bk
33
Cargo.lock
4+
jellyfish_small.avif

Cargo.toml

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

66
[lib]
@@ -9,7 +9,7 @@ crate-type = ["cdylib",'rlib']
99
[dependencies]
1010
wasm-bindgen = "0.2"
1111
avif-serialize = "0.8"
12-
rav1e = { version = "0.6.6", default-features = false, features = ["wasm"] }
12+
rav1e = { version = "0.7.1", default-features = false, features = ["wasm"] }
1313

1414
[profile.release]
1515
debug = false

avif.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ declare module 'avif' {
88
* @param {number} height
99
* @param {number} [quality=50] (1 to 100)
1010
* @param {number} [speed=6] (1 to 10)
11-
* @return {Promise<Uint8Array>}
11+
* @return {Uint8Array}
1212
*/
1313
export function avif(bytes: Uint8Array, width: number, height: number, quality: number, speed: number): Uint8Array;
14+
1415
export default avif;
15-
}
16+
}

avif.mjs

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
const url=new URL('./avif.wasm',import.meta.url);
1+
const url=new URL('avif.wasm',import.meta.url);
22
const imports={
3-
wbg:{
4-
__wbg_log_d415f1170b035824: (p,n)=>{
5-
console.log(
6-
new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n))
7-
)
3+
wbg: {
4+
__wbg_log_12edb8942696c207: (p,n)=>{
5+
console.log(new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n)));
86
}
97
}
108
};
11-
const {instance:{exports:wasm}}=await WebAssembly.instantiateStreaming(await fetch(url,{cache:'force-cache'}),imports);
9+
const {instance: {exports: wasm}}=await WebAssembly.instantiateStreaming(await fetch(url,{cache: 'force-cache'}),imports);
1210
const malloc=wasm.__wbindgen_malloc;
1311
const free=wasm.__wbindgen_free;
1412
const pointer=wasm.__wbindgen_add_to_stack_pointer;
@@ -19,21 +17,24 @@ const pointer=wasm.__wbindgen_add_to_stack_pointer;
1917
* @param {number} height
2018
* @param {number} quality (1 to 100)
2119
* @param {number} speed (1 to 10)
22-
* @return {Promise<Uint8Array>}
20+
* @return {Uint8Array}
2321
*/
24-
const avif=(bytes,width,height, quality=50,speed=6)=>{
22+
const avif=(bytes,width,height,quality=50,speed=6)=>{
2523
const n1=bytes.length;
2624
const p1=malloc(n1,1);
2725
const r=pointer(-16);
2826
try{
2927
new Uint8Array(wasm.memory.buffer).set(bytes,p1);
3028
wasm.avif_from_imagedata(r,p1,n1,width,height,quality,speed);
3129
const arr=new Int32Array(wasm.memory.buffer);
32-
const p2=arr[r/4];const n2=arr[r/4+1];
30+
const p2=arr[r/4];
31+
const n2=arr[r/4+1];
3332
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
3433
free(p2,n2);
3534
return res;
36-
}finally{pointer(16)}
35+
}finally{
36+
pointer(16)
37+
}
3738
};
3839
export {avif};
39-
export default avif;
40+
export default avif;

avif.svg

+7
Loading

avif.wasm

-2.61 KB
Binary file not shown.

avif.wasm.br

-1002 Bytes
Binary file not shown.

avif_for_importScripts.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
const avif=(async()=>{
22
const imports={
3-
wbg:{
4-
__wbg_log_d415f1170b035824: (p,n)=>{
5-
console.log(
6-
new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n))
7-
)
3+
wbg: {
4+
__wbg_log_12edb8942696c207: (p,n)=>{
5+
console.log(new TextDecoder().decode(new Uint8Array(wasm.memory.buffer).subarray(p,p+n)));
86
}
97
}
108
};
11-
const {instance:{exports:wasm}}=await WebAssembly.instantiateStreaming(await fetch('./avif.wasm',{cache:'force-cache'}),imports);
9+
const {instance: {exports: wasm}}=await WebAssembly.instantiateStreaming(await fetch('./avif.wasm',{cache: 'force-cache'}),imports);
1210
const malloc=wasm.__wbindgen_malloc;
1311
const free=wasm.__wbindgen_free;
1412
const pointer=wasm.__wbindgen_add_to_stack_pointer;
@@ -20,10 +18,13 @@ const avif=(async()=>{
2018
new Uint8Array(wasm.memory.buffer).set(data,p1);
2119
wasm.avif_from_imagedata(r,p1,n1,width,height,quality,speed);
2220
const arr=new Int32Array(wasm.memory.buffer);
23-
const p2=arr[r/4];const n2=arr[r/4+1];
21+
const p2=arr[r/4];
22+
const n2=arr[r/4+1];
2423
const res=new Uint8Array(wasm.memory.buffer).subarray(p2,p2+n2).slice();
2524
free(p2,n2);
2625
return res;
27-
}finally{pointer(16)}
26+
}finally{
27+
pointer(16)
28+
}
2829
};
29-
})();
30+
})();

avif_worker.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ await (await fetch(url)).arrayBuffer();
33
const worker=await new Promise(r=>{
44
// For browsers that don't support type: module on workers (firefox < 114, safari < 15)
55
// const worker=new Worker(new URL('./avif_worker_script.js',import.meta.url));
6-
const worker=new Worker(new URL('./avif_worker_script.mjs',import.meta.url),{type:'module'});
6+
const worker=new Worker(new URL('./avif_worker_script.mjs',import.meta.url),{type: 'module'});
77
worker.onmessage=msg=>{
88
if(msg.data==='ready'){
99
worker.onmessage=null;
@@ -20,7 +20,7 @@ const worker=await new Promise(r=>{
2020
* @param {number} speed (1 to 10)
2121
* @return {Promise<Uint8Array>}
2222
*/
23-
const avif=(bytes,width,height, quality=50,speed=6)=>new Promise(r=>{
23+
const avif=(bytes,width,height,quality=50,speed=6)=>new Promise(r=>{
2424
worker.onmessage=msg=>{
2525
worker.onmessage=null;
2626
r(msg.data);
@@ -29,4 +29,4 @@ const avif=(bytes,width,height, quality=50,speed=6)=>new Promise(r=>{
2929
});
3030

3131
export {avif};
32-
export default avif;
32+
export default avif;

jellyfish.jpg

567 KB
Loading

src/av1encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Encoder {
2020
// Quality `1..=100`. Panics if out of range.
2121
#[must_use]
2222
pub fn with_quality(mut self, quality: f32) -> Self {
23-
assert!(quality >= 1. && quality <= 100.);
23+
debug_assert!(quality >= 1. && quality <= 100.);
2424
self.quantizer = quality_to_quantizer(quality);
2525
self
2626
}
@@ -29,7 +29,7 @@ impl Encoder {
2929
// 10 = quick, but larger file sizes and lower quality.
3030
#[must_use]
3131
pub fn with_speed(mut self, speed: u8) -> Self {
32-
assert!(speed >= 1 && speed <= 10);
32+
debug_assert!(speed >= 1 && speed <= 10);
3333
self.speed = speed;
3434
self
3535
}
@@ -254,7 +254,7 @@ impl SpeedTweaks {
254254
}
255255
};
256256
if let Some((min, max)) = self.partition_range {
257-
assert!(min <= max);
257+
debug_assert!(min <= max);
258258
fn sz(s: u8) -> BlockSize {
259259
match s {
260260
4 => BlockSize::BLOCK_4X4,

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn avif_from_imagedata(
2929
.with_quality(quality)
3030
.with_speed(speed)
3131
.encode_rgb(width, height, rgba.chunks_exact(4))
32-
.map_err(|e| log(format!("{:?}", e).as_str()))
32+
.map_err(|e| log(format!("{e:?}").as_str()))
3333
.unwrap()
3434
}
3535

test.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
const image=new Image();
1616
await new Promise((r)=>{
1717
image.onload=r;
18-
image.src='jellyfish.jpg';
18+
image.src='./jellyfish.jpg';
1919
});
2020
canvas.width=image.width;
2121
canvas.height=image.height;
@@ -25,11 +25,11 @@
2525
const {avif}=await import('./avif_worker.mjs');
2626
const rgba=new Uint8Array(data.data);
2727
const quality=50.0;
28-
for (const speed of [10,9,8,7,6,5,4,3,2,1]){
28+
for(const speed of [10,9,8,7,6,5,4,3,2,1]){
2929
const t=Date.now();
3030
const bytes=await avif(rgba,data.width,data.height,quality,speed);
3131
console.log(`avif: ${bytes.length}, speed: ${speed}, time: ${((Date.now()-t)/1000).toFixed(1)}`);
32-
const b=new Blob([bytes],{type:'image/avif'});
32+
const b=new Blob([bytes],{type: 'image/avif'});
3333
const link=document.createElement('a');
3434
link.download=`jellyfish_s${speed}.avif`;
3535
const img=document.createElement('img');

0 commit comments

Comments
 (0)