diff --git a/src/ImageSharp/Formats/Heif/Av1/Pipeline/Av1FrameDecoder.cs b/src/ImageSharp/Formats/Heif/Av1/Pipeline/Av1FrameDecoder.cs
index 365cd46a54..77c69df3f7 100644
--- a/src/ImageSharp/Formats/Heif/Av1/Pipeline/Av1FrameDecoder.cs
+++ b/src/ImageSharp/Formats/Heif/Av1/Pipeline/Av1FrameDecoder.cs
@@ -95,6 +95,9 @@ internal class Av1FrameDecoder
}
}
+ ///
+ /// SVT: svt_aom_decode_super_block
+ ///
private void DecodeSuperblock(Point modeInfoPosition, Av1SuperblockInfo superblockInfo, Av1TileInfo tileInfo)
{
this.blockDecoder.UpdateSuperblock(superblockInfo);
@@ -102,6 +105,9 @@ internal class Av1FrameDecoder
this.DecodePartition(modeInfoPosition, superblockInfo, tileInfo);
}
+ ///
+ /// SVT: decode_partition
+ ///
private void DecodePartition(Point modeInfoPosition, Av1SuperblockInfo superblockInfo, Av1TileInfo tileInfo)
{
Av1BlockModeInfo modeInfo = superblockInfo.GetModeInfo(modeInfoPosition);
diff --git a/src/ImageSharp/Formats/Heif/Av1/Pipeline/Quantification/Av1InverseQuantizer.cs b/src/ImageSharp/Formats/Heif/Av1/Pipeline/Quantification/Av1InverseQuantizer.cs
index e06e9ba0f6..4cb7c1cc77 100644
--- a/src/ImageSharp/Formats/Heif/Av1/Pipeline/Quantification/Av1InverseQuantizer.cs
+++ b/src/ImageSharp/Formats/Heif/Av1/Pipeline/Quantification/Av1InverseQuantizer.cs
@@ -78,6 +78,9 @@ internal class Av1InverseQuantizer
}
}
+ ///
+ /// SVT: svt_aom_inverse_quantize
+ ///
public int InverseQuantize(Av1BlockModeInfo mode, Span level, Span qCoefficients, Av1TransformType transformType, Av1TransformSize transformSize, Av1Plane plane)
{
Guard.NotNull(this.deQuantsDeltaQ);
@@ -135,12 +138,15 @@ internal class Av1InverseQuantizer
return coefficientCount;
}
+ ///
+ /// SVT: get_dqv
+ ///
private static int GetDeQuantizedValue(short dequant, int coefficientIndex, ref int iqMatrix)
{
+ const int bias = 1 << (Av1ScanOrderConstants.QuantizationMatrixLevelBitCount - 1);
int deQuantifiedValue = dequant;
- // TODO: Check order of operators
- deQuantifiedValue = ((Unsafe.Add(ref iqMatrix, coefficientIndex) * deQuantifiedValue) + (1 << (Av1ScanOrderConstants.QuantizationMatrixLevelBitCount - 1))) >> Av1ScanOrderConstants.QuantizationMatrixLevelBitCount;
+ deQuantifiedValue = ((Unsafe.Add(ref iqMatrix, coefficientIndex) * deQuantifiedValue) + bias) >> Av1ScanOrderConstants.QuantizationMatrixLevelBitCount;
return deQuantifiedValue;
}
}
diff --git a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1BlockDecoder.cs b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1BlockDecoder.cs
index 9e76b20f4f..fc10f30994 100644
--- a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1BlockDecoder.cs
+++ b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1BlockDecoder.cs
@@ -183,8 +183,6 @@ internal class Av1BlockDecoder
quantizationCoefficients,
transformBlockReconstructionBuffer,
reconstructionStride,
- transformBlockReconstructionBuffer,
- reconstructionStride,
transformSize,
transformType,
plane,
diff --git a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformer.cs b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformer.cs
index ed05dc9e6d..6b36f191fc 100644
--- a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformer.cs
+++ b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformer.cs
@@ -8,7 +8,7 @@ internal class Av1InverseTransformer
///
/// SVT: svt_aom_inv_transform_recon8bit
///
- public static void Reconstruct8Bit(Span coefficientsBuffer, Span reconstructionBufferRead, int reconstructionReadStride, Span reconstructionBufferWrite, int reconstructionWriteStride, Av1TransformSize transformSize, Av1TransformType transformType, int plane, int numberOfCoefficients, bool isLossless)
+ public static void Reconstruct8Bit(Span coefficientsBuffer, Span reconstructionBuffer, int reconstructionStride, Av1TransformSize transformSize, Av1TransformType transformType, int plane, int numberOfCoefficients, bool isLossless)
{
Av1TransformFunctionParameters transformFunctionParameters = new()
{
@@ -20,33 +20,31 @@ internal class Av1InverseTransformer
Is16BitPipeline = false
};
- if (reconstructionBufferRead != reconstructionBufferWrite)
- {
- /* When output pointers to read and write are differents,
- * then kernel copy also all buffer from read to write,
- * and cannot be limited by End Of Buffer calculations. */
- transformFunctionParameters.EndOfBuffer = GetMaxEndOfBuffer(transformSize);
- }
-
Av1InverseTransformerFactory.InverseTransformAdd(
- coefficientsBuffer, reconstructionBufferRead, reconstructionReadStride, reconstructionBufferWrite, reconstructionWriteStride, transformFunctionParameters);
+ coefficientsBuffer, reconstructionBuffer, reconstructionStride, reconstructionBuffer, reconstructionStride, transformFunctionParameters);
}
///
- /// SVT: av1_get_max_eob
+ /// SVT: svt_aom_inv_transform_recon8bit
///
- private static int GetMaxEndOfBuffer(Av1TransformSize transformSize)
+ public static void Reconstruct8Bit(Span coefficientsBuffer, Span reconstructionBufferRead, int reconstructionReadStride, Span reconstructionBufferWrite, int reconstructionWriteStride, Av1TransformSize transformSize, Av1TransformType transformType, int plane, int numberOfCoefficients, bool isLossless)
{
- if (transformSize is Av1TransformSize.Size64x64 or Av1TransformSize.Size64x32 or Av1TransformSize.Size32x64)
+ Av1TransformFunctionParameters transformFunctionParameters = new()
{
- return 1024;
- }
+ TransformType = transformType,
+ TransformSize = transformSize,
+ EndOfBuffer = numberOfCoefficients,
+ IsLossless = isLossless,
+ BitDepth = 8,
+ Is16BitPipeline = false
+ };
- if (transformSize is Av1TransformSize.Size16x64 or Av1TransformSize.Size64x16)
- {
- return 512;
- }
+ /* When output pointers to read and write are differents,
+ * then kernel copy also all buffer from read to write,
+ * and cannot be limited by End Of Buffer calculations. */
+ transformFunctionParameters.EndOfBuffer = Av1InverseTransformMath.GetMaxEndOfBuffer(transformSize);
- return transformSize.GetSize2d();
+ Av1InverseTransformerFactory.InverseTransformAdd(
+ coefficientsBuffer, reconstructionBufferRead, reconstructionReadStride, reconstructionBufferWrite, reconstructionWriteStride, transformFunctionParameters);
}
}
diff --git a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformerFactory.cs b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformerFactory.cs
index 474364df8c..526ff5250e 100644
--- a/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformerFactory.cs
+++ b/src/ImageSharp/Formats/Heif/Av1/Transform/Av1InverseTransformerFactory.cs
@@ -7,6 +7,9 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.Transform;
internal static class Av1InverseTransformerFactory
{
+ ///
+ /// SVT: svt_av1_inv_txfm_add
+ ///
public static unsafe void InverseTransformAdd(Span coefficients, Span readBuffer, int readStride, Span writeBuffer, int writeStride, Av1TransformFunctionParameters transformFunctionParameters)
{
Guard.MustBeLessThanOrEqualTo(transformFunctionParameters.BitDepth, 8, nameof(transformFunctionParameters));