mirror of https://github.com/SixLabors/ImageSharp
18 changed files with 1235 additions and 1861 deletions
@ -1,163 +0,0 @@ |
|||||
// 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; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Describes the spatial, chroma, and transform layout of one AV1 block considered by mode-decision scanning.
|
|
||||
/// </summary>
|
|
||||
internal class Av1BlockGeometry |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The luma block size from which the cached luma dimensions are derived.
|
|
||||
/// </summary>
|
|
||||
private Av1BlockSize blockSize; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The chroma block size from which the cached chroma dimensions are derived.
|
|
||||
/// </summary>
|
|
||||
private Av1BlockSize blockSizeUv; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the <see cref="Av1BlockGeometry"/> class with storage for every supported transform depth.
|
|
||||
/// </summary>
|
|
||||
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]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the luma block size and updates <see cref="BlockWidth"/> and <see cref="BlockHeight"/> to match.
|
|
||||
/// </summary>
|
|
||||
public Av1BlockSize BlockSize |
|
||||
{ |
|
||||
get => this.blockSize; |
|
||||
set |
|
||||
{ |
|
||||
this.blockSize = value; |
|
||||
this.BlockWidth = value.GetWidth(); |
|
||||
this.BlockHeight = value.GetHeight(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the chroma block size and updates <see cref="BlockWidthUv"/> and <see cref="BlockHeightUv"/> to match.
|
|
||||
/// </summary>
|
|
||||
public Av1BlockSize BlockSizeUv |
|
||||
{ |
|
||||
get => this.blockSizeUv; |
|
||||
set |
|
||||
{ |
|
||||
this.blockSizeUv = value; |
|
||||
this.BlockWidthUv = value.GetWidth(); |
|
||||
this.BlockHeightUv = value.GetHeight(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the block origin in pixels relative to the top-left corner of its superblock.
|
|
||||
/// </summary>
|
|
||||
public Point Origin { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets a value indicating whether this luma block owns chroma samples in the mode-decision layout.
|
|
||||
/// </summary>
|
|
||||
public bool HasUv { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the luma block width in pixels.
|
|
||||
/// </summary>
|
|
||||
public int BlockWidth { get; private set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the luma block height in pixels.
|
|
||||
/// </summary>
|
|
||||
public int BlockHeight { get; private set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the number of luma transform blocks at each transform depth.
|
|
||||
/// </summary>
|
|
||||
public int[] TransformBlockCount { get; } = new int[Av1Constants.MaxVarTransform + 1]; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the luma transform size selected at each transform depth.
|
|
||||
/// </summary>
|
|
||||
public Av1TransformSize[] TransformSize { get; } = new Av1TransformSize[Av1Constants.MaxVarTransform + 1]; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the chroma transform size selected at each transform depth.
|
|
||||
/// </summary>
|
|
||||
public Av1TransformSize[] TransformSizeUv { get; } = new Av1TransformSize[Av1Constants.MaxVarTransform + 1]; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the pixel origins of the transform blocks at each transform depth.
|
|
||||
/// </summary>
|
|
||||
public Point[][] TransformOrigin { get; private set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the block index in mode-decision scan order.
|
|
||||
/// </summary>
|
|
||||
public int ModeDecisionIndex { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the scan offset from this square block to the next block at the same depth.
|
|
||||
/// </summary>
|
|
||||
public int NextDepthOffset { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the scan offset from this square block to its first child at the next depth.
|
|
||||
/// </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 mode-decision indices of blocks with the same size and origin as this block.
|
|
||||
/// </summary>
|
|
||||
public List<int> RedunancyList { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the zero-based component index of this block within a non-square partition.
|
|
||||
/// </summary>
|
|
||||
public int NonSquareIndex { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the number of component blocks produced by this partition shape.
|
|
||||
/// </summary>
|
|
||||
public int TotalNonSuareCount { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the chroma block width in pixels.
|
|
||||
/// </summary>
|
|
||||
public int BlockWidthUv { get; private set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the chroma block height in pixels.
|
|
||||
/// </summary>
|
|
||||
public int BlockHeightUv { get; private set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the quadtree depth of this block within its superblock.
|
|
||||
/// </summary>
|
|
||||
public int Depth { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets the width and height, in pixels, of the square sequence region that produced this block.
|
|
||||
/// </summary>
|
|
||||
public int SequenceSize { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets or sets a value indicating whether this block belongs to the last quadrant of its parent.
|
|
||||
/// </summary>
|
|
||||
public bool IsLastQuadrant { get; set; } |
|
||||
} |
|
||||
File diff suppressed because it is too large
@ -1,50 +0,0 @@ |
|||||
// Copyright (c) Six Labors.
|
|
||||
// Licensed under the Six Labors Split License.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.ModeDecision; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Identifies a predefined AV1 mode-decision geometry with a fixed superblock size, search depth, and partition set.
|
|
||||
/// </summary>
|
|
||||
internal enum Av1GeometryIndex |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, four-depth geometry limited to square partitions.
|
|
||||
/// </summary>
|
|
||||
Geometry0, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, four-depth geometry with horizontal and vertical binary partitions down to 16 pixels.
|
|
||||
/// </summary>
|
|
||||
Geometry1, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, four-depth geometry with horizontal and vertical binary partitions down to 8 pixels.
|
|
||||
/// </summary>
|
|
||||
Geometry2, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, four-depth geometry with binary partitions at every supported size.
|
|
||||
/// </summary>
|
|
||||
Geometry3, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, five-depth geometry with binary partitions at every supported size.
|
|
||||
/// </summary>
|
|
||||
Geometry4, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, five-depth geometry that also enables four-way horizontal and vertical partitions.
|
|
||||
/// </summary>
|
|
||||
Geometry5, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 64-pixel, five-depth geometry that enables all supported partition shapes.
|
|
||||
/// </summary>
|
|
||||
Geometry6, |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The 128-pixel, six-depth geometry that enables all supported partition shapes.
|
|
||||
/// </summary>
|
|
||||
Geometry7, |
|
||||
} |
|
||||
@ -0,0 +1,42 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using System.Runtime.InteropServices; |
||||
|
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Stores the entropy syntax retained for one AV1 transform block.
|
||||
|
/// </summary>
|
||||
|
[StructLayout(LayoutKind.Sequential, Size = sizeof(int))] |
||||
|
internal struct Av1EncoderTransformBlockState |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Stores the position after the final nonzero coefficient.
|
||||
|
/// </summary>
|
||||
|
private ushort endOfBlock; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Stores the selected transform type.
|
||||
|
/// </summary>
|
||||
|
private Av1TransformType transformType; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the position after the final nonzero coefficient.
|
||||
|
/// </summary>
|
||||
|
public ushort EndOfBlock |
||||
|
{ |
||||
|
readonly get => this.endOfBlock; |
||||
|
set => this.endOfBlock = value; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the selected transform type.
|
||||
|
/// </summary>
|
||||
|
public Av1TransformType TransformType |
||||
|
{ |
||||
|
readonly get => this.transformType; |
||||
|
set => this.transformType = value; |
||||
|
} |
||||
|
} |
||||
@ -1,15 +0,0 @@ |
|||||
// Copyright (c) Six Labors.
|
|
||||
// Licensed under the Six Labors Split License.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Describes a superblock node's location, dimensions, and children in the encoder partition tree.
|
|
||||
/// </summary>
|
|
||||
internal class Av1SuperblockGeometry |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Gets or sets a value indicating whether the superblock lies completely within the coded frame.
|
|
||||
/// </summary>
|
|
||||
public bool IsComplete { get; set; } |
|
||||
} |
|
||||
File diff suppressed because it is too large
@ -1,54 +0,0 @@ |
|||||
// Copyright (c) Six Labors.
|
|
||||
// Licensed under the Six Labors Split License.
|
|
||||
|
|
||||
using System.Diagnostics.CodeAnalysis; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Stores the transform syntax and coefficient range for one AV1 transform unit.
|
|
||||
/// </summary>
|
|
||||
internal struct Av1TransformUnit |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Stores the luma, blue-difference, and red-difference end-of-block positions.
|
|
||||
/// </summary>
|
|
||||
private InlineArray3<ushort> nzCoefficientCount; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Stores the luma and shared chroma transform types.
|
|
||||
/// </summary>
|
|
||||
private InlineArray2<Av1TransformType> transformType; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the nonzero-coefficient count for each color plane.
|
|
||||
/// </summary>
|
|
||||
[UnscopedRef] |
|
||||
public Span<ushort> NzCoefficientCount => this.nzCoefficientCount; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the transform type selected for each color plane.
|
|
||||
/// </summary>
|
|
||||
[UnscopedRef] |
|
||||
public Span<Av1TransformType> TransformType => this.transformType; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Stores the three per-plane coefficient counts inline.
|
|
||||
/// </summary>
|
|
||||
[InlineArray(3)] |
|
||||
private struct InlineArray3<T> |
|
||||
{ |
|
||||
private T element; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Stores the luma and shared chroma transform types inline.
|
|
||||
/// </summary>
|
|
||||
[InlineArray(Av1Constants.PlaneTypeCount)] |
|
||||
private struct InlineArray2<T> |
|
||||
{ |
|
||||
private T element; |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue