Ejemplo n.º 1
0
        public byte[] GetData()
        {
            var writer = new SwfWriter();

            WriteData(writer);
            return(writer.ToByteArray());
        }
Ejemplo n.º 2
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUIntEncoded((uint)_method.Index);
            writer.WriteUIntEncoded((uint)MaxStackDepth);
            writer.WriteUIntEncoded((uint)LocalCount);
            writer.WriteUIntEncoded((uint)MinScopeDepth);
            writer.WriteUIntEncoded((uint)MaxScopeDepth);

            if (_il != null)
            {
                using (var codeWriter = new SwfWriter())
                {
                    codeWriter.ABC = writer.ABC;
                    _il.Write(codeWriter);
                    var code = codeWriter.ToByteArray();
                    writer.WriteUIntEncoded((uint)code.Length);
                    writer.Write(code);
                }
            }
            else
            {
                writer.WriteUInt8(0);
            }

            _exceptions.Write(writer);
            _traits.Write(writer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets tag data.
        /// </summary>
        /// <returns></returns>
        public virtual byte[] GetData()
        {
            var body = new SwfWriter();

            WriteTagData(body);
            return(body.ToByteArray());
        }
Ejemplo n.º 4
0
        private static byte[] GetRGB24(Bitmap bmp, bool alpha)
        {
            var writer = new SwfWriter();
            //NOTE: The RGB data must already be multiplied by the alpha channel value.
            int w = bmp.Width;
            int h = bmp.Height;

            using (var fbmp = new FastBitmap(bmp))
            {
                for (int y = 0; y < h; ++y)
                {
                    for (int x = 0; x < w; ++x)
                    {
                        var c = fbmp[x, y];
                        if (alpha)
                        {
                            c = MulAlpha(c);
                            writer.WriteARGB(c);
                        }
                        else
                        {
                            writer.WriteUInt8(0);
                            writer.WriteUInt8(c.R);
                            writer.WriteUInt8(c.G);
                            writer.WriteUInt8(c.B);
                        }
                    }
                }
            }
            return(writer.ToByteArray());
        }
Ejemplo n.º 5
0
        public virtual byte[] GetData()
        {
            var writer = new SwfWriter();

            WriteBody(writer);
            return(writer.ToByteArray());
        }
Ejemplo n.º 6
0
        private static void WriteIndexed(SwfWriter writer, Bitmap bmp, bool alpha)
        {
            int w = bmp.Width;
            int h = bmp.Height;

            writer.WriteUInt8((byte)SwfBitmapFormat.Indexed);
            writer.WriteUInt16((ushort)w);
            writer.WriteUInt16((ushort)h);

            var pal     = bmp.Palette.Entries;
            int palSize = pal.Length;

            writer.WriteUInt8((byte)(palSize - 1));

            var bmpWriter = new SwfWriter();

            for (int i = 0; i < palSize; ++i)
            {
                bmpWriter.WriteColor(pal[i], alpha);
            }

            //NOTE: Row widths in the pixel data fields of these structures must be rounded up to the next
            //32-bit word boundary. For example, an 8-bit image that is 253 pixels wide must be
            //padded out to 256 bytes per line. To determine the appropriate padding, make sure to
            //take into account the actual size of the individual pixel structures; 15-bit pixels occupy 2
            //bytes and 24-bit pixels occupy 4 bytes (see PIX15 and PIX24).

            int pad = w % 4;

            if (pad != 0)
            {
                pad = 4 - pad;
            }

            using (var fbmp = new FastBitmap(bmp))
            {
                for (int y = 0; y < h; ++y)
                {
                    for (int x = 0; x < w; ++x)
                    {
                        int index = fbmp.GetIndex(x, y);
                        Debug.Assert(index >= 0 && index < palSize);
                        bmpWriter.WriteUInt8((byte)index);
                    }
                    if (pad > 0)
                    {
                        bmpWriter.Pad(pad);
                    }
                }
            }

            var data = bmpWriter.ToByteArray();

            data = Zip.Compress(data);
            writer.Write(data);
        }
Ejemplo n.º 7
0
 public byte[] ToByteArray()
 {
     if (!HasOperands)
     {
         return(new[] { (byte)Code });
     }
     using (var writer = new SwfWriter())
     {
         Write(writer);
         return(writer.ToByteArray());
     }
 }
Ejemplo n.º 8
0
        private static void TestMatrix2(byte[] data)
        {
            var reader = new SwfReader(data);
            var mat    = reader.ReadMatrix();

            var writer = new SwfWriter();

            writer.WriteMatrix(mat);

            var data2 = writer.ToByteArray();

            Assert.AreEqual(data, data2);
        }
Ejemplo n.º 9
0
        public void Write(SwfWriter writer)
        {
            int n = Count;

            for (int i = 0; i < n; ++i)
            {
                var tag       = this[i];
                var tagWriter = new SwfWriter {
                    FileVersion = writer.FileVersion
                };
                tag.Write(tagWriter);
                var tagData = tagWriter.ToByteArray();
                writer.WriteUInt32BE((uint)tagData.Length);
                writer.Write(tagData);
            }
        }
Ejemplo n.º 10
0
        public void TestSB()
        {
            var writer = new SwfWriter();

            writer.WriteSB(-2, 4);
            writer.WriteSB(-2, 2);
            writer.WriteSB(-1, 1);

            var data = writer.ToByteArray();

            var reader = new SwfReader(data);

            Assert.AreEqual(-2, reader.ReadSB(4));
            Assert.AreEqual(-2, reader.ReadSB(2));
            Assert.AreEqual(-1, reader.ReadSB(1));
        }
Ejemplo n.º 11
0
        private static void TestRect(RectangleF r)
        {
            var writer = new SwfWriter();

            writer.WriteRectTwip(r);

            var data = writer.ToByteArray();

            var reader = new SwfReader(data);

            var r2 = reader.ReadRectF();

            Assert.AreEqual(r.X, r2.X, 0.1f, "x");
            Assert.AreEqual(r.Y, r2.Y, 0.1f, "y");
            Assert.AreEqual(r.Width, r2.Width, 0.1f, "width");
            Assert.AreEqual(r.Height, r2.Height, 0.1f, "height");
        }
Ejemplo n.º 12
0
        private static void TestMatrix(Matrix m)
        {
            var writer = new SwfWriter();

            writer.WriteMatrix(m);

            var data = writer.ToByteArray();

            var reader = new SwfReader(data);

            var m2 = reader.ReadMatrix();
            var a  = m.Elements;
            var b  = m2.Elements;

            for (int i = 0; i < 6; ++i)
            {
                Assert.AreEqual(a[i], b[i], 0.1f, "e#" + i);
            }
        }
Ejemplo n.º 13
0
        private static void TestTwip(float v, int bits)
        {
            var writer = new SwfWriter();

            writer.WriteUB((uint)bits, 5);
            writer.WriteTwip(v, bits);
            writer.Align();

            var data = writer.ToByteArray();

            var reader = new SwfReader(data);
            int bits2  = (int)reader.ReadUB(5);

            Assert.AreEqual(bits, bits2);

            float v2 = reader.ReadTwip(bits2);

            Assert.AreEqual(v, v2);
        }
Ejemplo n.º 14
0
        public void TestPrimitives()
        {
            var writer = new SwfWriter();

            writer.WriteUIntEncoded(100);
            writer.WriteUIntEncoded(500);
            writer.WriteUIntEncoded(528);
            writer.WriteUIntEncoded(1000);
            writer.WriteUIntEncoded(10000);
            writer.WriteUIntEncoded(uint.MaxValue);
            writer.WriteIntEncoded(-100);
            writer.WriteIntEncoded(-500);
            writer.WriteIntEncoded(-1000);
            writer.WriteIntEncoded(-10000);
            writer.WriteIntEncoded(int.MinValue);
            writer.WriteIntEncoded(int.MaxValue);
            writer.WriteInt24(-100);
            writer.WriteInt24(-500);

            var data = writer.ToByteArray();

            var reader = new SwfReader(data);

            Assert.AreEqual(100, reader.ReadUIntEncoded());
            Assert.AreEqual(500, reader.ReadUIntEncoded());
            Assert.AreEqual(528, reader.ReadUIntEncoded());
            Assert.AreEqual(1000, reader.ReadUIntEncoded());
            Assert.AreEqual(10000, reader.ReadUIntEncoded());
            Assert.AreEqual(uint.MaxValue, reader.ReadUIntEncoded());
            Assert.AreEqual(-100, reader.ReadIntEncoded());
            Assert.AreEqual(-500, reader.ReadIntEncoded());
            Assert.AreEqual(-1000, reader.ReadIntEncoded());
            Assert.AreEqual(-10000, reader.ReadIntEncoded());
            Assert.AreEqual(int.MinValue, reader.ReadIntEncoded());
            Assert.AreEqual(int.MaxValue, reader.ReadIntEncoded());
            Assert.AreEqual(-100, reader.ReadInt24());
            Assert.AreEqual(-500, reader.ReadInt24());
        }