JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 339
  • Score
    100M100P100Q100376F
  • License MIT

Encodes and decodes AVIF images using WebAssembly

Package Exports

  • @saschazar/wasm-avif

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@saschazar/wasm-avif) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm

📦 WebAssembly AVIF decoder

A dependency-free AVIF decoder written in WebAssembly

It decodes AVIF-encoded image data in a Uint8Array containing raw RGB pixels.

Installation

yarn add @saschazar/wasm-avif

or

npm install --save @saschazar/wasm-avif

Usage

It supports usage in the browser, in a Web Worker and of course Node.js.

// Node.js
import wasm_avif from '@saschazar/wasm-avif'

// Web Worker - see: https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
importScripts('wasm_webp.js')

// -------- Browser/Web Worker/Node.js code below --------

// Load encoded AVIF image data in Uint8Array
const array = new Uint8Array(['some', 'encoded', 'AVIF', 'image', 'data'])
let result

// Initialize the WebAssembly Module
const avifModule = wasm_avif({
  onRuntimeInitialized() {
    result = avifModule.decode(array, array.length) // decode image data and return a new Uint8Array
    avifModule.free() // clean up memory after encoding is done
  }
})

Status

The main backbone of the project is the libavif library.

Currently only AVIF decoding using dav1d is enabled. Furthermore, only 8-bit images are getting decoded reliably.

Help needed

Concerning the encoding functionality, a few trials have been made towards using the libaom and rav1e encoder, but none of them succeeded yet.

The latest progress is visible as commented-out code in the build.sh and main.cpp.

Credits

This module uses the AOMediaCodec/libavif's source code and most of the code is written according to the examples provided in that repository.

License

Licensed under the MIT license.

Copyright ©️ 2020 Sascha Zarhuber