diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
index 4e74f62269..1eb74ff80d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
@@ -6,11 +6,8 @@ using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
///
- /// Converter used to convert jpeg spectral data.
+ /// Converter used to convert jpeg spectral data to color pixels.
///
- ///
- /// This is tightly coupled with and .
- ///
internal abstract class SpectralConverter
{
///
@@ -30,12 +27,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
///
- /// Called once per spectral stride for each component in .
- /// This is called only for baseline interleaved jpegs.
+ /// Converts single spectral jpeg stride to color stride in baseline
+ /// decoding mode.
///
///
+ /// Called once per decoded spectral stride in
+ /// only for baseline interleaved jpeg images.
/// Spectral 'stride' doesn't particularly mean 'single stride'.
- /// Actual stride height depends on the subsampling factor of the given component.
+ /// Actual stride height depends on the subsampling factor of the given image.
///
public abstract void ConvertStrideBaseline();
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
index ad19f476f4..0003437e74 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
@@ -11,28 +11,77 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
+ ///
+ ///
+ /// Color decoding scheme:
+ ///
+ ///
+ /// - 1. Decode spectral data to Jpeg color space
+ /// - 2. Convert from Jpeg color space to RGB
+ /// - 3. Convert from RGB to target pixel space
+ ///
+ ///
+ ///
internal class SpectralConverter : SpectralConverter, IDisposable
where TPixel : unmanaged, IPixel
{
+ ///
+ /// instance associated with current
+ /// decoding routine.
+ ///
private readonly Configuration configuration;
+ ///
+ /// Jpeg component converters from decompressed spectral to color data.
+ ///
private JpegComponentPostProcessor[] componentProcessors;
+ ///
+ /// Color converter from jpeg color space to target pixel color space.
+ ///
private JpegColorConverter colorConverter;
+ ///
+ /// Intermediate buffer of RGB components used in color conversion.
+ ///
private IMemoryOwner rgbBuffer;
+ ///
+ /// Proxy buffer used in packing from RGB to target TPixel pixels.
+ ///
private IMemoryOwner paddedProxyPixelRow;
+ ///
+ /// Resulting 2D pixel buffer.
+ ///
private Buffer2D pixelBuffer;
+ ///
+ /// How many pixel rows are processed in one 'stride'.
+ ///
private int pixelRowsPerStep;
+ ///
+ /// How many pixel rows were processed.
+ ///
private int pixelRowCounter;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The configuration.
public SpectralConverter(Configuration configuration) =>
this.configuration = configuration;
+ ///
+ /// Gets converted pixel buffer.
+ ///
+ ///
+ /// For non-baseline interleaved jpeg this method does a 'lazy' spectral
+ /// conversion from spectral to color.
+ ///
+ /// Cancellation token.
+ /// Pixel buffer.
public Buffer2D GetPixelBuffer(CancellationToken cancellationToken)
{
if (!this.Converted)
@@ -95,21 +144,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
- ///
- public void Dispose()
- {
- if (this.componentProcessors != null)
- {
- foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
- {
- cpp.Dispose();
- }
- }
-
- this.rgbBuffer?.Dispose();
- this.paddedProxyPixelRow?.Dispose();
- }
-
+ ///
+ /// Converts single spectral jpeg stride to color stride.
+ ///
+ /// Spectral stride index.
private void ConvertStride(int spectralStep)
{
int maxY = Math.Min(this.pixelBuffer.Height, this.pixelRowCounter + this.pixelRowsPerStep);
@@ -155,5 +193,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.pixelRowCounter += this.pixelRowsPerStep;
}
+
+ ///
+ public void Dispose()
+ {
+ if (this.componentProcessors != null)
+ {
+ foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
+ {
+ cpp.Dispose();
+ }
+ }
+
+ this.rgbBuffer?.Dispose();
+ this.paddedProxyPixelRow?.Dispose();
+ }
}
}