25 lines
786 B
HTML
25 lines
786 B
HTML
<!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>
|