Swf file header object contains main informations about the animation.

The header contains those informations:

  • File signature, to indicate of the file is compressed or not
  • Swf version (1 to 7)
  • Lenght of entire file in bytes
  • Frame size in twips
  • Frame delay in 8.8 fixed number of frame per second
  • Total number of frames in the movie

상속: ISwfSerializer
예제 #1
0
        /// <summary>
        /// Read swf (header and tags), this is the only
        /// public method of <see cref="SwfDotNet.IO.SwfReader">SwfReader</see>
        /// with <see cref="SwfDotNet.IO.SwfReader.Close">Close</see> and
        /// <see cref="SwfDotNet.IO.SwfReader.ReadSwfHeader">ReadSwfHeader</see> methods.
        /// The returned <see cref="SwfDotNet.IO.Swf">Swf</see> object contains swf headers informations and the
        /// tags list.
        /// </summary>
        public Swf ReadSwf()
        {
            // compressed swf?
            if (br.PeekChar() == 'C')
            {
                Inflate();
            }

            SwfHeader header = new SwfHeader();

            header.ReadData(br);
            this.version = header.Version;

            tagList = new BaseTagCollection();

            bool readEndTag = false; //necessary for the 1 more byte bug

            while (br.BaseStream.Position < br.BaseStream.Length && !readEndTag)
            {
                BaseTag b = SwfReader.ReadTag(this.version, this.br, this.tagList);
                if (b != null)
                {
                    if (b is EndTag)
                    {
                        readEndTag = true;
                    }
                    tagList.Add(b);
                }
            }
            ;

            br.Close();

            return(new Swf(header, tagList));
        }
예제 #2
0
파일: Swf.cs 프로젝트: Berenold/SwfExport
 /// <summary>
 /// Creates a new <see cref="Swf"/> instance.
 /// </summary>
 public Swf()
 {
     this.header            = new SwfHeader();
     this.tagList           = new BaseTagCollection();
     this.tagList.TagAdded += new TagAddedEvent(tagList_TagAdded);
     Init();
 }
예제 #3
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();
        }
예제 #4
0
        /// <summary>
        /// Reads the SWF header only.
        /// This method don't read the complete content of the
        /// SWF file. Then, it provides the possibility to
        /// get faster header informations, and only it.
        /// </summary>
        /// <returns></returns>
        public SwfHeader ReadSwfHeader()
        {
            // compressed swf?
            if (br.PeekChar() == 'C')
            {
                Inflate();
            }

            SwfHeader header = new SwfHeader();

            header.ReadData(br);
            this.version = header.Version;

            tagList = new BaseTagCollection();
            br.Close();
            return(header);
        }
예제 #5
0
파일: Swf.cs 프로젝트: Berenold/SwfExport
        /// <summary>
        /// Creates a new <see cref="Swf"/> instance.
        /// </summary>
        /// <param name="header">Swf Header.</param>
        /// <param name="tagList">Swf Tag list sequence.</param>
        public Swf(SwfHeader header, BaseTagCollection tagList)
        {
            this.header  = header;
            this.tagList = tagList;
            Init();

            // count actions
            _actionCount = 0;
            foreach (BaseTag b in tagList)
            {
                _actionCount += b.ActionRecCount;

                if (b is DefineTag)
                {
                    dictionnary.Add(b as DefineTag);
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Creates a new <see cref="Swf"/> instance.
 /// </summary>
 public Swf()
 {
     this.header = new SwfHeader();
     this.tagList = new BaseTagCollection();
     this.tagList.TagAdded += new TagAddedEvent(tagList_TagAdded);
     Init();
 }
예제 #7
0
        /// <summary>
        /// Creates a new <see cref="Swf"/> instance.
        /// </summary>
        /// <param name="header">Swf Header.</param>
        /// <param name="tagList">Swf Tag list sequence.</param>
        public Swf(SwfHeader header, BaseTagCollection tagList)
        {
            this.header = header;
            this.tagList = tagList;
            Init();

            // count actions
            _actionCount = 0;
            foreach (BaseTag b in tagList)
            {
                _actionCount += b.ActionRecCount;

                if (b is DefineTag)
                    dictionnary.Add(b as DefineTag);
            }
        }
예제 #8
0
        /// <summary>
        /// Reads the SWF header only.
        /// This method don't read the complete content of the 
        /// SWF file. Then, it provides the possibility to
        /// get faster header informations, and only it.
        /// </summary>
        /// <returns></returns>
        public SwfHeader ReadSwfHeader()
        {
            // compressed swf?
            if (br.PeekChar()=='C')
                Inflate();

            SwfHeader header = new SwfHeader();
            header.ReadData(br);
            this.version = header.Version;

            tagList = new BaseTagCollection();
            br.Close();
            return header;
        }
예제 #9
0
        /// <summary>
        /// Read swf (header and tags), this is the only 
        /// public method of <see cref="SwfDotNet.IO.SwfReader">SwfReader</see>
        /// with <see cref="SwfDotNet.IO.SwfReader.Close">Close</see> and
        /// <see cref="SwfDotNet.IO.SwfReader.ReadSwfHeader">ReadSwfHeader</see> methods.
        /// The returned <see cref="SwfDotNet.IO.Swf">Swf</see> object contains swf headers informations and the
        /// tags list.
        /// </summary>
        public Swf ReadSwf()
        {
            // compressed swf?
            if (br.PeekChar()=='C')
                Inflate();

            SwfHeader header = new SwfHeader();
            header.ReadData(br);
            this.version = header.Version;

            tagList = new BaseTagCollection();

            bool readEndTag = false; //necessary for the 1 more byte bug
            while (br.BaseStream.Position < br.BaseStream.Length && !readEndTag)
            {
                BaseTag b = SwfReader.ReadTag(this.version, this.br, this.tagList);
                if (b != null)
                {
                    if (b is EndTag)
                        readEndTag = true;
                    tagList.Add(b);
                }
            };

            br.Close();

            return new Swf(header, tagList);
        }