Beispiel #1
0
        public DefineSoundTag(SwfReader r, uint tagLen)
        {
            SoundId = r.GetUI16();
            SoundFormat = (SoundCompressionType)r.GetBits(4);
            uint sr = r.GetBits(2);
            switch (sr)
            {
                case 0:
                    SoundRate = 5512; // ?
                    break;
                case 1:
                    SoundRate = 11025;
                    break;
                case 2:
                    SoundRate = 22050;
                    break;
                case 3:
                    SoundRate = 44100;
                    break;
            }
            SoundSize = r.GetBit() ? 16U : 8U;
            IsStereo = r.GetBit();
            r.Align();

            SoundSampleCount = r.GetUI32();
            // todo: this needs to decompress if mp3 etc
            SoundData = r.GetBytes(tagLen - 7);
        }
Beispiel #2
0
        public SoundInfo(SwfReader r)
        {
            r.GetBits(2); // reserved

            IsSyncStop = r.GetBit();
            IsSyncNoMultiple = r.GetBit();
            HasEnvelope = r.GetBit();
            HasLoops = r.GetBit();
            HasOutPoint = r.GetBit();

            r.Align();
            if(HasInPoint)
            {
                InPoint = r.GetUI32();
            }
            if(HasOutPoint)
            {
                OutPoint = r.GetUI32();
            }
            if(HasLoops)
            {
                LoopCount = r.GetUI16();
            }
            if(HasEnvelope)
            {
                uint count = (uint)r.GetByte();

                uint pos;
                uint left;
                uint right;
                EnvelopeRecords = new SoundEnvelope[count];
                for (int i = 0; i < count; i++)
                {
                    pos = r.GetUI32();
                    left = r.GetUI16();
                    right = r.GetUI16();
                    EnvelopeRecords[i] = new SoundEnvelope(pos, left, right);
                }
            }
        }
Beispiel #3
0
        public ClipActionRecord(SwfReader r, bool isSwf6Plus)
        {
            uint highClip = r.GetBits(16) << 16;
            uint lowClip = 0;
            bool isEndRecord = false;
            if (highClip == 0)
            {
                if (isSwf6Plus)
                {
                    lowClip = r.GetBits(16);
                    if (lowClip == 0)
                    {
                        ClipEvents = (ClipEvents)0;
                        ActionRecordSize = 4;
                        isEndRecord = true;
                    }
                }
                else
                {
                    ClipEvents = (ClipEvents)0;
                    ActionRecordSize = 2;
                    isEndRecord = true;
                }
            }
            else
            {
                lowClip = r.GetBits(16);
            }

            if (!isEndRecord)
            {
                ClipEvents = (ClipEvents)(lowClip | highClip);
                ActionRecordSize = r.GetUI32();
                if ((ClipEvents & ClipEvents.KeyPress) > 0)
                {
                    KeyCode = r.GetByte();
                }
                ActionRecords = new ActionRecords(r, ActionRecordSize); // always is init tag?
            }
        }
Beispiel #4
0
        // this needs to combine with the jpegTables in the swfCompilationUnit to make an image
        public DefineBitsTag(SwfReader r, uint curTagLen, bool hasOwnTable, bool hasAlphaData)
        {
            this.HasOwnTable = hasOwnTable;
            this.HasAlphaData = hasAlphaData;

            if (hasOwnTable && !hasAlphaData)
            {
                tagType = TagType.DefineBitsJPEG2;
            }
            else if(hasOwnTable && hasAlphaData)
            {
                tagType = TagType.DefineBitsJPEG3;
            }

            CharacterId = r.GetUI16();
            if (!hasAlphaData)
            {
                if(!hasOwnTable)
                {
                    r.GetBytes(2); // SOI
                    JpegData = r.GetBytes(curTagLen - 6);
                    r.GetBytes(2); // EOI
                }
                else
                {
                    JpegData = r.GetBytes(curTagLen - 2);
                    CleanData();
                }
            }
            else
            {
                uint jpgDataSize = r.GetUI32();
                JpegData = r.GetBytes(jpgDataSize);

                // ignore alpha for now
                CompressedAlphaData = r.GetBytes(curTagLen - 6 - jpgDataSize);
                CleanData();
            }
        }
Beispiel #5
0
        public SwfHeader(SwfReader r)
        {
            this.Signature0 = r.GetByte();

            if (this.Signature0 == 'C')
            {
                this.IsCompressed = true;
                r.DecompressSwf();
            }
            else
            {
                this.IsCompressed = false;
            }

            this.Signature1 = r.GetByte();
            this.Signature2 = r.GetByte();

            this.IsSwf = (Signature2 == 'S') && (Signature1 == 'W') && ((Signature0 == 'C') || (Signature0 == 'F'));

            if (IsSwf)
            {
                this.Version = r.GetByte();
                this.FileLength = r.GetUI32();
                this.FrameSize = new Rect(r);
                UInt16 frate = r.GetUI16();
                this.FrameRate = (frate >> 8) + ((frate & 0xFF) / 0xFF);
                this.FrameCount = r.GetUI16();
            }
            else
            {
                this.Version = 0;
                this.FileLength = 0;
                this.FrameSize = new Rect(0,0,0,0);
                this.FrameRate = 0;
                this.FrameCount = 0;
            }
        }
Beispiel #6
0
        private void ParseTags(SwfReader r, byte swfVersion)
        {
            bool tagsRemain = true;

            uint curFrame = 0;
            while (tagsRemain)
            {
                uint b = r.GetUI16();
                curTag = (TagType)(b >> 6);
                curTagLen = b & 0x3F;
                if (curTagLen == 0x3F)
                {
                    curTagLen = r.GetUI32();
                }
                uint tagEnd = r.Position + curTagLen;
                Debug.WriteLine("sprite type: " + ((uint)curTag).ToString("X2") + " -- " + Enum.GetName(typeof(TagType), curTag));

                switch (curTag)
                {
                    case TagType.End:
                        tagsRemain = false;
                        ControlTags.Add(new EndTag(r));
                        break;

                    case TagType.PlaceObject:
                        PlaceObjectTag pot = new PlaceObjectTag(r, tagEnd);
                        FirstFrameObjects.Add(pot);
                        ControlTags.Add(pot);
                        break;
                    case TagType.PlaceObject2:
                        PlaceObject2Tag po2t = new PlaceObject2Tag(r, swfVersion);
                        if (po2t.HasCharacter)
                        {
                            FirstFrameObjects.Add(po2t);
                        }
                        ControlTags.Add(po2t);
                        break;
                    case TagType.PlaceObject3:
                        PlaceObject3Tag po3t = new PlaceObject3Tag(r);
                        if (po3t.HasCharacter)
                        {
                            FirstFrameObjects.Add(po3t);
                        }
                        ControlTags.Add(po3t);
                        break;

                    case TagType.RemoveObject:
                        ControlTags.Add(new RemoveObjectTag(r));
                        break;

                    case TagType.RemoveObject2:
                        ControlTags.Add(new RemoveObject2Tag(r));
                        break;

                    case TagType.ShowFrame:
                        ControlTags.Add(new ShowFrame(r));
                        curFrame++;
                        break;

                    case TagType.SoundStreamHead:
                    case TagType.SoundStreamHead2:
                        ControlTags.Add(new SoundStreamHeadTag(r));
                        break;

                    case TagType.FrameLabel:
                        ControlTags.Add(new FrameLabelTag(r));
                        break;

                    case TagType.DoAction:
                        ControlTags.Add(new DoActionTag(r, curTagLen));
                        break;

                    case TagType.DoInitAction:
                        ControlTags.Add(new DoActionTag(r, curTagLen, true));
                        break;

                    default:
                        // skip if unknown
                        Debug.WriteLine("invalid sprite tag: " + ((uint)curTag).ToString("X2") + " -- " + Enum.GetName(typeof(TagType), curTag));
                        r.SkipBytes(curTagLen);
                        break;
                }
                if (tagEnd != r.Position)
                {
                    Console.WriteLine("bad tag in sprite: " + Enum.GetName(typeof(TagType), curTag));
                }
            }
        }
Beispiel #7
0
 public FileAttributesTag(SwfReader r)
 {
     this.flags = r.GetUI32();
 }
Beispiel #8
0
        private TagType tagType = TagType.DefineFont2; // may be 3

        #endregion Fields

        #region Constructors

        public DefineFont2_3(SwfReader r, bool isHighRes)
        {
            this.IsHighRes = isHighRes; // true;
            if (isHighRes)
            {
                this.tagType = TagType.DefineFont3;
            }
            this.FontId = r.GetUI16();
            this.FontFlagsHasLayout = r.GetBit();
            this.FontFlagsShiftJIS = r.GetBit();
            this.FontFlagsSmallText = r.GetBit();
            this.FontFlagsANSI = r.GetBit();
            this.FontFlagsWideOffsets = r.GetBit();
            this.FontFlagsWideCodes = r.GetBit();
            this.FontFlagsItalic = r.GetBit();
            this.FontFlagsBold = r.GetBit();

            r.Align();

            this.LanguageCode = (uint)r.GetByte();
            uint fontNameLen = (uint)r.GetByte();
            this.FontName = r.GetString(fontNameLen);
            this.NumGlyphs = r.GetUI16();

            this.OffsetTable = new uint[this.NumGlyphs];
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                this.OffsetTable[i] = this.FontFlagsWideOffsets ? r.GetUI32() : r.GetUI16();
            }

            this.CodeTableOffset = this.FontFlagsWideOffsets ? r.GetUI32() : r.GetUI16();

            GlyphShapeTable = new List<Shape>();
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                Shape s = new Shape(r);
                GlyphShapeTable.Add(s);
            }

            this.CodeTable = new uint[this.NumGlyphs];
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                this.CodeTable[i] = r.GetUI16();
            }

            if (this.FontFlagsHasLayout)
            {
                this.FontAscent = r.GetInt16();
                this.FontDescent = r.GetInt16();
                this.FontLeading = r.GetInt16();

                this.FontAdvanceTable = new int[this.NumGlyphs];
                for (int i = 0; i < this.NumGlyphs; i++)
                {
                    this.FontAdvanceTable[i] = r.GetInt16();
                }

                this.FontBoundsTable = new Rect[this.NumGlyphs];
                for (int i = 0; i < this.NumGlyphs; i++)
                {
                    this.FontBoundsTable[i] = new Rect(r);
                }

                this.KerningCount = r.GetUI16();

                this.FontKerningTable = new KerningRecord[this.KerningCount];
                if(this.FontFlagsWideCodes)
                {
                    for (int i = 0; i < this.KerningCount; i++)
                    {
                        this.FontKerningTable[i] = new KerningRecord(r.GetUI16(), r.GetUI16(), r.GetInt16());
                    }
                }
                else
                {
                    for (int i = 0; i < this.KerningCount; i++)
                    {
                        this.FontKerningTable[i] = new KerningRecord((uint)r.GetByte(), (uint)r.GetByte(), r.GetInt16());
                    }
                }
            }
        }