示例#1
0
        public void ReadNegativeFixedPoint16FromBitsTest()
        {
            var       mem    = new MemoryStream();
            var       writer = new SwfStreamWriter(mem);
            const int val    = -81920;
            var       bits   = new SignedBitsCount(val).GetBits();

            writer.WriteSignedBits(val, bits);
            writer.FlushBits();
            mem.Seek(0, SeekOrigin.Begin);
            var    reader = new SwfStreamReader(mem);
            double actual = reader.ReadFixedPoint16(bits);

            Assert.AreEqual(-1.25, actual);
        }
示例#2
0
        public static SwfMatrix Read(SwfStreamReader reader, bool fill_style)
        {
            var matrix    = SwfMatrix.identity;
            var has_scale = reader.ReadBit();

            if (has_scale)
            {
                var bits = (byte)reader.ReadUnsignedBits(5);
                matrix.ScaleX = reader.ReadFixedPoint16(bits);
                matrix.ScaleY = reader.ReadFixedPoint16(bits);
            }
            else
            {
                matrix.ScaleX     =
                    matrix.ScaleY = 1.0f;
            }
            var has_rotate = reader.ReadBit();

            if (has_rotate)
            {
                var bits = (byte)reader.ReadUnsignedBits(5);
                matrix.RotateSkew0 = reader.ReadFixedPoint16(bits);
                matrix.RotateSkew1 = reader.ReadFixedPoint16(bits);
            }
            else
            {
                matrix.RotateSkew0     =
                    matrix.RotateSkew1 = 0.0f;
            }
            var translate_bits = (byte)reader.ReadUnsignedBits(5);

            matrix.TranslateX = reader.ReadSignedBits(translate_bits) / 20.0f;
            matrix.TranslateY = reader.ReadSignedBits(translate_bits) / 20.0f;
            reader.AlignToByte();
            return(matrix);
        }
示例#3
0
        public void WriteFixedPoint16FromBitsTest()
        {
            var          mem      = new MemoryStream();
            var          writer   = new SwfStreamWriter(mem);
            const int    val      = 0x03aa4523;
            const ushort hi       = val >> 16;
            const ushort low      = val & 0xffff;
            const double expected = hi + low / 65536.0;
            var          bits     = new SignedBitsCount(hi).GetBits() + 16;

            writer.WriteFixedPoint16(expected, bits);
            writer.FlushBits();
            mem.Seek(0, SeekOrigin.Begin);
            var    reader = new SwfStreamReader(mem);
            double actual = reader.ReadFixedPoint16(bits);

            Assert.AreEqual(expected, actual);
        }
示例#4
0
 public void ReadFixedPoint16FromBitsTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     const int val = 0x03aa4523;
     const ushort hi = val >> 16;
     const ushort low = val & 0xffff;
     const double expected = hi + low / 65536.0;
     var bits = new SignedBitsCount(hi).GetBits();
     writer.WriteUnsignedBits(hi, bits);
     writer.WriteUnsignedBits(low, 16);
     writer.FlushBits();
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     double actual = reader.ReadFixedPoint16(bits + 16);
     Assert.AreEqual(expected, actual);
 }
示例#5
0
 public void ReadNegativeFixedPoint16FromBitsTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     const int val = -81920;
     var bits = new SignedBitsCount(val).GetBits();
     writer.WriteSignedBits(val, bits);
     writer.FlushBits();
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     double actual = reader.ReadFixedPoint16(bits);
     Assert.AreEqual(-1.25, actual);
 }