Browse Source

Begin ProcessStartOfScan

af/merge-core
James Jackson-South 9 years ago
parent
commit
a2431cb5d0
  1. 10
      src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs
  2. 18
      src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs
  3. 43
      src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs

10
src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs

@ -49,5 +49,15 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// Gets or sets the number of blocks per column
/// </summary>
public int BlocksPerColumn;
/// <summary>
/// Gets the index for the DC Huffman table
/// </summary>
public int DCHuffmanTableId;
/// <summary>
/// Gets the index for the AC Huffman table
/// </summary>
public int ACHuffmanTableId;
}
}

18
src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs

@ -155,6 +155,24 @@ namespace ImageSharp.Formats.Jpeg.Port
/// </summary>
public const ushort DHT = 0xFFC4;
/// <summary>
/// Define Restart Interval
/// <remarks>
/// Specifies the interval between RSTn markers, in macroblocks.This marker is followed by two bytes indicating the fixed size so it can be treated like any other variable size segment.
/// </remarks>
/// </summary>
public const ushort DRI = 0xFFDD;
/// <summary>
/// Start of Scan
/// <remarks>
/// Begins a top-to-bottom scan of the image. In baseline DCT JPEG images, there is generally a single scan.
/// Progressive DCT JPEG images usually contain multiple scans. This marker specifies which slice of data it
/// will contain, and is immediately followed by entropy-coded data.
/// </remarks>
/// </summary>
public const ushort SOS = 0xFFDA;
/// <summary>
/// Contains JFIF specific markers
/// </summary>

43
src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs

@ -45,6 +45,8 @@ namespace ImageSharp.Formats.Jpeg.Port
private Frame frame;
private ushort resetInterval;
/// <summary>
/// COntains information about the jFIF marker
/// </summary>
@ -140,6 +142,14 @@ namespace ImageSharp.Formats.Jpeg.Port
case JpegConstants.Markers.DHT:
this.ProcessDefineHuffmanTablesMarker(remaining);
break;
case JpegConstants.Markers.DRI:
this.resetInterval = this.ReadUint16();
break;
case JpegConstants.Markers.SOS:
this.ProcessStartOfScan();
break;
}
// Read on
@ -319,6 +329,8 @@ namespace ImageSharp.Formats.Jpeg.Port
component.VerticalFactor = v;
component.QuantizationIdentifier = this.temp[index + 2];
this.frame.ComponentIds[i] = (byte)i;
// Don't assign the table yet.
index += 3;
}
@ -374,6 +386,35 @@ namespace ImageSharp.Formats.Jpeg.Port
}
}
/// <summary>
/// Processes the SOS (Start of scan marker).
/// </summary>
private void ProcessStartOfScan()
{
int selectorsCount = this.InputStream.ReadByte();
var components = new List<Component>();
for (int i = 0; i < selectorsCount; i++)
{
byte componentIndex = this.frame.ComponentIds[this.InputStream.ReadByte() - 1];
Component component = this.frame.Components[componentIndex];
int tableSpec = this.InputStream.ReadByte();
component.DCHuffmanTableId = tableSpec >> 4;
component.ACHuffmanTableId = tableSpec & 15;
components.Add(component);
}
this.InputStream.Read(this.temp, 0, 3);
int spectralStart = this.temp[0];
int spectralEnd = this.temp[1];
int successiveApproximation = this.temp[2];
}
private int DecodeScan(List<Component> components, int spectralStart, int spectralEnd, int successivePrev, int successive)
{
return 0;
}
/// <summary>
/// Builds the huffman tables
/// </summary>
@ -555,4 +596,4 @@ namespace ImageSharp.Formats.Jpeg.Port
// TODO: Thumbnail?
}
}
}
}
Loading…
Cancel
Save