Skip to content

Commit

Permalink
Implement TransformBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ynse01 committed Jul 4, 2024
1 parent 6c4e213 commit 1ff0150
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 70 deletions.
14 changes: 13 additions & 1 deletion src/ImageSharp/Formats/Heif/Av1/Av1BlockSizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ internal static class Av1BlockSizeExtensions
Av1TransformSize.Size16x64, Av1TransformSize.Size64x16
];

private static readonly int[] PelsLog2Count =
[4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13, 13, 14, 6, 6, 8, 8, 10, 10];

public static int Get4x4WideCount(this Av1BlockSize blockSize) => SizeWide[(int)blockSize];

public static int Get4x4HighCount(this Av1BlockSize blockSize) => SizeHigh[(int)blockSize];
Expand Down Expand Up @@ -82,13 +85,19 @@ public static int Get4x4HeightLog2(this Av1BlockSize blockSize)
/// Returns the block size of a sub sampled block.
/// </summary>
public static Av1BlockSize GetSubsampled(this Av1BlockSize blockSize, bool subX, bool subY)
=> GetSubsampled(blockSize, subX ? 1 : 0, subY ? 1 : 0);

/// <summary>
/// Returns the block size of a sub sampled block.
/// </summary>
public static Av1BlockSize GetSubsampled(this Av1BlockSize blockSize, int subX, int subY)
{
if (blockSize == Av1BlockSize.Invalid)
{
return Av1BlockSize.Invalid;
}

return SubSampled[(int)blockSize][subX ? 1 : 0][subY ? 1 : 0];
return SubSampled[(int)blockSize][subX][subY];
}

public static Av1TransformSize GetMaxUvTransformSize(this Av1BlockSize blockSize, bool subX, bool subY)
Expand All @@ -115,4 +124,7 @@ public static Av1TransformSize GetMaxUvTransformSize(this Av1BlockSize blockSize
/// </summary>
public static Av1TransformSize GetMaximumTransformSize(this Av1BlockSize blockSize)
=> MaxTransformSize[(int)blockSize];

public static int GetPelsLog2Count(this Av1BlockSize blockSize)
=> PelsLog2Count[(int)blockSize];
}
2 changes: 2 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ internal static class Av1Constants
/// Maximum transform size categories.
/// </summary>
public const int MaxTransformCategories = 4;

public const int CoefficientContextCount = 6;
}
8 changes: 0 additions & 8 deletions src/ImageSharp/Formats/Heif/Av1/Av1MainParseContext.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,6 @@ frameInfo.ReferenceFrameIndex[i] < ((1 << idLength) + (frameInfo.CurrentFrameId
ReadFrameDeltaLoopFilterParameters(ref reader, frameInfo);

// SetupSegmentationDequantization();
Av1MainParseContext mainParseContext = new();
if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone)
{
// ResetParseContext(mainParseContext, frameInfo.QuantizationParameters.BaseQIndex);
Expand Down
9 changes: 9 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/Tiling/Av1FrameBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public void SetTransformUv(int index, Av1TransformInfo transformInfo)
span[index] = transformInfo;
}

public Span<int> GetCoefficients(int plane) =>
plane switch
{
0 => (Span<int>)this.coefficientsY,
2 => (Span<int>)this.coefficientsY,
3 => (Span<int>)this.coefficientsY,
_ => null,
};

public Span<int> GetCoefficientsY(Point index)
{
Span<int> span = this.coefficientsY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public Av1ParseAboveNeighbor4x4Context(int planesCount, int modeInfoColumnCount)

public int[] AboveTransformWidth => this.aboveTransformWidth;

public int[] GetContext(int plane) => this.aboveContext[plane];

public void Clear(ObuSequenceHeader sequenceHeader)
{
int planeCount = sequenceHeader.ColorConfig.ChannelCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ public void UpdateTransformation(Point modeInfoLocation, Av1SuperblockInfo super

internal void ClearContext(int plane, int offset, int length)
=> Array.Fill(this.leftContext[plane], 0, offset, length);

internal int[] GetContext(int plane) => this.leftContext[plane];
}
4 changes: 4 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/Tiling/Av1PartitionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public Av1PartitionInfo(Av1BlockModeInfo modeInfo, Av1SuperblockInfo superblockI

public int[] ReferenceFrame { get; set; }

public int ModeBlockToRightEdge => this.modeBlockToRightEdge;

public int ModeBlockToBottomEdge => this.modeBlockToBottomEdge;

public void ComputeBoundaryOffsets(ObuFrameHeader frameInfo, Av1TileInfo tileInfo)
{
Av1BlockSize blockSize = this.ModeInfo.BlockSize;
Expand Down
272 changes: 212 additions & 60 deletions src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TransformBlockContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

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

internal class Av1TransformBlockContext
{
public int DcSignContext { get; set; }

public int SkipContext { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ internal static class Av1TransformSizeExtensions
// Transform block height in unit
private static readonly int[] HighUnit = [1, 2, 4, 8, 16, 2, 1, 4, 2, 8, 4, 16, 8, 4, 1, 8, 2, 16, 4];
// Transform size conversion into Block Size
private static readonly Av1BlockSize[] BlockSize = [
Av1BlockSize.Block4x4, // TX_4X4
Av1BlockSize.Block8x8, // TX_8X8
Av1BlockSize.Block16x16, // TX_16X16
Av1BlockSize.Block32x32, // TX_32X32
Av1BlockSize.Block64x64, // TX_64X64
Av1BlockSize.Block4x8, // TX_4X8
Av1BlockSize.Block8x4, // TX_8X4
Av1BlockSize.Block8x16, // TX_8X16
Av1BlockSize.Block16x8, // TX_16X8
Av1BlockSize.Block16x32, // TX_16X32
Av1BlockSize.Block32x16, // TX_32X16
Av1BlockSize.Block32x64, // TX_32X64
Av1BlockSize.Block64x32, // TX_64X32
Av1BlockSize.Block4x16, // TX_4X16
Av1BlockSize.Block16x4, // TX_16X4
Av1BlockSize.Block8x32, // TX_8X32
Av1BlockSize.Block32x8, // TX_32X8
Av1BlockSize.Block16x64, // TX_16X64
Av1BlockSize.Block64x16, // TX_64X16
];
public static int GetScale(this Av1TransformSize size)
{
int pels = Size2d[(int)size];
Expand All @@ -55,4 +78,6 @@ public static int GetScale(this Av1TransformSize size)
public static int Get4x4HighCount(this Av1TransformSize size) => HighUnit[(int)size];

public static Av1TransformSize GetSubSize(this Av1TransformSize size) => SubTransformSize[(int)size];

public static Av1BlockSize GetBlockSize(this Av1TransformSize transformSize) => (Av1BlockSize)BlockSize[(int)transformSize];
}

0 comments on commit 1ff0150

Please sign in to comment.