diff --git a/src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs b/src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs index 524e3b913..ca8744022 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs +++ b/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 /// public int BlocksPerColumn; + + /// + /// Gets the index for the DC Huffman table + /// + public int DCHuffmanTableId; + + /// + /// Gets the index for the AC Huffman table + /// + public int ACHuffmanTableId; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs index 236e38f96..f26dbded5 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs @@ -155,6 +155,24 @@ namespace ImageSharp.Formats.Jpeg.Port /// public const ushort DHT = 0xFFC4; + /// + /// Define Restart Interval + /// + /// 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. + /// + /// + public const ushort DRI = 0xFFDD; + + /// + /// Start of Scan + /// + /// 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. + /// + /// + public const ushort SOS = 0xFFDA; + /// /// Contains JFIF specific markers /// diff --git a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs index 95a83b086..9dd45f53b 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs @@ -45,6 +45,8 @@ namespace ImageSharp.Formats.Jpeg.Port private Frame frame; + private ushort resetInterval; + /// /// COntains information about the jFIF marker /// @@ -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 } } + /// + /// Processes the SOS (Start of scan marker). + /// + private void ProcessStartOfScan() + { + int selectorsCount = this.InputStream.ReadByte(); + var components = new List(); + + 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 components, int spectralStart, int spectralEnd, int successivePrev, int successive) + { + return 0; + } + /// /// Builds the huffman tables /// @@ -555,4 +596,4 @@ namespace ImageSharp.Formats.Jpeg.Port // TODO: Thumbnail? } } -} +} \ No newline at end of file