JpegXlEncoder Class
Immutable JPEG XL encoder settings. The output is lossless by default (Modular coding): every pixel format is stored as it is, 16-bit samples and the color of fully transparent pixels included. JpegXlEncoder.Compression selects the lossy coding (VarDCT), controlled by JpegXlEncoder.Quality; its alpha channel stays lossless. An image is written as a bare codestream, or in the JPEG XL container when it has EXIF or XMP metadata or when it needs level 10 of the format (16-bit samples, more than 262,144 pixels per side or 268,435,456 pixels, an ICC profile above 4 MiB).
public sealed class JpegXlEncoder : ImageEncoderRemarks
Animations are written as full frames that replace the image; durations are stored in milliseconds (JpegXlEncoder.DurationRounding). A frame of an animation must have a duration: JPEG XL defines a frame without duration as a layer of the next frame, not as an image that is shown.
The ICC profile is stored in the codestream, byte for byte; without a profile, the linear transfer function and a CICP color description that the format can enumerate are stored as its color encoding. The orientation is stored in the image header. Lossy output stores the samples in the XYB color space, which a decoder converts back to the color encoding of the image: it requires an enumerated encoding or an sRGB profile, and throws UnsupportedImageFeatureException for another profile and for the PQ and HLG transfer functions.
A frame of at least 65,536 pixels is coded by groups of 256x256 pixels, which up to ImageConfiguration.MaxDegreeOfParallelism workers of the configuration of the image encode at the same time; the output does not depend on the number of workers.
A JPEG file is recompressed without loss by JpegXlTranscoder, not by this encoder, which stores pixels.
- Inheritance
ImageEncoderJpegXlEncoder
Constructors
| Name | Description |
|---|---|
| JpegXlEncoder() |
JpegXlEncoder()
JpegXlEncoder.cspublic JpegXlEncoder()No documentation is available.
Properties
| Name | Description |
|---|---|
| Compression | Gets how every frame is coded. Defaults to JpegXlCompression.Lossless. |
| DurationRounding | Gets how frame durations are converted to JPEG XL ticks (milliseconds, 32-bit values). Defaults to FrameDurationRounding.RoundToNearest. |
| Effort | Gets the compression effort, from 0 (fastest, largest output) to 9 (slowest, smallest output). Defaults to 5. The effort never changes the decoded pixels of lossless output; for lossy output it changes the decisions of the encoder, not the file size that JpegXlEncoder.Quality aims at. |
| Format | Gets the format produced by this encoder. |
| Progressive | Gets a value indicating whether the frames are written so that a reader of a part of the file can show the image at a lower resolution, then refine it. Defaults to false. |
| Quality | Gets the quality of JpegXlCompression.Lossy output, from 0 (smallest) to 100 (best). Defaults to 75. Ignored by lossless output. |
Compression
JpegXlEncoder.csGets how every frame is coded. Defaults to JpegXlCompression.Lossless.
public JpegXlCompression Compression { get; init; }DurationRounding
JpegXlEncoder.csGets how frame durations are converted to JPEG XL ticks (milliseconds, 32-bit values). Defaults to FrameDurationRounding.RoundToNearest.
public FrameDurationRounding DurationRounding { get; init; }Property value
Exceptions
ArgumentOutOfRangeException- The value is not a defined
FrameDurationRounding.
Effort
JpegXlEncoder.csGets the compression effort, from 0 (fastest, largest output) to 9 (slowest, smallest output). Defaults to 5. The effort never changes the decoded pixels of lossless output; for lossy output it changes the decisions of the encoder, not the file size that JpegXlEncoder.Quality aims at.
public int Effort { get; init; }Property value
Exceptions
ArgumentOutOfRangeException- The value is not between 0 and 9.
Remarks
Lossless output: efforts 0 to 2 code each group with a fixed color transform and a fixed predictor. From 3 on, a tree of contexts is learned for the whole frame from samples of its rows, each context with its own predictor, and the frame is coded with a palette of its colors (screenshots, graphics) or with a reversible color transform; from 4 on, each cluster of contexts codes its values in its own way; from 5 on, repeated runs of values are copied (LZ77) when a trial on part of the frame finds that copies make it smaller (screenshots, graphics; rarely photographs). The higher efforts learn from more samples, properties, predictors (the weighted predictor from 7 on, which roughly doubles the time) and contexts, and search further for copies. At every effort, the samples are written with prefix codes or with ANS, whichever is smaller. Lossy output: efforts 0 to 2 only use the 8x8 transform and quantize every block alike; from 3 on, each block has its own quantization steps (see JpegXlEncoder.Quality), each area has the 8x8 or the 16x16 transform, whichever costs less, each tile has its own factors of the chroma from luma prediction, the predictor of the alpha channel is searched, and the low-frequency image and the description of the blocks are coded with trees learned from their values; from 6 on, the contexts of the coefficients have more distributions; from 7 on, the 16x8 and 8x16 transforms are tried and the weighted predictor codes the low-frequency image where it suits it, and from 8 on the transforms of up to 64x64 samples.
Format
JpegXlEncoder.csProgressive
JpegXlEncoder.csGets a value indicating whether the frames are written so that a reader of a part of the file can show the image at a lower resolution, then refine it. Defaults to false.
public bool Progressive { get; init; }Property value
Remarks
Lossy output is written in three passes after the image at one eighth of its resolution; lossless output is squeezed, each resolution in the sections of its pass. The decoded pixels are those of a file that is not progressive; the file is larger (a few percent for lossy output, more for lossless output). ImageReader<TPixel>.ReadFrameRefinementInto reads such a file stage by stage.
Quality
JpegXlEncoder.csGets the quality of JpegXlCompression.Lossy output, from 0 (smallest) to 100 (best). Defaults to 75. Ignored by lossless output.
public int Quality { get; init; }Property value
Exceptions
ArgumentOutOfRangeException- The value is not between 0 and 100.
Remarks
The quality selects the quantization steps: 90 is a quality at which the difference with the original is barely visible at a normal viewing distance, and 100 is the finest quantization the encoder uses, still lossy. From the JpegXlEncoder.Effort 3 and above the quality 80, the steps of a block also follow its content in part: they are finer where the image is flat or next to an edge, where an error shows, and coarser in texture, which hides it. Below the quality 94, the decoder removes the ringing of coarse steps with the edge-preserving filter of the format, more strongly as the quality goes down.