public static void ReadColorTransformRGBA(this ISwfStreamReader reader, out ColorTransformRGBA transform)
 {
     var hasAddTerms = reader.ReadBit();
     var hasMultTerms = reader.ReadBit();
     var bits = reader.ReadUnsignedBits(4);
     if (hasMultTerms) {
         transform.RedMultTerm = (short)reader.ReadSignedBits(bits);
         transform.GreenMultTerm = (short)reader.ReadSignedBits(bits);
         transform.BlueMultTerm = (short)reader.ReadSignedBits(bits);
         transform.AlphaMultTerm = (short)reader.ReadSignedBits(bits);
         transform.HasMultTerms = true;
     } else {
         transform.RedMultTerm = 0;
         transform.GreenMultTerm = 0;
         transform.BlueMultTerm = 0;
         transform.AlphaMultTerm = 0;
         transform.HasMultTerms = false;
     }
     if (hasAddTerms) {
         transform.RedAddTerm = (short)reader.ReadSignedBits(bits);
         transform.GreenAddTerm = (short)reader.ReadSignedBits(bits);
         transform.BlueAddTerm = (short)reader.ReadSignedBits(bits);
         transform.AlphaAddTerm = (short)reader.ReadSignedBits(bits);
         transform.HasAddTerms = true;
     } else {
         transform.RedAddTerm = 0;
         transform.GreenAddTerm = 0;
         transform.BlueAddTerm = 0;
         transform.AlphaAddTerm = 0;
         transform.HasAddTerms = false;
     }
     reader.AlignToByte();
 }
Beispiel #2
0
        public static void AreEqual(ColorTransformRGBA expected, ColorTransformRGBA actual, string message)
        {
            Assert.AreEqual(expected.HasAddTerms, actual.HasAddTerms, message + ".HasAddTerms");
            Assert.AreEqual(expected.HasMultTerms, actual.HasMultTerms, message + ".HasMultTerms");

            Assert.AreEqual(expected.RedAddTerm, actual.RedAddTerm, message + ".RedAddTerm");
            Assert.AreEqual(expected.GreenAddTerm, actual.GreenAddTerm, message + ".GreenAddTerm");
            Assert.AreEqual(expected.BlueAddTerm, actual.BlueAddTerm, message + ".BlueAddTerm");
            Assert.AreEqual(expected.AlphaAddTerm, actual.AlphaAddTerm, message + ".AlphaAddTerm");

            Assert.AreEqual(expected.RedMultTerm, actual.RedMultTerm, message + ".RedMultTerm");
            Assert.AreEqual(expected.GreenMultTerm, actual.GreenMultTerm, message + ".GreenMultTerm");
            Assert.AreEqual(expected.BlueMultTerm, actual.BlueMultTerm, message + ".BlueMultTerm");
            Assert.AreEqual(expected.AlphaMultTerm, actual.AlphaMultTerm, message + ".AlphaMultTerm");
        }
Beispiel #3
0
 public static XElement ToXml(ColorTransformRGBA transform)
 {
     var res = new XElement("ColorTransform2");
     if (transform.HasMultTerms) {
         res.Add(new XAttribute("factorRed", transform.RedMultTerm));
         res.Add(new XAttribute("factorGreen", transform.GreenMultTerm));
         res.Add(new XAttribute("factorBlue", transform.BlueMultTerm));
         res.Add(new XAttribute("factorAlpha", transform.AlphaMultTerm));
     }
     if (transform.HasAddTerms) {
         res.Add(new XAttribute("redadd", transform.RedAddTerm));
         res.Add(new XAttribute("greenadd", transform.GreenAddTerm));
         res.Add(new XAttribute("blueadd", transform.BlueAddTerm));
         res.Add(new XAttribute("alphaadd", transform.AlphaAddTerm));
     }
     return res;
 }
Beispiel #4
0
        public static void ReadColorTransformRGBA(this ISwfStreamReader reader, out ColorTransformRGBA transform)
        {
            var hasAddTerms  = reader.ReadBit();
            var hasMultTerms = reader.ReadBit();
            var bits         = reader.ReadUnsignedBits(4);

            if (hasMultTerms)
            {
                transform.RedMultTerm   = (short)reader.ReadSignedBits(bits);
                transform.GreenMultTerm = (short)reader.ReadSignedBits(bits);
                transform.BlueMultTerm  = (short)reader.ReadSignedBits(bits);
                transform.AlphaMultTerm = (short)reader.ReadSignedBits(bits);
                transform.HasMultTerms  = true;
            }
            else
            {
                transform.RedMultTerm   = 0;
                transform.GreenMultTerm = 0;
                transform.BlueMultTerm  = 0;
                transform.AlphaMultTerm = 0;
                transform.HasMultTerms  = false;
            }
            if (hasAddTerms)
            {
                transform.RedAddTerm   = (short)reader.ReadSignedBits(bits);
                transform.GreenAddTerm = (short)reader.ReadSignedBits(bits);
                transform.BlueAddTerm  = (short)reader.ReadSignedBits(bits);
                transform.AlphaAddTerm = (short)reader.ReadSignedBits(bits);
                transform.HasAddTerms  = true;
            }
            else
            {
                transform.RedAddTerm   = 0;
                transform.GreenAddTerm = 0;
                transform.BlueAddTerm  = 0;
                transform.AlphaAddTerm = 0;
                transform.HasAddTerms  = false;
            }
            reader.AlignToByte();
        }
Beispiel #5
0
        public static void WriteColorTransformRGBA(this ISwfStreamWriter writer, ref ColorTransformRGBA tranform)
        {
            var bitsCounter = new SignedBitsCount(0);

            if (tranform.HasAddTerms)
            {
                bitsCounter.AddValue(tranform.RedAddTerm);
                bitsCounter.AddValue(tranform.GreenAddTerm);
                bitsCounter.AddValue(tranform.BlueAddTerm);
                bitsCounter.AddValue(tranform.AlphaAddTerm);
            }
            if (tranform.HasMultTerms)
            {
                bitsCounter.AddValue(tranform.RedMultTerm);
                bitsCounter.AddValue(tranform.GreenMultTerm);
                bitsCounter.AddValue(tranform.BlueMultTerm);
                bitsCounter.AddValue(tranform.AlphaMultTerm);
            }
            writer.WriteBit(tranform.HasAddTerms);
            writer.WriteBit(tranform.HasMultTerms);
            var bits = bitsCounter.GetBits();

            writer.WriteUnsignedBits(bits, 4);
            if (tranform.HasMultTerms)
            {
                writer.WriteSignedBits(tranform.RedMultTerm, bits);
                writer.WriteSignedBits(tranform.GreenMultTerm, bits);
                writer.WriteSignedBits(tranform.BlueMultTerm, bits);
                writer.WriteSignedBits(tranform.AlphaMultTerm, bits);
            }
            if (tranform.HasAddTerms)
            {
                writer.WriteSignedBits(tranform.RedAddTerm, bits);
                writer.WriteSignedBits(tranform.GreenAddTerm, bits);
                writer.WriteSignedBits(tranform.BlueAddTerm, bits);
                writer.WriteSignedBits(tranform.AlphaAddTerm, bits);
            }
            writer.FlushBits();
        }
 public static void WriteColorTransformRGBA(this ISwfStreamWriter writer, ref ColorTransformRGBA tranform)
 {
     var bitsCounter = new SignedBitsCount(0);
     if (tranform.HasAddTerms) {
         bitsCounter.AddValue(tranform.RedAddTerm);
         bitsCounter.AddValue(tranform.GreenAddTerm);
         bitsCounter.AddValue(tranform.BlueAddTerm);
         bitsCounter.AddValue(tranform.AlphaAddTerm);
     }
     if (tranform.HasMultTerms) {
         bitsCounter.AddValue(tranform.RedMultTerm);
         bitsCounter.AddValue(tranform.GreenMultTerm);
         bitsCounter.AddValue(tranform.BlueMultTerm);
         bitsCounter.AddValue(tranform.AlphaMultTerm);
     }
     writer.WriteBit(tranform.HasAddTerms);
     writer.WriteBit(tranform.HasMultTerms);
     var bits = bitsCounter.GetBits();
     writer.WriteUnsignedBits(bits, 4);
     if (tranform.HasMultTerms) {
         writer.WriteSignedBits(tranform.RedMultTerm, bits);
         writer.WriteSignedBits(tranform.GreenMultTerm, bits);
         writer.WriteSignedBits(tranform.BlueMultTerm, bits);
         writer.WriteSignedBits(tranform.AlphaMultTerm, bits);
     }
     if (tranform.HasAddTerms) {
         writer.WriteSignedBits(tranform.RedAddTerm, bits);
         writer.WriteSignedBits(tranform.GreenAddTerm, bits);
         writer.WriteSignedBits(tranform.BlueAddTerm, bits);
         writer.WriteSignedBits(tranform.AlphaAddTerm, bits);
     }
     writer.FlushBits();
 }
 public static void WriteColorTransformRGBA(this ISwfStreamWriter writer, ColorTransformRGBA transform)
 {
     WriteColorTransformRGBA(writer, ref transform);
 }
Beispiel #8
0
 public static void WriteColorTransformRGBA(this ISwfStreamWriter writer, ColorTransformRGBA transform)
 {
     WriteColorTransformRGBA(writer, ref transform);
 }
 public void WriteColorTransformRGBAFromBitsAddTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     var tranform = new ColorTransformRGBA {
         RedMultTerm = 0,
         GreenMultTerm = 0,
         BlueMultTerm = 0,
         AlphaMultTerm = 0,
         HasMultTerms = false,
         RedAddTerm = 10,
         GreenAddTerm = -10,
         BlueAddTerm = 224,
         AlphaAddTerm = 192,
         HasAddTerms = true
     };
     writer.WriteColorTransformRGBA(ref tranform);
     CheckBits(mem,
         "1", "0", "1001", "0.00001010", "1.11110110", "0.11100000", "0.11000000");
 }