示例#1
0
        private bool ReadBit()
        {
            if (!initialised)
            {
                new BitArray(new Byte[] { StreamUtils.ReadByte(stream) }).CopyTo(buffer, 0);
                Array.Reverse(buffer);

                bufferPosition = 0;

                initialised = true;
            }

            if (Position >= Length)
            {
                throw new Exception("Cannot read past end of stream.");
            }

            if (bufferPosition == buffer.Length)
            {
                new BitArray(new Byte[] { StreamUtils.ReadByte(stream) }).CopyTo(buffer, 0);
                Array.Reverse(buffer);

                bufferPosition = 0;
            }

            ++Position;

            return(buffer[bufferPosition++]);
        }
示例#2
0
        public ElementHeader(Stream stream)
        {
            ElementLength = StreamUtils.ReadInt32(stream);
            ObjectTypeID  = new GUID(stream);

            if (ObjectTypeID.ToString() != ConstUtils.EndOfElementAsString)
            {
                ObjectBaseType = StreamUtils.ReadByte(stream);
            }
        }
        public PropertyProxyMetaDataElement(Stream stream)
        {
            PropertyKeys       = new List <MbString>();
            PropertyValueTypes = new List <byte>();
            PropertyValues     = new List <object>();

            var propertyKey = new MbString(stream);

            while (propertyKey.Count > 0)
            {
                PropertyKeys.Add(propertyKey);

                var propertyValueType = StreamUtils.ReadByte(stream);

                PropertyValueTypes.Add(propertyValueType);

                switch (propertyValueType)
                {
                case 1:
                {
                    PropertyValues.Add(new MbString(stream));         // MbString

                    break;
                }

                case 2:
                {
                    PropertyValues.Add(StreamUtils.ReadInt32(stream));         // Int32

                    break;
                }

                case 3:
                {
                    PropertyValues.Add(StreamUtils.ReadFloat(stream));         // Single

                    break;
                }

                case 4:
                {
                    PropertyValues.Add(new Date(stream));         // Date

                    break;
                }

                default:
                {
                    throw new Exception(String.Format("Property Value Type {0} is not recognised.", propertyValueType));
                }
                }

                propertyKey = new MbString(stream);
            }
        }
示例#4
0
        public FileHeader(Stream stream)
        {
            Version   = StreamUtils.ReadBytes(stream, 80, false);
            ByteOrder = StreamUtils.ReadByte(stream);

            StreamUtils.DataIsLittleEndian = ByteOrder == 0;

            ReservedField = StreamUtils.ReadInt32(stream);
            TOCOffset     = StreamUtils.ReadInt32(stream);
            LSGSegmentID  = new GUID(stream);
        }
示例#5
0
        private static int[] DecodeBytes(Stream stream)
        {
            var codecType = (CODECType)StreamUtils.ReadByte(stream);

            Int32ProbabilityContexts int32ProbabilityContexts = null;

            //int outOfBandValueCount;
            //int[] outOfBandValues;

            if (codecType == CODECType.Huffman || codecType == CODECType.Arithmetic)
            {
                throw new NotImplementedException("Huffman && Arithmetic codec NOT IMPLEMENTED");

                /*int32ProbabilityContexts = new Int32ProbabilityContexts(stream);
                 * outOfBandValueCount = StreamUtils.ReadInt32(stream);
                 *
                 * if (outOfBandValueCount > 0)
                 * {
                 *  outOfBandValues = DecodeBytes(stream);
                 * }*/
            }

            if (codecType != CODECType.Null)
            {
                var codeTextLength    = StreamUtils.ReadInt32(stream);
                var valueElementCount = StreamUtils.ReadInt32(stream);
                //var symbolCount = valueElementCount;

                if (int32ProbabilityContexts != null && int32ProbabilityContexts.ProbabilityContextTableEntries.Length > 1)
                {
                    StreamUtils.ReadInt32(stream); //symbolCount
                }

                var wordsToRead = StreamUtils.ReadInt32(stream);
                var codeText    = new uint[wordsToRead];
                for (int i = 0; i < wordsToRead; ++i)
                {
                    UInt32 codeTextWord;

                    if (StreamUtils.DataIsLittleEndian) // Convert to BigEndian
                    {
                        var bytes = StreamUtils.ReadBytes(stream, 4, true);
                        Array.Reverse(bytes);

                        /*var result = new UInt32[1];
                         * Buffer.BlockCopy(bytes, 0, result, 0, 4);
                         *
                         * codeTextWord = result[0];*/

                        codeTextWord = Convert.FromBytes <UInt32>(bytes);
                    }

                    else
                    {
                        codeTextWord = StreamUtils.ReadUInt32(stream);
                    }

                    codeText[i] = codeTextWord;
                }

                switch (codecType)
                {
                case CODECType.Bitlength:
                    return(BitlengthCoder.Decode(codeText, valueElementCount, codeTextLength));

                case CODECType.Huffman:
                    throw new NotImplementedException("Huffman codec NOT IMPLEMENTED");

                case CODECType.Arithmetic:
                    throw new NotImplementedException("Huffman codec NOT IMPLEMENTED");
                }
            }

            else
            {
                var integersToRead = StreamUtils.ReadInt32(stream);

                var decodedSymbols = new int[integersToRead];

                for (int i = 0; i < integersToRead; ++i)
                {
                    decodedSymbols[i] = StreamUtils.ReadInt32(stream);
                }

                return(decodedSymbols);
            }

            return(new int[0]);
        }
示例#6
0
        public VertexBasedShapeCompressedRepData(Stream stream)
        {
            VersionNumber          = StreamUtils.ReadInt16(stream);
            NormalBinding          = StreamUtils.ReadByte(stream);
            TextureCoordBinding    = StreamUtils.ReadByte(stream);
            ColourBinding          = StreamUtils.ReadByte(stream);
            QuantizationParameters = new QuantizationParameters(stream);

            var primitiveListIndices = Int32CompressedDataPacket.GetArrayI32(stream, Int32CompressedDataPacket.PredictorType.Stride1);

            MemoryStream vertexDataStream;

            if (QuantizationParameters.BitsPerVertex == 0)
            {
                LosslessCompressedRawVertexData = new LosslessCompressedRawVertexData(stream);

                vertexDataStream = new MemoryStream(LosslessCompressedRawVertexData.VertexData);
            }

            else
            {
                throw new NotImplementedException("LossyQuantizedRawVertexData NOT IMPLEMENTED");
            }

            var readNormals       = NormalBinding == 1;
            var readTextureCoords = TextureCoordBinding == 1;
            var readColours       = ColourBinding == 1;

            var vertexEntrySize  = 3 + (readNormals ? 3 : 0) + (readTextureCoords ? 2 : 0) + (readColours ? 3 : 0);
            var vertexEntryCount = (vertexDataStream.Length / 4) / vertexEntrySize;

            var vertexPositions          = new float[vertexEntryCount][];
            var vertexNormals            = readNormals ? new float[vertexEntryCount][] : null;
            var vertexColours            = readColours ? new float[vertexEntryCount][] : null;
            var vertexTextureCoordinates = readTextureCoords ? new float[vertexEntryCount][] : null;

            for (int i = 0; i < vertexEntryCount; ++i)
            {
                if (readTextureCoords)
                {
                    vertexTextureCoordinates[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                if (readColours)
                {
                    vertexColours[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                if (readNormals)
                {
                    vertexNormals[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                vertexPositions[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) };
            }

            Positions = vertexPositions;
            Normals   = vertexNormals;

            var triStripCount = primitiveListIndices.Length - 1;
            var triStrips     = new int[triStripCount][];

            for (int triStripIndex = 0; triStripIndex < triStripCount; ++triStripIndex)
            {
                var startIndex = primitiveListIndices[triStripIndex];
                var endIndex   = primitiveListIndices[triStripIndex + 1];

                var indicesCount = endIndex - startIndex;
                var indices      = new int[indicesCount];

                for (int i = 0; i < indicesCount; ++i)
                {
                    indices[i] = startIndex + i;
                }

                triStrips[triStripIndex] = indices;
            }

            TriStrips = triStrips;
        }
    }
}
示例#7
0
 public UniformQuantizerData(Stream stream)
 {
     Min          = StreamUtils.ReadFloat(stream);
     Max          = StreamUtils.ReadFloat(stream);
     NumberOfBits = StreamUtils.ReadByte(stream);
 }
示例#8
0
 public QuantizationParameters(Stream stream) : this(StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream))
 {
 }
示例#9
0
 public LogicElementHeaderZLIB(Stream stream)
 {
     CompressionFlag      = StreamUtils.ReadInt32(stream);
     CompressedDataLength = StreamUtils.ReadInt32(stream);
     CompressionAlgorithm = StreamUtils.ReadByte(stream);
 }
示例#10
0
 public BaseAttributeElement(Stream stream)
 {
     ObjectId          = StreamUtils.ReadInt32(stream);
     StateFlags        = StreamUtils.ReadByte(stream);
     FieldInhibitFlags = StreamUtils.ReadUInt32(stream);
 }