JPEG XL (JXL) is a fascinating and technically advanced image format designed to be a comprehensive successor to existing image formats like JPEG, PNG, GIF, and WebP. Its ability to handle both highly compressed lossless files and losslessly recompress JPEGs stems from its sophisticated, modular design.
How JPEG XL Achieves Its Dual Capabilities
1. Heavily Compressing Lossless Files (General Lossless Mode)
JXL's general lossless mode is designed from the ground up to surpass older lossless formats like PNG, GIF, and WebP in compression efficiency while maintaining high quality. It achieves this through several advanced techniques:
- Modular Coding Structure: JXL uses a highly flexible and modular coding system. This allows it to adapt to different image characteristics and apply the most suitable compression tools.
- Context-Adaptive Prediction: Instead of simple linear prediction, JXL uses advanced context modeling. It analyzes surrounding pixels and their features to predict the value of the current pixel with high accuracy. The residual (the difference between the actual and predicted value) is then encoded, which is typically much smaller and thus more compressible.
- Advanced Transforms: While JXL can operate directly on pixel data for very simple lossless cases, its main lossless mode utilizes sophisticated, reversible transforms (e.g., Haar-like transforms, which are conceptually similar to wavelets but designed for integer operations to ensure perfect reconstruction). These transforms decorrelate image data, making it easier to compress.
- Asymmetric Numeral Systems (ANS) Entropy Coding: JXL employs ANS, a state-of-the-art entropy coding method. ANS is more efficient than Huffman coding (used in JPEG) or DEFLATE (used in PNG) for high-entropy data, leading to smaller file sizes.
- Adaptive Quantization/De-quantization: Even in lossless modes, JXL can internally use components that help in organizing data for better compression, ensuring that the final output is bit-for-bit identical to the input.
The combination of these techniques allows JXL to achieve significantly smaller file sizes for lossless images (often 20-50% smaller than PNG) while maintaining perfect fidelity.
2. Losslessly Recompressing JPEGs (JPEG Transcoding Mode)
This is one of JXL's most unique and powerful features, and it's distinct from general lossless compression.
- The Problem: When you typically recompress a JPEG (e.g., from JPEG to WebP, or JPEG to AVIF), you have to fully decode the JPEG to raw pixel data, which introduces loss due to the original JPEG's quantization. Then, you re-encode that (already degraded) pixel data into the new format, potentially introducing further loss (generational loss) or making the file much larger if you try to make it truly lossless relative to the raw pixel data.
- JXL's Solution: Direct DCT Coefficient Re-encoding: JPEG works by dividing an image into 8x8 blocks, applying a Discrete Cosine Transform (DCT) to these blocks, and then quantizing the resulting DCT coefficients. The quantization is where the lossiness comes from.
- JXL's "JPEG Transcoding" mode does not decompress the JPEG to pixel data. Instead, it directly takes the quantized DCT coefficients from the original JPEG bitstream.
- It then re-encodes these exact same quantized coefficients using JXL's more efficient entropy coding (ANS) and other advanced techniques.
- Crucially, it preserves the original JPEG's DCT coefficients and quantization tables exactly.
- The Benefit: This means:
- No Generational Loss: The recompressed JXL file is bit-for-bit identical to the original JPEG if decoded back to a JPEG. It doesn't lose any quality compared to the original JPEG.
- Smaller File Sizes: By using JXL's superior entropy coding on the existing DCT coefficients, the file size can be reduced (typically 10-20% for typical JPEGs) without altering the image data.
- Fast Encoding/Decoding: Because it avoids the computationally intensive DCT/iDCT steps (and their floating-point complexities) during transcoding, this mode is incredibly fast for both encoding and decoding.
This feature is invaluable for web migration, as it allows websites to upgrade their vast libraries of existing JPEGs to a more efficient format without any quality degradation or significant computational cost.
Why Google Prioritized AVIF Over JXL
The question states "abandoned lightweight JXL in favor of bulky, resource-heavy AVIF." This characterization of AVIF is sometimes true for encoding (it can be slower and more CPU-intensive), but for decoding, especially with hardware acceleration, AVIF can be quite fast. And while AVIF can be larger than JXL for lossless images, it often achieves very competitive compression (and sometimes better) for lossy photographic images at lower bitrates.
Google's decision to prioritize AVIF in Chrome (and thus, largely in the web ecosystem) is multifaceted and stems from strategic alignment and existing investments:
- Alliance for Open Media (AOMedia): Google is a founding member of AOMedia, a consortium that created AV1 (video codec) and subsequently AVIF (image format derived from AV1). Other key members include Apple, Microsoft, Amazon, Netflix, Meta, Cisco, Intel, NVIDIA, Samsung, etc. This is a collaborative effort aimed at creating royalty-free, high-performance codecs.
- Royalty-Free Ambition: AOMedia was explicitly formed to provide royalty-free alternatives to proprietary codecs like HEVC (H.265), which suffered from complex and expensive licensing schemes. Google, as a major content distributor and web platform, has a strong interest in open, royalty-free standards to avoid future legal and cost burdens.
- Video-First Strategy: AV1 was primarily developed as a video codec. AVIF leverages the immense R&D investment already poured into AV1. This means a significant portion of the core technology (like the highly optimized encoder/decoder designs, hardware acceleration potential) was already being developed for video, making AVIF a relatively "cheap" spin-off in terms of new R&D effort for Google.
- Existing Ecosystem: Google already had WebP, an image format they developed, that serves well for many web use cases (especially for mixed content and transparency, where it often outperforms JPEG). AVIF was positioned as the next step, specifically for high-quality photographic lossy compression, leveraging the advancements of AV1.
- Perceived Overlap/Redundancy: While JXL is technically superior in many ways (especially lossless, JPEG transcoding, and progressive decoding), from Google's perspective, they might have seen it as somewhat redundant with their existing WebP + AVIF strategy. They had "good enough" solutions for most of their use cases.
- "Not Invented Here" Syndrome (Less Direct): While Google did participate in JXL development, their deeper strategic commitment and financial investment were with AOMedia's AV1/AVIF. Pushing JXL would have meant diverting resources and attention from a multi-company, royalty-free consortium effort they heavily invested in.
- Implementation Complexity: JXL, being a "superset" format aiming to replace everything, is inherently more complex to implement fully compared to AVIF, which is a more focused, still-image derivative of a video codec. This can be a factor for browser vendors.
In essence, Google prioritized AVIF not because it was inherently superior in every technical metric (JXL often beats AVIF in lossless compression, progressive decoding, and offers the unique JPEG transcoding), but because it aligned better with their broader strategic goals, consortium commitments (AOMedia), and existing video codec investments. The lack of strong backing from Google (and subsequently, other browser vendors besides Safari, which has now added support) prevented JXL from gaining the widespread adoption it might have otherwise achieved.