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

            bool compress = _allowCompression && _version >= MinVersionSupportedComression;

            //write header
            writer.Write(compress ? SigCWS : SigFWS);

            writer.WriteUInt8((byte)_version);     //file version

            //NOTE: Comment below is from SWF specification.
            //The FileLength field is the total length of the SWF file, including the header. If this is an
            //uncompressed SWF file (FWS signature), the FileLength field should exactly match the file
            //size. If this is a compressed SWF file (CWS signature), the FileLength field indicates the total
            //length of the file after decompression, and thus generally does not match the file size.

            var data = GetFileData();
            int len  = data.Length;

            if (compress)
            {
                data = Zip.Compress(data);
                //if (data.Length > len)
                //    len = data.Length;
            }

            writer.WriteUInt32((uint)(8 + len)); //file length
            writer.Write(data);

            data = writer.ToByteArray();
            return(data);
        }
Ejemplo n.º 2
0
        public virtual void Write(SwfWriter writer)
        {
            int n = Count;

            writer.WriteUIntEncoded(n);
            for (int i = 0; i < n; ++i)
            {
                this[i].Write(writer);
            }
        }
Ejemplo n.º 3
0
        public static void WriteFlags(SwfWriter writer, SwfEventFlags f)
        {
            int  ver = writer.FileVersion;
            uint v   = ToUInt32(f, ver);

            if (ver >= 6)
            {
                writer.WriteUInt32(v);
            }
            else
            {
                writer.WriteUInt16((ushort)v);
            }
        }
Ejemplo n.º 4
0
        public void Write(SwfWriter writer, bool alpha)
        {
            bool hasAddTerms = HasAddTerms(alpha);
            bool hasMulTerms = HasMulTerms(alpha);

            writer.WriteBit(hasAddTerms);
            writer.WriteBit(hasMulTerms);

            int nbits;

            if (hasMulTerms && hasAddTerms)
            {
                nbits = Math.Max(MulBits(alpha), AddBits(alpha));
            }
            else if (hasMulTerms)
            {
                nbits = MulBits(alpha);
            }
            else
            {
                nbits = AddBits(alpha);
            }
            writer.WriteUB((uint)nbits, 4);

            if (hasMulTerms)
            {
                writer.WriteFB16(MulRed, Q, nbits);
                writer.WriteFB16(MulGreen, Q, nbits);
                writer.WriteFB16(MulBlue, Q, nbits);
                if (alpha)
                {
                    writer.WriteFB16(MulAlpha, Q, nbits);
                }
            }

            if (hasAddTerms)
            {
                writer.WriteFB16(AddRed, Q, nbits);
                writer.WriteFB16(AddGreen, Q, nbits);
                writer.WriteFB16(AddBlue, Q, nbits);
                if (alpha)
                {
                    writer.WriteFB16(AddAlpha, Q, nbits);
                }
            }

            writer.Align();
        }
Ejemplo n.º 5
0
        public void Write(SwfWriter writer)
        {
            WriteFlags(writer, Flags);

            var eventWriter = new SwfWriter {
                FileVersion = writer.FileVersion
            };

            if ((Flags & SwfEventFlags.KeyPress) != 0)
            {
                eventWriter.WriteUInt8(KeyCode);
            }
            _actions.Write(eventWriter);

            var eventData = eventWriter.ToByteArray();

            writer.WriteUInt32((uint)eventData.Length);
            writer.Write(eventData);
        }
Ejemplo n.º 6
0
        public virtual void Write(SwfWriter writer, bool alpha)
        {
            writer.WriteUB((uint)SpreadMode, 2);
            writer.WriteUB((uint)InterpolationMode, 2);
            int n = Ratios.Length;

            writer.WriteUB((uint)n, 4);
            for (int i = 0; i < n; ++i)
            {
                writer.WriteUInt8(Ratios[i]);
                if (alpha)
                {
                    writer.WriteRGBA(Colors[i]);
                }
                else
                {
                    writer.WriteRGB(Colors[i]);
                }
            }
        }
Ejemplo n.º 7
0
        private byte[] GetFileData()
        {
            if (_autoFrameCount)
            {
                _frameCount = (ushort)_tags.Count(tag => tag.TagCode == SwfTagCode.ShowFrame);
            }

            var writer = new SwfWriter();

            int w = _frameSize.Width.ToTwips();
            int h = _frameSize.Height.ToTwips();

            writer.WriteRect(0, 0, w, h);     //frame size
            writer.WriteUFloat16(_frameRate); //frame rate
            writer.WriteUInt16(_frameCount);  //frame count

            //tags (content)
            _tags.Write(writer);

            return(writer.ToByteArray());
        }
Ejemplo n.º 8
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUInt16(0);             //reserved
            SwfEvent.WriteFlags(writer, AllEventFlags);

            int n = Count;

            for (int i = 0; i < n; ++i)
            {
                this[i].Write(writer);
            }

            if (writer.FileVersion >= 6)
            {
                writer.WriteUInt32(0);
            }
            else
            {
                writer.WriteUInt16(0);
            }
        }
Ejemplo n.º 9
0
 public override void Write(SwfWriter writer, bool alpha)
 {
     base.Write(writer, alpha);
     writer.WriteFixed16(FocalPoint);
 }
Ejemplo n.º 10
0
 public void Write(SwfWriter writer, SwfTagCode shapeType)
 {
     Write(writer, SwfShape.HasAlpha(shapeType));
 }