Browse Source

Fix code analysis warnings

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
0cf8f9cb0b
  1. 4
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1Distribution.cs
  2. 2
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1NzMap.cs
  3. 10
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolDecoder.cs
  4. 2
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs
  5. 18
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolReader.cs
  6. 28
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolWriter.cs
  7. 2
      src/ImageSharp/Formats/Heif/Av1/Tiling/Av1BlockStruct.cs
  8. 2
      src/ImageSharp/Formats/Heif/Av1/Tiling/Av1EncoderBlockStruct.cs
  9. 8
      src/ImageSharp/Formats/Heif/Av1/Tiling/Av1PictureControlSet.cs

4
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1Distribution.cs

@ -115,11 +115,11 @@ internal class Av1Distribution
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);
}
}

2
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1NzMap.cs

@ -336,7 +336,7 @@ internal static class Av1NzMap
return 0;
}
int ctx = stats + 1 >> 1;
int ctx = (stats + 1) >> 1;
ctx = Math.Min(ctx, 4);
switch (transformClass)
{

10
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolDecoder.cs

@ -250,7 +250,7 @@ internal ref struct Av1SymbolDecoder
transformInfo.CodeBlockFlag = false;
}
this.UpdateCoefficientContext(modeInfo, aboveContexts, leftContexts, blocksWide, blocksHigh, transformSize, blockPosition, aboveOffset, leftOffset, culLevel, modeBlocksToRightEdge, modeBlocksToBottomEdge);
UpdateCoefficientContext(modeInfo, aboveContexts, leftContexts, blocksWide, blocksHigh, transformSize, blockPosition, aboveOffset, leftOffset, culLevel, modeBlocksToRightEdge, modeBlocksToBottomEdge);
return 0;
}
@ -281,7 +281,7 @@ internal ref struct Av1SymbolDecoder
DebugGuard.MustBeGreaterThan(scan.Length, 0, nameof(scan));
culLevel = this.ReadCoefficientsDc(coefficientBuffer, endOfBlock, scan, bwl, levels, transformBlockContext.DcSignContext, planeType);
this.UpdateCoefficientContext(modeInfo, aboveContexts, leftContexts, blocksWide, blocksHigh, transformSize, blockPosition, aboveOffset, leftOffset, culLevel, modeBlocksToRightEdge, modeBlocksToBottomEdge);
UpdateCoefficientContext(modeInfo, aboveContexts, leftContexts, blocksWide, blocksHigh, transformSize, blockPosition, aboveOffset, leftOffset, culLevel, modeBlocksToRightEdge, modeBlocksToBottomEdge);
transformInfo.CodeBlockFlag = true;
return endOfBlock;
@ -298,7 +298,7 @@ internal ref struct Av1SymbolDecoder
bool bit = this.ReadEndOfBlockExtra(transformSizeContext, planeType, endOfBlockContext);
if (bit)
{
endOfBlockExtra += 1 << endOfBlockShift - 1;
endOfBlockExtra += 1 << (endOfBlockShift - 1);
}
else
{
@ -306,7 +306,7 @@ internal ref struct Av1SymbolDecoder
{
if (this.ReadLiteral(1) != 0)
{
endOfBlockExtra += 1 << endOfBlockShift - 1 - j;
endOfBlockExtra += 1 << (endOfBlockShift - 1 - j);
}
}
}
@ -497,7 +497,7 @@ internal ref struct Av1SymbolDecoder
return x - 1;
}
private void UpdateCoefficientContext(
private static void UpdateCoefficientContext(
Av1BlockModeInfo modeInfo,
int[] aboveContexts,
int[] leftContexts,

2
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs

@ -273,8 +273,8 @@ internal class Av1SymbolEncoder : IDisposable
Av1FilterIntraMode filterIntraMode,
Av1PredictionMode intraDirection)
{
ref Av1SymbolWriter w = ref this.writer;
// bool isInter = mbmi->block_mi.use_intrabc || is_inter_mode(mbmi->block_mi.mode);
ref Av1SymbolWriter w = ref this.writer;
if (Av1SymbolContextHelper.GetExtendedTransformTypeCount(transformSize, useReducedTransformSet) > 1 && baseQIndex > 0)
{
Av1TransformSize square_tx_size = transformSize.GetSquareSize();

18
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolReader.cs

@ -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)
{

28
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolWriter.cs

@ -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);

2
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1BlockStruct.cs

@ -7,7 +7,7 @@ internal class Av1BlockStruct
{
public Av1TransformUnit[] TransformBlocks { get; } = new Av1TransformUnit[Av1Constants.MaxTransformUnitCount];
public required Av1MacroBlockD av1xd { get; set; }
public required Av1MacroBlockD MacroBlock { get; set; }
public int MdScanIndex { get; set; }

2
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1EncoderBlockStruct.cs

@ -7,7 +7,7 @@ internal partial class Av1TileWriter
{
internal class Av1EncoderBlockStruct
{
public required Av1MacroBlockD av1xd { get; internal set; }
public required Av1MacroBlockD MacroBlock { get; internal set; }
public required int[] PaletteSize { get; internal set; }

8
src/ImageSharp/Formats/Heif/Av1/Tiling/Av1PictureControlSet.cs

@ -5,13 +5,13 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.Tiling;
internal class Av1PictureControlSet
{
public required Av1NeighborArrayUnit<byte>[] luma_dc_sign_level_coeff_na { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] LuminanceDcSignLevelCoefficientNeighbors { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] cr_dc_sign_level_coeff_na { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] CrDcSignLevelCoefficientNeighbors { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] cb_dc_sign_level_coeff_na { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] CbDcSignLevelCoefficientNeighbors { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] txfm_context_array { get; internal set; }
public required Av1NeighborArrayUnit<byte>[] TransformFunctionContexts { get; internal set; }
public required Av1SequenceControlSet Sequence { get; internal set; }

Loading…
Cancel
Save