Browse Source

Rename Av1Constants class

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
a8539f24b9
  1. 6
      src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs
  2. 10
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs
  3. 2
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs
  4. 52
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs
  5. 6
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs
  6. 4
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs
  7. 24
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs
  8. 44
      src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs

6
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuConstants.cs → src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs

@ -1,11 +1,11 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System; using SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; namespace SixLabors.ImageSharp.Formats.Heif.Av1;
internal static class ObuConstants internal static class Av1Constants
{ {
public const ObuSequenceProfile MaxSequenceProfile = ObuSequenceProfile.Professional; public const ObuSequenceProfile MaxSequenceProfile = ObuSequenceProfile.Professional;

10
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs

@ -19,7 +19,7 @@ internal class ObuFrameHeader
public bool CodedLossless { get; set; } public bool CodedLossless { get; set; }
public bool[] LosslessArray { get; set; } = new bool[ObuConstants.MaxSegmentCount]; public bool[] LosslessArray { get; set; } = new bool[Av1Constants.MaxSegmentCount];
public ObuQuantizationParameters QuantizationParameters { get; set; } = new ObuQuantizationParameters(); public ObuQuantizationParameters QuantizationParameters { get; set; } = new ObuQuantizationParameters();
@ -63,9 +63,9 @@ internal class ObuFrameHeader
internal ObuFrameType FrameType { get; set; } internal ObuFrameType FrameType { get; set; }
internal bool[] ReferenceValid { get; set; } = new bool[ObuConstants.ReferenceFrameCount]; internal bool[] ReferenceValid { get; set; } = new bool[Av1Constants.ReferenceFrameCount];
internal bool[] ReferenceOrderHint { get; set; } = new bool[ObuConstants.ReferenceFrameCount]; internal bool[] ReferenceOrderHint { get; set; } = new bool[Av1Constants.ReferenceFrameCount];
internal bool ShowFrame { get; set; } internal bool ShowFrame { get; set; }
@ -79,11 +79,11 @@ internal class ObuFrameHeader
internal uint CurrentFrameId { get; set; } internal uint CurrentFrameId { get; set; }
internal uint[] ReferenceFrameIndex { get; set; } = new uint[ObuConstants.ReferenceFrameCount]; internal uint[] ReferenceFrameIndex { get; set; } = new uint[Av1Constants.ReferenceFrameCount];
internal uint OrderHint { get; set; } internal uint OrderHint { get; set; }
internal uint PrimaryReferenceFrame { get; set; } = ObuConstants.PrimaryReferenceFrameNone; internal uint PrimaryReferenceFrame { get; set; } = Av1Constants.PrimaryReferenceFrameNone;
internal uint RefreshFrameFlags { get; set; } internal uint RefreshFrameFlags { get; set; }
} }

2
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs

@ -7,7 +7,7 @@ internal class ObuQuantizationParameters
{ {
public int BaseQIndex { get; set; } public int BaseQIndex { get; set; }
public int[] QIndex { get; set; } = new int[ObuConstants.MaxSegmentCount]; public int[] QIndex { get; set; } = new int[Av1Constants.MaxSegmentCount];
public bool IsUsingQMatrix { get; internal set; } public bool IsUsingQMatrix { get; internal set; }

52
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs

@ -197,7 +197,7 @@ internal class ObuReader
{ {
frameInfo.ModeInfoColumnCount = 2 * ((frameInfo.FrameSize.FrameWidth + 7) >> 3); frameInfo.ModeInfoColumnCount = 2 * ((frameInfo.FrameSize.FrameWidth + 7) >> 3);
frameInfo.ModeInfoRowCount = 2 * ((frameInfo.FrameSize.FrameHeight + 7) >> 3); frameInfo.ModeInfoRowCount = 2 * ((frameInfo.FrameSize.FrameHeight + 7) >> 3);
frameInfo.ModeInfoStride = Av1Math.AlignPowerOf2(sequenceHeader.MaxFrameWidth, ObuConstants.MaxSuperBlockSizeLog2) >> ObuConstants.ModeInfoSizeLog2; frameInfo.ModeInfoStride = Av1Math.AlignPowerOf2(sequenceHeader.MaxFrameWidth, Av1Constants.MaxSuperBlockSizeLog2) >> Av1Constants.ModeInfoSizeLog2;
} }
private static bool IsValidObuType(ObuType type) => type switch private static bool IsValidObuType(ObuType type) => type switch
@ -211,7 +211,7 @@ internal class ObuReader
private static void ReadSequenceHeader(ref Av1BitStreamReader reader, ObuSequenceHeader sequenceHeader) private static void ReadSequenceHeader(ref Av1BitStreamReader reader, ObuSequenceHeader sequenceHeader)
{ {
sequenceHeader.SequenceProfile = (ObuSequenceProfile)reader.ReadLiteral(3); sequenceHeader.SequenceProfile = (ObuSequenceProfile)reader.ReadLiteral(3);
if (sequenceHeader.SequenceProfile > ObuConstants.MaxSequenceProfile) if (sequenceHeader.SequenceProfile > Av1Constants.MaxSequenceProfile)
{ {
throw new ImageFormatException("Unknown sequence profile."); throw new ImageFormatException("Unknown sequence profile.");
} }
@ -230,7 +230,7 @@ internal class ObuReader
ObuOperatingPoint operatingPoint = new(); ObuOperatingPoint operatingPoint = new();
sequenceHeader.OperatingPoint[0] = operatingPoint; sequenceHeader.OperatingPoint[0] = operatingPoint;
operatingPoint.OperatorIndex = 0; operatingPoint.OperatorIndex = 0;
operatingPoint.SequenceLevelIndex = (int)reader.ReadLiteral(ObuConstants.LevelBits); operatingPoint.SequenceLevelIndex = (int)reader.ReadLiteral(Av1Constants.LevelBits);
if (!IsValidSequenceLevel(sequenceHeader.OperatingPoint[0].SequenceLevelIndex)) if (!IsValidSequenceLevel(sequenceHeader.OperatingPoint[0].SequenceLevelIndex))
{ {
throw new ImageFormatException("Invalid sequence level."); throw new ImageFormatException("Invalid sequence level.");
@ -388,20 +388,20 @@ internal class ObuReader
if (useSuperResolution) if (useSuperResolution)
{ {
frameInfo.FrameSize.SuperResolutionDenominator = (int)reader.ReadLiteral(ObuConstants.SuperResolutionScaleBits) + ObuConstants.SuperResolutionScaleDenominatorMinimum; frameInfo.FrameSize.SuperResolutionDenominator = (int)reader.ReadLiteral(Av1Constants.SuperResolutionScaleBits) + Av1Constants.SuperResolutionScaleDenominatorMinimum;
} }
else else
{ {
frameInfo.FrameSize.SuperResolutionDenominator = ObuConstants.ScaleNumerator; frameInfo.FrameSize.SuperResolutionDenominator = Av1Constants.ScaleNumerator;
} }
frameInfo.FrameSize.SuperResolutionUpscaledWidth = frameInfo.FrameSize.FrameWidth; frameInfo.FrameSize.SuperResolutionUpscaledWidth = frameInfo.FrameSize.FrameWidth;
frameInfo.FrameSize.FrameWidth = frameInfo.FrameSize.FrameWidth =
((frameInfo.FrameSize.SuperResolutionUpscaledWidth * ObuConstants.ScaleNumerator) + ((frameInfo.FrameSize.SuperResolutionUpscaledWidth * Av1Constants.ScaleNumerator) +
(frameInfo.FrameSize.SuperResolutionDenominator / 2)) / (frameInfo.FrameSize.SuperResolutionDenominator / 2)) /
frameInfo.FrameSize.SuperResolutionDenominator; frameInfo.FrameSize.SuperResolutionDenominator;
if (frameInfo.FrameSize.SuperResolutionDenominator != ObuConstants.ScaleNumerator) if (frameInfo.FrameSize.SuperResolutionDenominator != Av1Constants.ScaleNumerator)
{ {
int manWidth = Math.Min(16, frameInfo.FrameSize.SuperResolutionUpscaledWidth); int manWidth = Math.Min(16, frameInfo.FrameSize.SuperResolutionUpscaledWidth);
frameInfo.FrameSize.FrameWidth = Math.Max(manWidth, frameInfo.FrameSize.FrameWidth); frameInfo.FrameSize.FrameWidth = Math.Max(manWidth, frameInfo.FrameSize.FrameWidth);
@ -426,7 +426,7 @@ internal class ObuReader
private static void ReadFrameSizeWithReferences(ref Av1BitStreamReader reader, ObuSequenceHeader sequenceHeader, ObuFrameHeader frameInfo, bool frameSizeOverrideFlag) private static void ReadFrameSizeWithReferences(ref Av1BitStreamReader reader, ObuSequenceHeader sequenceHeader, ObuFrameHeader frameInfo, bool frameSizeOverrideFlag)
{ {
bool foundReference = false; bool foundReference = false;
for (int i = 0; i < ObuConstants.ReferencesPerFrame; i++) for (int i = 0; i < Av1Constants.ReferencesPerFrame; i++)
{ {
foundReference = reader.ReadBoolean(); foundReference = reader.ReadBoolean();
if (foundReference) if (foundReference)
@ -485,13 +485,13 @@ internal class ObuReader
} }
int superBlockSize = superBlockShift + 2; int superBlockSize = superBlockShift + 2;
int maxTileAreaOfSuperBlock = ObuConstants.MaxTileArea >> (2 * superBlockSize); int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize);
tileInfo.MaxTileWidthSuperBlock = ObuConstants.MaxTileWidth >> superBlockSize; tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superBlockSize;
tileInfo.MaxTileHeightSuperBlock = (ObuConstants.MaxTileArea / ObuConstants.MaxTileWidth) >> superBlockSize; tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superBlockSize;
tileInfo.MinLog2TileColumnCount = TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount); tileInfo.MinLog2TileColumnCount = TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount);
tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superBlockColumnCount, ObuConstants.MaxTileColumnCount)); tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superBlockColumnCount, Av1Constants.MaxTileColumnCount));
tileInfo.MaxLog2TileRowCount = TileLog2(1, Math.Min(superBlockRowCount, ObuConstants.MaxTileRowCount)); tileInfo.MaxLog2TileRowCount = TileLog2(1, Math.Min(superBlockRowCount, Av1Constants.MaxTileRowCount));
tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount)); tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount));
tileInfo.HasUniformTileSpacing = reader.ReadBoolean(); tileInfo.HasUniformTileSpacing = reader.ReadBoolean();
if (tileInfo.HasUniformTileSpacing) if (tileInfo.HasUniformTileSpacing)
@ -610,7 +610,7 @@ internal class ObuReader
tileInfo.TileRowCountLog2 = TileLog2(1, tileInfo.TileRowCount); tileInfo.TileRowCountLog2 = TileLog2(1, tileInfo.TileRowCount);
} }
if (tileInfo.TileColumnCount > ObuConstants.MaxTileColumnCount || tileInfo.TileRowCount > ObuConstants.MaxTileRowCount) if (tileInfo.TileColumnCount > Av1Constants.MaxTileColumnCount || tileInfo.TileRowCount > Av1Constants.MaxTileRowCount)
{ {
throw new ImageFormatException("Tile width or height too big."); throw new ImageFormatException("Tile width or height too big.");
} }
@ -659,9 +659,9 @@ internal class ObuReader
if (frameInfo.FrameType == ObuFrameType.KeyFrame && frameInfo.ShowFrame) if (frameInfo.FrameType == ObuFrameType.KeyFrame && frameInfo.ShowFrame)
{ {
frameInfo.ReferenceValid = new bool[ObuConstants.ReferenceFrameCount]; frameInfo.ReferenceValid = new bool[Av1Constants.ReferenceFrameCount];
frameInfo.ReferenceOrderHint = new bool[ObuConstants.ReferenceFrameCount]; frameInfo.ReferenceOrderHint = new bool[Av1Constants.ReferenceFrameCount];
for (int i = 0; i < ObuConstants.ReferenceFrameCount; i++) for (int i = 0; i < Av1Constants.ReferenceFrameCount; i++)
{ {
frameInfo.ReferenceValid[i] = false; frameInfo.ReferenceValid[i] = false;
frameInfo.ReferenceOrderHint[i] = false; frameInfo.ReferenceOrderHint[i] = false;
@ -717,7 +717,7 @@ internal class ObuReader
} }
int diffLength = sequenceHeader.DeltaFrameIdLength; int diffLength = sequenceHeader.DeltaFrameIdLength;
for (int i = 0; i < ObuConstants.ReferenceFrameCount; i++) for (int i = 0; i < Av1Constants.ReferenceFrameCount; i++)
{ {
if (frameInfo.CurrentFrameId > (1U << diffLength)) if (frameInfo.CurrentFrameId > (1U << diffLength))
{ {
@ -756,11 +756,11 @@ internal class ObuReader
if (isIntraFrame || frameInfo.ErrorResilientMode) if (isIntraFrame || frameInfo.ErrorResilientMode)
{ {
frameInfo.PrimaryReferenceFrame = ObuConstants.PrimaryReferenceFrameNone; frameInfo.PrimaryReferenceFrame = Av1Constants.PrimaryReferenceFrameNone;
} }
else else
{ {
frameInfo.PrimaryReferenceFrame = reader.ReadLiteral(ObuConstants.PimaryReferenceBits); frameInfo.PrimaryReferenceFrame = reader.ReadLiteral(Av1Constants.PimaryReferenceBits);
} }
// Skipping, as no decoder info model present // Skipping, as no decoder info model present
@ -785,7 +785,7 @@ internal class ObuReader
{ {
if (frameInfo.ErrorResilientMode && sequenceHeader.OrderHintInfo != null) if (frameInfo.ErrorResilientMode && sequenceHeader.OrderHintInfo != null)
{ {
for (int i = 0; i < ObuConstants.ReferenceFrameCount; i++) for (int i = 0; i < Av1Constants.ReferenceFrameCount; i++)
{ {
int referenceOrderHint = (int)reader.ReadLiteral(sequenceHeader.OrderHintInfo.OrderHintBits); int referenceOrderHint = (int)reader.ReadLiteral(sequenceHeader.OrderHintInfo.OrderHintBits);
if (referenceOrderHint != (frameInfo.ReferenceOrderHint[i] ? 1U : 0U)) if (referenceOrderHint != (frameInfo.ReferenceOrderHint[i] ? 1U : 0U))
@ -822,7 +822,7 @@ internal class ObuReader
frameInfo.DisableFrameEndUpdateCdf = true; frameInfo.DisableFrameEndUpdateCdf = true;
} }
if (frameInfo.PrimaryReferenceFrame == ObuConstants.PrimaryReferenceFrameNone) if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone)
{ {
SetupPastIndependence(frameInfo); SetupPastIndependence(frameInfo);
} }
@ -836,14 +836,14 @@ internal class ObuReader
// SetupSegmentationDequantization(); // SetupSegmentationDequantization();
Av1MainParseContext mainParseContext = new(); Av1MainParseContext mainParseContext = new();
if (frameInfo.PrimaryReferenceFrame == ObuConstants.PrimaryReferenceFrameNone) if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone)
{ {
// ResetParseContext(mainParseContext, frameInfo.QuantizationParameters.BaseQIndex); // ResetParseContext(mainParseContext, frameInfo.QuantizationParameters.BaseQIndex);
} }
int tilesCount = frameInfo.TilesInfo.TileColumnCount * frameInfo.TilesInfo.TileRowCount; int tilesCount = frameInfo.TilesInfo.TileColumnCount * frameInfo.TilesInfo.TileRowCount;
frameInfo.CodedLossless = true; frameInfo.CodedLossless = true;
for (int segmentId = 0; segmentId < ObuConstants.MaxSegmentCount; segmentId++) for (int segmentId = 0; segmentId < Av1Constants.MaxSegmentCount; segmentId++)
{ {
int qIndex = GetQIndex(frameInfo.SegmentationParameters, segmentId, frameInfo.QuantizationParameters.BaseQIndex); int qIndex = GetQIndex(frameInfo.SegmentationParameters, segmentId, frameInfo.QuantizationParameters.BaseQIndex);
frameInfo.QuantizationParameters.QIndex[segmentId] = qIndex; frameInfo.QuantizationParameters.QIndex[segmentId] = qIndex;
@ -907,7 +907,7 @@ internal class ObuReader
{ {
int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer]; int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer];
int qIndex = baseQIndex + data; int qIndex = baseQIndex + data;
return Av1Math.Clamp(qIndex, 0, ObuConstants.MaxQ); return Av1Math.Clamp(qIndex, 0, Av1Constants.MaxQ);
} }
else else
{ {
@ -1180,7 +1180,7 @@ internal class ObuReader
} }
} }
frameInfo.LoopRestorationParameters[0].Size = ObuConstants.RestorationMaxTileSize >> (int)(2 - loopRestorationShift); frameInfo.LoopRestorationParameters[0].Size = Av1Constants.RestorationMaxTileSize >> (int)(2 - loopRestorationShift);
int uvShift = 0; int uvShift = 0;
if (sequenceHeader.ColorConfig.SubSamplingX && sequenceHeader.ColorConfig.SubSamplingY && usesChromaLoopRestoration) if (sequenceHeader.ColorConfig.SubSamplingX && sequenceHeader.ColorConfig.SubSamplingY && usesChromaLoopRestoration)
{ {

6
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs

@ -5,13 +5,13 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit;
internal class ObuSegmentationParameters internal class ObuSegmentationParameters
{ {
public int[,] QMLevel { get; internal set; } = new int[3, ObuConstants.MaxSegmentCount]; public int[,] QMLevel { get; internal set; } = new int[3, Av1Constants.MaxSegmentCount];
public bool[,] FeatureEnabled { get; internal set; } = new bool[ObuConstants.MaxSegmentCount, ObuConstants.SegmentationLevelMax]; public bool[,] FeatureEnabled { get; internal set; } = new bool[Av1Constants.MaxSegmentCount, Av1Constants.SegmentationLevelMax];
public bool Enabled { get; internal set; } public bool Enabled { get; internal set; }
public int[,] FeatureData { get; internal set; } = new int[ObuConstants.MaxSegmentCount, ObuConstants.SegmentationLevelMax]; public int[,] FeatureData { get; internal set; } = new int[Av1Constants.MaxSegmentCount, Av1Constants.SegmentationLevelMax];
public bool SegmentIdPrecedesSkip { get; internal set; } public bool SegmentIdPrecedesSkip { get; internal set; }

4
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs

@ -23,13 +23,13 @@ internal class ObuTileInfo
internal int TileColumnCount { get; set; } internal int TileColumnCount { get; set; }
internal int[] TileColumnStartModeInfo { get; set; } = new int[ObuConstants.MaxTileRowCount + 1]; internal int[] TileColumnStartModeInfo { get; set; } = new int[Av1Constants.MaxTileRowCount + 1];
internal int MinLog2TileRowCount { get; set; } internal int MinLog2TileRowCount { get; set; }
internal int TileRowCountLog2 { get; set; } internal int TileRowCountLog2 { get; set; }
internal int[] TileRowStartModeInfo { get; set; } = new int[ObuConstants.MaxTileColumnCount + 1]; internal int[] TileRowStartModeInfo { get; set; } = new int[Av1Constants.MaxTileColumnCount + 1];
internal int TileRowCount { get; set; } internal int TileRowCount { get; set; }

24
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs

@ -82,7 +82,7 @@ internal class ObuWriter
writer.WriteLiteral((uint)sequenceHeader.SequenceProfile, 3); writer.WriteLiteral((uint)sequenceHeader.SequenceProfile, 3);
writer.WriteBoolean(true); // IsStillPicture writer.WriteBoolean(true); // IsStillPicture
writer.WriteBoolean(true); // IsReducedStillPicture writer.WriteBoolean(true); // IsReducedStillPicture
writer.WriteLiteral((uint)sequenceHeader.OperatingPoint[0].SequenceLevelIndex, ObuConstants.LevelBits); writer.WriteLiteral((uint)sequenceHeader.OperatingPoint[0].SequenceLevelIndex, Av1Constants.LevelBits);
// Frame width and Height // Frame width and Height
writer.WriteLiteral((uint)sequenceHeader.FrameWidthBits - 1, 4); writer.WriteLiteral((uint)sequenceHeader.FrameWidthBits - 1, 4);
@ -168,7 +168,7 @@ internal class ObuWriter
if (useSuperResolution) if (useSuperResolution)
{ {
writer.WriteLiteral((uint)frameInfo.FrameSize.SuperResolutionDenominator - ObuConstants.SuperResolutionScaleDenominatorMinimum, ObuConstants.SuperResolutionScaleBits); writer.WriteLiteral((uint)frameInfo.FrameSize.SuperResolutionDenominator - Av1Constants.SuperResolutionScaleDenominatorMinimum, Av1Constants.SuperResolutionScaleBits);
} }
} }
@ -186,7 +186,7 @@ internal class ObuWriter
private static void WriteFrameSizeWithReferences(ref Av1BitStreamWriter writer, ObuSequenceHeader sequenceHeader, ObuFrameHeader frameInfo, bool frameSizeOverrideFlag) private static void WriteFrameSizeWithReferences(ref Av1BitStreamWriter writer, ObuSequenceHeader sequenceHeader, ObuFrameHeader frameInfo, bool frameSizeOverrideFlag)
{ {
bool foundReference = false; bool foundReference = false;
for (int i = 0; i < ObuConstants.ReferencesPerFrame; i++) for (int i = 0; i < Av1Constants.ReferencesPerFrame; i++)
{ {
writer.WriteBoolean(foundReference); writer.WriteBoolean(foundReference);
if (foundReference) if (foundReference)
@ -237,13 +237,13 @@ internal class ObuWriter
} }
int superBlockSize = superBlockShift + 2; int superBlockSize = superBlockShift + 2;
int maxTileAreaOfSuperBlock = ObuConstants.MaxTileArea >> (2 * superBlockSize); int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize);
tileInfo.MaxTileWidthSuperBlock = ObuConstants.MaxTileWidth >> superBlockSize; tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superBlockSize;
tileInfo.MaxTileHeightSuperBlock = (ObuConstants.MaxTileArea / ObuConstants.MaxTileWidth) >> superBlockSize; tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superBlockSize;
tileInfo.MinLog2TileColumnCount = ObuReader.TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount); tileInfo.MinLog2TileColumnCount = ObuReader.TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount);
tileInfo.MaxLog2TileColumnCount = ObuReader.TileLog2(1, Math.Min(superBlockColumnCount, ObuConstants.MaxTileColumnCount)); tileInfo.MaxLog2TileColumnCount = ObuReader.TileLog2(1, Math.Min(superBlockColumnCount, Av1Constants.MaxTileColumnCount));
tileInfo.MaxLog2TileRowCount = ObuReader.TileLog2(1, Math.Min(superBlockRowCount, ObuConstants.MaxTileRowCount)); tileInfo.MaxLog2TileRowCount = ObuReader.TileLog2(1, Math.Min(superBlockRowCount, Av1Constants.MaxTileRowCount));
tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, ObuReader.TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount)); tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, ObuReader.TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount));
writer.WriteBoolean(tileInfo.HasUniformTileSpacing); writer.WriteBoolean(tileInfo.HasUniformTileSpacing);
@ -348,7 +348,7 @@ internal class ObuWriter
} }
int diffLength = sequenceHeader.DeltaFrameIdLength; int diffLength = sequenceHeader.DeltaFrameIdLength;
for (int i = 0; i < ObuConstants.ReferenceFrameCount; i++) for (int i = 0; i < Av1Constants.ReferenceFrameCount; i++)
{ {
if (frameInfo.CurrentFrameId > (1U << diffLength)) if (frameInfo.CurrentFrameId > (1U << diffLength))
{ {
@ -370,7 +370,7 @@ internal class ObuWriter
if (!isIntraFrame && !frameInfo.ErrorResilientMode) if (!isIntraFrame && !frameInfo.ErrorResilientMode)
{ {
writer.WriteLiteral(frameInfo.PrimaryReferenceFrame, ObuConstants.PimaryReferenceBits); writer.WriteLiteral(frameInfo.PrimaryReferenceFrame, Av1Constants.PimaryReferenceBits);
} }
// Skipping, as no decoder info model present // Skipping, as no decoder info model present
@ -395,7 +395,7 @@ internal class ObuWriter
} }
} }
if (frameInfo.PrimaryReferenceFrame == ObuConstants.PrimaryReferenceFrameNone) if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone)
{ {
SetupPastIndependence(frameInfo); SetupPastIndependence(frameInfo);
} }
@ -436,7 +436,7 @@ internal class ObuWriter
{ {
int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer]; int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer];
int qIndex = baseQIndex + data; int qIndex = baseQIndex + data;
return Av1Math.Clamp(qIndex, 0, ObuConstants.MaxQ); return Av1Math.Clamp(qIndex, 0, Av1Constants.MaxQ);
} }
else else
{ {

44
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs

@ -59,7 +59,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
this.superblockColumnCount = superblockAlignedWidth >> superblockSizeLog2; this.superblockColumnCount = superblockAlignedWidth >> superblockSizeLog2;
this.superblockRowCount = superblockAlignedHeight >> superblockSizeLog2; this.superblockRowCount = superblockAlignedHeight >> superblockSizeLog2;
int superblockCount = this.superblockColumnCount * this.superblockRowCount; int superblockCount = this.superblockColumnCount * this.superblockRowCount;
this.numModeInfosInSuperblock = (1 << (superblockSizeLog2 - ObuConstants.ModeInfoSizeLog2)) * (1 << (superblockSizeLog2 - ObuConstants.ModeInfoSizeLog2)); this.numModeInfosInSuperblock = (1 << (superblockSizeLog2 - Av1Constants.ModeInfoSizeLog2)) * (1 << (superblockSizeLog2 - Av1Constants.ModeInfoSizeLog2));
this.superblockInfos = new Av1SuperblockInfo[superblockCount]; this.superblockInfos = new Av1SuperblockInfo[superblockCount];
this.modeInfos = new Av1BlockModeInfo[superblockCount * this.numModeInfosInSuperblock]; this.modeInfos = new Av1BlockModeInfo[superblockCount * this.numModeInfosInSuperblock];
@ -75,7 +75,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
this.deltaQ = new int[superblockCount]; this.deltaQ = new int[superblockCount];
this.cdefStrength = new int[superblockCount * (this.SequenceHeader.Use128x128SuperBlock ? 4 : 1)]; this.cdefStrength = new int[superblockCount * (this.SequenceHeader.Use128x128SuperBlock ? 4 : 1)];
Array.Fill(this.cdefStrength, -1); Array.Fill(this.cdefStrength, -1);
this.deltaLoopFilter = new int[superblockCount * ObuConstants.FrameLoopFilterCount]; this.deltaLoopFilter = new int[superblockCount * Av1Constants.FrameLoopFilterCount];
} }
public bool SequenceHeaderDone { get; set; } public bool SequenceHeaderDone { get; set; }
@ -108,7 +108,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
this.referenceLrWiener[plane] = new int[2][]; this.referenceLrWiener[plane] = new int[2][];
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
this.referenceLrWiener[plane][pass] = new int[ObuConstants.WienerCoefficientCount]; this.referenceLrWiener[plane][pass] = new int[Av1Constants.WienerCoefficientCount];
Array.Copy(WienerTapsMid, this.referenceLrWiener[plane][pass], WienerTapsMid.Length); Array.Copy(WienerTapsMid, this.referenceLrWiener[plane][pass], WienerTapsMid.Length);
} }
} }
@ -117,11 +117,11 @@ internal class Av1TileDecoder : IAv1TileDecoder
int superBlock4x4Size = superBlockSize.Get4x4WideCount(); int superBlock4x4Size = superBlockSize.Get4x4WideCount();
for (int row = this.TileInfo.TileRowStartModeInfo[tileRowIndex]; row < this.TileInfo.TileRowStartModeInfo[tileRowIndex + 1]; row += this.SequenceHeader.ModeInfoSize) for (int row = this.TileInfo.TileRowStartModeInfo[tileRowIndex]; row < this.TileInfo.TileRowStartModeInfo[tileRowIndex + 1]; row += this.SequenceHeader.ModeInfoSize)
{ {
int superBlockRow = row << ObuConstants.ModeInfoSizeLog2 >> this.SequenceHeader.SuperBlockSizeLog2; int superBlockRow = row << Av1Constants.ModeInfoSizeLog2 >> this.SequenceHeader.SuperBlockSizeLog2;
this.leftContext.Clear(); this.leftContext.Clear();
for (int column = this.TileInfo.TileColumnStartModeInfo[tileColumnIndex]; column < this.TileInfo.TileColumnStartModeInfo[tileColumnIndex + 1]; column += this.SequenceHeader.ModeInfoSize) for (int column = this.TileInfo.TileColumnStartModeInfo[tileColumnIndex]; column < this.TileInfo.TileColumnStartModeInfo[tileColumnIndex + 1]; column += this.SequenceHeader.ModeInfoSize)
{ {
int superBlockColumn = column << ObuConstants.ModeInfoSizeLog2 >> this.SequenceHeader.SuperBlockSizeLog2; int superBlockColumn = column << Av1Constants.ModeInfoSizeLog2 >> this.SequenceHeader.SuperBlockSizeLog2;
bool subSamplingX = this.SequenceHeader.ColorConfig.SubSamplingX; bool subSamplingX = this.SequenceHeader.ColorConfig.SubSamplingX;
bool subSamplingY = this.SequenceHeader.ColorConfig.SubSamplingY; bool subSamplingY = this.SequenceHeader.ColorConfig.SubSamplingY;
@ -137,7 +137,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
CoefficientsU = this.coefficientsU, CoefficientsU = this.coefficientsU,
CoefficientsV = this.coefficientsV, CoefficientsV = this.coefficientsV,
CdefStrength = this.cdefStrength[superblockIndex * cdefFactor], CdefStrength = this.cdefStrength[superblockIndex * cdefFactor],
SuperblockDeltaLoopFilter = this.deltaLoopFilter[ObuConstants.FrameLoopFilterCount * superblockIndex], SuperblockDeltaLoopFilter = this.deltaLoopFilter[Av1Constants.FrameLoopFilterCount * superblockIndex],
SuperblockDeltaQ = this.deltaQ[superblockIndex] SuperblockDeltaQ = this.deltaQ[superblockIndex]
}; };
@ -415,10 +415,10 @@ internal class Av1TileDecoder : IAv1TileDecoder
int num4x4Height = planeSize.Get4x4HighCount(); int num4x4Height = planeSize.Get4x4HighCount();
int subX = plane > 0 && subsamplingX ? 1 : 0; int subX = plane > 0 && subsamplingX ? 1 : 0;
int subY = plane > 0 && subsamplingY ? 1 : 0; int subY = plane > 0 && subsamplingY ? 1 : 0;
int baseX = (columnChunk >> subX) * (1 << ObuConstants.ModeInfoSizeLog2); int baseX = (columnChunk >> subX) * (1 << Av1Constants.ModeInfoSizeLog2);
int baseY = (rowChunk >> subY) * (1 << ObuConstants.ModeInfoSizeLog2); int baseY = (rowChunk >> subY) * (1 << Av1Constants.ModeInfoSizeLog2);
int baseXBlock = (columnIndex >> subX) * (1 << ObuConstants.ModeInfoSizeLog2); int baseXBlock = (columnIndex >> subX) * (1 << Av1Constants.ModeInfoSizeLog2);
int baseYBlock = (rowIndex >> subY) * (1 << ObuConstants.ModeInfoSizeLog2); int baseYBlock = (rowIndex >> subY) * (1 << Av1Constants.ModeInfoSizeLog2);
for (int y = 0; y < num4x4Height; y += stepY) for (int y = 0; y < num4x4Height; y += stepY)
{ {
for (int x = 0; x < num4x4Width; x += stepX) for (int x = 0; x < num4x4Width; x += stepX)
@ -455,15 +455,15 @@ internal class Av1TileDecoder : IAv1TileDecoder
bool subsamplingY = this.SequenceHeader.ColorConfig.SubSamplingY; bool subsamplingY = this.SequenceHeader.ColorConfig.SubSamplingY;
int subX = plane > 0 && subsamplingX ? 1 : 0; int subX = plane > 0 && subsamplingX ? 1 : 0;
int subY = plane > 0 && subsamplingY ? 1 : 0; int subY = plane > 0 && subsamplingY ? 1 : 0;
int columnIndex = startX << subX >> ObuConstants.ModeInfoSizeLog2; int columnIndex = startX << subX >> Av1Constants.ModeInfoSizeLog2;
int rowIndex = startY << subY >> ObuConstants.ModeInfoSizeLog2; int rowIndex = startY << subY >> Av1Constants.ModeInfoSizeLog2;
int superBlockMask = this.SequenceHeader.Use128x128SuperBlock ? 31 : 15; int superBlockMask = this.SequenceHeader.Use128x128SuperBlock ? 31 : 15;
int subBlockColumn = columnIndex & superBlockMask; int subBlockColumn = columnIndex & superBlockMask;
int subBlockRow = rowIndex & superBlockMask; int subBlockRow = rowIndex & superBlockMask;
int stepX = transformSize.GetWidth() >> ObuConstants.ModeInfoSizeLog2; int stepX = transformSize.GetWidth() >> Av1Constants.ModeInfoSizeLog2;
int stepY = transformSize.GetHeight() >> ObuConstants.ModeInfoSizeLog2; int stepY = transformSize.GetHeight() >> Av1Constants.ModeInfoSizeLog2;
int maxX = (this.SequenceHeader.ModeInfoSize * (1 << ObuConstants.ModeInfoSizeLog2)) >> subX; int maxX = (this.SequenceHeader.ModeInfoSize * (1 << Av1Constants.ModeInfoSizeLog2)) >> subX;
int maxY = (this.SequenceHeader.ModeInfoSize * (1 << ObuConstants.ModeInfoSizeLog2)) >> subY; int maxY = (this.SequenceHeader.ModeInfoSize * (1 << Av1Constants.ModeInfoSizeLog2)) >> subY;
if (startX >= maxX || startY >= maxY) if (startX >= maxX || startY >= maxY)
{ {
return; return;
@ -724,7 +724,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
if (blockSize >= Av1BlockSize.Block8x8 && IsDirectionalMode(mode)) if (blockSize >= Av1BlockSize.Block8x8 && IsDirectionalMode(mode))
{ {
int symbol = reader.ReadAngleDelta(mode); int symbol = reader.ReadAngleDelta(mode);
angleDelta = symbol - ObuConstants.MaxAngleDelta; angleDelta = symbol - Av1Constants.MaxAngleDelta;
} }
return angleDelta; return angleDelta;
@ -811,7 +811,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
int bh4 = partitionInfo.ModeInfo.BlockSize.Get4x4HighCount(); int bh4 = partitionInfo.ModeInfo.BlockSize.Get4x4HighCount();
int xMin = Math.Min(this.FrameInfo.ModeInfoColumnCount - columnIndex, bw4); int xMin = Math.Min(this.FrameInfo.ModeInfoColumnCount - columnIndex, bw4);
int yMin = Math.Min(this.FrameInfo.ModeInfoRowCount - rowIndex, bh4); int yMin = Math.Min(this.FrameInfo.ModeInfoRowCount - rowIndex, bh4);
int segmentId = ObuConstants.MaxSegments - 1; int segmentId = Av1Constants.MaxSegments - 1;
for (int y = 0; y < yMin; y++) for (int y = 0; y < yMin; y++)
{ {
for (int x = 0; x < xMin; x++) for (int x = 0; x < xMin; x++)
@ -912,13 +912,13 @@ internal class Av1TileDecoder : IAv1TileDecoder
int frameLoopFilterCount = 1; int frameLoopFilterCount = 1;
if (this.FrameInfo.DeltaLoopFilterParameters.Multi) if (this.FrameInfo.DeltaLoopFilterParameters.Multi)
{ {
frameLoopFilterCount = this.SequenceHeader.ColorConfig.ChannelCount > 1 ? ObuConstants.FrameLoopFilterCount : ObuConstants.FrameLoopFilterCount - 2; frameLoopFilterCount = this.SequenceHeader.ColorConfig.ChannelCount > 1 ? Av1Constants.FrameLoopFilterCount : Av1Constants.FrameLoopFilterCount - 2;
} }
for (int i = 0; i < frameLoopFilterCount; i++) for (int i = 0; i < frameLoopFilterCount; i++)
{ {
int deltaLoopFilterAbsolute = reader.ReadDeltaLoopFilterAbsolute(); int deltaLoopFilterAbsolute = reader.ReadDeltaLoopFilterAbsolute();
if (deltaLoopFilterAbsolute == ObuConstants.DeltaLoopFilterSmall) if (deltaLoopFilterAbsolute == Av1Constants.DeltaLoopFilterSmall)
{ {
int deltaLoopFilterRemainingBits = reader.ReadLiteral(3) + 1; int deltaLoopFilterRemainingBits = reader.ReadLiteral(3) + 1;
int deltaLoopFilterAbsoluteBitCount = reader.ReadLiteral(deltaLoopFilterRemainingBits); int deltaLoopFilterAbsoluteBitCount = reader.ReadLiteral(deltaLoopFilterRemainingBits);
@ -929,7 +929,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
{ {
bool deltaLoopFilterSign = reader.ReadLiteral(1) > 0; bool deltaLoopFilterSign = reader.ReadLiteral(1) > 0;
int reducedDeltaLoopFilterLevel = deltaLoopFilterSign ? -deltaLoopFilterAbsolute : deltaLoopFilterAbsolute; int reducedDeltaLoopFilterLevel = deltaLoopFilterSign ? -deltaLoopFilterAbsolute : deltaLoopFilterAbsolute;
this.deltaLoopFilter[i] = Av1Math.Clip3(-ObuConstants.MaxLoopFilter, ObuConstants.MaxLoopFilter, this.deltaLoopFilter[i] + (reducedDeltaLoopFilterLevel << this.deltaLoopFilterResolution)); this.deltaLoopFilter[i] = Av1Math.Clip3(-Av1Constants.MaxLoopFilter, Av1Constants.MaxLoopFilter, this.deltaLoopFilter[i] + (reducedDeltaLoopFilterLevel << this.deltaLoopFilterResolution));
} }
} }
} }
@ -963,7 +963,7 @@ internal class Av1TileDecoder : IAv1TileDecoder
if (partitionInfo.ModeInfo.BlockSize != this.SequenceHeader.SuperBlockSize || !partitionInfo.ModeInfo.Skip) if (partitionInfo.ModeInfo.BlockSize != this.SequenceHeader.SuperBlockSize || !partitionInfo.ModeInfo.Skip)
{ {
int deltaQuantizerAbsolute = reader.ReadDeltaQuantizerAbsolute(); int deltaQuantizerAbsolute = reader.ReadDeltaQuantizerAbsolute();
if (deltaQuantizerAbsolute == ObuConstants.DeltaQuantizerSmall) if (deltaQuantizerAbsolute == Av1Constants.DeltaQuantizerSmall)
{ {
int deltaQuantizerRemainingBits = reader.ReadLiteral(3) + 1; int deltaQuantizerRemainingBits = reader.ReadLiteral(3) + 1;
int deltaQuantizerAbsoluteBitCount = reader.ReadLiteral(deltaQuantizerRemainingBits); int deltaQuantizerAbsoluteBitCount = reader.ReadLiteral(deltaQuantizerRemainingBits);

Loading…
Cancel
Save