From 874ec5bcfb67d5a214b839481f5f03704e6c01b5 Mon Sep 17 00:00:00 2001 From: winscripter <142818255+winscripter@users.noreply.github.com> Date: Wed, 26 Aug 2026 00:46:03 +0400 Subject: [PATCH] Complete quantizer encoding --- .../Jxl/Processing/JxlQuantizerEncoding.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlQuantizerEncoding.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlQuantizerEncoding.cs index a50b7ad25..fead5354c 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/JxlQuantizerEncoding.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/JxlQuantizerEncoding.cs @@ -10,6 +10,34 @@ namespace SixLabors.ImageSharp.Formats.Jxl.Processing; /// internal sealed class JxlQuantizerEncoding { + public JxlQuantizerEncoding() + { + } + + public JxlQuantizerEncoding(JxlQuantizerEncoding other) + { + // Simple shallow copy + this.AfvWeights = other.AfvWeights; + this.Dct2Weights = other.Dct2Weights; + this.Dct4Multipliers = other.Dct4Multipliers; + this.Dct4x8Multipliers = other.Dct4x8Multipliers; + this.DctParameters = other.DctParameters; + this.DctParametersAfv4x4 = other.DctParametersAfv4x4; + this.IdWeights = other.IdWeights; + this.Mode = other.Mode; + this.Predefined = other.Predefined; + this.QuantizationTable = other.QuantizationTable; + this.QuantizationTableDenominator = other.QuantizationTableDenominator; + + if (other.QuantizationTable is not null) + { + // Do a deep clone for the quantization table. + // Using AsSpan() should be way faster than a normal array copy... + this.QuantizationTable = GC.AllocateUninitializedArray(other.QuantizationTable.Length); + other.QuantizationTable.AsSpan().CopyTo(this.QuantizationTable); + } + } + /// /// Gets or sets the kind of transform used for this quantizer encoding. /// @@ -177,4 +205,23 @@ internal sealed class JxlQuantizerEncoding AfvWeights = weights, DctParametersAfv4x4 = params4x4 }; + + /// + /// Creates a new raw quantizer encoding. + /// + /// The quantization table for raw quantization. + /// The shift value for the denominator. + /// A raw quantizer encoding. + public static JxlQuantizerEncoding Raw(Span quantizationTable, int shift = 0) + { + JxlQuantizerEncoding encoding = new() + { + Mode = JxlQuantMode.Raw, + QuantizationTableDenominator = (1 << shift) * (1f / (8 * 255)), + QuantizationTable = GC.AllocateUninitializedArray(quantizationTable.Length) + }; + + quantizationTable.CopyTo(encoding.QuantizationTable); + return encoding; + } }