The DCTDecode encoder: a managed baseline JPEG encoder for 8-bit gray, RGB and CMYK image samples, with a quality setting
and chroma subsampling chosen when it is constructed. Encoding is lossy: DctDecodeFilter decodes the output to
samples close to the input, not equal to it.
public sealed class DctEncoder : IStreamEncoder
ISO 32000-2 §7.4.8 (DCTDecode, Table 13 ColorTransform); ITU-T T.81 (ISO/IEC 10918-1) baseline sequential process:
Annex A (level shift, FDCT, quantization), Annex B (interchange format), Annex C and §F.1.2 (Huffman encoding), Annex K
(the typical quantization tables, scaled by the IJG quality formula, and the typical Huffman tables); Adobe Technical Note #5116
(APP14). Every operation is integer arithmetic ported from libjpeg (the islow FDCT, the YCbCr tables, libjpeg's edge padding and
downsampling), so the output equals libjpeg-turbo's cjpeg -dct int (or TurboJPEG with the same settings) byte for byte,
and the same input encodes to the same bytes on every platform.
The stream dictionary describes the samples (§8.9.5, Table 87): Width and Height (1 to 65535), and the data holds
width x height pixels of 1, 3 or 4 interleaved 8-bit components, top to bottom with no row padding. BitsPerComponent, when
present, must be 8; a device ColorSpace name, when present, must have that many components; image masks are refused.
The component count decides the layout, and the ColorTransform parameter of the stream's DecodeParms
(Table 13) decides the transform the decoder undoes, so the encoder writes data that decodes with those same parameters:
The output is one interleaved SOF0 scan, Huffman-coded with the Annex K tables, without restart intervals. The CompressionLevel is ignored: Quality trades size for fidelity. At quality 90 the test pictures decode through DctDecodeFilter above 38 dB PSNR in every layout (40 dB and more for RGB at any subsampling, gray and untransformed CMYK).
Thread safety: immutable and stateless; one instance serves every thread. An encode allocates nothing on the managed heap beyond pooled buffers for one row of MCUs, never per block or row.
kind:method, kind:property, kind:ctor. Press Esc to clear.DctEncoder()Initializes a new instance of the DctEncoder class at quality 75 with 4:2:0 chroma subsampling, libjpeg's defaults.DctEncoder(Int32, DctChromaSubsampling)Initializes a new instance of the DctEncoder class.DctEncoder(Int32)Initializes a new instance of the DctEncoder class at a quality with 4:2:0 chroma subsampling.DefaultQualityThe quality the parameterless constructor uses: 75, libjpeg's default.ChromaSubsamplingGets how much chrominance is subsampled when colour is transformed.NameGets the name of the filter that decodes what this encoder writes, such as FlateDecode: the key it is registered under.QualityGets the quality, 1 to 100.Encode(ReadOnlySpan<Byte>, IBufferWriter<Byte>, StreamEncoderContext)Encodes data and writes the result to output.