Skip to content

Commit

Permalink
Some more forward transform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ynse01 committed Oct 11, 2024
1 parent c19d687 commit 47c2416
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 25 deletions.
21 changes: 14 additions & 7 deletions src/ImageSharp/Formats/Heif/Av1/Transform/Av1ForwardTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ internal static void Transform2d(Span<short> input, Span<int> coefficients, uint
Av1Transform2dFlipConfiguration config = new(transformType, transformSize);
IAv1Forward1dTransformer? columnTransformer = GetTransformer(config.TransformFunctionTypeColumn);
IAv1Forward1dTransformer? rowTransformer = GetTransformer(config.TransformFunctionTypeRow);
if (columnTransformer != null && rowTransformer != null)
Transform2d(columnTransformer, rowTransformer, input, coefficients, stride, config, bitDepth);
}

internal static void Transform2d<TColumn, TRow>(TColumn? transformFunctionColumn, TRow? transformFunctionRow, Span<short> input, Span<int> coefficients, uint stride, Av1Transform2dFlipConfiguration config, int bitDepth)
where TColumn : IAv1Forward1dTransformer
where TRow : IAv1Forward1dTransformer
{
if (transformFunctionColumn != null && transformFunctionRow != null)
{
Transform2dCore(columnTransformer, rowTransformer, input, stride, coefficients, config, TemporaryCoefficientsBuffer, bitDepth);
Transform2dCore(transformFunctionColumn, transformFunctionRow, input, stride, coefficients, config, TemporaryCoefficientsBuffer, bitDepth);
}
else
{
Expand Down Expand Up @@ -142,20 +149,20 @@ private static void Transform2dCore<TColumn, TRow>(TColumn transformFunctionColu
}

// Rows
for (r = 0; r < transformRowCount; ++r)
for (r = 0; r < transformCount; r += transformColumnCount)
{
transformFunctionRow.Transform(
buf.Slice(r * transformColumnCount, transformColumnCount),
output.Slice(r * transformColumnCount, transformColumnCount),
buf.Slice(r, transformColumnCount),
output.Slice(r, transformColumnCount),
cosBitRow,
stageRangeRow);
RoundShiftArray(ref Unsafe.Add(ref outputRef, r * transformColumnCount), transformColumnCount, -shift[2]);
RoundShiftArray(ref Unsafe.Add(ref outputRef, r), transformColumnCount, -shift[2]);

if (Math.Abs(rectangleType) == 1)
{
// Multiply everything by Sqrt2 if the transform is rectangular and the
// size difference is a factor of 2.
int t = r * transformColumnCount;
int t = r;
for (c = 0; c < transformColumnCount; ++c)
{
ref int current = ref Unsafe.Add(ref outputRef, t);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Drawing;

namespace SixLabors.ImageSharp.Formats.Heif.Av1.Transform;

internal class Av1Transform2dFlipConfiguration
Expand Down Expand Up @@ -124,10 +122,12 @@ internal class Av1Transform2dFlipConfiguration
[5], // fidtx64_range_mult2
];

private readonly int[] shift;
private int[] shift;

public Av1Transform2dFlipConfiguration(Av1TransformType transformType, Av1TransformSize transformSize)
{
// SVT: svt_av1_get_inv_txfm_cfg
// SVT: svt_aom_transform_config
this.TransformSize = transformSize;
this.TransformType = transformType;
this.SetFlip(transformType);
Expand Down Expand Up @@ -248,6 +248,14 @@ public bool IsAllowed()
return supportedTypes.Contains(this.TransformType);
}

internal void SetShift(int shift0, int shift1, int shift2) => this.shift = [shift0, shift1, shift2];

internal void SetFlip(bool upsideDown, bool leftToRight)
{
this.FlipUpsideDown = upsideDown;
this.FlipLeftToRight = leftToRight;
}

private void SetFlip(Av1TransformType transformType)
{
switch (transformType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal enum Av1TransformType : byte
AdstDct,

/// <summary>
/// DCT in vertical, ADST in horizontal.
/// DCT in vertical, ADST in horizontal.
/// </summary>
DctAdst,

Expand Down
Loading

0 comments on commit 47c2416

Please sign in to comment.