Example #1
0
        /// <summary>
        /// Reads the data.
        /// </summary>
        /// <param name="reader">Reader.</param>
        /// <param name="bitmapColorTableSize">Size of the bitmap color table.</param>
        /// <param name="bitmapWidth">Width of the bitmap.</param>
        /// <param name="bitmapHeight">Height of the bitmap.</param>
        /// <param name="toRead">To read.</param>
        public void ReadData(BufferedBinaryReader reader, byte bitmapColorTableSize,
                             ushort bitmapWidth, ushort bitmapHeight, int toRead)
        {
            int size = ((bitmapColorTableSize + 1) * 3) + (bitmapWidth * bitmapHeight);

            byte[] uncompressed = new byte[size];

            byte[] compressed = reader.ReadBytes(toRead);
            uncompressed = DeflatorWraper.Decompress(compressed);

            int readed = 0;
            int offset = size;

            colorTableRGB = new RGB[bitmapColorTableSize + 1];
            for (int i = 0; i < bitmapColorTableSize + 1; i++)
            {
                byte red = uncompressed[readed];
                readed++;
                byte green = uncompressed[readed];
                readed++;
                byte blue = uncompressed[readed];
                readed++;
                colorTableRGB[i] = new RGB(red, green, blue);
                offset          -= 3;
            }

            colorMapPixelData = new byte[offset];
            for (int i = 0; i < offset; i++, readed++)
            {
                colorMapPixelData[i] = uncompressed[readed];
            }
        }
Example #2
0
        /// <summary>
        /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see>
        /// </summary>
        public override void UpdateData(byte version)
        {
            if (version < 2)
            {
                return;
            }

            // Compression process
            int lenghtOfCompressedBlock = 0;

            byte[]               compressArray      = null;
            MemoryStream         unCompressedStream = new MemoryStream();
            BufferedBinaryWriter unCompressedWriter = new BufferedBinaryWriter(unCompressedStream);

            if (this._bitmapFormat == 3)
            {
                this._colorMapData.WriteTo(unCompressedWriter);
            }
            else if (this._bitmapFormat == 4 || this._bitmapFormat == 5)
            {
                this._bitmapColorData.WriteTo(unCompressedWriter);
            }

            MemoryStream compressedStream = new MemoryStream(DeflatorWraper.Compress(unCompressedStream.ToArray()));

            //Writing process
            MemoryStream         m = new MemoryStream();
            BufferedBinaryWriter w = new BufferedBinaryWriter(m);

            RecordHeader rh = new RecordHeader(TagCode, GetSizeOf(lenghtOfCompressedBlock));

            rh.WriteTo(w);
            w.Write(this._characterId);
            w.Write(this._bitmapFormat);
            w.Write(this._bitmapWidth);
            w.Write(this._bitmapHeight);

            if (this._bitmapFormat == 3)
            {
                w.Write(this._bitmapColorTableSize);
                w.Write(compressArray);
            }
            else if (this._bitmapFormat == 4 || this._bitmapFormat == 5)
            {
                w.Write(compressArray);
            }

            w.Flush();
            // write to data array
            _data = m.ToArray();
        }
Example #3
0
        /// <summary>
        /// Decompiles to stream.
        /// </summary>
        /// <param name="stream">Stream.</param>
        private void DecompileToStream(Stream stream)
        {
            using (MemoryStream ms = new MemoryStream(jpegData))
            {
                Bitmap bmp = (Bitmap)Bitmap.FromStream(ms);
                if (alphaData.Length > 0)
                {
                    //Bitmap png = new Bitmap(bmp.Width, bmp.Height);

                    Bitmap png = new Bitmap(bmp);
                    png.MakeTransparent();

                    using (var fbmp = png.FastLock())
                    {
                        // Do your changes here...
                        byte[] dealphaData = DeflatorWraper.Decompress(alphaData);
                        int    height      = bmp.Height;
                        int    width       = bmp.Width;
                        for (int j = 0; j < height; j++)
                        {
                            for (int i = 0; i < width; i++)
                            {
                                if (dealphaData[(j * width) + i] != 255)
                                {
                                    Color pixel     = fbmp.GetPixel(i, j);
                                    Color withAlpha = Color.FromArgb(dealphaData[(j * width) + i], pixel.R, pixel.G, pixel.B);
                                    fbmp.SetPixel(i, j, withAlpha);
                                }
                            }
                        }
                    }
                    png.Save(stream, ImageFormat.Png);
                    png.Dispose();
                }
                else
                {
                    bmp.Save(stream, ImageFormat.Bmp);
                }
                bmp.Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// Inflate compressed swf
        /// </summary>
        private void Inflate()
        {
            // read size
            br.BaseStream.Position = 4;             // skip signature
            int size = Convert.ToInt32(br.ReadUInt32());

            // read swf head
            byte[] uncompressed = new byte[size];
            br.BaseStream.Position = 0;
            br.Read(uncompressed, 0, 8);           // header data is not compress

            // un-zip
            byte[] compressed = br.ReadBytes(size);
            uncompressed = DeflatorWraper.Decompress(compressed);

            // new memory stream for uncompressed swf
            MemoryStream m = new MemoryStream(uncompressed);

            br = new BufferedBinaryReader(m);
            br.BaseStream.Position = 0;
        }
        /// <summary>
        /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see>
        /// </summary>
        public override void ReadData(byte version, BufferedBinaryReader binaryReader)
        {
            RecordHeader rh = new RecordHeader();

            rh.ReadData(binaryReader);

            int beforePos = (int)binaryReader.BaseStream.Position;
            int toReaded  = (int)rh.TagLength - 7;

            _characterId          = binaryReader.ReadUInt16();
            _bitmapFormat         = binaryReader.ReadByte();
            _bitmapWidth          = binaryReader.ReadUInt16();
            _bitmapHeight         = binaryReader.ReadUInt16();
            _bitmapColorTableSize = 0;

            if (_bitmapFormat == 3)
            {
                _bitmapColorTableSize = binaryReader.ReadByte();
                toReaded--;
            }

            int imageSize = _bitmapWidth * _bitmapHeight;

            if (_bitmapFormat == 3)
            {
                int    uncompressedSize = imageSize + ((_bitmapColorTableSize + 1) * 4);
                byte[] uncompressed     = new byte[uncompressedSize];
                byte[] compressed       = binaryReader.ReadBytes(toReaded);
                uncompressed = DeflatorWraper.Decompress(compressed);

                _alphaColorMapData = new AlphaColorMapData();
                _alphaColorMapData.ColorTableRgb = new RGBA[_bitmapColorTableSize + 1];
                int offset = 0;
                for (int i = 0; i < _bitmapColorTableSize + 1; i++, offset += 4)
                {
                    byte red   = uncompressed[offset];
                    byte green = uncompressed[offset + 1];
                    byte blue  = uncompressed[offset + 2];
                    byte alpha = uncompressed[offset + 3];
                    _alphaColorMapData.ColorTableRgb[i] = new RGBA(red, green, blue, alpha);
                }
                _alphaColorMapData.ColorMapPixelData = new byte[uncompressedSize - offset];
                for (int i = 0; i < uncompressedSize - offset; i++, offset++)
                {
                    _alphaColorMapData.ColorMapPixelData[i] = uncompressed[offset];
                }
            }
            else if (_bitmapFormat == 4 || _bitmapFormat == 5)
            {
                int    uncompressedSize = imageSize * 4;
                byte[] uncompressed     = new byte[uncompressedSize];
                byte[] compressed       = binaryReader.ReadBytes(toReaded);
                uncompressed = DeflatorWraper.Decompress(compressed);

                _alphaBitmapData = new AlphaBitmapData();
                _alphaBitmapData.BitmapPixelData = new RGBA[imageSize];
                for (int i = 0, j = 0; i < imageSize; i++, j += 4)
                {
                    byte red   = uncompressed[j];
                    byte green = uncompressed[j + 1];
                    byte blue  = uncompressed[j + 2];
                    byte alpha = uncompressed[j + 3];
                    _alphaBitmapData.BitmapPixelData[i] = new RGBA(red, green, blue, alpha);
                }
            }
        }
Example #6
0
        /// <summary>
        /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see>
        /// </summary>
        public override void ReadData(byte version, BufferedBinaryReader binaryReader)
        {
            RecordHeader rh = new RecordHeader();

            rh.ReadData(binaryReader);

            int beforePos = (int)binaryReader.BaseStream.Position;
            int toReaded  = (int)rh.TagLength - 7;

            _characterId          = binaryReader.ReadUInt16();
            _bitmapFormat         = binaryReader.ReadByte();
            _bitmapWidth          = binaryReader.ReadUInt16();
            _bitmapHeight         = binaryReader.ReadUInt16();
            _bitmapColorTableSize = 0;

            if (_bitmapFormat == 3)
            {
                _bitmapColorTableSize = binaryReader.ReadByte();
                toReaded--;
            }

            if (_bitmapFormat == 3)
            {
                _colorMapData = new ColorMapData();
                _colorMapData.ReadData(binaryReader, _bitmapColorTableSize, _bitmapWidth, _bitmapHeight, toReaded);
            }
            else if (_bitmapFormat == 4 || _bitmapFormat == 5)
            {
                int imageSize        = _bitmapWidth * _bitmapHeight;
                int uncompressedSize = imageSize;
                if (_bitmapFormat == 4)
                {
                    uncompressedSize *= 2;
                }
                else
                {
                    uncompressedSize *= 4;
                }

                byte[] uncompressed = new byte[uncompressedSize];
                byte[] compressed   = binaryReader.ReadBytes(toReaded);
                uncompressed = DeflatorWraper.Decompress(compressed);

                _bitmapColorData = null;
                if (_bitmapFormat == 4)
                {
                    Pix15[] bitmapPixelData = new Pix15[imageSize];
                    for (int i = 0, j = 0; i < imageSize; i++, j += 2)
                    {
                        byte[] data = new byte[2] {
                            uncompressed[j], uncompressed[j + 1]
                        };
                        bitmapPixelData[i] = new Pix15(data);
                    }
                    _bitmapColorData = new BitmapColorData(bitmapPixelData);
                }
                else
                {
                    Pix24[] bitmapPixelData = new Pix24[imageSize];
                    for (int i = 0, j = 0; i < imageSize; i++, j += 4)
                    {
                        byte reserved = uncompressed[j];
                        byte red      = uncompressed[j + 1];
                        byte green    = uncompressed[j + 2];
                        byte blue     = uncompressed[j + 3];
                        bitmapPixelData[i] = new Pix24(red, green, blue);
                    }
                    _bitmapColorData = new BitmapColorData(bitmapPixelData);
                }
            }
        }