Skip to content

Commit

Permalink
Fix code analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ynse01 committed Nov 24, 2024
1 parent c7c0039 commit 0cf8f9c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Heif/Av1/Entropy/Av1Distribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public void Update(int value)
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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Heif/Av1/Entropy/Av1NzMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public static int GetNzMapContextFromStats(int stats, int pos, int bwl, Av1Trans
return 0;
}

int ctx = stats + 1 >> 1;
int ctx = (stats + 1) >> 1;
ctx = Math.Min(ctx, 4);
switch (transformClass)
{
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public int ReadCoefficients(
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;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public int ReadCoefficients(

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;
Expand All @@ -298,15 +298,15 @@ public int ReadEndOfBlockPosition(Av1TransformSize transformSize, Av1TransformCl
bool bit = this.ReadEndOfBlockExtra(transformSizeContext, planeType, endOfBlockContext);
if (bit)
{
endOfBlockExtra += 1 << endOfBlockShift - 1;
endOfBlockExtra += 1 << (endOfBlockShift - 1);
}
else
{
for (int j = 1; j < endOfBlockShift; j++)
{
if (this.ReadLiteral(1) != 0)
{
endOfBlockExtra += 1 << endOfBlockShift - 1 - j;
endOfBlockExtra += 1 << (endOfBlockShift - 1 - j);
}
}
}
Expand Down Expand Up @@ -497,7 +497,7 @@ private int ReadGolomb()
return x - 1;
}

private void UpdateCoefficientContext(
private static void UpdateCoefficientContext(
Av1BlockModeInfo modeInfo,
int[] aboveContexts,
int[] leftContexts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ private void WriteTransformType(
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();
Expand Down
18 changes: 9 additions & 9 deletions src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Av1SymbolReader(Span<byte> span)
{
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();
Expand All @@ -49,7 +49,7 @@ public int ReadSymbol(Av1Distribution distribution)

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--)
{
Expand Down Expand Up @@ -82,9 +82,9 @@ private bool DecodeBoolQ15(uint frequency)

// 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)
Expand Down Expand Up @@ -118,25 +118,25 @@ private int DecodeIntegerQ15(Av1Distribution distribution)
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);

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;
}
Expand All @@ -156,7 +156,7 @@ private void Normalize(uint dif, uint rng)
/*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)
{
Expand Down
28 changes: 14 additions & 14 deletions src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -40,7 +40,7 @@ public void WriteLiteral(uint value, int bitCount)
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);
}
}
Expand All @@ -54,15 +54,15 @@ public IMemoryOwner<byte> Exit()
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;
Expand All @@ -72,7 +72,7 @@ public IMemoryOwner<byte> Exit()
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.
Expand Down Expand Up @@ -104,7 +104,7 @@ private void EncodeBoolQ15(bool val, uint frequency)
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)
{
Expand Down Expand Up @@ -145,17 +145,17 @@ private void EncodeIntegerQ15(uint lowFrequency, uint highFrequency, int symbol,
{
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);
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Heif/Av1/Tiling/Av1BlockStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 0cf8f9c

Please sign in to comment.