Browse Source

Fixed invalid baseline jpeg decoding

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
e39adf85f6
  1. 5
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 16
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
  3. 10
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

5
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

@ -185,7 +185,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
for (int y = 0; y < v; y++) for (int y = 0; y < v; y++)
{ {
int blockRow = (mcuRow * v) + y; int blockRow = (mcuRow * v) + y;
Span<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(blockRow); Span<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(y);
ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan);
for (int x = 0; x < h; x++) for (int x = 0; x < h; x++)
@ -213,7 +213,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
// convert from spectral to actual pixels via given converter // convert from spectral to actual pixels via given converter
this.spectralConverter.ConvertStride(j, j); this.spectralConverter.ConvertStride(j, 0);
this.spectralConverter.ClearStride(0);
} }
} }

16
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs

@ -108,6 +108,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
} }
public void ClearSpectralStride(int step)
{
int yBlockStart = step * this.BlockRowsPerStep;
for (int y = 0; y < this.BlockRowsPerStep; y++)
{
int yBlock = yBlockStart + y;
if (yBlock >= this.SizeInBlocks.Height)
{
break;
}
this.Component.SpectralBlocks.GetRowSpan(yBlock).Clear();
}
}
public void CopyBlocksToColorBuffer() public void CopyBlocksToColorBuffer()
{ {
this.CopyBlocksToColorBuffer(this.currentComponentRowInBlocks); this.CopyBlocksToColorBuffer(this.currentComponentRowInBlocks);

10
src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

@ -21,6 +21,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
public abstract void ConvertStride(int step, int spectralStep); public abstract void ConvertStride(int step, int spectralStep);
public abstract void ClearStride(int spectralStep);
public abstract void Dispose(); public abstract void Dispose();
} }
@ -134,6 +136,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
} }
public override void ClearStride(int spectralStep)
{
foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
{
cpp.ClearSpectralStride(spectralStep);
}
}
public override void Dispose() public override void Dispose()
{ {
foreach (JpegComponentPostProcessor cpp in this.componentProcessors) foreach (JpegComponentPostProcessor cpp in this.componentProcessors)

Loading…
Cancel
Save