Esempio n. 1
0
 internal JPEGTables(SwfReader r, uint curTagLen)
     : base(TagType.JPEGTables)
 {
     if (curTagLen > 8)
     {
         r.GetBytes(2);                 //jpg SOI Marker
         JpegTable = r.GetBytes(curTagLen - 4);
         r.GetBytes(2);                 //jpg EOI Marker
     }
     else
     {
         JpegTable = new byte[0];
     }
 }
Esempio n. 2
0
        internal DefineSoundTag(SwfReader r, uint tagLen)
            : base(TagType.DefineSound)
        {
            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);
        }
Esempio n. 3
0
 internal DefineBinaryDataTag(SwfReader r, uint tagLen)
     : base(TagType.DefineBinaryData)
 {
     _data    = new ByteReader(r.GetBytes(tagLen));
     id       = _data.GetUI16();
     reserved = _data.GetInt32();
     data     = _data.GetBytes(tagLen - 6);
 }
Esempio n. 4
0
        internal SoundStreamBlockTag(SwfReader r, uint tagLen)
            : base(TagType.SoundStreamBlock)
        {
            SampleCount = r.GetUI16();
            SoundData   = r.GetBytes(tagLen - 2);

            // assume mp3 for now
            //SoundData = new Mp3SoundData[SampleCount];
            //for (int i = 0; i < SampleCount; i++)
            //{
            //    SoundData[i] = new Mp3SoundData(r);
            //}
        }
Esempio n. 5
0
        // this needs to combine with the jpegTables in the swfCompilationUnit to make an image
        internal DefineBitsTag(SwfReader r, uint curTagLen, bool hasOwnTable, bool hasAlphaData)
            : base(TagType.DefineBits)
        {
            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();
            }
        }
Esempio n. 6
0
        internal DefineBitsLosslessTag(SwfReader r, uint curTagLen, bool hasAlpha)
            : base(TagType.DefineBitsLossless)
        {
            TagLen   = curTagLen;
            HasAlpha = hasAlpha;
            if (hasAlpha)
            {
                tagType = TagType.DefineBitsLossless2;
            }

            CharacterId  = r.GetUI16();
            BitmapFormat = (BitmapFormat)r.GetByte();

            this.Width  = r.GetUI16();
            this.Height = r.GetUI16();

            if (BitmapFormat == BitmapFormat.Colormapped8Bit) // 8-bit colormapped image
            {
                this.ColorCount = (uint)r.GetByte() + 1;

                this.isIndexedColors = true;
                uint colorBytes = hasAlpha ? (uint)4 : (uint)3;
                uint padWidth   = this.Width + (4 - (this.Width % 4));

                // temp for debugging
                uint pos = r.Position;
                OrgBitmapData = r.GetBytes(curTagLen - 8);
                r.Position    = pos;
                // end temp

                uint   unzippedSize = (this.ColorCount * colorBytes) + (padWidth * this.Height);
                byte[] mapData      = r.DecompressZLIB(curTagLen - 8, unzippedSize);

                uint index = 0;
                this.ColorTable = new RGBA[this.ColorCount];
                for (int i = 0; i < this.ColorCount; i++)
                {
                    if (hasAlpha)
                    {
                        this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2], mapData[index + 3]);
                    }
                    else
                    {
                        this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2]);
                    }
                    index += colorBytes;
                }
                this.ColorData = new uint[this.Width * this.Height];
                index          = 0;
                int offset = (int)(this.ColorCount * colorBytes);
                for (int i = 0; i < padWidth * this.Height; i++)
                {
                    if ((i % padWidth) < this.Width)                    // exclude padding
                    {
                        this.ColorData[index++] = mapData[i + offset];
                    }
                }
            }
            else if (BitmapFormat == BitmapFormat.RGB15Bit) // RGBx555
            {
                // todo: find a test file for rgb555
                uint colorBytes = 2;
                uint padWidth   = this.Width * colorBytes;
                padWidth += (4 - padWidth) % 4;

                // temp for debugging
                uint pos = r.Position;
                OrgBitmapData = r.GetBytes(curTagLen - 7);
                r.Position    = pos;
                // end temp

                uint   unzippedSize = (padWidth * this.Height) * colorBytes;
                byte[] mapData      = r.DecompressZLIB(curTagLen - 7, unzippedSize);

                int index = 0;
                this.BitmapData = new RGBA[this.Width * this.Height];
                for (uint i = 0; i < unzippedSize; i += colorBytes)
                {
                    if ((i % padWidth) < (this.Width * colorBytes))                     // exclude padding
                    {
                        byte b0 = mapData[i];
                        byte b1 = mapData[i + 1];
                        byte rd = (byte)((b0 & 0x7C) << 1);
                        byte gr = (byte)(((b0 & 0x03) << 6) | ((b1 & 0xE0) >> 2));
                        byte bl = (byte)((b1 & 0x1F) << 3);
                        this.BitmapData[index++] = new RGBA(rd, gr, bl);
                    }
                }
            }
            else if (BitmapFormat == BitmapFormat.RGB24Bit) // RGB 24
            {
                // temp for debugging
                uint pos = r.Position;
                OrgBitmapData = r.GetBytes(curTagLen - 7);
                r.Position    = pos;
                // end temp

                uint   colorBytes   = 4;             // 4 bytes will always be byte aligned
                uint   unzippedSize = (this.Width * this.Height) * colorBytes;
                byte[] mapData      = r.DecompressZLIB(curTagLen - 7, unzippedSize);

                int index = 0;
                this.BitmapData = new RGBA[this.Width * this.Height];
                for (uint i = 0; i < unzippedSize; i += colorBytes)
                {
                    if (hasAlpha)
                    {
                        this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3], mapData[i]);
                    }
                    else
                    {
                        this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3]);
                    }
                }
            }
        }