Skip to content

Commit bc61781

Browse files
committed
Fixed bugs
1 parent 5d111db commit bc61781

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

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

5454
private ArithmeticDecodingTable[] acDecodingTables;
5555

56+
private static readonly byte[] FixedBin = { 113, 0, 0, 0 };
57+
5658
private readonly CancellationToken cancellationToken;
5759

5860
private static readonly int[] ArithmeticTable =
@@ -229,13 +231,7 @@ public void InitDecodingTables(List<ArithmeticDecodingTable> arithmeticDecodingT
229231
}
230232
}
231233

232-
private static ref byte GetFixedBinReference()
233-
{
234-
// This uses C#'s optimization to refer to the static data segment of the assembly.
235-
// No allocation occurs.
236-
ReadOnlySpan<byte> fixedBin = new byte[] { 113, 0, 0, 0 };
237-
return ref MemoryMarshal.GetReference(fixedBin);
238-
}
234+
private static ref byte GetFixedBinReference() => ref MemoryMarshal.GetArrayDataReference(FixedBin);
239235

240236
/// <summary>
241237
/// Decodes the entropy coded data.
@@ -765,7 +761,7 @@ private void DecodeBlockProgressiveDc(ArithmeticDecodingComponent component, ref
765761
}
766762
}
767763

768-
v += 1;
764+
v++;
769765
if (sign != 0)
770766
{
771767
v = -v;
@@ -860,7 +856,7 @@ private void DecodeBlockProgressiveAc(ArithmeticDecodingComponent component, ref
860856
}
861857
}
862858

863-
v += 1;
859+
v++;
864860
if (sign != 0)
865861
{
866862
v = -v;
@@ -1016,7 +1012,7 @@ private void DecodeBlockBaseline(
10161012
}
10171013
}
10181014

1019-
v += 1;
1015+
v++;
10201016
if (sign != 0)
10211017
{
10221018
v = -v;
@@ -1086,7 +1082,7 @@ private void DecodeBlockBaseline(
10861082
}
10871083
}
10881084

1089-
v += 1;
1085+
v++;
10901086
if (sign != 0)
10911087
{
10921088
v = -v;

src/ImageSharp/Primitives/Rectangle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public int Bottom
195195
/// <param name="rectangle">The rectangle.</param>
196196
/// <returns>The <see cref="Point"/>.</returns>
197197
[MethodImpl(MethodImplOptions.AggressiveInlining)]
198-
public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width & 1), rectangle.Top + (rectangle.Height & 1)); // & 1 is bit-hack for / 2
198+
public static Point Center(Rectangle rectangle) => new(rectangle.Left + (rectangle.Width >> 1), rectangle.Top + (rectangle.Height >> 1)); // >> 1 is bit-hack for / 2
199199

200200
/// <summary>
201201
/// Creates a rectangle that represents the intersection between <paramref name="a"/> and

0 commit comments

Comments
 (0)