The Swf class is basically a data structure for swf data, containing header informations and a collection of swf tags.
Inheritance: IBaseTagContainer
Esempio n. 1
0
 public SwfConverter(string file)
 {
     SwfReader reader = new SwfReader(file);
     swf = reader.ReadSwf();
     reader.Close();
     Convert();
 }
Esempio n. 2
0
 /// <summary>
 /// Remove a swf
 /// </summary>
 /// <param name="value"></param>
 public void Remove(Swf value)
 {
     if (List.Contains(value))
     {
         List.Remove(value as object);
     }
 }
Esempio n. 3
0
 public SwfConverter(Stream stream)
 {
     SwfReader reader = new SwfReader(stream);
     swf = reader.ReadSwf();
     reader.Close();
     Convert();
 }
Esempio n. 4
0
        /// <summary>
        /// Writes the (compressed or uncompressed) swf data to a stream.
        /// The stream gets flushed and closed afterwards.
        /// </summary>
        /// <param name="swf">Swf</param>
        public void Write(Swf swf)
        {
            if (swf == null)
            {
                return;
            }

            // add EndTag is is not the last one
            BaseTag lastTag = swf.Tags.GetLastOne();

            if (lastTag == null || !(lastTag is EndTag))
            {
                swf.Tags.Add(new EndTag());
            }

            // update tag lengths to adapt to bytecode length
            swf.UpdateData();
            SwfHeader header = swf.Header;

            // ASCII seems to be ok for Flash 5 and 6+ as well
            BufferedBinaryWriter writer     = new BufferedBinaryWriter(baseStream, System.Text.Encoding.GetEncoding("ascii"));
            BufferedBinaryWriter dataWriter = writer;

            bool isCompressed = (header.Signature[0] == 'C');

            if (isCompressed && swf.Version >= 6)
            {
                // SharpZipLib makes it easy for us, simply
                // chain a Deflater into the stream
                DeflaterOutputStream def = new DeflaterOutputStream(baseStream);
                dataWriter = new BufferedBinaryWriter(def);
            }

            // writer header data, always uncompressed
            writer.WriteString(header.Signature, 3);
            writer.Write(swf.Version);
            writer.Write(swf.ByteCount);
            writer.Flush();

            // write header data pt.2, using either
            // original stream or deflater stream
            header.Size.WriteTo(dataWriter);
            dataWriter.SynchBits();
            dataWriter.WriteFWord(header.Fps, 8, 8);
            dataWriter.Write(header.Frames);

            // write tags data
            IEnumerator tags = swf.Tags.GetEnumerator();

            while (tags.MoveNext())
            {
                BaseTag tagToWrite = (BaseTag)tags.Current;
                dataWriter.Write(tagToWrite.Data);
            }

            // flush + close
            dataWriter.Flush();
            dataWriter.Close();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            //string imgPath = "Untitled-1.bmp";
            //File name of the result swf file
            string path = "test.swf";

            //Load the picture to a GDI image
            Image img = Image.FromFile(imgPath);
            int posX = 0;
            int posY = 0;
            int imgWidth = img.Width + 100;
            int imgHeight = img.Height + 100;

            //Create a new Swf instance
            Swf swf = new Swf();
            swf.Size = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();
            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();
            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes = new ShapeRecordCollection();
            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);
            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Swf swf = new Swf();
            swf.Version = 5;
            swf.Tags.Add(new SetBackgroundColorTag(new RGB(0, 0, 255)));
            swf.Tags.Add(new ShowFrameTag());
            swf.Tags.Add(new EndTag());

            SwfWriter writer = new SwfWriter(path);
            writer.Write(swf);
            writer.Close();
        }
Esempio n. 7
0
        /// <summary>
        /// Convert collection to array
        /// </summary>
        /// <returns>swf array</returns>
        public Swf[] ToArray()
        {
            Swf[] res = null;

            if (this.Count > 0)
            {
                res = new Swf[this.Count];
                for (int i = 0; i < this.Count; i++)
                {
                    res[i] = this[i];
                }
            }
            return(res);
        }
Esempio n. 8
0
        private void ReadSwf(Swf swf)
        {
            this.labelVersion.Text = swf.Version.ToString();
            this.labelFileSize.Text = swf.Header.FileSize.ToString();
            this.labelFps.Text = swf.Header.Fps.ToString();
            this.labelWidth.Text = swf.Header.Size.Rectangle.Width.ToString();
            this.labelHeight.Text = swf.Header.Size.Rectangle.Height.ToString();
            this.labelFrameCnt.Text = swf.Header.Frames.ToString();
            this.labelSignature.Text = swf.Header.Signature;
            this.labelASbytes.Text = swf.ActionCount.ToString();

            this.listBoxActions.Items.Clear();
            BaseTagCollection tags = swf.Tags;
            int i = 0;
            for (; i < tags.Count; i++)
            {
                BaseTag tag = tags[i];
                int code = tag.TagCode;
                if (code != -1)
                {
                    SwfDotNet.IO.Tags.TagCodeEnum val = SwfDotNet.IO.Tags.TagCodeEnum.DefineBits;
                    val = (SwfDotNet.IO.Tags.TagCodeEnum)System.Enum.Parse(val.GetType(), code.ToString());
                    this.listBoxActions.Items.Add(val.ToString());

                    if (tag is SetBackgroundColorTag)
                    {
                        this.listBoxActions.Items.Add("       R:" +
                            ((SetBackgroundColorTag)tag).RGB.red +
                            "  G:" + ((SetBackgroundColorTag)tag).RGB.green +
                            "  B:" + ((SetBackgroundColorTag)tag).RGB.blue);
                    }

                    if (tag is FrameLabelTag)
                    {
                        this.listBoxActions.Items.Add("       Name: " +
                            ((FrameLabelTag)tag).Name);
                    }

                    if (((SwfDotNet.IO.Tags.BaseTag)tag) is DefineFontInfo2Tag)
                    {
                        this.listBoxActions.Items.Add("       FontName: " +
                            ((DefineFontInfo2Tag)tag).FontName);
                    }

                    if (((SwfDotNet.IO.Tags.BaseTag)tag).ActionRecCount != 0)
                    {
                        IEnumerator enum2 = ((SwfDotNet.IO.Tags.BaseTag)tag).GetEnumerator();
                        while (enum2.MoveNext())
                        {
                            SwfDotNet.IO.ByteCode.Decompiler dc = new SwfDotNet.IO.ByteCode.Decompiler(swf.Version);
                            ArrayList actions = dc.Decompile((byte[])enum2.Current);
                            foreach (BaseAction obj in actions)
                            {
                              	this.listBoxActions.Items.Add("       " +  obj.ToString());
                            }
                        }
                    }
                }
            }
            this.labelTagsCnt.Text = i.ToString();
        }
Esempio n. 9
0
 /// <summary>
 /// Add an array of swf
 /// </summary>
 /// <param name="values">swf array</param>
 public void AddRange(Swf[] values)
 {
     foreach(Swf ip in values)
         Add(ip);
 }
Esempio n. 10
0
 /// <summary>
 /// Add a base tag
 /// </summary>
 /// <param name="value">base tag to add</param>
 /// <returns>base tag added</returns>
 public Swf Add(Swf value)
 {
     List.Add(value as object);
     return value;
 }
Esempio n. 11
0
        /// <summary>
        /// Convert collection to array
        /// </summary>
        /// <returns>swf array</returns>
        public Swf[] ToArray()
        {
            Swf[] res = null;

            if (this.Count > 0)
            {
                res = new Swf[this.Count];
                for (int i = 0; i < this.Count; i++)
                    res[i] = this[i];
            }
            return res;
        }
Esempio n. 12
0
 /// <summary>
 /// Remove a swf
 /// </summary>
 /// <param name="value"></param>
 public void Remove(Swf value)
 {
     if (List.Contains(value))
         List.Remove(value as object);
 }
Esempio n. 13
0
 /// <summary>
 /// Insert a swf at
 /// </summary>
 /// <param name="index">index</param>
 /// <param name="value">swf</param>
 public void Insert(int index, Swf value)
 {
     List.Insert(index, value as object);
 }
Esempio n. 14
0
 /// <summary>
 /// Test if list contain a swf
 /// </summary>
 /// <param name="value">swf</param>
 /// <returns>contain result</returns>
 public bool Contains(Swf value)
 {
     return(List.Contains(value as object));
 }
Esempio n. 15
0
 /// <summary>
 /// Test if list contain a swf
 /// </summary>
 /// <param name="value">swf</param>
 /// <returns>contain result</returns>
 public bool Contains(Swf value)
 {
     return List.Contains(value as object);
 }
Esempio n. 16
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            string path = "test_alpha.swf";
            //Alpha translation informations
            int alphaFrameNum = 35; //frame duration
            int alphaStart = 10; //alpha percent start
            int alphaEnd = 100; //alpha percent end

            //Load the picture to a GDI image
            Image img = Image.FromFile(imgPath);
            int posX = 0;
            int posY = 0;
            int imgWidth = img.Width / 2;
            int imgHeight = img.Height / 2;

            //Create a new Swf instance
            Swf swf = new Swf();
            swf.Size = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();
            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();
            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes = new ShapeRecordCollection();
            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            for (int i = 0; i < alphaFrameNum; i++)
            {
                int percent = (i * 100) / alphaFrameNum;
                int diff = alphaEnd - alphaStart;
                int valPercent = (diff * percent) / 100 + alphaStart;
                int valRgb = (255 * valPercent) / 100;
                swf.Tags.Add(new PlaceObject2Tag(1, new CXFormWithAlphaData(256, 256, 256,  valRgb)));
                swf.Tags.Add(new ShowFrameTag());
            }
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);
            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            string path = "test_color.swf";
            //Alpha translation informations
            int colorEffectFrameNum = 20; //frame duration
            System.Drawing.Color startColor = System.Drawing.Color.Yellow;
            System.Drawing.Color endColor = System.Drawing.Color.Black;

            //Load the picture to a GDI image
            Image img = Image.FromFile(imgPath);
            int posX = 0;
            int posY = 0;
            int imgWidth = img.Width / 2;
            int imgHeight = img.Height / 2;

            //Create a new Swf instance
            Swf swf = new Swf();
            swf.Size = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();
            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();
            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes = new ShapeRecordCollection();
            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            for (int i = 0; i < colorEffectFrameNum; i++)
            {
                int red = GetRGBValue(i, startColor.R, endColor.R, colorEffectFrameNum);
                int green = GetRGBValue(i, startColor.G, endColor.G, colorEffectFrameNum);
                int blue = GetRGBValue(i, startColor.B, endColor.B, colorEffectFrameNum);
                int alpha = GetRGBValue(i, startColor.A, endColor.A, colorEffectFrameNum);
                swf.Tags.Add(new PlaceObject2Tag(1, new CXFormWithAlphaData(red, green, blue,  alpha)));
                swf.Tags.Add(new ShowFrameTag());
            }
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);
            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
Esempio n. 18
0
 /// <summary>
 /// Add a base tag
 /// </summary>
 /// <param name="value">base tag to add</param>
 /// <returns>base tag added</returns>
 public Swf Add(Swf value)
 {
     List.Add(value as object);
     return(value);
 }
Esempio n. 19
0
 /// <summary>
 /// Get index of a swf
 /// </summary>
 /// <param name="value">swf</param>
 /// <returns>swf index if is contain, -1 else.</returns>
 public int IndexOf(Swf value)
 {
     return(List.IndexOf(value));
 }
Esempio n. 20
0
 /// <summary>
 /// Get index of a swf
 /// </summary>
 /// <param name="value">swf</param>
 /// <returns>swf index if is contain, -1 else.</returns>
 public int IndexOf(Swf value)
 {
     return List.IndexOf(value);
 }
Esempio n. 21
0
        /// <summary>
        /// Writes the (compressed or uncompressed) swf data to a stream.
        /// The stream gets flushed and closed afterwards.
        /// </summary>
        /// <param name="swf">Swf</param>
        public void Write(Swf swf)
        {
            if (swf == null)
                return;

            // add EndTag is is not the last one
            BaseTag lastTag = swf.Tags.GetLastOne();
            if (lastTag == null || !(lastTag is EndTag))
                swf.Tags.Add(new EndTag());

            // update tag lengths to adapt to bytecode length
            swf.UpdateData();
            SwfHeader header = swf.Header;

            // ASCII seems to be ok for Flash 5 and 6+ as well
            BufferedBinaryWriter writer = new BufferedBinaryWriter(baseStream, System.Text.Encoding.GetEncoding("ascii"));
            BufferedBinaryWriter dataWriter = writer;

            bool isCompressed = (header.Signature[0] == 'C');

            if (isCompressed && swf.Version >= 6)
            {
                // SharpZipLib makes it easy for us, simply
                // chain a Deflater into the stream
                DeflaterOutputStream def = new DeflaterOutputStream(baseStream);
                dataWriter = new BufferedBinaryWriter(def);
            }

            // writer header data, always uncompressed
            writer.WriteString(header.Signature, 3);
            writer.Write(swf.Version);
            writer.Write(swf.ByteCount);
            writer.Flush();

            // write header data pt.2, using either
            // original stream or deflater stream
            header.Size.WriteTo(dataWriter);
            dataWriter.SynchBits();
            dataWriter.WriteFWord(header.Fps, 8, 8);
            dataWriter.Write(header.Frames);

            // write tags data
            IEnumerator tags = swf.Tags.GetEnumerator();
            while (tags.MoveNext())
            {
                BaseTag tagToWrite = (BaseTag)tags.Current;
                dataWriter.Write(tagToWrite.Data);
            }

            // flush + close
            dataWriter.Flush();
            dataWriter.Close();
        }
Esempio n. 22
0
 /// <summary>
 /// Insert a swf at
 /// </summary>
 /// <param name="index">index</param>
 /// <param name="value">swf</param>
 public void Insert(int index, Swf value)
 {
     List.Insert(index, value as object);
 }