public static SosHeader ReadSosHeader(byte[] bytes) { //SOS HEADER UInt32 sosHeaderOffset = RawReader.FindByteValueIndex(bytes, 0xFF, 0xDA); byte[] sosHeaderBytes = RawReader.ReadBytes(bytes, sosHeaderOffset); UInt32 sosHeaderLengthOffset = 2; byte[] sosHeaderLengthBytes = RawReader.ReadBytes(sosHeaderBytes, sosHeaderLengthOffset, 2); UInt16 sosHeaderLength = ConvertHelper.ConvertToUInt16(sosHeaderLengthBytes, true); UInt32 sosHeaderComponentsNumberOffset = 4; byte sosHeaderComponentsNumber = RawReader.ReadByte(sosHeaderBytes, sosHeaderComponentsNumberOffset); SosHeaderComponentInfo[] components = new SosHeaderComponentInfo[sosHeaderComponentsNumber]; UInt32 sosHeaderComponentsOffset = 5; for (byte k = 0; k < sosHeaderComponentsNumber; k++) { SosHeaderComponentInfo componentInfo = RawReader.ReadSosHeaderComponentInfo(sosHeaderBytes, sosHeaderComponentsOffset); components[k] = componentInfo; sosHeaderComponentsOffset += 2; } return(new SosHeader() { Offset = sosHeaderOffset, HeaderLength = sosHeaderLength, Components = components }); }
private static uint GetEntryOffsetByTagID(byte[] bytes, int entryTagID) { byte[] tagIdBytes = BitConverter.GetBytes(entryTagID); uint offset = RawReader.FindByteValueIndex(bytes, tagIdBytes[0], tagIdBytes[1]); return(offset); }
public static Sof3Header ReadSof3Header(byte[] bytes) { //SOF3 HEADER UInt32 sof3HeaderOffset = RawReader.FindByteValueIndex(bytes, 0xFF, 0xC3); byte[] sof3HeaderBytes = RawReader.ReadBytes(bytes, sof3HeaderOffset); UInt32 sof3HeaderLengthOffset = 2; byte[] sof3HeaderLengthBytes = RawReader.ReadBytes(sof3HeaderBytes, sof3HeaderLengthOffset, 2); UInt16 sof3HeaderLength = ConvertHelper.ConvertToUInt16(sof3HeaderLengthBytes, true); UInt32 sof3HeaderSamplePrecisionOffset = 4; byte sof3HeaderSamplePrecision = RawReader.ReadByte(sof3HeaderBytes, sof3HeaderSamplePrecisionOffset); UInt32 sof3HeaderLinesNumberOffset = 5; byte[] sof3HeaderLinesNumberBytes = RawReader.ReadBytes(sof3HeaderBytes, sof3HeaderLinesNumberOffset, 2); UInt16 sof3HeaderLinesNumber = ConvertHelper.ConvertToUInt16(sof3HeaderLinesNumberBytes, true); UInt32 sof3HeaderSamplesPerLineNumberOffset = 7; byte[] sof3HeaderSamplesPerLineNumberBytes = RawReader.ReadBytes(sof3HeaderBytes, sof3HeaderSamplesPerLineNumberOffset, 2); UInt16 sof3HeaderSamplesPerLineNumber = ConvertHelper.ConvertToUInt16(sof3HeaderSamplesPerLineNumberBytes, true); UInt32 sof3HeaderImageComponentsPerFrameNumberOffset = 9; byte sof3HeaderImageComponentsPerFrameNumber = RawReader.ReadByte(sof3HeaderBytes, sof3HeaderImageComponentsPerFrameNumberOffset); Sof3HeaderComponentInfo[] components = new Sof3HeaderComponentInfo[sof3HeaderImageComponentsPerFrameNumber]; UInt32 sof3HeaderComponentsOffset = 10; for (byte k = 0; k < sof3HeaderImageComponentsPerFrameNumber; k++) { Sof3HeaderComponentInfo componentInfo = RawReader.ReadSof3HeaderComponentInfo(sof3HeaderBytes, sof3HeaderComponentsOffset); components[k] = componentInfo; sof3HeaderComponentsOffset += 3; } return(new Sof3Header() { Offset = sof3HeaderOffset, HeaderLength = sof3HeaderLength, SamplePrecision = sof3HeaderSamplePrecision, LinesNumber = sof3HeaderLinesNumber, SamplesPerLineNumber = sof3HeaderSamplesPerLineNumber, Components = components }); }
public static DhtHeader ReadDhtHeader(byte[] bytes) { UInt32 dhtHeaderOffset = RawReader.FindByteValueIndex(bytes, 0xFF, 0xC4); byte[] dhtHeaderBytes = RawReader.ReadBytes(bytes, dhtHeaderOffset); UInt32 dhtHeaderLengthOffset = 2; byte[] dhtHeaderLengthBytes = RawReader.ReadBytes(dhtHeaderBytes, dhtHeaderLengthOffset, 2); UInt16 dhtHeaderLength = ConvertHelper.ConvertToUInt16(dhtHeaderLengthBytes, true); UInt32 valueHuffmanCodesOffset; UInt32 lengthNumberHuffmanCodesSum = 0; //Huffman table 1 UInt32 dhtHeaderTableIndexOffset = 4; byte dhtHeaderTableIndex; UInt32 tableOffset = dhtHeaderTableIndexOffset + 1; HuffmanTable tableOne = new HuffmanTable(); dhtHeaderTableIndex = RawReader.ReadByte(dhtHeaderBytes, dhtHeaderTableIndexOffset); tableOne.TableClass = (new HalvedByte(dhtHeaderTableIndex)).High; tableOne.TableIndex = (new HalvedByte(dhtHeaderTableIndex)).Low; byte[] lengthNumberHuffmanCodesBytes = RawReader.ReadBytes(dhtHeaderBytes, tableOffset, DhtHeader.LENGTH_NUMBER_HUFFMAN_CODES_COUNT); lengthNumberHuffmanCodesSum = Convert.ToUInt32(lengthNumberHuffmanCodesBytes.Sum(x => x)); valueHuffmanCodesOffset = tableOffset + DhtHeader.LENGTH_NUMBER_HUFFMAN_CODES_COUNT; byte[] valueHuffmanCodesBytes = RawReader.ReadBytes(dhtHeaderBytes, valueHuffmanCodesOffset, lengthNumberHuffmanCodesSum); tableOne.LengthHuffmanCodes = lengthNumberHuffmanCodesBytes; tableOne.ValueHuffmanCodes = valueHuffmanCodesBytes; //Huffman table 2 dhtHeaderTableIndexOffset = valueHuffmanCodesOffset + lengthNumberHuffmanCodesSum; tableOffset = dhtHeaderTableIndexOffset + 1; HuffmanTable tableTwo = new HuffmanTable(); dhtHeaderTableIndex = RawReader.ReadByte(dhtHeaderBytes, dhtHeaderTableIndexOffset); tableTwo.TableClass = (new HalvedByte(dhtHeaderTableIndex)).High; tableTwo.TableIndex = (new HalvedByte(dhtHeaderTableIndex)).Low; lengthNumberHuffmanCodesBytes = RawReader.ReadBytes(dhtHeaderBytes, tableOffset, DhtHeader.LENGTH_NUMBER_HUFFMAN_CODES_COUNT); lengthNumberHuffmanCodesSum = Convert.ToUInt32(lengthNumberHuffmanCodesBytes.Sum(x => x)); valueHuffmanCodesOffset = tableOffset + DhtHeader.LENGTH_NUMBER_HUFFMAN_CODES_COUNT; valueHuffmanCodesBytes = RawReader.ReadBytes(dhtHeaderBytes, valueHuffmanCodesOffset, lengthNumberHuffmanCodesSum); tableTwo.LengthHuffmanCodes = lengthNumberHuffmanCodesBytes; tableTwo.ValueHuffmanCodes = valueHuffmanCodesBytes; return(new DhtHeader() { Offset = dhtHeaderOffset, HeaderLength = dhtHeaderLength, HuffmanTables = new HuffmanTable[] { tableOne, tableTwo } }); }