Skip to content

Commit deaabf1

Browse files
committed
Fixed Bug Pt. II
1 parent bc61781 commit deaabf1

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
5353

5454
private ArithmeticDecodingTable[] acDecodingTables;
5555

56-
private static readonly byte[] FixedBin = { 113, 0, 0, 0 };
56+
private readonly byte[] fixedBin = { 113, 0, 0, 0 };
5757

5858
private readonly CancellationToken cancellationToken;
5959

@@ -231,7 +231,7 @@ public void InitDecodingTables(List<ArithmeticDecodingTable> arithmeticDecodingT
231231
}
232232
}
233233

234-
private static ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(FixedBin);
234+
private ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(this.fixedBin);
235235

236236
/// <summary>
237237
/// Decodes the entropy coded data.
@@ -775,7 +775,7 @@ private void DecodeBlockProgressiveDc(ArithmeticDecodingComponent component, ref
775775
else
776776
{
777777
// Refinement scan.
778-
ref byte st = ref GetFixedBinReference();
778+
ref byte st = ref this.GetFixedBinReference();
779779

780780
blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow);
781781
}
@@ -821,7 +821,7 @@ private void DecodeBlockProgressiveAc(ArithmeticDecodingComponent component, ref
821821

822822
// Figure F.21: Decoding nonzero value v.
823823
// Figure F.22: Decoding the sign of v.
824-
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
824+
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
825825
st = ref Unsafe.Add(ref st, 2);
826826

827827
// Figure F.23: Decoding the magnitude category of v.
@@ -917,7 +917,7 @@ private void ReadBlockProgressiveAcRefined(ArithmeticStatistics acStatistics, re
917917

918918
if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0)
919919
{
920-
bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0;
920+
bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0;
921921
coef = (short)(coef + (flag ? m1 : p1));
922922

923923
break;
@@ -1047,7 +1047,7 @@ private void DecodeBlockBaseline(
10471047

10481048
// Figure F.21: Decoding nonzero value v.
10491049
// Figure F.22: Decoding the sign of v.
1050-
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
1050+
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
10511051
st = ref Unsafe.Add(ref st, 2);
10521052

10531053
// Figure F.23: Decoding the magnitude category of v.

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,7 @@ private static uint ClampedAddSubtractHalf(uint c0, uint c1, uint c2)
14401440
}
14411441

14421442
[MethodImpl(InliningOptions.ShortMethod)]
1443-
private static int AddSubtractComponentHalf(int a, int b)
1444-
{
1445-
uint ua = (uint)a;
1446-
uint ub = (uint)b;
1447-
return (int)Clip255(ua + ((ua - ub) / 2));
1448-
}
1443+
private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) >> 1))); // >> 1 is bit-hack for / 2
14491444

14501445
[MethodImpl(InliningOptions.ShortMethod)]
14511446
private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c));

0 commit comments

Comments
 (0)