Browse Source

Entropy directory and namespace

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
87c57f7705
  1. 2
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1DefaultDistributions.cs
  2. 8
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1Distribution.cs
  3. 4
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1NzMap.cs
  4. 37
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolDecoder.cs
  5. 36
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs
  6. 20
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolReader.cs
  7. 30
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolWriter.cs
  8. 1
      src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileReader.cs
  9. 14
      tests/ImageSharp.Tests/Formats/Heif/Av1/EntropyTests.cs

2
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1DefaultDistributions.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1DefaultDistributions.cs

@ -3,7 +3,7 @@
using System;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal static class Av1DefaultDistributions
{

8
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1Distribution.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1Distribution.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
/// <summary>
/// Class representing the probability distribution used for symbol coding.
@ -111,15 +111,15 @@ internal class Av1Distribution
// Single loop (faster)
for (int i = 0; i < this.NumberOfSymbols - 1; i++)
{
tmp = (i == value) ? 0 : tmp;
tmp = i == value ? 0 : tmp;
uint p = this.probabilities[i];
if (tmp < p)
{
this.probabilities[i] -= (ushort)((p - tmp) >> rate);
this.probabilities[i] -= (ushort)(p - tmp >> rate);
}
else
{
this.probabilities[i] += (ushort)((tmp - p) >> rate);
this.probabilities[i] += (ushort)(tmp - p >> rate);
}
}

4
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1NzMap.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1NzMap.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal static class Av1NzMap
{
@ -321,7 +321,7 @@ internal static class Av1NzMap
return 0;
}
int ctx = (stats + 1) >> 1;
int ctx = stats + 1 >> 1;
ctx = Math.Min(ctx, 4);
switch (transformClass)
{

37
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1SymbolDecoder.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolDecoder.cs

@ -2,9 +2,10 @@
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Heif.Av1.Prediction;
using SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal ref struct Av1SymbolDecoder
{
@ -140,7 +141,7 @@ internal ref struct Av1SymbolDecoder
public int ReadAngleDelta(Av1PredictionMode mode)
{
ref Av1SymbolReader r = ref this.reader;
return r.ReadSymbol(this.angleDelta[((int)mode) - 1]);
return r.ReadSymbol(this.angleDelta[(int)mode - 1]);
}
public bool ReadUseFilterUltra(Av1BlockSize blockSize)
@ -216,7 +217,7 @@ internal ref struct Av1SymbolDecoder
bool bit = this.ReadEndOfBlockExtra(transformSizeContext, planeType, endOfBlockContext);
if (bit)
{
endOfBlockExtra += 1 << (endOfBlockShift - 1);
endOfBlockExtra += 1 << endOfBlockShift - 1;
}
else
{
@ -224,7 +225,7 @@ internal ref struct Av1SymbolDecoder
{
if (this.ReadLiteral(1) != 0)
{
endOfBlockExtra += 1 << (endOfBlockShift - 1 - j);
endOfBlockExtra += 1 << endOfBlockShift - 1 - j;
}
}
}
@ -409,9 +410,9 @@ internal ref struct Av1SymbolDecoder
return 0;
}
if ((transformClass == Av1TransformClass.Class2D && row < 2 && col < 2) ||
(transformClass == Av1TransformClass.ClassHorizontal && col == 0) ||
(transformClass == Av1TransformClass.ClassVertical && row == 0))
if (transformClass == Av1TransformClass.Class2D && row < 2 && col < 2 ||
transformClass == Av1TransformClass.ClassHorizontal && col == 0 ||
transformClass == Av1TransformClass.ClassVertical && row == 0)
{
return 7;
}
@ -426,12 +427,12 @@ internal ref struct Av1SymbolDecoder
return 0;
}
if (scanIndex <= (height << bwl) >> 3)
if (scanIndex <= height << bwl >> 3)
{
return 1;
}
if (scanIndex <= (height << bwl) >> 2)
if (scanIndex <= height << bwl >> 2)
{
return 2;
}
@ -445,12 +446,12 @@ internal ref struct Av1SymbolDecoder
int row = c >> bwl;
int col = c - (row << bwl);
int stride = (1 << bwl) + Av1Constants.TransformPadHorizontal;
int pos = (row * stride) + col;
int pos = row * stride + col;
int mag =
Math.Min((int)levels[pos + 1], Av1Constants.MaxBaseRange) +
Math.Min((int)levels[pos + stride], Av1Constants.MaxBaseRange) +
Math.Min((int)levels[pos + 1 + stride], Av1Constants.MaxBaseRange);
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if ((row | col) < 2)
{
return mag + 7;
@ -470,7 +471,7 @@ internal ref struct Av1SymbolDecoder
mag += Math.Min((int)levels[2], 3); // { 0, 2 }
mag += Math.Min((int)levels[(2 << bwl) + (2 << Av1Constants.TransformPadHorizontalLog2)], 3); // { 2, 0 }
int ctx = Math.Min((mag + 1) >> 1, 4);
int ctx = Math.Min(mag + 1 >> 1, 4);
return ctx + Av1NzMap.GetNzMapContext(transformSize, pos);
}
@ -479,20 +480,20 @@ internal ref struct Av1SymbolDecoder
int row = c >> bwl;
int col = c - (row << bwl);
int stride = (1 << bwl) + Av1Constants.TransformPadHorizontal;
int pos = (row * stride) + col;
int pos = row * stride + col;
int mag = levels[pos + 1];
mag += levels[pos + stride];
switch (transformClass)
{
case Av1TransformClass.Class2D:
mag += levels[pos + stride + 1];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
}
if ((row < 2) && (col < 2))
if (row < 2 && col < 2)
{
return mag + 7;
}
@ -500,7 +501,7 @@ internal ref struct Av1SymbolDecoder
break;
case Av1TransformClass.ClassHorizontal:
mag += levels[pos + 2];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
@ -514,7 +515,7 @@ internal ref struct Av1SymbolDecoder
break;
case Av1TransformClass.ClassVertical:
mag += levels[pos + (stride << 1)];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
@ -540,7 +541,7 @@ internal ref struct Av1SymbolDecoder
}
public static int GetPaddedIndex(int scanIndex, int bwl)
=> scanIndex + ((scanIndex >> bwl) << Av1Constants.TransformPadHorizontalLog2);
=> scanIndex + (scanIndex >> bwl << Av1Constants.TransformPadHorizontalLog2);
private int ReadGolomb()
{

36
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1SymbolEncoder.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs

@ -6,10 +6,12 @@ using System.Buffers;
using System.Drawing;
using System.Formats.Asn1;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Heif.Av1;
using SixLabors.ImageSharp.Formats.Heif.Av1.Prediction;
using SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal class Av1SymbolEncoder : IDisposable
{
@ -101,7 +103,7 @@ internal class Av1SymbolEncoder : IDisposable
public void WriteSplitOrHorizontal(Av1PartitionType partitionType, Av1BlockSize blockSize, int context)
{
Av1Distribution distribution = Av1SymbolDecoder.GetSplitOrHorizontalDistribution(this.tilePartitionTypes, blockSize, context);
int value = (partitionType == Av1PartitionType.Split) ? 1 : 0;
int value = partitionType == Av1PartitionType.Split ? 1 : 0;
ref Av1SymbolWriter w = ref this.writer;
w.WriteSymbol(value, distribution);
}
@ -109,7 +111,7 @@ internal class Av1SymbolEncoder : IDisposable
public void WriteSplitOrVertical(Av1PartitionType partitionType, Av1BlockSize blockSize, int context)
{
Av1Distribution distribution = Av1SymbolDecoder.GetSplitOrVerticalDistribution(this.tilePartitionTypes, blockSize, context);
int value = (partitionType == Av1PartitionType.Split) ? 1 : 0;
int value = partitionType == Av1PartitionType.Split ? 1 : 0;
ref Av1SymbolWriter w = ref this.writer;
w.WriteSymbol(value, distribution);
}
@ -138,7 +140,7 @@ internal class Av1SymbolEncoder : IDisposable
Av1ScanOrder scanOrder = Av1ScanOrderConstants.GetScanOrder(transformSize, transformType);
ReadOnlySpan<short> scan = scanOrder.Scan;
int bwl = transformSize.GetBlockWidthLog2();
Av1TransformSize transformSizeContext = (Av1TransformSize)(((int)transformSize.GetSquareSize() + (int)transformSize.GetSquareUpSize() + 1) >> 1);
Av1TransformSize transformSizeContext = (Av1TransformSize)((int)transformSize.GetSquareSize() + (int)transformSize.GetSquareUpSize() + 1 >> 1);
ref Av1SymbolWriter w = ref this.writer;
@ -169,12 +171,12 @@ internal class Av1SymbolEncoder : IDisposable
if (eob_offset_bits > 0)
{
int eob_shift = eob_offset_bits - 1;
int bit = Math.Max(1, eob_extra & (1 << eob_shift));
int bit = Math.Max(1, eob_extra & 1 << eob_shift);
w.WriteSymbol(bit, this.endOfBlockExtra[(int)transformSizeContext][(int)componentType][endOfBlockPosition]);
for (int i = 1; i < eob_offset_bits; i++)
{
eob_shift = eob_offset_bits - 1 - i;
bit = Math.Max(1, eob_extra & (1 << eob_shift));
bit = Math.Max(1, eob_extra & 1 << eob_shift);
w.WriteLiteral((uint)bit, 1);
}
}
@ -224,7 +226,7 @@ internal class Av1SymbolEncoder : IDisposable
int level = Math.Abs(v);
cul_level += level;
uint sign = (v < 0) ? 1u : 0u;
uint sign = v < 0 ? 1u : 0u;
if (level > 0)
{
if (c == 0)
@ -273,20 +275,20 @@ internal class Av1SymbolEncoder : IDisposable
int row = c >> bwl;
int col = c - (row << bwl);
int stride = (1 << bwl) + Av1Constants.TransformPadHorizontal;
int pos = (row * stride) + col;
int pos = row * stride + col;
int mag = levels[pos + 1];
mag += levels[pos + stride];
switch (transformClass)
{
case Av1TransformClass.Class2D:
mag += levels[pos + stride + 1];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
}
if ((row < 2) && (col < 2))
if (row < 2 && col < 2)
{
return mag + 7;
}
@ -294,7 +296,7 @@ internal class Av1SymbolEncoder : IDisposable
break;
case Av1TransformClass.ClassHorizontal:
mag += levels[pos + 2];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
@ -308,7 +310,7 @@ internal class Av1SymbolEncoder : IDisposable
break;
case Av1TransformClass.ClassVertical:
mag += levels[pos + (stride << 1)];
mag = Math.Min((mag + 1) >> 1, 6);
mag = Math.Min(mag + 1 >> 1, 6);
if (c == 0)
{
return mag;
@ -339,7 +341,7 @@ internal class Av1SymbolEncoder : IDisposable
}
else
{
int e = Math.Min((endOfBlock - 1) >> 5, 16);
int e = Math.Min(endOfBlock - 1 >> 5, 16);
t = EndOfBlockToPositionLarge[e];
}
@ -413,13 +415,13 @@ internal class Av1SymbolEncoder : IDisposable
ref byte ls = ref levels[0];
Unsafe.InitBlock(ref levels[-Av1Constants.TransformPadTop * stride], 0, (uint)(Av1Constants.TransformPadTop * stride));
Unsafe.InitBlock(ref levels[stride * height], 0, (uint)((Av1Constants.TransformPadBottom * stride) + Av1Constants.TransformPadEnd));
Unsafe.InitBlock(ref levels[stride * height], 0, (uint)(Av1Constants.TransformPadBottom * stride + Av1Constants.TransformPadEnd));
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
ls = (byte)Av1Math.Clamp(Math.Abs(coefficientBuffer[(i * width) + j]), 0, byte.MaxValue);
ls = (byte)Av1Math.Clamp(Math.Abs(coefficientBuffer[i * width + j]), 0, byte.MaxValue);
ls = ref Unsafe.Add(ref ls, 1);
}
@ -474,7 +476,7 @@ internal class Av1SymbolEncoder : IDisposable
for (int j = length - 1; j >= 0; --j)
{
w.WriteLiteral((uint)((x >> j) & 0x01), 1);
w.WriteLiteral((uint)(x >> j & 0x01), 1);
}
}
@ -499,7 +501,7 @@ internal class Av1SymbolEncoder : IDisposable
{
ref Av1SymbolWriter w = ref this.writer;
bool isInter = false; // mbmi->block_mi.use_intrabc || is_inter_mode(mbmi->block_mi.mode);
if (GetExtendedTransformTypeCount(transformSize, isInter, useReducedTransformSet) > 1 && (baseQIndex > 0))
if (GetExtendedTransformTypeCount(transformSize, isInter, useReducedTransformSet) > 1 && baseQIndex > 0)
{
Av1TransformSize square_tx_size = transformSize.GetSquareSize();
Guard.MustBeLessThanOrEqualTo((int)square_tx_size, Av1Constants.ExtendedTransformCount, nameof(square_tx_size));

20
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1SymbolReader.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolReader.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal ref struct Av1SymbolReader
{
@ -32,7 +32,7 @@ internal ref struct Av1SymbolReader
{
this.buffer = span;
this.position = 0;
this.difference = (1U << (DecoderWindowsSize - 1)) - 1;
this.difference = (1U << DecoderWindowsSize - 1) - 1;
this.range = 0x8000;
this.count = -15;
this.Refill();
@ -49,7 +49,7 @@ internal ref struct Av1SymbolReader
public int ReadLiteral(int bitCount)
{
const uint prob = (0x7FFFFFU - (128 << 15) + 128) >> 8;
const uint prob = 0x7FFFFFU - (128 << 15) + 128 >> 8;
int literal = 0;
for (int bit = bitCount - 1; bit >= 0; bit--)
{
@ -82,9 +82,9 @@ internal ref struct Av1SymbolReader
// assert(dif >> (DecoderWindowsSize - 16) < r);
// assert(32768U <= r);
v = ((range >> 8) * (frequency >> Av1Distribution.ProbabilityShift)) >> (7 - Av1Distribution.ProbabilityShift);
v = (range >> 8) * (frequency >> Av1Distribution.ProbabilityShift) >> 7 - Av1Distribution.ProbabilityShift;
v += Av1Distribution.ProbabilityMinimum;
vw = v << (DecoderWindowsSize - 16);
vw = v << DecoderWindowsSize - 16;
ret = true;
newRange = v;
if (dif >= vw)
@ -118,17 +118,17 @@ internal ref struct Av1SymbolReader
uint r = this.range;
int n = distribution.NumberOfSymbols - 1;
DebugGuard.MustBeLessThan(dif >> (DecoderWindowsSize - 16), r, nameof(r));
DebugGuard.MustBeLessThan(dif >> DecoderWindowsSize - 16, r, nameof(r));
DebugGuard.IsTrue(distribution[n] == 0, "Last value in probability array needs to be zero.");
DebugGuard.MustBeGreaterThanOrEqualTo(r, 32768U, nameof(r));
DebugGuard.MustBeGreaterThanOrEqualTo(7 - Av1Distribution.ProbabilityShift - Av1Distribution.CdfShift, 0, nameof(Av1Distribution.CdfShift));
c = dif >> (DecoderWindowsSize - 16);
c = dif >> DecoderWindowsSize - 16;
v = r;
ret = -1;
do
{
u = v;
v = ((r >> 8) * (distribution[++ret] >> Av1Distribution.ProbabilityShift)) >> (7 - Av1Distribution.ProbabilityShift - Av1Distribution.CdfShift);
v = (r >> 8) * (distribution[++ret] >> Av1Distribution.ProbabilityShift) >> 7 - Av1Distribution.ProbabilityShift - Av1Distribution.CdfShift;
v += (uint)(Av1Distribution.ProbabilityMinimum * (n - ret));
}
while (c < v);
@ -136,7 +136,7 @@ internal ref struct Av1SymbolReader
DebugGuard.MustBeLessThan(v, u, nameof(v));
DebugGuard.MustBeLessThanOrEqualTo(u, r, nameof(u));
r = u - v;
dif -= v << (DecoderWindowsSize - 16);
dif -= v << DecoderWindowsSize - 16;
this.Normalize(dif, r);
return ret;
}
@ -156,7 +156,7 @@ internal ref struct Av1SymbolReader
/*d bits in dec->dif are consumed.*/
this.count -= d;
/*This is equivalent to shifting in 1's instead of 0's.*/
this.difference = ((dif + 1) << d) - 1;
this.difference = (dif + 1 << d) - 1;
this.range = rng << d;
if (this.count < 0)
{

30
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1SymbolWriter.cs → src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolWriter.cs

@ -4,7 +4,7 @@
using System.Buffers;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
internal class Av1SymbolWriter : IDisposable
{
@ -20,7 +20,7 @@ internal class Av1SymbolWriter : IDisposable
public Av1SymbolWriter(Configuration configuration, int initialSize)
{
this.configuration = configuration;
this.memory = new AutoExpandingMemory<ushort>(configuration, (initialSize + 1) >> 1);
this.memory = new AutoExpandingMemory<ushort>(configuration, initialSize + 1 >> 1);
}
public void Dispose() => this.memory.Dispose();
@ -40,7 +40,7 @@ internal class Av1SymbolWriter : IDisposable
const uint p = 0x4000U; // (0x7FFFFFU - (128 << 15) + 128) >> 8;
for (int bit = bitCount - 1; bit >= 0; bit--)
{
bool bitValue = ((value >> bit) & 0x1) > 0;
bool bitValue = (value >> bit & 0x1) > 0;
this.EncodeBoolQ15(bitValue, p);
}
}
@ -54,15 +54,15 @@ internal class Av1SymbolWriter : IDisposable
int pos = this.position;
int s = 10;
uint m = 0x3FFFU;
uint e = ((l + m) & ~m) | (m + 1);
uint e = l + m & ~m | m + 1;
s += c;
Span<ushort> buffer = this.memory.GetSpan(this.position + ((s + 7) >> 3));
Span<ushort> buffer = this.memory.GetSpan(this.position + (s + 7 >> 3));
if (s > 0)
{
uint n = (1U << (c + 16)) - 1;
uint n = (1U << c + 16) - 1;
do
{
buffer[pos] = (ushort)(e >> (c + 16));
buffer[pos] = (ushort)(e >> c + 16);
pos++;
e &= n;
s -= 8;
@ -72,7 +72,7 @@ internal class Av1SymbolWriter : IDisposable
while (s > 0);
}
c = Math.Max((s + 7) >> 3, 0);
c = Math.Max(s + 7 >> 3, 0);
IMemoryOwner<byte> output = this.configuration.MemoryAllocator.Allocate<byte>(pos + c);
// Perform carry propagation.
@ -104,7 +104,7 @@ internal class Av1SymbolWriter : IDisposable
l = this.low;
r = this.rng;
DebugGuard.MustBeGreaterThanOrEqualTo(r, 32768U, nameof(r));
v = ((r >> 8) * (frequency >> Av1Distribution.ProbabilityShift)) >> (7 - Av1Distribution.ProbabilityShift);
v = (r >> 8) * (frequency >> Av1Distribution.ProbabilityShift) >> 7 - Av1Distribution.ProbabilityShift;
v += Av1Distribution.ProbabilityMinimum;
if (val)
{
@ -145,17 +145,17 @@ internal class Av1SymbolWriter : IDisposable
{
uint u;
uint v;
u = (uint)((((r >> 8) * (lowFrequency >> Av1Distribution.ProbabilityShift)) >> totalShift) +
(Av1Distribution.ProbabilityMinimum * (n - (symbol - 1))));
v = (uint)((((r >> 8) * (highFrequency >> Av1Distribution.ProbabilityShift)) >> totalShift) +
(Av1Distribution.ProbabilityMinimum * (n - symbol)));
u = (uint)(((r >> 8) * (lowFrequency >> Av1Distribution.ProbabilityShift) >> totalShift) +
Av1Distribution.ProbabilityMinimum * (n - (symbol - 1)));
v = (uint)(((r >> 8) * (highFrequency >> Av1Distribution.ProbabilityShift) >> totalShift) +
Av1Distribution.ProbabilityMinimum * (n - symbol));
l += r - u;
r = u - v;
}
else
{
r -= (uint)((((r >> 8) * (highFrequency >> Av1Distribution.ProbabilityShift)) >> totalShift) +
(Av1Distribution.ProbabilityMinimum * (n - symbol)));
r -= (uint)(((r >> 8) * (highFrequency >> Av1Distribution.ProbabilityShift) >> totalShift) +
Av1Distribution.ProbabilityMinimum * (n - symbol));
}
this.Normalize(l, r);

1
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1TileReader.cs

@ -3,6 +3,7 @@
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Heif.Av1;
using SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
using SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit;
using SixLabors.ImageSharp.Formats.Heif.Av1.Pipeline;
using SixLabors.ImageSharp.Formats.Heif.Av1.Prediction;

14
tests/ImageSharp.Tests/Formats/Heif/Av1/SymbolTests.cs → tests/ImageSharp.Tests/Formats/Heif/Av1/EntropyTests.cs

@ -3,15 +3,15 @@
using System.Buffers;
using SixLabors.ImageSharp.Formats.Heif.Av1;
using SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
using SixLabors.ImageSharp.Formats.Heif.Av1.Entropy;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Tests.Formats.Heif.Av1;
[Trait("Format", "Avif")]
public class SymbolTests
public class EntropyTests
{
private const int baseQIndex = 23;
private const int BaseQIndex = 23;
[Fact]
public void ReadRandomLiteral()
@ -194,7 +194,7 @@ public class SymbolTests
// Assign
int ctx = 7;
Configuration configuration = Configuration.Default;
Av1SymbolEncoder encoder = new(configuration, 100 / 8, baseQIndex);
Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex);
Av1PartitionType[] values = [
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.None,
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.None, Av1PartitionType.None];
@ -231,7 +231,7 @@ public class SymbolTests
{
// Assign
Configuration configuration = Configuration.Default;
Av1SymbolEncoder encoder = new(configuration, 100 / 8, baseQIndex);
Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex);
Av1PartitionType[] values = [
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Horizontal,
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Horizontal, Av1PartitionType.Horizontal];
@ -268,7 +268,7 @@ public class SymbolTests
{
// Assign
Configuration configuration = Configuration.Default;
Av1SymbolEncoder encoder = new(configuration, 100 / 8, baseQIndex);
Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex);
Av1PartitionType[] values = [
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Vertical,
Av1PartitionType.Split, Av1PartitionType.Split, Av1PartitionType.Vertical, Av1PartitionType.Vertical];
@ -299,7 +299,7 @@ public class SymbolTests
// Assign
bool[] values = [true, true, false, true, false, false, false];
Configuration configuration = Configuration.Default;
Av1SymbolEncoder encoder = new(configuration, 100 / 8, baseQIndex);
Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex);
bool[] actuals = new bool[values.Length];
// Act
Loading…
Cancel
Save