public SOFInfo GetSOF(uint offset, uint size) { // JPEG is big endian if (Common.GetHostEndianness() == Endianness.Big) { input = new ImageBinaryReader(input.BaseStream, offset); } else { input = new ImageBinaryReaderBigEndian(input.BaseStream, offset); } if (GetNextMarker(false) != JpegMarker.SOI) { throw new RawDecoderException("Image did not start with SOI. Probably not an LJPEG"); } while (true) { JpegMarker m = GetNextMarker(true); if (m == JpegMarker.Sof3) { SOFInfo sof = new SOFInfo(); ParseSOF(sof); return(sof); } if (m == JpegMarker.EOI) { throw new RawDecoderException("Could not locate Start of Frame."); } } }
public void ParseSOF(SOFInfo sof) { uint headerLength = input.ReadUInt16(); sof.precision = input.ReadByte(); sof.height = input.ReadUInt16(); sof.width = input.ReadUInt16(); sof.numComponents = input.ReadByte(); if (sof.precision > 16) { throw new RawDecoderException("More than 16 bits per channel is not supported."); } if (sof.numComponents > 4 || sof.numComponents < 1) { throw new RawDecoderException("Only from 1 to 4 components are supported."); } if (headerLength != 8 + sof.numComponents * 3) { throw new RawDecoderException("Header size mismatch."); } for (int i = 0; i < sof.numComponents; i++) { sof.ComponentInfo[i].componentId = input.ReadByte(); uint subs = input.ReadByte(); frame.ComponentInfo[i].superV = subs & 0xf; frame.ComponentInfo[i].superH = subs >> 4; uint Tq = input.ReadByte(); if (Tq != 0) { throw new RawDecoderException("Quantized components not supported."); } } sof.Initialized = true; }