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); }
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); }
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); }
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); }