diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs
index 6d06abecf..95693c09b 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs
@@ -35,9 +35,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
///
- /// Gets a reference to the first element of the AC table indexed by ///
+ /// Gets a reference to the first element of the AC table indexed by ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref short GetAcTableReference(JpegFrameComponent component)
+ public ref short GetAcTableReference(JpegComponent component)
{
return ref this.tables.GetRowSpan(component.ACHuffmanTableId)[0];
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
similarity index 88%
rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs
rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
index 3ce7cacfa..73a69a069 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
@@ -13,11 +13,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Represents a single frame component
///
- internal class JpegFrameComponent : IDisposable, IJpegComponent
+ internal class JpegComponent : IDisposable, IJpegComponent
{
private readonly MemoryAllocator memoryAllocator;
- public JpegFrameComponent(MemoryAllocator memoryAllocator, JpegFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
+ public JpegComponent(MemoryAllocator memoryAllocator, JpegFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
{
this.memoryAllocator = memoryAllocator;
this.Frame = frame;
@@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
else
{
- JpegFrameComponent c0 = this.Frame.Components[0];
+ JpegComponent c0 = this.Frame.Components[0];
this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors);
}
@@ -138,16 +138,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public int GetBlockBufferOffset(int row, int col)
+ public ref short GetBlockDataReference(int column, int row)
{
- return 64 * (((this.WidthInBlocks + 1) * row) + col);
- }
-
- // TODO: we need consistence in (row, col) VS (col, row) ordering
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref short GetBlockDataReference(int row, int col)
- {
- ref Block8x8 blockRef = ref this.GetBlockReference(col, row);
+ ref Block8x8 blockRef = ref this.GetBlockReference(column, row);
return ref Unsafe.As(ref blockRef);
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
index a238e0734..da089fa44 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
@@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Gets or sets the frame component collection
///
- public JpegFrameComponent[] Components { get; set; }
+ public JpegComponent[] Components { get; set; }
///
/// Gets or sets the maximum horizontal sampling factor
@@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
for (int i = 0; i < this.ComponentCount; i++)
{
- JpegFrameComponent component = this.Components[i];
+ JpegComponent component = this.Components[i];
component.Init();
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs
index 5afe6382f..99eaf7f43 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs
@@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private readonly FastACTables fastACTables;
private readonly DoubleBufferedStreamReader stream;
- private readonly JpegFrameComponent[] components;
+ private readonly JpegComponent[] components;
private readonly ZigZag dctZigZag;
// The restart interval.
@@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
// Scan an interleaved mcu... process components in order
for (int k = 0; k < this.componentsLength; k++)
{
- JpegFrameComponent component = this.components[k];
+ JpegComponent component = this.components[k];
ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId];
ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId];
@@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
private void ParseBaselineDataNonInterleaved()
{
- JpegFrameComponent component = this.components[this.componentIndex];
+ JpegComponent component = this.components[this.componentIndex];
int w = component.WidthInBlocks;
int h = component.HeightInBlocks;
@@ -294,7 +294,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
// Scan an interleaved mcu... process components in order
for (int k = 0; k < this.componentsLength; k++)
{
- JpegFrameComponent component = this.components[k];
+ JpegComponent component = this.components[k];
ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId];
int h = component.HorizontalSamplingFactor;
int v = component.VerticalSamplingFactor;
@@ -343,7 +343,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
private void ParseProgressiveDataNonInterleaved()
{
- JpegFrameComponent component = this.components[this.componentIndex];
+ JpegComponent component = this.components[this.componentIndex];
int w = component.WidthInBlocks;
int h = component.HeightInBlocks;
@@ -394,7 +394,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
private void DecodeBlockBaseline(
- JpegFrameComponent component,
+ JpegComponent component,
int row,
int col,
ref HuffmanTable dcTable,
@@ -409,7 +409,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
JpegThrowHelper.ThrowBadHuffmanCode();
}
- ref short blockDataRef = ref component.GetBlockDataReference(row, col);
+ ref short blockDataRef = ref component.GetBlockDataReference(col, row);
int diff = t != 0 ? this.ExtendReceive(t) : 0;
int dc = component.DcPredictor + diff;
@@ -473,7 +473,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
private void DecodeBlockProgressiveDC(
- JpegFrameComponent component,
+ JpegComponent component,
int row,
int col,
ref HuffmanTable dcTable)
@@ -485,7 +485,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.CheckBits();
- ref short blockDataRef = ref component.GetBlockDataReference(row, col);
+ ref short blockDataRef = ref component.GetBlockDataReference(col, row);
if (this.successiveHigh == 0)
{
@@ -509,7 +509,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
private void DecodeBlockProgressiveAC(
- JpegFrameComponent component,
+ JpegComponent component,
int row,
int col,
ref HuffmanTable acTable,
@@ -520,7 +520,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
JpegThrowHelper.ThrowImageFormatException("Can't merge DC and AC.");
}
- ref short blockDataRef = ref component.GetBlockDataReference(row, col);
+ ref short blockDataRef = ref component.GetBlockDataReference(col, row);
if (this.successiveHigh == 0)
{
@@ -939,7 +939,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
for (int i = 0; i < this.components.Length; i++)
{
- JpegFrameComponent c = this.components[i];
+ JpegComponent c = this.components[i];
c.DcPredictor = 0;
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 5c4dbfc24..07209bc28 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
/// Gets the components.
///
- public JpegFrameComponent[] Components => this.Frame.Components;
+ public JpegComponent[] Components => this.Frame.Components;
///
IEnumerable IRawJpegData.Components => this.Components;
@@ -666,7 +666,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
// No need to pool this. They max out at 4
this.Frame.ComponentIds = new byte[this.Frame.ComponentCount];
- this.Frame.Components = new JpegFrameComponent[this.Frame.ComponentCount];
+ this.Frame.Components = new JpegComponent[this.Frame.ComponentCount];
this.ColorSpace = this.DeduceJpegColorSpace();
for (int i = 0; i < this.Frame.ComponentCount; i++)
@@ -685,7 +685,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
maxV = v;
}
- var component = new JpegFrameComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i);
+ var component = new JpegComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i);
this.Frame.Components[i] = component;
this.Frame.ComponentIds[i] = component.Id;
@@ -793,7 +793,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
throw new ImageFormatException("Unknown component selector");
}
- ref JpegFrameComponent component = ref this.Frame.Components[componentIndex];
+ ref JpegComponent component = ref this.Frame.Components[componentIndex];
int tableSpec = this.InputStream.ReadByte();
component.DCHuffmanTableId = tableSpec >> 4;
component.ACHuffmanTableId = tableSpec & 15;
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs
index e4d8d29d4..3657110c6 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs
@@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU);
var uniform1 = new Size(1, 1);
- JpegFrameComponent c0 = decoder.Components[0];
+ JpegComponent c0 = decoder.Components[0];
VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1);
}
}
@@ -71,8 +71,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
sb.AppendLine(imageFile);
sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
- JpegFrameComponent c0 = decoder.Components[0];
- JpegFrameComponent c1 = decoder.Components[1];
+ JpegComponent c0 = decoder.Components[0];
+ JpegComponent c1 = decoder.Components[1];
sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}");
sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}");
@@ -107,9 +107,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(componentCount, decoder.ComponentCount);
Assert.Equal(componentCount, decoder.Components.Length);
- JpegFrameComponent c0 = decoder.Components[0];
- JpegFrameComponent c1 = decoder.Components[1];
- JpegFrameComponent c2 = decoder.Components[2];
+ JpegComponent c0 = decoder.Components[0];
+ JpegComponent c1 = decoder.Components[1];
+ JpegComponent c2 = decoder.Components[2];
var uniform1 = new Size(1, 1);
@@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
if (componentCount == 4)
{
- JpegFrameComponent c3 = decoder.Components[2];
+ JpegComponent c3 = decoder.Components[2];
VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1);
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
index 5ffd5d62b..a10deb983 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
@@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
this.SpectralBlocks[x, y] = new Block8x8(data);
}
- public static ComponentData Load(JpegFrameComponent c, int index)
+ public static ComponentData Load(JpegComponent c, int index)
{
var result = new ComponentData(
c.WidthInBlocks,
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs
index e9f0b1138..bcfabca39 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs
@@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public static SpectralData LoadFromImageSharpDecoder(JpegDecoderCore decoder)
{
- JpegFrameComponent[] srcComponents = decoder.Frame.Components;
+ JpegComponent[] srcComponents = decoder.Frame.Components;
LibJpegTools.ComponentData[] destComponents = srcComponents.Select(LibJpegTools.ComponentData.Load).ToArray();
return new SpectralData(destComponents);