Repository navigation
Add the JPEG XL encoder effort levels and make JPEG XL faster than libjxl - #3295
Open
JimBobSquarePants wants to merge 11 commits into
Open
JimBobSquarePants wants to merge 11 commits into
JimBobSquarePants wants to merge 11 commits into
Conversation
JxlEncoder.Effort selects the libjxl effort from 1 to 10, with the libjxl default of 7. Each stream type uses the libjxl entropy choices of the effort: run, greedy and optimal copies, the fast and best clustering, the hybrid integer search, and ANS or prefix codes. The fast lossless mode runs only at effort 1. The WebP lossless LZ77 search, optimal parse, pair-merge clustering and entropy estimates move to Compression as shared owners for WebP and JPEG XL.
- Write every non fast lossless modular frame with one global tree and one shared entropy code, with libjxl group sizes, palettes, RCT, squeeze and weighted predictor modes by effort. - Add the tree learner, tokenizer, properties, VarDCT search tools and the Butteraugli comparator. - Share one owner per operation: JxlSignedPacking, JxlSymmetricConvolution (Mirror, FilterRow, Separable5), JxlQuantization.DequantizeAc, JxlHybridUintSearch.AddPartialCounts, Numerics.Log2Ceiling and the TensorPrimitives_ Log2 and Exp2 operators. - Raise a lossy distance below 0.05 to 0.05 once in JxlEncoderCore.
- XYB forward conversion: the absorbance matrix on linear sRGB in the libjxl order. - Initial quant field: the 1x1 mask blur taps for the knight and corner positions. - Chroma from luma: the outlier mask of the Newton solver also masks the terms at x + eps and x - eps. - AC strategy search at effort 5 and up with the frame matrices. - Restoration filter: write the all-default form only for Gaborish with two EPF iterations. - Dynamic EPF sharpness at effort 6 and up. The encoder reconstructs the frame with the decoder DC dequantization, DC smoothing, AC dequantization, inverse transforms and restoration, then selects the sharpness of each block from the masked block errors. - The libjxl reference encoder in the tests uses the effort of each case.
- VarDCT (effort 7 and up): find text-like patches, or dots from distance 3, before the initial quant field. Write the lossy XYB patch frame and subtract the decoded reference samples. - Lossless modular (effort 5 and up, at most 16 bits): search the float color planes, write a lossless patch frame, and subtract the patches without a clamp. - Follow the libjxl streaming decision: streamed frames have no patch search and no butteraugli search. - Tests compare the frame list with libjxl for patch images.
- Count the coefficient order zeros through the libjxl group read cursor when blocks are sampled, with one sampler for all passes. - Compute the EPF block errors from per-row terms and per-block running sums, with the libjxl summation order and no int overflow for wide frames. - Return the linear planes of the butteraugli search to the pool after the search. - Order equal patch candidates by position, and apply patches through one method. - Return every owned buffer when an encoder allocation fails: patch candidates, tree learner samples, palette channels, RCT candidates, entropy streams and codes, copy matches, squeeze channels, AC passes and the butteraugli levels. - Add a test that fails each encoder allocation at effort 9 in turn and checks that no buffer stays live. - Use real-size images for the libjxl comparisons.
- Encode a large VarDCT frame by DC group, as libjxl does at efforts 1-7 and 8-9 at low distances: each DC group gets its own patch for the invisible smoothing, the initial quant field and inverse Gaborish, and its own histogram set. lz77 runs only with one DC group. - Resample the frame by two at distance 10 and up: a quarter of the distance plus 0.25, the sharper and iterative downsamplers, box-averaged extra channels and upsampling 2 in the frame header. - Reconstruct the EPF sharpness candidates of a resampled frame with the patches, then the upsampling, as the decoder does. - Make Clear the JPEG XL default. Lossless zeroes the color of transparent pixels. Lossy smooths it from the visible neighbors. Encoders can now select their own default through a protected constructor. - Write EXIF and XMP Brotli boxes without a payload copy. - Keep the earlier nearest cluster when histograms tie, and add a Vector512 path to the histogram divergence. - Use one xorshift128+ owner for the encoder and the noise generator, and run the 8x8 DCT through the block operator pattern. - Benchmark encoding at every effort from 1 through 10. - Test streaming with more than 8 DC groups, distance 10 at efforts 7 and 10, and the Preserve mode in the source-fidelity tests.
- Compare each frame with the frame that the decoder draws it on. The disposal mode of each frame selects that reference frame. - Add the Source, Mask and Over blend modes. GIF uses Mask. PNG, WebP and JPEG XL use the blend mode of the frame. - With Over, unblend partly transparent pixels. Source-over blending cannot lower alpha, so such a frame uses Source and writes Source. - Separate the canvas color from the replacement color. - Write RestoreToBackground frames at full size, because the formats clear only the frame area. - Use Source for PNG color types without alpha. - Fix the GIF decoder: RestoreToPrevious after RestoreToBackground now restores the cleared canvas. - Add APNG, WebP and GIF round-trip tests.
… XL encoder - Remove the Source fallback from animation deduplication. Each encoder writes the blend mode of the frame metadata. - Remove the PNG color-type check on the Over blend. - Scale the PNG tRNS gray key on read and write like the pixel samples, and mask it to the bit depth on read. - Replace transparent and deduplicated PNG pixels with the metadata transparent color. ReplaceTransparentPixels takes an optional replacement color. - Write the JPEG XL Over blend for pixel types without alpha. - Round-trip the JPEG XL frame blend and disposal modes. - Continue the JPEG XL encoder effort work: LF frames, modular XYB, squeeze, coefficient orders and the VarDCT encoder.
…math - Make the JPEG XL encoder and decoder faster than libjxl on the EncodeJxl and DecodeJxl benchmark rows. - Update the shared companding, power and exponential helpers, and their JPEG XL, ICC and working-space callers. - Add the sRGB companding comparison benchmark. - Promote the BokehBlur and Resize reference images for the changed companding output.
…indings The LosslessFloat lossy encoder cases compare against float EXR reference files. The sRGB companding range checks and an animation unblend condition are simpler, with the same results.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the libjxl effort levels to the JPEG XL encoder. Encode and decode are faster than libjxl in each benchmark row. It also fixes animation deduplication and frame blending across the animated encoders.
JPEG XL
JxlEncoder.Effortselects the libjxl effort from 1 to 10. The default is 7, as in libjxl.Clearis the JPEG XL default for transparent pixels. Encoders can select their own default through a protected constructor.Animation and other codecs
Compressionas shared owners for WebP and JPEG XL.Shared math
Benchmarks
Ratio to libjxl. A value below 1.00 means ImageSharp is faster.
The BenchmarkDotNet tables are in the results blocks of
EncodeJxl.csandDecodeJxl.cs.