Esempio n. 1
0
        public static short[] ReadAnimationFrameValues(this System.IO.BinaryReader br, Int32 count)
        {
            /*
             * RLE data:
             * Byte compressed_length - compressed number of values in the data
             * Byte uncompressed_length - uncompressed number of values in run
             * short values[compressed_length] - values in the run, the last value is repeated to reach the uncompressed length
             */
            Int16[] values = new Int16[count];

            for (var i = 0; i < count; /* i = i */)
            {
                Byte[]  run  = br.ReadBytes(2);           // read the compressed and uncompressed lengths
                Int16[] vals = br.ReadShortArray(run[0]); // read the compressed data
                for (Int32 j = 0; j < run[1] && i < count; i++, j++)
                {
                    Int32 idx = Math.Min(run[0] - 1, j); // value in the data or the last value if we're past the end
                    values[i] = vals[idx];
                }
            }

            return(values);
        }