/// <summary> /// parse an ODS packet which contain the image data /// </summary> /// <param name="buffer">raw byte date, starting right after segment</param> /// <param name="segment">object containing info about the current segment</param> /// <returns>true if this is a valid new object (neither invalid nor a fragment)</returns> private static OdsData ParseOds(byte[] buffer, SupSegment segment, bool forceFirst) { int objId = BigEndianInt16(buffer, 0); // 16bit object_id int objVer = buffer[2]; // 16bit object_id nikse - index 2 or 1??? int objSeq = buffer[3]; // 8bit first_in_sequence (0x80), // last_in_sequence (0x40), 6bits reserved bool first = ((objSeq & 0x80) == 0x80) || forceFirst; bool last = (objSeq & 0x40) == 0x40; var info = new ImageObjectFragment(); if (first) { int width = BigEndianInt16(buffer, 7); // object_width int height = BigEndianInt16(buffer, 9); // object_height info.ImagePacketSize = segment.Size - 11; // Image packet size (image bytes) info.ImageBuffer = new byte[info.ImagePacketSize]; Buffer.BlockCopy(buffer, 11, info.ImageBuffer, 0, info.ImagePacketSize); return new OdsData { IsFirst = true, Size = new Size(width, height), ObjectId = objId, ObjectVersion = objVer, Fragment = info, Message = "ObjId: " + objId + ", ver: " + objVer + ", seq: first" + (last ? "/" : "") + (last ? "" + "last" : "") + ", width: " + width + ", height: " + height, }; } else { info.ImagePacketSize = segment.Size - 4; info.ImageBuffer = new byte[info.ImagePacketSize]; Buffer.BlockCopy(buffer, 4, info.ImageBuffer, 0, info.ImagePacketSize); return new OdsData { IsFirst = false, ObjectId = objId, ObjectVersion = objVer, Fragment = info, Message = "Continued ObjId: " + objId + ", ver: " + objVer + ", seq: " + (last ? "" + "last" : ""), }; } }