예제 #1
0
        private bool ReadHeader()
        {
            // Signature
            _swf.ReadUI8(3);

            // File version
            _swf.ReadUI8();

            // File length
            _swf.ReadUI32();

            // The swf is Zlib compressed from here on
            _swf.Stream.ReadByte(); // The first two bytes are Zlib info
            _swf.Stream.ReadByte(); //
            DeflateStream inflatedStream = new DeflateStream(_stream, CompressionMode.Decompress);

            _swf.Stream = inflatedStream;

            // Frame size
            int nBits = (int)_swf.ReadUB(5);

            _swf.ReadSB(nBits);
            _swf.ReadSB(nBits);
            _swf.ReadSB(nBits);
            _swf.ReadSB(nBits);

            // Frame rate (stored in UI8.UI8 format)
            _swf.ReadUI8();
            _swf.ReadUI8();

            // Frame count
            _swf.ReadUI16();

            return(true);
        }
예제 #2
0
파일: Tag.cs 프로젝트: Briles/Kurouzu
        public Tag(SwfReader swf)
        {
            ushort tagInfo = swf.ReadUI16();
            Code = (ushort)(tagInfo >> 6);
            Length = (ulong)(tagInfo & 0x3f);

            // Is this a long data block?
            if (Length == 0x3f)
            {
                Length = swf.ReadUI32();
            }

            switch (Code)
            {
                // DefineBitsLossless2
                case 36:
                    ulong remainingLength = Length - 7;

                    Png.CharacterId = swf.ReadUI16();
                    Png.BitmapFormat = swf.ReadUI8();
                    Png.BitmapWidth = swf.ReadUI16();
                    Png.BitmapHeight = swf.ReadUI16();

                    List<byte> compressedPixelData = new List<byte>();
                    for (ulong b = 0; b < remainingLength; b++)
                    {
                        compressedPixelData.Add(swf.ReadByte());
                    }
                    byte[] compressedBitMapPixelData = compressedPixelData.ToArray();
                    Stream pixelStream = new MemoryStream(compressedBitMapPixelData);

                    pixelStream.ReadByte();
                    pixelStream.ReadByte();

                    DeflateStream inflatedStream = new DeflateStream(pixelStream, CompressionMode.Decompress);
                    pixelStream = inflatedStream;

                    for (long c = 0; c < Png.BitmapArea; c++)
                    {
                        byte alpha = Convert.ToByte(pixelStream.ReadByte());
                        byte red = Convert.ToByte(pixelStream.ReadByte());
                        byte green = Convert.ToByte(pixelStream.ReadByte());
                        byte blue = Convert.ToByte(pixelStream.ReadByte());
                        Png.BitmapPixelData.AddRange(new[] { blue, green, red, alpha });
                    }
                    break;

                // SymbolClass
                case 76:
                    ushort numSymbols = swf.ReadUI16();
                    for (ushort s = 0; s < numSymbols; s++)
                    {
                        short tagId = swf.ReadSI16();
                        string tagName = swf.ReadSTRING();
                        string prettyName = Regex.Replace(tagName, @"ImagePack_((items)|(masteryIcons)|(spells))_Embeds__e_(Spell_)?", "");
                        if (!Symbols.ContainsKey(tagId)) {
                            Symbols[tagId] = prettyName;
                        }
                    }
                    break;

                // Everything Else
                default:
                    for (ulong index = 0; index < Length; index++)
                    {
                        swf.Stream.ReadByte();
                    }
                    break;
            }
        }
예제 #3
0
        public Tag(SwfReader swf)
        {
            ushort tagInfo = swf.ReadUI16();

            Code   = (ushort)(tagInfo >> 6);
            Length = (ulong)(tagInfo & 0x3f);

            // Is this a long data block?
            if (Length == 0x3f)
            {
                Length = swf.ReadUI32();
            }

            switch (Code)
            {
            // DefineBitsLossless2
            case 36:
                ulong remainingLength = Length - 7;

                Png.CharacterId  = swf.ReadUI16();
                Png.BitmapFormat = swf.ReadUI8();
                Png.BitmapWidth  = swf.ReadUI16();
                Png.BitmapHeight = swf.ReadUI16();

                List <byte> compressedPixelData = new List <byte>();
                for (ulong b = 0; b < remainingLength; b++)
                {
                    compressedPixelData.Add(swf.ReadByte());
                }
                byte[] compressedBitMapPixelData = compressedPixelData.ToArray();
                Stream pixelStream = new MemoryStream(compressedBitMapPixelData);

                pixelStream.ReadByte();
                pixelStream.ReadByte();

                DeflateStream inflatedStream = new DeflateStream(pixelStream, CompressionMode.Decompress);
                pixelStream = inflatedStream;

                for (long c = 0; c < Png.BitmapArea; c++)
                {
                    byte alpha = Convert.ToByte(pixelStream.ReadByte());
                    byte red   = Convert.ToByte(pixelStream.ReadByte());
                    byte green = Convert.ToByte(pixelStream.ReadByte());
                    byte blue  = Convert.ToByte(pixelStream.ReadByte());
                    Png.BitmapPixelData.AddRange(new[] { blue, green, red, alpha });
                }
                break;

            // SymbolClass
            case 76:
                ushort numSymbols = swf.ReadUI16();
                for (ushort s = 0; s < numSymbols; s++)
                {
                    short  tagId      = swf.ReadSI16();
                    string tagName    = swf.ReadSTRING();
                    string prettyName = Regex.Replace(tagName, @"ImagePack_((items)|(masteryIcons)|(spells))_Embeds__e_(Spell_)?", "");
                    if (!Symbols.ContainsKey(tagId))
                    {
                        Symbols[tagId] = prettyName;
                    }
                }
                break;

            // Everything Else
            default:
                for (ulong index = 0; index < Length; index++)
                {
                    swf.Stream.ReadByte();
                }
                break;
            }
        }