|
|
@ -1,6 +1,7 @@ |
|
|
// Copyright (c) Six Labors.
|
|
|
// Copyright (c) Six Labors.
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
|
|
|
|
using System.Buffers; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.Color; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.Color; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.Entropy; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.Entropy; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; |
|
|
using SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; |
|
|
@ -41,6 +42,11 @@ internal sealed class Av1Decoder : IAv1TileReader, IDisposable |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private readonly Buffer2D<byte> chromaPaletteColorIndexMap; |
|
|
private readonly Buffer2D<byte> chromaPaletteColorIndexMap; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The shared backing owner for both reusable palette maps.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly IMemoryOwner<byte> paletteColorIndexMapOwner; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// The reconstructed references and selected presentation output owned by the current bounded decode session.
|
|
|
/// The reconstructed references and selected presentation output owned by the current bounded decode session.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -96,26 +102,21 @@ internal sealed class Av1Decoder : IAv1TileReader, IDisposable |
|
|
this.configuration = configuration; |
|
|
this.configuration = configuration; |
|
|
this.obuReader = new(operatingPointIndex, this.referenceFrames); |
|
|
this.obuReader = new(operatingPointIndex, this.referenceFrames); |
|
|
|
|
|
|
|
|
Buffer2D<byte>? lumaPaletteColorIndexMap = null; |
|
|
// Sequential tile decoding needs only the palette indices belonging to the current superblock. One fixed
|
|
|
Buffer2D<byte>? chromaPaletteColorIndexMap = null; |
|
|
// owner keeps both maximum-superblock maps reusable across the bounded session without fragmented group rents.
|
|
|
|
|
|
int paletteMapLength = 1 << Av1Constants.MaxSuperBlockSizeLog2; |
|
|
try |
|
|
int paletteMapArea = paletteMapLength * paletteMapLength; |
|
|
{ |
|
|
this.paletteColorIndexMapOwner = configuration.MemoryAllocator.Allocate<byte>(2 * paletteMapArea); |
|
|
// Sequential tile decoding needs only the palette indices belonging to the current superblock. Keeping
|
|
|
Memory<byte> paletteMaps = this.paletteColorIndexMapOwner.Memory; |
|
|
// two maximum-superblock surfaces at decoder scope makes the memory bound independent of frame size and
|
|
|
this.lumaPaletteColorIndexMap = Buffer2D<byte>.WrapMemory( |
|
|
// reuses the same allocator rents across every frame in the bounded sequence.
|
|
|
paletteMaps[..paletteMapArea], |
|
|
int paletteMapLength = 1 << Av1Constants.MaxSuperBlockSizeLog2; |
|
|
paletteMapLength, |
|
|
lumaPaletteColorIndexMap = configuration.MemoryAllocator.Allocate2D<byte>(paletteMapLength, paletteMapLength); |
|
|
paletteMapLength); |
|
|
chromaPaletteColorIndexMap = configuration.MemoryAllocator.Allocate2D<byte>(paletteMapLength, paletteMapLength); |
|
|
|
|
|
this.lumaPaletteColorIndexMap = lumaPaletteColorIndexMap; |
|
|
this.chromaPaletteColorIndexMap = Buffer2D<byte>.WrapMemory( |
|
|
this.chromaPaletteColorIndexMap = chromaPaletteColorIndexMap; |
|
|
paletteMaps[paletteMapArea..], |
|
|
} |
|
|
paletteMapLength, |
|
|
catch |
|
|
paletteMapLength); |
|
|
{ |
|
|
|
|
|
chromaPaletteColorIndexMap?.Dispose(); |
|
|
|
|
|
lumaPaletteColorIndexMap?.Dispose(); |
|
|
|
|
|
throw; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -958,6 +959,7 @@ internal sealed class Av1Decoder : IAv1TileReader, IDisposable |
|
|
this.FrameInfo = null; |
|
|
this.FrameInfo = null; |
|
|
this.lumaPaletteColorIndexMap.Dispose(); |
|
|
this.lumaPaletteColorIndexMap.Dispose(); |
|
|
this.chromaPaletteColorIndexMap.Dispose(); |
|
|
this.chromaPaletteColorIndexMap.Dispose(); |
|
|
|
|
|
this.paletteColorIndexMapOwner.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
|