Browse Source

Fixed warnings from CI

pull/2401/head
Günther Foidl 3 years ago
parent
commit
957ee98259
  1. 4
      src/ImageSharp/Common/Helpers/HexConverter.cs
  2. 19
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
  3. 2
      src/ImageSharp/Formats/Webp/AlphaDecoder.cs
  4. 4
      src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs

4
src/ImageSharp/Common/Helpers/HexConverter.cs

@ -16,12 +16,12 @@ internal static class HexConverter
/// <returns>The number of bytes written to <paramref name="bytes"/>.</returns> /// <returns>The number of bytes written to <paramref name="bytes"/>.</returns>
public static int HexStringToBytes(ReadOnlySpan<char> chars, Span<byte> bytes) public static int HexStringToBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
{ {
if ((chars.Length & 1) != 0) // bit-hack for % 2 if ((chars.Length & 1 /* bit-hack for % 2 */) != 0)
{ {
throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars)); throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars));
} }
if ((bytes.Length << 1) < chars.Length) // bit-hack for * 2 if ((bytes.Length << 1 /* bit-hack for * 2 */) < chars.Length)
{ {
throw new ArgumentException("Output span must be at least half the length of the input string"); throw new ArgumentException("Output span must be at least half the length of the input string");
} }

19
src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs

@ -53,9 +53,6 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
private ArithmeticDecodingTable[] acDecodingTables; private ArithmeticDecodingTable[] acDecodingTables;
// Use C#'s optimization to refer to assembly's data segment, no allocation occurs.
private ReadOnlySpan<byte> fixedBin => new byte[] { 113, 0, 0, 0 };
private readonly CancellationToken cancellationToken; private readonly CancellationToken cancellationToken;
private static readonly int[] ArithmeticTable = private static readonly int[] ArithmeticTable =
@ -232,7 +229,13 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
} }
} }
private ref byte GetFixedBinReference() => ref MemoryMarshal.GetReference(fixedBin); private static ref byte GetFixedBinReference()
{
// This uses C#'s optimization to refer to the static data segment of the assembly.
// No allocation occurs.
ReadOnlySpan<byte> fixedBin = new byte[] { 113, 0, 0, 0 };
return ref MemoryMarshal.GetReference(fixedBin);
}
/// <summary> /// <summary>
/// Decodes the entropy coded data. /// Decodes the entropy coded data.
@ -776,7 +779,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
else else
{ {
// Refinement scan. // Refinement scan.
ref byte st = ref this.GetFixedBinReference(); ref byte st = ref GetFixedBinReference();
blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow); blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow);
} }
@ -822,7 +825,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
// Figure F.21: Decoding nonzero value v. // Figure F.21: Decoding nonzero value v.
// Figure F.22: Decoding the sign of v. // Figure F.22: Decoding the sign of v.
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
st = ref Unsafe.Add(ref st, 2); st = ref Unsafe.Add(ref st, 2);
// Figure F.23: Decoding the magnitude category of v. // Figure F.23: Decoding the magnitude category of v.
@ -918,7 +921,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0) if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0)
{ {
bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0; bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0;
coef = (short)(coef + (flag ? m1 : p1)); coef = (short)(coef + (flag ? m1 : p1));
break; break;
@ -1048,7 +1051,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
// Figure F.21: Decoding nonzero value v. // Figure F.21: Decoding nonzero value v.
// Figure F.22: Decoding the sign of v. // Figure F.22: Decoding the sign of v.
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()); int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
st = ref Unsafe.Add(ref st, 2); st = ref Unsafe.Add(ref st, 2);
// Figure F.23: Decoding the magnitude category of v. // Figure F.23: Decoding the magnitude category of v.

2
src/ImageSharp/Formats/Webp/AlphaDecoder.cs

@ -376,7 +376,7 @@ internal class AlphaDecoder : IDisposable
Unsafe.As<byte, Vector256<byte>>(ref outputRef) = c0; Unsafe.As<byte, Vector256<byte>>(ref outputRef) = c0;
} }
for (; i < (uint) width; i++) for (; i < (uint)width; i++)
{ {
dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]); dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]);
} }

4
src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs

@ -1553,7 +1553,7 @@ internal static class LossyUtils
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (3 * stride)))) = p2.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (3 * stride)))) = p2.AsInt32();
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (2 * stride)))) = p1.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (2 * stride)))) = p1.AsInt32();
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - stride))) = p0.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - stride))) = p0.AsInt32();
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset))) = q0.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)offset)) = q0.AsInt32();
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + stride))) = q1.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + stride))) = q1.AsInt32();
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + (2 * stride)))) = q2.AsInt32(); Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + (2 * stride)))) = q2.AsInt32();
} }
@ -1599,7 +1599,7 @@ internal static class LossyUtils
if (Sse2.IsSupported) if (Sse2.IsSupported)
{ {
ref byte pRef = ref MemoryMarshal.GetReference(p); ref byte pRef = ref MemoryMarshal.GetReference(p);
Vector128<byte> p3 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset))); Vector128<byte> p3 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)offset));
Vector128<byte> p2 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + stride))); Vector128<byte> p2 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + stride)));
Vector128<byte> p1 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride)))); Vector128<byte> p1 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride))));
Vector128<byte> p0 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride)))); Vector128<byte> p0 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride))));

Loading…
Cancel
Save