Browse Source

Fixed Bug Pt. II

pull/2401/head
Günther Foidl 3 years ago
parent
commit
deaabf1571
  1. 12
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
  2. 7
      src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs

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

@ -53,7 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
private ArithmeticDecodingTable[] acDecodingTables;
private static readonly byte[] FixedBin = { 113, 0, 0, 0 };
private readonly byte[] fixedBin = { 113, 0, 0, 0 };
private readonly CancellationToken cancellationToken;
@ -231,7 +231,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
}
}
private static ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(FixedBin);
private ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(this.fixedBin);
/// <summary>
/// Decodes the entropy coded data.
@ -775,7 +775,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
else
{
// Refinement scan.
ref byte st = ref GetFixedBinReference();
ref byte st = ref this.GetFixedBinReference();
blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow);
}
@ -821,7 +821,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
// Figure F.21: Decoding nonzero value v.
// Figure F.22: Decoding the sign of v.
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
st = ref Unsafe.Add(ref st, 2);
// Figure F.23: Decoding the magnitude category of v.
@ -917,7 +917,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0)
{
bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0;
bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0;
coef = (short)(coef + (flag ? m1 : p1));
break;
@ -1047,7 +1047,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
// Figure F.21: Decoding nonzero value v.
// Figure F.22: Decoding the sign of v.
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
st = ref Unsafe.Add(ref st, 2);
// Figure F.23: Decoding the magnitude category of v.

7
src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs

@ -1440,12 +1440,7 @@ internal static unsafe class LosslessUtils
}
[MethodImpl(InliningOptions.ShortMethod)]
private static int AddSubtractComponentHalf(int a, int b)
{
uint ua = (uint)a;
uint ub = (uint)b;
return (int)Clip255(ua + ((ua - ub) / 2));
}
private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) >> 1))); // >> 1 is bit-hack for / 2
[MethodImpl(InliningOptions.ShortMethod)]
private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c));

Loading…
Cancel
Save