Comments (6)
Thanks @talhaozdemir! I think I might need a little more information:
-
How are you decoding images? Would it be possible to provide a minimal code sample in a GitHub repo or CodeSandbox link?
-
Is this specifically about the
@jsquash/avif
package? -
when I use an AVIF supported browser, speed is about 200ms - 300ms
Is this the browser's native image decoding speed? If so, I would anticipate it to be faster as it's likely using an optimized binary for your OS without the overhead of WASM and JS.
from jsquash.
hi, thanks for reply, here is what I tried;
import * as avif from "@jsquash/avif";
.
.
.
const buffer = base64ToArrayBuffer(imageFile);
let imgData = await avif.decode(buffer);
var base64 = imageDataToBase64(imgData);
image.onload = function () {
callback();
};
image.src = base64;
imageFile is an base64 avif file
and some functions for above code;
function base64ToArrayBuffer(base64) {
base64 = base64.replace(/^data:image\/(png|jpeg|jpg|avif);base64,/, "");
var binaryString = atob(base64);
var bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
function imageDataToBase64(imageData) {
const canvas = document.createElement("canvas");
canvas.width = imageData.width;
canvas.height = imageData.height;
const ctx = canvas.getContext("2d");
ctx.putImageData(imageData, 0, 0);
return canvas.toDataURL();
}
and yes it is browser's native decoding speed
from jsquash.
Thanks for the extra context! That makes it very clear. Yeah... I am not sure if we can compete with the browser's own decoder.
There are some optimizations that could be made to help improve the speed of this project's AVIF decoder like
- Upgrading to a newer
lib/avif
version - Testing if SIMD compilation is available and if it improves the speed
- Testing if parallelization improves the speed
I don't have the expertise or time to explore that right now, but I would consider a pull request if someone is interested.
If you're after speed in the browser, I recommend sticking with the Canvas API or seeing if there's a more optimized AVIF wasm library out there.
from jsquash.
Thank you for the suggestions; I don't have much technical knowledge in these areas either. These suggestions are sufficient, you can close this issue if you want.
from jsquash.
Looks like there is an existing PR upstream for upgrading to a newer avif version. When I find time I'll see if we can pull this in.
from jsquash.
Awesome news! Thanks for your support.
from jsquash.
Related Issues (20)
- Simple CDN example HOT 5
- Cannot find module in sveltekit project HOT 6
- Issues with multi-threaded worker modules and Vite HOT 13
- Basic Node.js Support HOT 1
- Provide way to override WASM file location HOT 2
- Deno fails with "NotSupported: Classic workers are not supported." HOT 1
- @jsquash/png fails to decode some images HOT 14
- Create a reference decode speed benchmark page HOT 1
- Module not found HOT 1
- gif support? HOT 1
- Add type declarations for all wasm files? HOT 5
- jpeg and webp fail to import inside web worker HOT 2
- Resize component memory leak HOT 7
- Nuxt build error: UMD and IIFE output formats are not supported for code-splitting builds. HOT 4
- Passing a custom fetch function
- background execution? HOT 2
- How can I create my own CDN version and host on my server ? HOT 3
- node 18.8 > pnpm 安装的 不能自动加载 WASM HOT 1
- png > Pls support https://lib.rs/crates/imagequant [pngquant lib in rust!] HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsquash.