Browse Source

Additional review changes

pull/2073/head
Brian Popow 4 years ago
parent
commit
0bc0cd82ff
  1. 22
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
  2. 18
      src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs

22
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<Block8x8> 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);

18
src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Gets the component id.
/// </summary>
public byte Id { get; }
byte Id { get; }
/// <summary>
/// Gets the component's position in the components array.
@ -33,12 +33,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Gets the horizontal sampling factor.
/// </summary>
public int HorizontalSamplingFactor { get; }
int HorizontalSamplingFactor { get; }
/// <summary>
/// Gets the vertical sampling factor.
/// </summary>
public int VerticalSamplingFactor { get; }
int VerticalSamplingFactor { get; }
/// <summary>
/// Gets the divisors needed to apply when calculating colors.
@ -63,34 +63,34 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Gets or sets DC coefficient predictor.
/// </summary>
public int DcPredictor { get; set; }
int DcPredictor { get; set; }
/// <summary>
/// Gets or sets the index for the DC table.
/// </summary>
public int DcTableId { get; set; }
int DcTableId { get; set; }
/// <summary>
/// Gets or sets the index for the AC table.
/// </summary>
public int AcTableId { get; set; }
int AcTableId { get; set; }
/// <summary>
/// Initializes component for future buffers initialization.
/// </summary>
/// <param name="maxSubFactorH">Maximal horizontal subsampling factor among all the components.</param>
/// <param name="maxSubFactorV">Maximal vertical subsampling factor among all the components.</param>
public void Init(int maxSubFactorH, int maxSubFactorV);
void Init(int maxSubFactorH, int maxSubFactorV);
/// <summary>
/// Allocates the spectral blocks.
/// </summary>
/// <param name="fullScan">if set to true, use the full height of a block, otherwise use the vertical sampling factor.</param>
public void AllocateSpectral(bool fullScan);
void AllocateSpectral(bool fullScan);
/// <summary>
/// Releases resources.
/// </summary>
public void Dispose();
void Dispose();
}
}

Loading…
Cancel
Save