Exemplo n.º 1
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);
        }
        public LosslessCompressedRawVertexData(Stream stream)
        {
            StreamUtils.ReadInt32(stream); //uncompressedDataSize
            var compressedDataSize = StreamUtils.ReadInt32(stream);

            if (compressedDataSize > 0)
            {
                CompressedVertexData = StreamUtils.ReadBytes(stream, compressedDataSize, false);
            }
            else if (compressedDataSize < 0)
            {
                VertexData = StreamUtils.ReadBytes(stream, Math.Abs(compressedDataSize), false);
            }
            else
            {
                VertexData = CompressedVertexData = new byte[0];
            }
        }
Exemplo n.º 3
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]);
        }
Exemplo n.º 4
0
 public GUID(Stream stream)
 {
     guid = new Guid(StreamUtils.ReadInt32(stream), StreamUtils.ReadInt16(stream), StreamUtils.ReadInt16(stream), StreamUtils.ReadBytes(stream, 8, false));
 }