Browse Source

Rolled back to counter enumeration for spectral converter

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
7afca199b7
  1. 22
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

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

@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData); public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
public abstract void ConvertStride(int step, int spectralStep); public abstract void ConvertStride(int spectralStep);
public abstract void ClearStride(int spectralStep); public abstract void ClearStride(int spectralStep);
public abstract void Dispose(); public abstract void Dispose();
} }
internal class SpectralConverter<TPixel> : SpectralConverter internal sealed class SpectralConverter<TPixel> : SpectralConverter
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
private Configuration configuration; private Configuration configuration;
@ -48,6 +48,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private int PixelRowsPerStep; private int PixelRowsPerStep;
private int PixelRowCounter;
private bool converted; private bool converted;
@ -62,7 +64,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
for (int i = 0; i < steps; i++) for (int i = 0; i < steps; i++)
{ {
this.cancellationToken.ThrowIfCancellationRequested(); this.cancellationToken.ThrowIfCancellationRequested();
this.ConvertStride(i, i); this.ConvertStride(i);
} }
this.converted = true; this.converted = true;
@ -109,11 +111,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.colorConverter = JpegColorConverter.GetConverter(jpegData.ColorSpace, frame.Precision); this.colorConverter = JpegColorConverter.GetConverter(jpegData.ColorSpace, frame.Precision);
} }
public override void ConvertStride(int step, int spectralStep) public override void ConvertStride(int spectralStep)
{ {
int pixelRowStart = this.PixelRowsPerStep * step; int maxY = Math.Min(this.pixelBuffer.Height, this.PixelRowCounter + this.PixelRowsPerStep);
int maxY = Math.Min(this.pixelBuffer.Height, pixelRowStart + this.PixelRowsPerStep);
var buffers = new Buffer2D<float>[this.componentProcessors.Length]; var buffers = new Buffer2D<float>[this.componentProcessors.Length];
for (int i = 0; i < this.componentProcessors.Length; i++) for (int i = 0; i < this.componentProcessors.Length; i++)
@ -122,9 +122,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
buffers[i] = this.componentProcessors[i].ColorBuffer; buffers[i] = this.componentProcessors[i].ColorBuffer;
} }
for (int yy = pixelRowStart; yy < maxY; yy++) for (int yy = this.PixelRowCounter; yy < maxY; yy++)
{ {
int y = yy - pixelRowStart; int y = yy - this.PixelRowCounter;
var values = new JpegColorConverter.ComponentValues(buffers, y); var values = new JpegColorConverter.ComponentValues(buffers, y);
this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan()); this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan());
@ -134,13 +134,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
// TODO: Investigate if slicing is actually necessary // TODO: Investigate if slicing is actually necessary
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow); PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow);
} }
this.PixelRowCounter += this.PixelRowsPerStep;
} }
public override void ClearStride(int spectralStep) public override void ClearStride(int spectralStep)
{ {
foreach (JpegComponentPostProcessor cpp in this.componentProcessors) foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
{ {
cpp.ClearSpectralStride(spectralStep); cpp.ClearSpectralBuffers(spectralStep);
} }
} }

Loading…
Cancel
Save