PureJsImage · JPEG XL

JPEG XL encoder and decoder

First-party JavaScript tools for lossless and static lossy encoding, viewing, animation, native samples and exact JPEG reconstruction.

These tools use the current repository build. Repository functionality may be newer than the npm release. Static lossy encoding is qualified; lossy animation remains Experimental.

Quick answer

Open a local file or try a generated sample. PureJsImage runs the codecs locally, even when your browser has no native JPEG XL support.

Try a sample Open a file

Use the browser APIs

Pixel conversion workbench · Transcode eligible JPEG coefficients · API and precision guide

Progressive and Range explorer

The explorer has its own page, including a local progressive sample.

Current limits and qualified scope

The documented static Modular and VarDCT subsets support all eight orientations, structured color, native integer precision, high-depth and float VarDCT output, independent alpha precision, and explicit HDR display conversion. Source metadata and emitted pixel semantics are distinct: gray plus alpha expands to RGBA with RGB semantics. The explicit sequence API adds rational animation timing, frame replay, composition, streamed lossless writing and Experimental lossy animation writing. Native channel APIs preserve exact unsigned samples through the JPEG XL maximum of 31 bits in Uint32 storage, legal floating-point bit patterns, grouped shifted extra channels, black channels and matching GRAY/RGB/CMYK ICC profiles. Level 10 native and general forward VarDCT output uses a container with jxll=10; writers choose the minimum valid level from depth, dimensions, pixel count, profile size and channel metadata, and reject conflicting raw or Level 5 requests. Forward VarDCT selects Level 10 automatically for exact Modular alpha above 12 bits and accepts an explicit Level 10 request across its existing integer gray/RGB/RGBA subset. Streamed Level 10 animation uses an unbounded jxlc box instead of buffering the completed output. Explicit finite-range IEEE binary16/binary32 gray/RGB-to-RGBA16 conversion accepts integer or IEEE alpha, including associated and shifted alpha; it emits straight alpha and records source and output meaning. Profile-defined CMYK-to-RGBA8 conversion accepts straight integer or IEEE alpha and shifted black/alpha planes. Explicit GRAY/RGB/CMYK ICC-to-sRGB16 conversion accepts 8- through 16-bit integer color, mixed integer or IEEE alpha, and associated alpha; the 8-bit CMYK API still rejects associated alpha. Native planes with shifts 0 through 3 can be written across multiple 1024-pixel Modular groups. Ordinary native Modular decoding accepts legal JPEG XL floating-point fields, including the independently checked 24-bit/8-exponent and 16-bit/4-exponent layouts, as finite Float32 rows. Integer gray/RGB with floating alpha emits normalized rgbaf32. Alpha may use unsigned depths through 31 bits. Opaque unsigned color through 31 bits retains exact gray32/rgb32 samples and depth on re-encode. Integer color with wide or floating alpha uses normalized Float32 and reports precision loss. Wider integer VarDCT display remains unsupported. The ordinary pixel pipeline converts supported GRAY and RGB ICC integer samples through 16 bits to sRGB, including gray plus alpha, mixed integer alpha precision, associated alpha and the checked constant 2x shifted alpha case. High-depth conversion emits full-range sRGB16 and straight alpha. Lossless ordinary JPEG XL encoding preserves explicitly retained matching GRAY/RGB ICC profiles for integer and Float32 samples. Equal expanded gray-alpha RGB channels fold back to native grayscale; unrelated RGB samples cannot use a GRAY profile. Explicit ordinary structured SDR conversion supports linear, gamma, BT.709, P3 and Rec. 2020 color through 16-bit integer precision, including mixed and associated alpha. Relative custom white points and primaries also convert to sRGB at 8- through 16-bit precision. Structured samples remain native by default. Ordinary static full-canvas Modular IEEE binary16/binary32 gray and RGB input emits grayf32, rgbf32 or rgbaf32 rows, retaining finite signed values, subnormals and highlights. Mixed integer or IEEE alpha can be preserved or straightened; gray alpha expands to RGB. Explicit pixel-format range conversion supports integer output. Float source color is preserved by default. Explicit colorOutput: srgb converts structured SDR binary16/binary32 gray and RGB to straight sRGB16, including integer or IEEE alpha, linear, gamma, BT.709, sRGB, P3, Rec. 2020 and relative custom chromaticities. Associated color is straightened before source samples are clipped to [0,1]; converted gamut values are clipped at the SDR output boundary. Float ICC conversion supports GRAY curves and RGB matrix/TRC, mAB, LUT8 and LUT16 A2B0 profiles. RGB legacy LUT XYZ conversion is independently qualified against LittleCMS. Structured PQ/HLG/linear HDR supports relative custom primaries; source-primary linear output retains highlights and tone-mapped output uses sRGB8. Nonrelative custom conversion and profiles without supported HDR transfer metadata remain unsupported. Explicit PQ/HLG or linear HDR output supports sRGB, Display P3 and Rec. 2020 primaries: linear-float retains source primaries and highlight headroom, while tone-map-srgb uses 203-nit reference white and source-gamut Reinhard mapping. Native Modular float composition precedes ICC conversion or HDR tone mapping. Lossless ordinary JPEG XL encoding accepts grayf32/rgbf32/rgbaf32, retains finite binary32 sample bits and associated alpha, and preserves matching embedded GRAY/RGB profiles through keepIcc. GRAY ICC plus alpha folds equal expanded RGB channels back into native grayscale when re-encoding. Other conversion profile families remain unsupported. Ordinary static full-canvas Modular CMYK uses integer color and black through 16 bits with a supported embedded mft2 A2B0 ICC profile. It emits straight sRGB8 or sRGB16 rows, including mixed integer/IEEE alpha, associated alpha and the checked constant 2x black/alpha grids. Selected composed CMYK frames use source-domain native planes before supported mft2 ICC conversion, including cropped layers, references and associated IEEE alpha. Animation requires an explicit displayed-frame index. Ordinary native Modular CMYK with a supported embedded mft2 A2B0 profile accepts unsigned C/M/Y/black through 31 bits or legal floating samples. It emits straight sRGB8/16 with mixed or associated alpha. Floating black is supported. Source CMYK preservation requires native extraction. Other CMYK profile families remain unsupported; constant 2x black/alpha grids retain their earlier independent rendered qualification. Other non-alpha extra channels and nonrelative custom-color conversion remain unsupported. Native extraction is separate from rendering; raw layers reconstruct patch and progressive dependencies; uncommon display layouts remain explicit errors. Stable static forward VarDCT encoding supports integer gray/RGB/RGBA, exact straight alpha with lossy replacement of fully transparent color samples, DCT8 with effort-5/7/9 Hornuss and rectangular half-block choices, local chroma-from-luma, adaptive quantization, and optional two-pass output. Ordinary grayf32/rgbf32/rgbaf32 output defaults to bit-exact lossless binary32 in a Level 10 container. Explicit lossy mode rounds color mantissas in Modular coding while preserving Float32 storage and exact alpha. This mode has no progressive passes and no perceptual quality equivalence claim. Float32 animation writing and selected HDR XYB VarDCT frame rendering are supported. HDR reference composition uses linear color before the output transfer curve. Forward integer VarDCT writing accepts HLG, relative custom chromaticities, associated alpha and nondefault intensity targets. Eligible regular effort-7/9 opaque standard-sRGB RGB8/RGBA8 photos with more than 2,048 visible colors can also select 32x32, 16x32 and 32x16 DCT at distance 2 or above when 4x4-block context fits and optional working storage is available. This photo policy has no pixel-count window. Other larger DCT and AFV choices and Gaborish remain unsupported by the forward writer. Residual-scaled edge-preserving restoration is available for opaque standard-sRGB gray/RGB at effort 5/7/9 and distance 2 or above when most blocks need filtering. Exact JPEG reconstruction accepts checked one- or three-component 8-bit Huffman baseline and progressive JPEGs, orientation absent or 1, and absent or independently checked sRGB profile signaling. Native re-encode inherits depths and luminance metadata; storage conversion retains luminance fields, while explicit HDR-to-SDR conversion replaces incompatible signaling. Display-window and LUT re-encode cannot inherit source color meaning. Explicit sessions support embedded previews and selective XYB VarDCT DC/pass output for 8- or 16-bit SDR RGB, 16-bit linear or PQ RGB, and straight or associated integer alpha through 16 bits in global or grouped native planes, including a 2x shifted alpha grid. Grouped alpha dependencies may read HF and later AC passes before an early color stage; global Squeeze requires every alpha group. Other dependencies use declared complete static fallbacks or strict rejection; unavailable native stages are errors. Forward lossy distance remains 0.25 through 25; quantized AC magnitudes above 4095 are explicit unsupported-operation errors. Ordinary XYB VarDCT binary16/binary32 and checked custom floating color metadata emits Float32 rows; floating alpha is preserved. Selective progressive float stages retain their declared static fallback. Slow effort 9 retains effort 7 tools and adds complete AC iteration, RGB strategy, luma-context, cone-frame and exhaustive advanced Modular DC alternatives, gated by effort rather than image area or channel count. Lossless effort 9 uses effort 7 search policy.

The pixel encoder retains full input and accounts for owned backing buffers before allocation through maxWorkingBytes, defaulting to maxDecodedBytes (1 GiB by default). Optional DCT32 and 16x32/32x16 photo selection uses bounded source tiles and transform scratch plus staged block maps, precision and compact DC arrays. It adds no full source-sized XYB or AC cache. All optional storage is admitted before changing the original geometry; allocation-limit failure keeps the preceding transform path and cancellation releases optional state. It adds encoding work. It includes candidates, entropy state, writer growth and sections. Optional effort-7 denser prediction training retains the previous complete group and uses up to 262,144 deterministic positions per plane, with the original 256-leaf and depth-16 bounds. Group-local training and entropy scratch count against maxWorkingBytes; ties or optional allocation-limit failure keep the previous complete stream. This adds encoding work without another source-sized input bitmap. Optional effort-7 per-histogram layout search reuses the learned tree and retains one additional bounded group of packed residuals plus small histogram scratch; working or output allocation-limit failures retain the prior stream. Optional effort-7 reversible color search reserves at most 394,240 bytes of sample scratch and one additional bounded group of planar samples and entropy state. It retains the ordinary stream when optional search exceeds working storage. Forward VarDCT retains compact DC/control planes and reuses group-local AC storage; progressive output reuses quantized candidates across passes; caller input, sink storage and JavaScript object overhead are separate. maxOutputBytes bounds encoded output including metadata, up to 128 MiB. Explicit session DC preview retains compact LF state and restoration bands without full-resolution color working planes; early alpha retains its complete native plane. Grouped-alpha DC plans report full native alpha storage plus DC restoration; locating AC alpha retains one temporary color coefficient group and the required HF metadata. Spatial alpha transforms require all alpha groups even for a color viewport. Pass and final VarDCT stages retain full output; common 8-bit sRGB uses bounded restoration bands. High-depth, float and compositing paths retain full working planes. JPEG-derived decode uses compact coefficients and bounded component rows. Exact grayscale transcode temporarily allocates one zero coefficient plane for two unused VarDCT channels and accounts for it in managed peak bytes and maxDecodedBytes. Grouped Modular palettes without spatial prediction retain global tables and intersecting bands. Global Squeeze, spatial Palette prediction and shifted prefix layouts use compact full-frame channel planes with explicit planner fallback reporting. Large VarDCT scratch and dequantization tables are allocated only for strategies present; preflight reserves geometry-compatible large transforms. ICC and metadata have separate limits. Ordinary ICC and high-depth structured SDR conversion modify emitted rows without an additional frame; conservative color-table storage is reserved from maxDecodedBytes before native working allocation and included in planner estimates. Sequence decoding retains a full canvas, the current layer and up to four references, with cumulative replay-work limits and no decoded sequence cache. Native planar writing emits bounded 1024-pixel AC group sections, puts shift-3 planes in DC group sections, and preserves encoded sample grids. The caller retains input planes and the writer retains compressed sections until output assembly. Independent unshifted native Modular groups decode intersecting crop bands without retaining full source channel planes. Global transforms, shifted extras, dependent groups and composition retain their declared native-plane or canvas/reference fallbacks. Output rows and color tables are reserved before decoding. Native integer/float encoding stages planar samples and retains compressed sections and output assembly within configured budgets. Normalized and upsampled selected extras, output rows and CMYK ICC tables are reserved before native allocation. Structured float SDR conversion reserves 4 KiB for matrix construction and scratch; it evaluates float transfer functions directly without image-sized lookup tables. There is no additional full rendered output bitmap. Float ICC tables and HDR scratch are reserved before native allocation. Float-preserving ordinary encoding stages planar binary32 bits once and retains native compressed sections and assembled output; it enforces maxWorkingBytes and maxOutputBytes before consuming rows. Composed native float and CMYK decoding uses the sequence canvas/reference budget and cumulative replay limit, then converts output rows without a second full rendered bitmap. Optional regular effort-7 RGBA8 artwork search through 1,048,576 pixels retains full Modular candidate planes and compressed sections, plus a full RGBA8 normalization copy for nonzero fully transparent colors or eligible opaque palette-edge quantization. The latter uses at most 2,048 colors and three 4,096-slot typed lookup arrays, all within maxWorkingBytes. The previous Modular winner is retained while the optional quantized candidate runs. Classifier, normalization and candidate storage share one maxWorkingBytes scope; only winning output escapes, and optional storage-limit failure retains the previous complete stream. This search adds encoding work. Optional effort-7 learned palette search retains the complete previous group candidate while evaluating bounded group-local training and entropy scratch. Only smaller output escapes; losing candidates are released before later searches and working-limit failures keep the previous complete stream. The same bounded search evaluates the three existing reordered RGBA8 palettes at effort 7, through 1,048,576 pixels with no delta colors. Each extra search keeps all prior ordered variants as a complete size floor and retains them on optional working-limit failure. It adds group-local training and entropy scratch and encoding work.

Dated comparison evidence and limitations

FAQ

What is JPEG XL?

JPEG XL is an image format for lossless and lossy images. It also defines a way to carry JPEG coefficients and reconstruction data.

Can JavaScript decode JXL?

Yes. PureJsImage decodes its documented JPEG XL subset in first-party TypeScript in Node.js and modern browsers.

What does pixel-lossless mean?

Pixel-lossless output preserves the supported decoded sample values. It does not promise the same source file bytes or metadata layout.

Can PureJsImage reconstruct the original JPEG byte for byte?

Yes, for the documented eligible JPEG subset. Exact mode rebuilds the JPEG from parsed coefficients and reconstruction data, then compares every byte before it succeeds. The checked corpus also reconstructs each output through pinned djxl.

Why can an exact JXL be larger than its source JPEG?

Container and entropy-model overhead can still make small JPEGs grow. Select the size requirement to reject those results.

Which JPEG files are currently eligible?

Eligible files use the checked grayscale and three-component 8-bit Huffman baseline or progressive subset, supported marker structure, orientation absent or 1, and no ICC or the checked sRGB ICC.

Are Exif orientation and non-sRGB ICC supported by exact transcode?

Non-default Exif orientation and non-sRGB or malformed ICC profiles are rejected because the current JPEG XL codestream writer cannot represent those display semantics correctly.

Does PureJsImage have a general lossy JPEG XL encoder?

Forward VarDCT encoding is available through explicit lossy mode. The default pixel pipeline stays lossless. See the capability summary above for the qualified scope.

Does this work in Node.js and browsers?

Yes. The shared codec runs in both. This page performs local work in a browser worker, and Node.js uses the same portable implementation through its platform adapters.