Skip to content

Commit

Permalink
Introduce BlockGeometry factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ynse01 committed Dec 11, 2024
1 parent 37ea4ca commit 88e1464
Show file tree
Hide file tree
Showing 6 changed files with 1,134 additions and 73 deletions.
11 changes: 11 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/Av1BlockSizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ internal static class Av1BlockSizeExtensions
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];

private static readonly Av1BlockSize[][] HeightWidthToSize = [
[Av1BlockSize.Block4x4, Av1BlockSize.Block4x8, Av1BlockSize.Block4x16, Av1BlockSize.Invalid, Av1BlockSize.Invalid, Av1BlockSize.Invalid],
[Av1BlockSize.Block8x4, Av1BlockSize.Block8x8, Av1BlockSize.Block8x16, Av1BlockSize.Block8x32, Av1BlockSize.Invalid, Av1BlockSize.Invalid],
[Av1BlockSize.Block16x4, Av1BlockSize.Block16x8, Av1BlockSize.Block16x16, Av1BlockSize.Block16x32, Av1BlockSize.Block16x64, Av1BlockSize.Invalid],
[Av1BlockSize.Invalid, Av1BlockSize.Block32x8, Av1BlockSize.Block32x16, Av1BlockSize.Block32x32, Av1BlockSize.Block32x64, Av1BlockSize.Invalid],
[Av1BlockSize.Invalid, Av1BlockSize.Invalid, Av1BlockSize.Block64x16, Av1BlockSize.Block64x32, Av1BlockSize.Block64x64, Av1BlockSize.Block64x128],
[Av1BlockSize.Invalid, Av1BlockSize.Invalid, Av1BlockSize.Invalid, Av1BlockSize.Invalid, Av1BlockSize.Block128x64, Av1BlockSize.Block128x128]
];

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

public static int Get4x4HighCount(this Av1BlockSize blockSize) => SizeHigh[(int)blockSize];

public static Av1BlockSize FromWidthAndHeight(uint widthLog2, uint heightLog2) => HeightWidthToSize[heightLog2][widthLog2];

/// <summary>
/// Returns the width of the block in samples.
/// </summary>
Expand Down
111 changes: 111 additions & 0 deletions src/ImageSharp/Formats/Heif/Av1/ModeDecision/Av1BlockGeometry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

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

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

internal class Av1BlockGeometry
{
private Av1BlockSize blockSize;
private Av1BlockSize blockSizeUv;

public Av1BlockGeometry()
{
this.RedunancyList = [];
this.TransformOrigin = new Point[Av1Constants.MaxVarTransform + 1][];
for (int i = 0; i < this.TransformOrigin.Length; i++)
{
this.TransformOrigin[i] = new Point[Av1Constants.MaxTransformBlockCount];
}
}

public Av1BlockSize BlockSize
{
get => this.blockSize;
internal set
{
this.blockSize = value;
this.BlockWidth = value.GetWidth();
this.BlockHeight = value.GetHeight();
}
}

public Av1BlockSize BlockSizeUv
{
get => this.blockSizeUv;
internal set
{
this.blockSizeUv = value;
this.BlockWidthUv = value.GetWidth();
this.BlockHeightUv = value.GetHeight();
}
}

/// <summary>
/// Gets or sets the Origin point from lop left of the superblock.
/// </summary>
public Point Origin { get; internal set; }

public bool HasUv { get; internal set; }

/// <summary>
/// Gets the blocks width.
/// </summary>
public int BlockWidth { get; private set; }

/// <summary>
/// Gets the blocks height.
/// </summary>
public int BlockHeight { get; private set; }

public int[] TransformBlockCount { get; } = new int[Av1Constants.MaxVarTransform + 1];

public Av1TransformSize[] TransformSize { get; } = new Av1TransformSize[Av1Constants.MaxVarTransform + 1];

public Av1TransformSize[] TransformSizeUv { get; } = new Av1TransformSize[Av1Constants.MaxVarTransform + 1];

public Point[][] TransformOrigin { get; private set; }

/// <summary>
/// Gets or sets the blocks index in the Mode Decision scan.
/// </summary>
public int ModeDecisionIndex { get; set; }

/// <summary>
/// Gets or sets the offset to the next nsq block (skip remaining d2 blocks).
/// </summary>
public int NextDepthOffset { get; set; }

/// <summary>
/// Gets or sets the offset to the next d1 sq block
/// </summary>
public int Depth1Offset { get; set; }

/// <summary>
/// Gets a value indicating whether this block is redundant to another.
/// </summary>
public bool IsRedundant => this.RedunancyList.Count > 0;

/// <summary>
/// Gets or sets the list where the block is redundant.
/// </summary>
public List<int> RedunancyList { get; internal set; }

/// <summary>
/// Gets or sets the non square index within a partition 0..totns-1
/// </summary>
public int NonSquareIndex { get; internal set; }

public int TotalNonSuareCount { get; internal set; }

public int BlockWidthUv { get; private set; }

public int BlockHeightUv { get; private set; }

public int Depth { get; internal set; }

public int SequenceSize { get; internal set; }

public bool IsLastQuadrant { get; internal set; }
}
Loading

0 comments on commit 88e1464

Please sign in to comment.