Browse Source

More Superblock renaming

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
4e1aca91b8
  1. 1
      src/ImageSharp/Formats/Heif/Av1/Av1Math.cs
  2. 30
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs
  3. 4
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuTileGroupHeader.cs
  4. 10
      src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs

1
src/ImageSharp/Formats/Heif/Av1/Av1Math.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Heif.Av1; namespace SixLabors.ImageSharp.Formats.Heif.Av1;
internal static class Av1Math internal static class Av1Math

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

@ -703,9 +703,9 @@ internal class ObuReader
int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (superblockSizeLog2 << 1); int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (superblockSizeLog2 << 1);
tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superblockSizeLog2; tileInfo.MaxTileWidthSuperblock = Av1Constants.MaxTileWidth >> superblockSizeLog2;
tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superblockSizeLog2; tileInfo.MaxTileHeightSuperblock = (Av1Constants.MaxTileArea / Av1Constants.MaxTileWidth) >> superblockSizeLog2;
tileInfo.MinLog2TileColumnCount = TileLog2(tileInfo.MaxTileWidthSuperBlock, superblockColumnCount); tileInfo.MinLog2TileColumnCount = TileLog2(tileInfo.MaxTileWidthSuperblock, superblockColumnCount);
tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superblockColumnCount, Av1Constants.MaxTileColumnCount)); tileInfo.MaxLog2TileColumnCount = TileLog2(1, Math.Min(superblockColumnCount, Av1Constants.MaxTileColumnCount));
tileInfo.MaxLog2TileRowCount = TileLog2(1, Math.Min(superblockRowCount, Av1Constants.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));
@ -726,12 +726,12 @@ internal class ObuReader
} }
int tileWidthSuperblock = Av1Math.DivideLog2Ceiling(superblockColumnCount, tileInfo.TileColumnCountLog2); int tileWidthSuperblock = Av1Math.DivideLog2Ceiling(superblockColumnCount, tileInfo.TileColumnCountLog2);
DebugGuard.MustBeLessThanOrEqualTo(tileWidthSuperblock, tileInfo.MaxTileWidthSuperBlock, nameof(tileWidthSuperblock)); DebugGuard.MustBeLessThanOrEqualTo(tileWidthSuperblock, tileInfo.MaxTileWidthSuperblock, nameof(tileWidthSuperblock));
int i = 0; int i = 0;
tileInfo.TileColumnStartModeInfo = new int[superblockColumnCount + 1]; tileInfo.TileColumnStartModeInfo = new int[superblockColumnCount + 1];
for (int startSuperBlock = 0; startSuperBlock < superblockColumnCount; startSuperBlock += tileWidthSuperblock) for (int startSuperblock = 0; startSuperblock < superblockColumnCount; startSuperblock += tileWidthSuperblock)
{ {
tileInfo.TileColumnStartModeInfo[i] = startSuperBlock << superblockShift; tileInfo.TileColumnStartModeInfo[i] = startSuperblock << superblockShift;
i++; i++;
} }
@ -752,17 +752,13 @@ internal class ObuReader
} }
} }
int tileHeightSuperBlock = Av1Math.DivideLog2Ceiling(superblockRowCount, tileInfo.TileRowCountLog2); int tileHeightSuperblock = Av1Math.DivideLog2Ceiling(superblockRowCount, tileInfo.TileRowCountLog2);
if (tileHeightSuperBlock > tileInfo.MaxTileHeightSuperBlock) DebugGuard.MustBeLessThanOrEqualTo(tileHeightSuperblock, tileInfo.MaxTileHeightSuperblock, nameof(tileHeightSuperblock));
{
throw new ImageFormatException("Invalid tile height specified.");
}
i = 0; i = 0;
tileInfo.TileRowStartModeInfo = new int[superblockRowCount + 1]; tileInfo.TileRowStartModeInfo = new int[superblockRowCount + 1];
for (int startSuperBlock = 0; startSuperBlock < superblockRowCount; startSuperBlock += tileHeightSuperBlock) for (int startSuperblock = 0; startSuperblock < superblockRowCount; startSuperblock += tileHeightSuperblock)
{ {
tileInfo.TileRowStartModeInfo[i] = startSuperBlock << superblockShift; tileInfo.TileRowStartModeInfo[i] = startSuperblock << superblockShift;
i++; i++;
} }
@ -777,7 +773,7 @@ internal class ObuReader
for (; startSuperBlock < superblockColumnCount; i++) for (; startSuperBlock < superblockColumnCount; i++)
{ {
tileInfo.TileColumnStartModeInfo[i] = startSuperBlock << superblockShift; tileInfo.TileColumnStartModeInfo[i] = startSuperBlock << superblockShift;
uint maxWidth = (uint)Math.Min(superblockColumnCount - startSuperBlock, tileInfo.MaxTileWidthSuperBlock); uint maxWidth = (uint)Math.Min(superblockColumnCount - startSuperBlock, tileInfo.MaxTileWidthSuperblock);
uint widthInSuperBlocks = reader.ReadNonSymmetric(maxWidth) + 1; uint widthInSuperBlocks = reader.ReadNonSymmetric(maxWidth) + 1;
widestTileSuperBlock = Math.Max(widthInSuperBlocks, widestTileSuperBlock); widestTileSuperBlock = Math.Max(widthInSuperBlocks, widestTileSuperBlock);
startSuperBlock += (int)widthInSuperBlocks; startSuperBlock += (int)widthInSuperBlocks;
@ -801,13 +797,13 @@ internal class ObuReader
} }
DebugGuard.MustBeGreaterThan(widestTileSuperBlock, 0U, nameof(widestTileSuperBlock)); DebugGuard.MustBeGreaterThan(widestTileSuperBlock, 0U, nameof(widestTileSuperBlock));
tileInfo.MaxTileHeightSuperBlock = Math.Max(maxTileAreaOfSuperBlock / (int)widestTileSuperBlock, 1); tileInfo.MaxTileHeightSuperblock = Math.Max(maxTileAreaOfSuperBlock / (int)widestTileSuperBlock, 1);
startSuperBlock = 0; startSuperBlock = 0;
for (i = 0; startSuperBlock < superblockRowCount; i++) for (i = 0; startSuperBlock < superblockRowCount; i++)
{ {
tileInfo.TileRowStartModeInfo[i] = startSuperBlock << superblockShift; tileInfo.TileRowStartModeInfo[i] = startSuperBlock << superblockShift;
uint maxHeight = (uint)Math.Min(superblockRowCount - startSuperBlock, tileInfo.MaxTileHeightSuperBlock); uint maxHeight = (uint)Math.Min(superblockRowCount - startSuperBlock, tileInfo.MaxTileHeightSuperblock);
uint heightInSuperBlocks = reader.ReadNonSymmetric(maxHeight) + 1; uint heightInSuperBlocks = reader.ReadNonSymmetric(maxHeight) + 1;
startSuperBlock += (int)heightInSuperBlocks; startSuperBlock += (int)heightInSuperBlocks;
} }

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

@ -5,9 +5,9 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit;
internal class ObuTileGroupHeader internal class ObuTileGroupHeader
{ {
internal int MaxTileWidthSuperBlock { get; set; } internal int MaxTileWidthSuperblock { get; set; }
internal int MaxTileHeightSuperBlock { get; set; } internal int MaxTileHeightSuperblock { get; set; }
internal int MinLog2TileColumnCount { get; set; } internal int MinLog2TileColumnCount { get; set; }

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

@ -239,9 +239,9 @@ internal class ObuWriter
int superBlockSize = superBlockShift + 2; int superBlockSize = superBlockShift + 2;
int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize); int maxTileAreaOfSuperBlock = Av1Constants.MaxTileArea >> (2 * superBlockSize);
tileInfo.MaxTileWidthSuperBlock = Av1Constants.MaxTileWidth >> superBlockSize; tileInfo.MaxTileWidthSuperblock = Av1Constants.MaxTileWidth >> superBlockSize;
tileInfo.MaxTileHeightSuperBlock = (Av1Constants.MaxTileArea / Av1Constants.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, Av1Constants.MaxTileColumnCount)); tileInfo.MaxLog2TileColumnCount = ObuReader.TileLog2(1, Math.Min(superBlockColumnCount, Av1Constants.MaxTileColumnCount));
tileInfo.MaxLog2TileRowCount = ObuReader.TileLog2(1, Math.Min(superBlockRowCount, Av1Constants.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));
@ -276,7 +276,7 @@ internal class ObuWriter
for (; startSuperBlock < superBlockColumnCount; i++) for (; startSuperBlock < superBlockColumnCount; i++)
{ {
uint widthInSuperBlocks = (uint)((tileInfo.TileColumnStartModeInfo[i] >> superBlockShift) - startSuperBlock); uint widthInSuperBlocks = (uint)((tileInfo.TileColumnStartModeInfo[i] >> superBlockShift) - startSuperBlock);
uint maxWidth = (uint)Math.Min(superBlockColumnCount - startSuperBlock, tileInfo.MaxTileWidthSuperBlock); uint maxWidth = (uint)Math.Min(superBlockColumnCount - startSuperBlock, tileInfo.MaxTileWidthSuperblock);
writer.WriteNonSymmetric(widthInSuperBlocks - 1, maxWidth); writer.WriteNonSymmetric(widthInSuperBlocks - 1, maxWidth);
startSuperBlock += (int)widthInSuperBlocks; startSuperBlock += (int)widthInSuperBlocks;
} }
@ -290,7 +290,7 @@ internal class ObuWriter
for (i = 0; startSuperBlock < superBlockRowCount; i++) for (i = 0; startSuperBlock < superBlockRowCount; i++)
{ {
uint heightInSuperBlocks = (uint)((tileInfo.TileRowStartModeInfo[i] >> superBlockShift) - startSuperBlock); uint heightInSuperBlocks = (uint)((tileInfo.TileRowStartModeInfo[i] >> superBlockShift) - startSuperBlock);
uint maxHeight = (uint)Math.Min(superBlockRowCount - startSuperBlock, tileInfo.MaxTileHeightSuperBlock); uint maxHeight = (uint)Math.Min(superBlockRowCount - startSuperBlock, tileInfo.MaxTileHeightSuperblock);
writer.WriteNonSymmetric(heightInSuperBlocks - 1, maxHeight); writer.WriteNonSymmetric(heightInSuperBlocks - 1, maxHeight);
startSuperBlock += (int)heightInSuperBlocks; startSuperBlock += (int)heightInSuperBlocks;
} }

Loading…
Cancel
Save