Support for JPEG XL (JXL) images#3153
Conversation
Implementation of ac_strategy.h and ac_strategy.c
For now JxlMemoryManager will be a wrapper around MemoryPool<T>.
Implementation of image.h and image.c; AC strategy implementation was slightly adjusted to reduce errors.
This is an implementation of field_encodings.h. Note that I avoided implementing EnumValid() and Values() functions, as we have dedicated methods in .NET to do exactly that (Enum.IsDefined, Enum.GetValues)
Implementation of spline.h
Implemented ANS constants
|
While I'm working on this, I'd like to note something important. Libjxl is licensed under the BSD 3-Clause license, and since I'm using libjxl code as reference, that means the license must be included. I'm not really sure what would be the proper way to include the license. I might place the LICENSE.txt file in the Jxl folder or add a README linking to the libjxl repo. |
See ans_common.h
It is too large for a struct.
See ans_common.h
Add JxlAnsEntry and JxlAnsSymbol. See ans_common.h. These correspond to the Entry and Symbol structures within AliasTable.
Currently, there's a VarLenUint8/VarLenUint16 as well as histogram parsing implementation. I will additionally have to implement parsing of ANS codes, uint config and LZ77 parameters.
| nonZeroesLeft = (nonZeroesLeft + coveredBlocks - 1) >> log2CoveredBlocks; | ||
| k >>= log2CoveredBlocks; | ||
|
|
||
| Debug.Assert(k > 0); |
There was a problem hiding this comment.
Just to note. We don't use Debug.Assert in this codebase. We have explicit DebugGuard APIs instead
There was a problem hiding this comment.
In some cases DebugGuard feels too limiting.
For example, in the following condition:
JXL_DASSERT(!extension_states_.IsBegun() || extension_states_.IsEnded());I'd have to write:
DebugGuard.IsTrue(!this.extensionStates.IsBegun || this.extensionStates.IsEnded);where it expects a parameter name, which doesn't fit because 1. it's not a parameter (but a property) and 2. there are multiple properties involved in the assertion.
Any ideas?
There was a problem hiding this comment.
Sorry I didn't get it right - the second parameter is a message, not the parameter name.
Would DebugGuard.IsTrue(false, "message") be considered a good replacement for Debug.Fail?
|
Thanks @winscripter I really appreciate you attempting this.
On a performance note. I think it would be best if you use these immediately as that can affect design. Any new code should also reuse utility components already available in the library where possible. In addition, I normally document internal type as well as public types. This stuff is tough and every little helps. |
|
@JimBobSquarePants The examples I mentioned were the aggressive performance optimizations that I'd apply when the implementation can encode and decode images properly. I'd prefer not to apply them just yet, because in that case, the optimizations may introduce bugs that would later be difficult to diagnose while the implementation isn't fully complete. I do consider applying light optimizations right now, e.g. using spans, pooling arrays with I'd consider documenting the internal stuff, but it might be easier said than done, because not all things in libjxl source are documented. |
See convolve.h
See convolve.h
See dct_scales.h and dct_scales.cc
See pack_signed.h
See loop_filter.h, loop_filter.cc, epf.h and epf.cc
See fields.h and fields.cc
See frame_header.h
Prerequisites
Description
This is a work-in-progress PR whose goal is to introduce decoding and encoding of JPEG XL (*.jxl) images.
Reference software
I use libjxl as reference. See https://github.com/libjxl/libjxl.
Performance
I will begin by applying light optimizations as I implement parts of the JPEG XL codec. Once the codec seems complete enough to handle decoding and encoding of JPEG XL images, I will apply heavier optimizations. Examples include but are not limited to stack allocation, array pooling, and SIMD.
Other components
The JPEG XL codec, additionally, uses the LZ77 and Brotli compression codec. I will also have to implement those eventually.
Implementations
The JPEG XL codec lives under
src/ImageSharp/Formats/Jxl.Brotli and LZ77 implementations will live under
src/ImageSharp/Compression.Testing
I will start adding tests whenever the codec is complete enough to handle decoding of JPEG XL images.
Additionally, JPEG XL reference software, libjxl, contains its own tests too, which I might also implement without modification.