mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 10:39:53 +00:00
Add avif decoder binaries
This commit is contained in:
24
codecs/avif_dec/example.html
Normal file
24
codecs/avif_dec/example.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<script src='avif_dec.js'></script>
|
||||
<script>
|
||||
const Module = avif_dec();
|
||||
|
||||
async function loadFile(src) {
|
||||
const resp = await fetch(src);
|
||||
return await resp.arrayBuffer();
|
||||
}
|
||||
|
||||
Module.onRuntimeInitialized = async _ => {
|
||||
const image = await loadFile('../example.avif');
|
||||
const result = Module.decode(image);
|
||||
console.log(result.width, result.height, result.buffer);
|
||||
const imageData = new ImageData(new Uint8ClampedArray(result.buffer), result.width, result.height);
|
||||
Module.free_result();
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = result.width;
|
||||
canvas.height = result.height;
|
||||
document.body.appendChild(canvas);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user