SDK JS
    Preparing search index...

    Module @bitruvius/turbo-webp

    @bitruvius/turbo-webp — WebP image decode in the browser, powered by a pure-Rust SIMD wasm codec.

    Construct a WebpDecoder and call WebpDecoder.decode to turn a WebP byte buffer into WebpImageData (RGBA8 pixels + dimensions). Still images decode in every bitstream family — lossy VP8 , lossless VP8L, and the extended VP8X container with an ALPH alpha chunk. Animated WebP (ANIM/ANMF) is not supported and rejects.

    import { WebpDecoder } from '@bitruvius/turbo-webp';
    const img = await new WebpDecoder().decode(bytes);
    const pixels = new ImageData(new Uint8ClampedArray(img.rgba), img.width, img.height);

    Bitruvius

    @bitruvius/turbo-webp

    WebP decode in the browser. Byte-identical to libwebp, without libwebp.

    Your existing WebP files, your existing pipeline, your existing tooling. Swap the decoder implementation and keep everything else: decoded RGBA bytes are byte-identical to libwebp on every input.

    Turbocharged by Bitruvius TurboWebP.

    libwebp's lossy decode path has been frozen at SSE2/SSE4.1 since around 2012, and AVX2 only landed for the lossless path in libwebp 1.6.0. TurboWebP is a from-scratch Rust codec with current SIMD on every target it ships to.

    Bitruvius' summary of the decode result: "Decode the same files. Get there ~20% faster."

    Tile size Decode speedup vs libwebp 1.6.0, Win AVX2
    256² 1.03×
    512² 1.20×
    1024² 1.23×
    2048² 1.24×

    Pooled decode over a 400-sample real-world geospatial and EO corpus, n=100 per tile size, files produced by libwebp m=6, measured on Win AVX2 (Intel Core Ultra 9). Counting every cell in the published matrix: 27 of 32 decode cells faster on Win AVX2, 20 of 32 on Mac NEON (Apple M3 Max), 47 of 64 cross-host. Those figures are measured on the native builds. This package is the same codec compiled to WASM SIMD128.

    Memory-safe implementation. The codec is Rust, not C, so it removes the CVE-2023-4863 risk class rather than only the bugs that have been patched so far. Bitruvius reports the turbowebp-safe implementation as zero-unsafe. No emscripten anywhere in the build.

    import { WebpDecoder } from '@bitruvius/turbo-webp';

    const decoder = new WebpDecoder();
    const img = await decoder.decode(bytes); // bytes: Uint8Array of a .webp file

    // img.rgba is RGBA8, length img.width * img.height * 4
    const pixels = new ImageData(new Uint8ClampedArray(img.rgba), img.width, img.height);

    That is the whole API. decode() returns { width, height, hasAlpha, rgba }. Construct the decoder once and reuse it; the wasm initializes on the first decode and is shared from there.

    Serving the wasm yourself, from a CDN or a cross-origin host:

    const decoder = new WebpDecoder({
    wasmInit: { wasmUrl: 'https://cdn.example.com/turbowebp_wasm_bg.wasm' },
    });

    The wasm is a process-wide singleton, so the first decode wins: whichever decoder decodes first supplies the wasmInit that takes effect.

    npm i @bitruvius/turbo-webp
    

    Decoder only. This package decodes WebP. It does not encode. TurboWebP's encoder is part of the native library, not this browser build, so do not plan a write path around this dependency.

    Every still-image bitstream family decodes: lossy VP8 , lossless VP8L, and the extended VP8X container with an ALPH alpha chunk. That matrix is asserted against the shipped wasm in src/webp-conformance.test.ts, over fixtures encoded by libwebp 1.6.0. Animated WebP (ANIM/ANMF) is not supported and rejects.

    The wasm is committed to the package, so there is nothing to download at build time. The one runtime dependency is @bitruvius/foundation, installed with it. Allow script-src 'wasm-unsafe-eval' in your CSP. A self-contained ESM bundle and a script-tag build are also published on the Bitruvius CDN if you would rather skip the bundler entirely.

    WebP is a trademark of Google LLC. Google and libwebp are trademarks of Google LLC. Intel and Intel Core are trademarks of Intel Corporation. Apple is a trademark of Apple Inc. Arm and Neon are trademarks of Arm Limited. Rust is a trademark of the Rust Foundation. All other marks are the property of their respective owners.

    These names are used solely to describe the data formats this software interoperates with, the hardware the published figures were measured on, and the language it is written in. Bitruvius is not affiliated with, sponsored by, or endorsed by any of them, and no such relationship is implied.

    Proprietary. The full terms ship as LICENSE inside this package, and are readable before installing at cdn.bitruvius.com/legal/sdk-license-v1.txt.

    © Bitruvius, Inc.

    Classes

    WebpDecoder

    Interfaces

    WasmHostInit
    WebpDecoderOptions
    WebpImageData