Browse Source

Docs & review fixes

pull/2076/head
Dmitry Pentin 4 years ago
parent
commit
6747339659
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverterBase.cs
  2. 20
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs
  3. 3
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs
  4. 5
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs
  5. 5
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs
  6. 13
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs
  7. 1
      tests/ImageSharp.Tests/Formats/Jpg/SpectralConverterTests.cs

2
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.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public abstract int ElementsPerBatch { get; }

20
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs

@ -6,6 +6,9 @@ using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
/// <summary>
/// Base class for processing component spectral data and converting it to raw color data.
/// </summary>
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);
/// <summary>
/// Converts spectral data to color data accessible via <see cref="GetColorBufferRowSpan(int)"/>.
/// </summary>
/// <param name="row">Spectral row index to convert.</param>
public abstract void CopyBlocksToColorBuffer(int row);
/// <summary>
/// Clears spectral buffers.
/// </summary>
/// <remarks>
/// Should only be called during baseline interleaved decoding.
/// </remarks>
public void ClearSpectralBuffers()
{
Buffer2D<Block8x8> spectralBlocks = this.Component.SpectralBlocks;
@ -39,6 +52,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
/// <summary>
/// Gets converted color buffer row.
/// </summary>
/// <param name="row">Row index.</param>
/// <returns>Color buffer row.</returns>
public Span<float> GetColorBufferRowSpan(int row) =>
this.ColorBuffer.DangerousGetRowSpan(row);

3
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs

@ -6,6 +6,9 @@ using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
/// <summary>
/// Processes component spectral data and converts it to color data in 1-to-1 scale.
/// </summary>
internal sealed class DirectComponentProcessor : ComponentProcessor
{
private Block8x8F dequantizationTable;

5
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs

@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
/// <summary>
/// Processes component spectral data and converts it to color data in 2-to-1 scale.
/// </summary>
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;
}
}
}

5
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs

@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
/// <summary>
/// Processes component spectral data and converts it to color data in 4-to-1 scale.
/// </summary>
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;
}
}
}

13
src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs

@ -7,6 +7,9 @@ using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
/// <summary>
/// Processes component spectral data and converts it to color data in 8-to-1 scale.
/// </summary>
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);
}
}
}

1
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)]

Loading…
Cancel
Save