From a8539f24b9b240ccb52a78c07fe6c4a7fadd936c Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Mon, 3 Jun 2024 21:33:56 +0200 Subject: [PATCH] Rename Av1Constants class --- .../ObuConstants.cs => Av1Constants.cs} | 6 +-- .../Av1/OpenBitstreamUnit/ObuFrameHeader.cs | 10 ++-- .../ObuQuantizationParameters.cs | 2 +- .../Heif/Av1/OpenBitstreamUnit/ObuReader.cs | 52 +++++++++---------- .../ObuSegmentationParameters.cs | 6 +-- .../Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs | 4 +- .../Heif/Av1/OpenBitstreamUnit/ObuWriter.cs | 24 ++++----- .../Formats/Heif/Av1/Tiling/Av1TileDecoder.cs | 44 ++++++++-------- 8 files changed, 74 insertions(+), 74 deletions(-) rename src/ImageSharp/Formats/Heif/Av1/{OpenBitstreamUnit/ObuConstants.cs => Av1Constants.cs} (95%) diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuConstants.cs b/src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs similarity index 95% rename from src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuConstants.cs rename to src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs index d3d2194a2e..d83389d9dc 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuConstants.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Av1Constants.cs @@ -1,11 +1,11 @@ // Copyright (c) Six Labors. // 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; diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs index 7ebca0c235..f3f7e957dd 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuFrameHeader.cs @@ -19,7 +19,7 @@ internal class ObuFrameHeader 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(); @@ -63,9 +63,9 @@ internal class ObuFrameHeader 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; } @@ -79,11 +79,11 @@ internal class ObuFrameHeader 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 PrimaryReferenceFrame { get; set; } = ObuConstants.PrimaryReferenceFrameNone; + internal uint PrimaryReferenceFrame { get; set; } = Av1Constants.PrimaryReferenceFrameNone; internal uint RefreshFrameFlags { get; set; } } diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs index 53aa1c88bb..58aa3d6316 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuQuantizationParameters.cs @@ -7,7 +7,7 @@ internal class ObuQuantizationParameters { 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; } diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs index fcae54d647..1a90eaebfc 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs @@ -197,7 +197,7 @@ internal class ObuReader { frameInfo.ModeInfoColumnCount = 2 * ((frameInfo.FrameSize.FrameWidth + 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 @@ -211,7 +211,7 @@ internal class ObuReader private static void ReadSequenceHeader(ref Av1BitStreamReader reader, ObuSequenceHeader sequenceHeader) { sequenceHeader.SequenceProfile = (ObuSequenceProfile)reader.ReadLiteral(3); - if (sequenceHeader.SequenceProfile > ObuConstants.MaxSequenceProfile) + if (sequenceHeader.SequenceProfile > Av1Constants.MaxSequenceProfile) { throw new ImageFormatException("Unknown sequence profile."); } @@ -230,7 +230,7 @@ internal class ObuReader ObuOperatingPoint operatingPoint = new(); sequenceHeader.OperatingPoint[0] = operatingPoint; operatingPoint.OperatorIndex = 0; - operatingPoint.SequenceLevelIndex = (int)reader.ReadLiteral(ObuConstants.LevelBits); + operatingPoint.SequenceLevelIndex = (int)reader.ReadLiteral(Av1Constants.LevelBits); if (!IsValidSequenceLevel(sequenceHeader.OperatingPoint[0].SequenceLevelIndex)) { throw new ImageFormatException("Invalid sequence level."); @@ -388,20 +388,20 @@ internal class ObuReader if (useSuperResolution) { - frameInfo.FrameSize.SuperResolutionDenominator = (int)reader.ReadLiteral(ObuConstants.SuperResolutionScaleBits) + ObuConstants.SuperResolutionScaleDenominatorMinimum; + frameInfo.FrameSize.SuperResolutionDenominator = (int)reader.ReadLiteral(Av1Constants.SuperResolutionScaleBits) + Av1Constants.SuperResolutionScaleDenominatorMinimum; } else { - frameInfo.FrameSize.SuperResolutionDenominator = ObuConstants.ScaleNumerator; + frameInfo.FrameSize.SuperResolutionDenominator = Av1Constants.ScaleNumerator; } frameInfo.FrameSize.SuperResolutionUpscaledWidth = frameInfo.FrameSize.FrameWidth; frameInfo.FrameSize.FrameWidth = - ((frameInfo.FrameSize.SuperResolutionUpscaledWidth * ObuConstants.ScaleNumerator) + + ((frameInfo.FrameSize.SuperResolutionUpscaledWidth * Av1Constants.ScaleNumerator) + (frameInfo.FrameSize.SuperResolutionDenominator / 2)) / frameInfo.FrameSize.SuperResolutionDenominator; - if (frameInfo.FrameSize.SuperResolutionDenominator != ObuConstants.ScaleNumerator) + if (frameInfo.FrameSize.SuperResolutionDenominator != Av1Constants.ScaleNumerator) { int manWidth = Math.Min(16, frameInfo.FrameSize.SuperResolutionUpscaledWidth); 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) { bool foundReference = false; - for (int i = 0; i < ObuConstants.ReferencesPerFrame; i++) + for (int i = 0; i < Av1Constants.ReferencesPerFrame; i++) { foundReference = reader.ReadBoolean(); if (foundReference) @@ -485,13 +485,13 @@ internal class ObuReader } int superBlockSize = superBlockShift + 2; - int maxTileAreaOfSuperBlock = ObuConstants.MaxTileArea >> (2 * superBlockSize); + int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize); - tileInfo.MaxTileWidthSuperBlock = ObuConstants.MaxTileWidth >> superBlockSize; - tileInfo.MaxTileHeightSuperBlock = (ObuConstants.MaxTileArea / ObuConstants.MaxTileWidth) >> superBlockSize; + tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superBlockSize; + tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superBlockSize; tileInfo.MinLog2TileColumnCount = TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount); - tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superBlockColumnCount, ObuConstants.MaxTileColumnCount)); - tileInfo.MaxLog2TileRowCount = TileLog2(1, Math.Min(superBlockRowCount, ObuConstants.MaxTileRowCount)); + tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superBlockColumnCount, Av1Constants.MaxTileColumnCount)); + tileInfo.MaxLog2TileRowCount = TileLog2(1, Math.Min(superBlockRowCount, Av1Constants.MaxTileRowCount)); tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount)); tileInfo.HasUniformTileSpacing = reader.ReadBoolean(); if (tileInfo.HasUniformTileSpacing) @@ -610,7 +610,7 @@ internal class ObuReader 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."); } @@ -659,9 +659,9 @@ internal class ObuReader if (frameInfo.FrameType == ObuFrameType.KeyFrame && frameInfo.ShowFrame) { - frameInfo.ReferenceValid = new bool[ObuConstants.ReferenceFrameCount]; - frameInfo.ReferenceOrderHint = new bool[ObuConstants.ReferenceFrameCount]; - for (int i = 0; i < ObuConstants.ReferenceFrameCount; i++) + frameInfo.ReferenceValid = new bool[Av1Constants.ReferenceFrameCount]; + frameInfo.ReferenceOrderHint = new bool[Av1Constants.ReferenceFrameCount]; + for (int i = 0; i < Av1Constants.ReferenceFrameCount; i++) { frameInfo.ReferenceValid[i] = false; frameInfo.ReferenceOrderHint[i] = false; @@ -717,7 +717,7 @@ internal class ObuReader } 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)) { @@ -756,11 +756,11 @@ internal class ObuReader if (isIntraFrame || frameInfo.ErrorResilientMode) { - frameInfo.PrimaryReferenceFrame = ObuConstants.PrimaryReferenceFrameNone; + frameInfo.PrimaryReferenceFrame = Av1Constants.PrimaryReferenceFrameNone; } else { - frameInfo.PrimaryReferenceFrame = reader.ReadLiteral(ObuConstants.PimaryReferenceBits); + frameInfo.PrimaryReferenceFrame = reader.ReadLiteral(Av1Constants.PimaryReferenceBits); } // Skipping, as no decoder info model present @@ -785,7 +785,7 @@ internal class ObuReader { 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); if (referenceOrderHint != (frameInfo.ReferenceOrderHint[i] ? 1U : 0U)) @@ -822,7 +822,7 @@ internal class ObuReader frameInfo.DisableFrameEndUpdateCdf = true; } - if (frameInfo.PrimaryReferenceFrame == ObuConstants.PrimaryReferenceFrameNone) + if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone) { SetupPastIndependence(frameInfo); } @@ -836,14 +836,14 @@ internal class ObuReader // SetupSegmentationDequantization(); Av1MainParseContext mainParseContext = new(); - if (frameInfo.PrimaryReferenceFrame == ObuConstants.PrimaryReferenceFrameNone) + if (frameInfo.PrimaryReferenceFrame == Av1Constants.PrimaryReferenceFrameNone) { // ResetParseContext(mainParseContext, frameInfo.QuantizationParameters.BaseQIndex); } int tilesCount = frameInfo.TilesInfo.TileColumnCount * frameInfo.TilesInfo.TileRowCount; 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); frameInfo.QuantizationParameters.QIndex[segmentId] = qIndex; @@ -907,7 +907,7 @@ internal class ObuReader { int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer]; int qIndex = baseQIndex + data; - return Av1Math.Clamp(qIndex, 0, ObuConstants.MaxQ); + return Av1Math.Clamp(qIndex, 0, Av1Constants.MaxQ); } 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; if (sequenceHeader.ColorConfig.SubSamplingX && sequenceHeader.ColorConfig.SubSamplingY && usesChromaLoopRestoration) { diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs index c74a698b2f..64624e8535 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuSegmentationParameters.cs @@ -5,13 +5,13 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; 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 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; } diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs index ac5379f88a..b995713d8a 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileInfo.cs @@ -23,13 +23,13 @@ internal class ObuTileInfo 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 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; } diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs index 45a05653d8..00346743f8 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs @@ -82,7 +82,7 @@ internal class ObuWriter writer.WriteLiteral((uint)sequenceHeader.SequenceProfile, 3); writer.WriteBoolean(true); // IsStillPicture 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 writer.WriteLiteral((uint)sequenceHeader.FrameWidthBits - 1, 4); @@ -168,7 +168,7 @@ internal class ObuWriter 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) { bool foundReference = false; - for (int i = 0; i < ObuConstants.ReferencesPerFrame; i++) + for (int i = 0; i < Av1Constants.ReferencesPerFrame; i++) { writer.WriteBoolean(foundReference); if (foundReference) @@ -237,13 +237,13 @@ internal class ObuWriter } int superBlockSize = superBlockShift + 2; - int maxTileAreaOfSuperBlock = ObuConstants.MaxTileArea >> (2 * superBlockSize); + int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize); - tileInfo.MaxTileWidthSuperBlock = ObuConstants.MaxTileWidth >> superBlockSize; - tileInfo.MaxTileHeightSuperBlock = (ObuConstants.MaxTileArea / ObuConstants.MaxTileWidth) >> superBlockSize; + tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superBlockSize; + tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superBlockSize; tileInfo.MinLog2TileColumnCount = ObuReader.TileLog2(tileInfo.MaxTileWidthSuperBlock, superBlockColumnCount); - tileInfo.MaxLog2TileColumnCount = ObuReader.TileLog2(1, Math.Min(superBlockColumnCount, ObuConstants.MaxTileColumnCount)); - tileInfo.MaxLog2TileRowCount = ObuReader.TileLog2(1, Math.Min(superBlockRowCount, ObuConstants.MaxTileRowCount)); + tileInfo.MaxLog2TileColumnCount = ObuReader.TileLog2(1, Math.Min(superBlockColumnCount, Av1Constants.MaxTileColumnCount)); + tileInfo.MaxLog2TileRowCount = ObuReader.TileLog2(1, Math.Min(superBlockRowCount, Av1Constants.MaxTileRowCount)); tileInfo.MinLog2TileCount = Math.Max(tileInfo.MinLog2TileColumnCount, ObuReader.TileLog2(maxTileAreaOfSuperBlock, superBlockColumnCount * superBlockRowCount)); writer.WriteBoolean(tileInfo.HasUniformTileSpacing); @@ -348,7 +348,7 @@ internal class ObuWriter } 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)) { @@ -370,7 +370,7 @@ internal class ObuWriter if (!isIntraFrame && !frameInfo.ErrorResilientMode) { - writer.WriteLiteral(frameInfo.PrimaryReferenceFrame, ObuConstants.PimaryReferenceBits); + writer.WriteLiteral(frameInfo.PrimaryReferenceFrame, Av1Constants.PimaryReferenceBits); } // 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); } @@ -436,7 +436,7 @@ internal class ObuWriter { int data = segmentationParameters.FeatureData[segmentId, (int)ObuSegmentationLevelFeature.AlternativeQuantizer]; int qIndex = baseQIndex + data; - return Av1Math.Clamp(qIndex, 0, ObuConstants.MaxQ); + return Av1Math.Clamp(qIndex, 0, Av1Constants.MaxQ); } else { diff --git a/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs b/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs index 46f682db75..2be0110be9 100644 --- a/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileDecoder.cs @@ -59,7 +59,7 @@ internal class Av1TileDecoder : IAv1TileDecoder this.superblockColumnCount = superblockAlignedWidth >> superblockSizeLog2; this.superblockRowCount = superblockAlignedHeight >> superblockSizeLog2; 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.modeInfos = new Av1BlockModeInfo[superblockCount * this.numModeInfosInSuperblock]; @@ -75,7 +75,7 @@ internal class Av1TileDecoder : IAv1TileDecoder this.deltaQ = new int[superblockCount]; this.cdefStrength = new int[superblockCount * (this.SequenceHeader.Use128x128SuperBlock ? 4 : 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; } @@ -108,7 +108,7 @@ internal class Av1TileDecoder : IAv1TileDecoder this.referenceLrWiener[plane] = new int[2][]; 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); } } @@ -117,11 +117,11 @@ internal class Av1TileDecoder : IAv1TileDecoder int superBlock4x4Size = superBlockSize.Get4x4WideCount(); 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(); 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 subSamplingY = this.SequenceHeader.ColorConfig.SubSamplingY; @@ -137,7 +137,7 @@ internal class Av1TileDecoder : IAv1TileDecoder CoefficientsU = this.coefficientsU, CoefficientsV = this.coefficientsV, CdefStrength = this.cdefStrength[superblockIndex * cdefFactor], - SuperblockDeltaLoopFilter = this.deltaLoopFilter[ObuConstants.FrameLoopFilterCount * superblockIndex], + SuperblockDeltaLoopFilter = this.deltaLoopFilter[Av1Constants.FrameLoopFilterCount * superblockIndex], SuperblockDeltaQ = this.deltaQ[superblockIndex] }; @@ -415,10 +415,10 @@ internal class Av1TileDecoder : IAv1TileDecoder int num4x4Height = planeSize.Get4x4HighCount(); int subX = plane > 0 && subsamplingX ? 1 : 0; int subY = plane > 0 && subsamplingY ? 1 : 0; - int baseX = (columnChunk >> subX) * (1 << ObuConstants.ModeInfoSizeLog2); - int baseY = (rowChunk >> subY) * (1 << ObuConstants.ModeInfoSizeLog2); - int baseXBlock = (columnIndex >> subX) * (1 << ObuConstants.ModeInfoSizeLog2); - int baseYBlock = (rowIndex >> subY) * (1 << ObuConstants.ModeInfoSizeLog2); + int baseX = (columnChunk >> subX) * (1 << Av1Constants.ModeInfoSizeLog2); + int baseY = (rowChunk >> subY) * (1 << Av1Constants.ModeInfoSizeLog2); + int baseXBlock = (columnIndex >> subX) * (1 << Av1Constants.ModeInfoSizeLog2); + int baseYBlock = (rowIndex >> subY) * (1 << Av1Constants.ModeInfoSizeLog2); for (int y = 0; y < num4x4Height; y += stepY) { for (int x = 0; x < num4x4Width; x += stepX) @@ -455,15 +455,15 @@ internal class Av1TileDecoder : IAv1TileDecoder bool subsamplingY = this.SequenceHeader.ColorConfig.SubSamplingY; int subX = plane > 0 && subsamplingX ? 1 : 0; int subY = plane > 0 && subsamplingY ? 1 : 0; - int columnIndex = startX << subX >> ObuConstants.ModeInfoSizeLog2; - int rowIndex = startY << subY >> ObuConstants.ModeInfoSizeLog2; + int columnIndex = startX << subX >> Av1Constants.ModeInfoSizeLog2; + int rowIndex = startY << subY >> Av1Constants.ModeInfoSizeLog2; int superBlockMask = this.SequenceHeader.Use128x128SuperBlock ? 31 : 15; int subBlockColumn = columnIndex & superBlockMask; int subBlockRow = rowIndex & superBlockMask; - int stepX = transformSize.GetWidth() >> ObuConstants.ModeInfoSizeLog2; - int stepY = transformSize.GetHeight() >> ObuConstants.ModeInfoSizeLog2; - int maxX = (this.SequenceHeader.ModeInfoSize * (1 << ObuConstants.ModeInfoSizeLog2)) >> subX; - int maxY = (this.SequenceHeader.ModeInfoSize * (1 << ObuConstants.ModeInfoSizeLog2)) >> subY; + int stepX = transformSize.GetWidth() >> Av1Constants.ModeInfoSizeLog2; + int stepY = transformSize.GetHeight() >> Av1Constants.ModeInfoSizeLog2; + int maxX = (this.SequenceHeader.ModeInfoSize * (1 << Av1Constants.ModeInfoSizeLog2)) >> subX; + int maxY = (this.SequenceHeader.ModeInfoSize * (1 << Av1Constants.ModeInfoSizeLog2)) >> subY; if (startX >= maxX || startY >= maxY) { return; @@ -724,7 +724,7 @@ internal class Av1TileDecoder : IAv1TileDecoder if (blockSize >= Av1BlockSize.Block8x8 && IsDirectionalMode(mode)) { int symbol = reader.ReadAngleDelta(mode); - angleDelta = symbol - ObuConstants.MaxAngleDelta; + angleDelta = symbol - Av1Constants.MaxAngleDelta; } return angleDelta; @@ -811,7 +811,7 @@ internal class Av1TileDecoder : IAv1TileDecoder int bh4 = partitionInfo.ModeInfo.BlockSize.Get4x4HighCount(); int xMin = Math.Min(this.FrameInfo.ModeInfoColumnCount - columnIndex, bw4); 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 x = 0; x < xMin; x++) @@ -912,13 +912,13 @@ internal class Av1TileDecoder : IAv1TileDecoder int frameLoopFilterCount = 1; 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++) { int deltaLoopFilterAbsolute = reader.ReadDeltaLoopFilterAbsolute(); - if (deltaLoopFilterAbsolute == ObuConstants.DeltaLoopFilterSmall) + if (deltaLoopFilterAbsolute == Av1Constants.DeltaLoopFilterSmall) { int deltaLoopFilterRemainingBits = reader.ReadLiteral(3) + 1; int deltaLoopFilterAbsoluteBitCount = reader.ReadLiteral(deltaLoopFilterRemainingBits); @@ -929,7 +929,7 @@ internal class Av1TileDecoder : IAv1TileDecoder { bool deltaLoopFilterSign = reader.ReadLiteral(1) > 0; 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) { int deltaQuantizerAbsolute = reader.ReadDeltaQuantizerAbsolute(); - if (deltaQuantizerAbsolute == ObuConstants.DeltaQuantizerSmall) + if (deltaQuantizerAbsolute == Av1Constants.DeltaQuantizerSmall) { int deltaQuantizerRemainingBits = reader.ReadLiteral(3) + 1; int deltaQuantizerAbsoluteBitCount = reader.ReadLiteral(deltaQuantizerRemainingBits);