diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs index e653e505ea..6d5d2548f6 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs @@ -451,6 +451,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component. + int mcuColMulh = mcuCol * h; for (int y = 0; y < v; y++) { Span blockSpan = component.SpectralBlocks.DangerousGetRowSpan(y); @@ -466,11 +467,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder return; } - int blockCol = (mcuCol * h) + x; + int blockCol = mcuColMulh + x; this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, blockCol), + ref Unsafe.Add(ref blockRef, (nint)(uint)blockCol), ref acDecodingTable, ref dcDecodingTable); } @@ -521,7 +522,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, k), + ref Unsafe.Add(ref blockRef, (nint)(uint)k), ref acDecodingTable, ref dcDecodingTable); @@ -560,7 +561,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.DecodeBlockBaseline( component, - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (nint)(uint)i), ref acDecodingTable, ref dcDecodingTable); @@ -593,6 +594,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component. + int mcuColMulh = mcuCol * h; for (int y = 0; y < v; y++) { int blockRow = (mcuRow * v) + y; @@ -606,11 +608,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder return; } - int blockCol = (mcuCol * h) + x; + int blockCol = mcuColMulh + x; this.DecodeBlockProgressiveDc( component, - ref Unsafe.Add(ref blockRef, blockCol), + ref Unsafe.Add(ref blockRef, (nint)(uint)blockCol), ref dcDecodingTable); } } @@ -652,7 +654,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.DecodeBlockProgressiveDc( component, - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (nint)(uint)i), ref dcDecodingTable); this.HandleRestart(); @@ -679,7 +681,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.DecodeBlockProgressiveAc( component, - ref Unsafe.Add(ref blockRef, i), + ref Unsafe.Add(ref blockRef, (nint)(uint)i), ref acDecodingTable); this.HandleRestart(); @@ -716,7 +718,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Figure F.21: Decoding nonzero value v. // Figure F.22: Decoding the sign of v. int sign = this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)); - st = ref Unsafe.Add(ref st, 2 + sign); + st = ref Unsafe.Add(ref st, (nint)(uint)(2 + sign)); // Figure F.23: Decoding the magnitude category of v. int m = this.DecodeBinaryDecision(ref reader, ref st); @@ -966,7 +968,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Figure F.21: Decoding nonzero value v // Figure F.22: Decoding the sign of v int sign = this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)); - st = ref Unsafe.Add(ref st, 2 + sign); + st = ref Unsafe.Add(ref st, (nint)(uint)(2 + sign)); // Figure F.23: Decoding the magnitude category of v. int m = this.DecodeBinaryDecision(ref reader, ref st); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs index 63e0ac09c5..adab8c2ec3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Gets the component id. /// - public byte Id { get; } + byte Id { get; } /// /// Gets the component's position in the components array. @@ -33,12 +33,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Gets the horizontal sampling factor. /// - public int HorizontalSamplingFactor { get; } + int HorizontalSamplingFactor { get; } /// /// Gets the vertical sampling factor. /// - public int VerticalSamplingFactor { get; } + int VerticalSamplingFactor { get; } /// /// Gets the divisors needed to apply when calculating colors. @@ -63,34 +63,34 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Gets or sets DC coefficient predictor. /// - public int DcPredictor { get; set; } + int DcPredictor { get; set; } /// /// Gets or sets the index for the DC table. /// - public int DcTableId { get; set; } + int DcTableId { get; set; } /// /// Gets or sets the index for the AC table. /// - public int AcTableId { get; set; } + int AcTableId { get; set; } /// /// Initializes component for future buffers initialization. /// /// Maximal horizontal subsampling factor among all the components. /// Maximal vertical subsampling factor among all the components. - public void Init(int maxSubFactorH, int maxSubFactorV); + void Init(int maxSubFactorH, int maxSubFactorV); /// /// Allocates the spectral blocks. /// /// if set to true, use the full height of a block, otherwise use the vertical sampling factor. - public void AllocateSpectral(bool fullScan); + void AllocateSpectral(bool fullScan); /// /// Releases resources. /// - public void Dispose(); + void Dispose(); } }