diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverterBase.cs index 95ac123472..c625e2e6bd 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverterBase.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverterBase.cs @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters /// Gets a value indicating how many pixels are processed in a single batch. /// /// - /// This generaly should be equal to register size, + /// This generally should be equal to register size, /// e.g. 1 for scalar implementation, 8 for AVX implementation and so on. /// public abstract int ElementsPerBatch { get; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs index 14109b796b..fe5c452820 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs @@ -6,6 +6,9 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { + /// + /// Base class for processing component spectral data and converting it to raw color data. + /// internal abstract class ComponentProcessor : IDisposable { public ComponentProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, Size postProcessorBufferSize, IJpegComponent component, int blockSize) @@ -28,8 +31,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder protected Size BlockAreaSize { get; } - public abstract void CopyBlocksToColorBuffer(int spectralStep); + /// + /// Converts spectral data to color data accessible via . + /// + /// Spectral row index to convert. + public abstract void CopyBlocksToColorBuffer(int row); + /// + /// Clears spectral buffers. + /// + /// + /// Should only be called during baseline interleaved decoding. + /// public void ClearSpectralBuffers() { Buffer2D spectralBlocks = this.Component.SpectralBlocks; @@ -39,6 +52,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } } + /// + /// Gets converted color buffer row. + /// + /// Row index. + /// Color buffer row. public Span GetColorBufferRowSpan(int row) => this.ColorBuffer.DangerousGetRowSpan(row); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs index be9fd98c11..ff3b502c9a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs @@ -6,6 +6,9 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { + /// + /// Processes component spectral data and converts it to color data in 1-to-1 scale. + /// internal sealed class DirectComponentProcessor : ComponentProcessor { private Block8x8F dequantizationTable; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs index 81fdced66f..39174b3fb2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs @@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { + /// + /// Processes component spectral data and converts it to color data in 2-to-1 scale. + /// internal sealed class DownScalingComponentProcessor2 : ComponentProcessor { private Block8x8F dequantizationTable; @@ -88,7 +91,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int j = 0; j < horizontalScale; j++) { // area[xx + j, yy + i] = value; - Unsafe.Add(ref areaOrigin, baseIdx + j) = value; + Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value; } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs index 505e37fa40..aa96b28261 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs @@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { + /// + /// Processes component spectral data and converts it to color data in 4-to-1 scale. + /// internal sealed class DownScalingComponentProcessor4 : ComponentProcessor { private Block8x8F dequantizationTable; @@ -88,7 +91,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int j = 0; j < horizontalScale; j++) { // area[xx + j, yy + i] = value; - Unsafe.Add(ref areaOrigin, baseIdx + j) = value; + Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value; } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs index 7961b59170..36a72769ec 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs @@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { + /// + /// Processes component spectral data and converts it to color data in 8-to-1 scale. + /// internal sealed class DownScalingComponentProcessor8 : ComponentProcessor { private readonly float dcDequantizatizer; @@ -63,10 +66,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder if (horizontalScale == 2 && verticalScale == 2) { - Unsafe.Add(ref destRef, 0) = value; + destRef = value; Unsafe.Add(ref destRef, 1) = value; - Unsafe.Add(ref destRef, 0 + destStrideWidth) = value; - Unsafe.Add(ref destRef, 1 + destStrideWidth) = value; + Unsafe.Add(ref destRef, 0 + (nint)(uint)destStrideWidth) = value; + Unsafe.Add(ref destRef, 1 + (nint)(uint)destStrideWidth) = value; return; } @@ -75,10 +78,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { for (int x = 0; x < horizontalScale; x++) { - Unsafe.Add(ref destRef, x) = value; + Unsafe.Add(ref destRef, (nint)(uint)x) = value; } - destRef = ref Unsafe.Add(ref destRef, destStrideWidth); + destRef = ref Unsafe.Add(ref destRef, (nint)(uint)destStrideWidth); } } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralConverterTests.cs index 10b5df8c83..008ca20c3f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralConverterTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Trait("Format", "Jpg")] public class SpectralConverterTests { + // Test for null target size, i.e. when no scaling is needed [Theory] [InlineData(1, 1)] [InlineData(800, 400)]