WebP Recompression vs JPEG XL Lossless Transcoding
Migrating legacy JPEG images to modern image formats is essential for reducing bandwidth and accelerating web performance, but the methods used by WebP and JPEG XL differ fundamentally. While converting a JPEG to WebP requires decoding the image to raw pixels and re-encoding it—a process called recompression—JPEG XL can directly rewrite the JPEG bitstream into its own format without decoding. This article examines the technical mechanics, visual fidelity, reversibility, and performance differences between WebP recompression and JPEG XL lossless transcoding.
The Recompression Process in WebP
Converting an existing JPEG to WebP requires a full decode-and-re-encode pipeline:
- Decoding: The source JPEG is fully decoded into uncompressed pixel data (RGB or YUV).
- Analysis and Re-encoding: The WebP encoder analyzes these raw pixels and applies its own compression algorithms, utilizing spatial prediction, transform coding (VP8 intra-frame coding for lossy WebP), and entropy encoding.
Because the encoder evaluates pixels rather than the original frequency data, the process introduces generational loss if lossy WebP is chosen. Compression artifacts from the original JPEG are treated as genuine image detail by the WebP encoder, which attempts to preserve those artifacts at the expense of compression efficiency or introduces new artifacts on top of the old ones. Alternatively, using WebP lossless on raw pixel data decoded from a JPEG typically results in a file size significantly larger than the original JPEG.
Lossless Bitstream Transcoding in JPEG XL
JPEG XL approaches existing JPEGs through native bitstream transcoding rather than pixel-level recompression:
- Direct Parsing: JPEG XL parses the existing discrete cosine transform (DCT) coefficients, quantization matrices, and Huffman metadata directly from the JPEG file.
- Direct Mapping: Instead of rendering pixels, JPEG XL maps these 8x8 DCT blocks directly into its own VarDCT (Variable-block-size DCT) structures.
- Advanced Entropy Coding: The parsed coefficients are re-encoded using JPEG XL’s entropy coding mechanism (context-adaptive ANS or Brotli-based entropy coding), which is substantially more efficient than legacy JPEG Huffman tables.
This process operates strictly on mathematical representations rather than raw pixel buffers, requiring far less computational power than re-encoding.
Visual Fidelity and Generational Loss
- WebP Recompression: Inherently lossy when aiming for smaller file sizes. Re-encoding decoded pixels alters color values and sharp edges, compounding loss over successive saves.
- JPEG XL Transcoding: Mathematically lossless relative to the original JPEG. Because the DCT coefficients are copied directly without rendering, not a single pixel value changes. There is zero generational loss.
Reversibility: Byte-for-Byte Restoration
A defining difference between the two formats is reversibility:
- WebP: One-way operation. Once an image is converted to WebP, the original JPEG cannot be reconstructed. Converting the WebP back to JPEG constitutes a third compression cycle, further degrading image quality.
- JPEG XL: Fully reversible. JPEG XL stores the original JPEG headers and metadata within the container. At any point, the JPEG XL file can be instantly restored into a byte-identical copy of the original JPEG file.
Performance and File Size
JPEG XL transcoding reduces existing JPEG file sizes by roughly 16% to 22% while guaranteeing exact bitstream preservation. The operation is extremely fast because it bypasses motion estimation, frequency analysis, and color conversion.
WebP can often achieve greater size reductions (25% to 35%) when converting from JPEG, but it does so by sacrificing data fidelity via lossy approximation. Achieving these smaller sizes requires intensive CPU usage during the re-encoding phase to tune compression parameters and avoid introducing noticeable secondary artifacts.