예제 #1
0
        /// <summary>
        /// Reads the data from the binary reader.
        /// </summary>
        /// <param name="binaryReader">Binary reader.</param>
        public override void ReadData(BufferedBinaryReader binaryReader)
        {
            byte[] b = binaryReader.ReadBytes(4);
            BitArray ba = BitParser.GetBitValues(b);

            blockWidth = (int)BitParser.ReadUInt32(ba, 0, 4);
            imageWidth = (int)BitParser.ReadUInt32(ba, 4, 12);
            blockHeight = (int)BitParser.ReadUInt32(ba, 16, 4);
            imageHeight = (int)BitParser.ReadUInt32(ba, 20, 12);

            int nbWBlock = 0;
            int nbBlockWInt = imageWidth / blockWidth;
            float nbBlockWDec = imageWidth / blockWidth;
            if (nbBlockWInt == nbBlockWDec)
                nbWBlock = nbBlockWInt;
            else
                nbWBlock = nbBlockWInt + 1;

            int nbHBlock = 0;
            int nbBlockHInt = imageHeight / blockHeight;
            float nbBlockHDec = imageHeight / blockHeight;
            if (nbBlockHInt == nbBlockHDec)
                nbHBlock = nbBlockHInt;
            else
                nbHBlock = nbBlockHInt + 1;

            int nbBlock = nbWBlock * nbHBlock;

            if (nbBlock > 0)
            {
                blocks = new ImageBlock[nbBlock];

                for (int i = 0; i < nbBlock; i++)
                {
                    blocks[i] = new ImageBlock();
                    blocks[i].ReadData(binaryReader);
                }
            }
        }
예제 #2
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);
                Inflater zipInflator = 	new Inflater();
                zipInflator.SetInput(compressed);
                zipInflator.Inflate(uncompressed, 0, uncompressedSize);

                _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);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Reads the data from a binary reader.
        /// </summary>
        /// <param name="binaryReader">Binary reader.</param>
        public void ReadData(BufferedBinaryReader binaryReader)
        {
            byte[] b = binaryReader.ReadBytes(2);
            BitArray ba = BitParser.GetBitValues(b);

            dataSize = (int)BitParser.ReadUInt32(ba, 0, 16);

            data = null;
            if (dataSize != 0)
            {
                data = new byte[dataSize];
                for (int i = 0; i < dataSize; i++)
                    data[i] = binaryReader.ReadByte();
            }
        }
예제 #4
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 tl = System.Convert.ToInt32(rh.TagLength);
            jpegData = binaryReader.ReadBytes(tl);
        }
예제 #5
0
        /// <summary>
        /// Reads the data.
        /// </summary>
        /// <param name="binaryReader">Binary reader.</param>
        /// <param name="condActionSize">Size of the cond action.</param>
        public void ReadData(BufferedBinaryReader binaryReader, 
            ushort condActionSize)
        {
            int offset = condActionSize - 5;
            condO = binaryReader.ReadByte();
            condKey = binaryReader.ReadByte();

            actions = binaryReader.ReadBytes(offset);
            byte end = binaryReader.ReadByte();
        }
예제 #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);

            spriteId = binaryReader.ReadUInt16();
            int lenght = System.Convert.ToInt32(rh.TagLength-2);
            actionRecord = binaryReader.ReadBytes(lenght);
        }
        /// <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);
                Inflater zipInflator = 	new Inflater();
                zipInflator.SetInput(compressed);
                zipInflator.Inflate(uncompressed, 0, uncompressedSize);

                _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);
                Inflater zipInflator = 	new Inflater();
                zipInflator.SetInput(compressed);
                zipInflator.Inflate(uncompressed, 0, uncompressedSize);

                _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);
                }
            }
        }
예제 #8
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);

            buttonId = binaryReader.ReadUInt16();
            characters = new ButtonRecordCollection();

            bool characterEndFlag = false;
            while (!characterEndFlag)
            {
                byte first = binaryReader.ReadByte();
                if (first == 0)
                    characterEndFlag = true;
                else
                {
                    ButtonRecord buttRecord = new ButtonRecord();
                    buttRecord.ReadData(binaryReader, first, TagCodeEnum.DefineButton);
                    characters.Add(buttRecord);
                }
            }

            int offset = 2;
            foreach (ButtonRecord butRec in characters)
                offset += butRec.GetSizeOf();

            int lenght = System.Convert.ToInt32(rh.TagLength) - offset - 1;
            //-1 for the ActionEndFlag
            actions = binaryReader.ReadBytes(lenght);
            //Read ActionEndFlag
            binaryReader.ReadByte();
        }
예제 #9
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 tl = System.Convert.ToInt32(rh.TagLength);
            characterId = binaryReader.ReadUInt16();
            int imgLen = Convert.ToInt32(binaryReader.ReadUInt32());
            if (imgLen > 0)
            {
                jpegData = binaryReader.ReadBytes(imgLen);
                alphaData = binaryReader.ReadBytes(tl - 6 - imgLen);
            }
        }
예제 #10
0
        /// <summary>
        /// Read next tag from swf input stream.
        /// </summary>
        /// <param name="version">Version.</param>
        /// <param name="binaryReader">Binary reader.</param>
        /// <param name="tagList">Tag list.</param>
        /// <returns></returns>
        internal static BaseTag ReadTag(byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList)
        {
            long posBefore = binaryReader.BaseStream.Position;
            RecordHeader rh = new RecordHeader();
            rh.ReadData(binaryReader);

            int offset = (int)(binaryReader.BaseStream.Position - posBefore);
            binaryReader.BaseStream.Position = posBefore;

            BaseTag resTag = null;

            switch (rh.TagCode)
            {
                case (int)TagCodeEnum.DefineBits: resTag = new DefineBitsTag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg2: resTag = new DefineBitsJpeg2Tag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg3: resTag = new DefineBitsJpeg3Tag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess: resTag = new DefineBitsLossLessTag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess2: resTag = new DefineBitsLossLess2Tag(); break;
                case (int)TagCodeEnum.DefineButton: resTag = new DefineButtonTag(); break;
                case (int)TagCodeEnum.DefineButton2: resTag = new DefineButton2Tag(); break;
                case (int)TagCodeEnum.DefineButtonCxForm: resTag = new DefineButtonCxFormTag(); break;
                case (int)TagCodeEnum.DefineButtonSound: resTag = new DefineButtonSoundTag(); break;
                case (int)TagCodeEnum.DefineEditText: resTag = new DefineEditTextTag(); break;
                case (int)TagCodeEnum.DefineFont: resTag = new DefineFontTag(); break;
                case (int)TagCodeEnum.DefineFont2: resTag = new DefineFont2Tag(); break;
                case (int)TagCodeEnum.DefineFontInfo: resTag = new DefineFontInfoTag(); break;
                case (int)TagCodeEnum.DefineFontInfo2: resTag = new DefineFontInfo2Tag(); break;
                case (int)TagCodeEnum.DefineMorphShape: resTag = new DefineMorphShapeTag(); break;
                case (int)TagCodeEnum.DefineShape: resTag = new DefineShapeTag(); break;
                case (int)TagCodeEnum.DefineShape2: resTag = new DefineShape2Tag(); break;
                case (int)TagCodeEnum.DefineShape3: resTag = new DefineShape3Tag(); break;
                case (int)TagCodeEnum.DefineSound: resTag = new DefineSoundTag(); break;
                case (int)TagCodeEnum.DefineSprite: resTag = new DefineSpriteTag(); break;
                case (int)TagCodeEnum.DefineText: resTag = new DefineTextTag(); break;
                case (int)TagCodeEnum.DefineText2: resTag = new DefineText2Tag(); break;
                case (int)TagCodeEnum.DefineVideoStream: resTag = new DefineVideoStreamTag(); break;
                case (int)TagCodeEnum.DoAction: resTag = new DoActionTag(); break;
                case (int)TagCodeEnum.EnableDebugger: resTag = new EnableDebuggerTag(); break;
                case (int)TagCodeEnum.EnableDebugger2: resTag = new EnableDebugger2Tag(); break;
                case (int)TagCodeEnum.End: resTag = new EndTag(); break;
                case (int)TagCodeEnum.ExportAssets: resTag = new ExportAssetsTag(); break;
                case (int)TagCodeEnum.FrameLabel: resTag = new FrameLabelTag(); break;
                case (int)TagCodeEnum.ImportAssets: resTag = new ImportAssetsTag(); break;
                case (int)TagCodeEnum.InitAction: resTag = new InitActionTag(); break;
                case (int)TagCodeEnum.JpegTable: resTag = new JpegTableTag(); break;
                case (int)TagCodeEnum.PlaceObject: resTag = new PlaceObjectTag(); break;
                case (int)TagCodeEnum.PlaceObject2:	resTag = new PlaceObject2Tag(); break;
                case (int)TagCodeEnum.Protect: resTag = new ProtectTag(); break;
                case (int)TagCodeEnum.RemoveObject: resTag = new RemoveObjectTag(); break;
                case (int)TagCodeEnum.RemoveObject2: resTag = new RemoveObject2Tag(); break;
                case (int)TagCodeEnum.ScriptLimit: resTag = new ScriptLimitTag(); break;
                case (int)TagCodeEnum.SetBackgroundColor: resTag = new SetBackgroundColorTag(); break;
                case (int)TagCodeEnum.SetTabIndex: resTag = new SetTabIndexTag(); break;
                case (int)TagCodeEnum.ShowFrame: resTag = new ShowFrameTag(); break;
                case (int)TagCodeEnum.SoundStreamBlock: resTag = new SoundStreamBlockTag(); break;
                case (int)TagCodeEnum.SoundStreamHead: resTag = new SoundStreamHeadTag(); break;
                case (int)TagCodeEnum.SoundStreamHead2: resTag = new SoundStreamHead2Tag(); break;
                case (int)TagCodeEnum.StartSound: resTag = new StartSoundTag(); break;
                //TODO: Sorenson Codec
                case (int)TagCodeEnum.VideoFrame: resTag = ReadVideoFrameTag(binaryReader, tagList); break;
                default: resTag = new BaseTag(binaryReader.ReadBytes(System.Convert.ToInt32(rh.TagLength + offset))); break;
            }

            //Read the data of the current tag
            resTag.ReadData(version, binaryReader);

            //LOG
            long mustRead = rh.TagLength + offset;
            if (posBefore + mustRead != binaryReader.BaseStream.Position)
            {
                binaryReader.BaseStream.Position = posBefore + rh.TagLength + offset;
                if (log.IsErrorEnabled)
                    log.Error(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....KO");
            }
            else if (log.IsInfoEnabled)
                log.Info(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....OK (" + mustRead + ")");

            return resTag;
        }
예제 #11
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);
            Inflater zipInflator = 	new Inflater();
            zipInflator.SetInput(compressed);
            zipInflator.Inflate(uncompressed, 0, size);

            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];
        }
예제 #12
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);

            bool placeFlagHasClipActions = binaryReader.ReadBoolean();
            bool placeFlagHasClipDepth = binaryReader.ReadBoolean();
            bool placeFlagHasName = binaryReader.ReadBoolean();
            bool placeFlagHasRatio = binaryReader.ReadBoolean();
            bool placeFlagHasColorTransform = binaryReader.ReadBoolean();
            bool placeFlagHasMatrix = binaryReader.ReadBoolean();
            bool placeFlagHasCharacter = binaryReader.ReadBoolean();
            placeFlagMove = binaryReader.ReadBoolean();

            depth = binaryReader.ReadUInt16();
            characterId = 0;
            if (placeFlagHasCharacter)
                characterId = binaryReader.ReadUInt16();
            matrix = null;
            if (placeFlagHasMatrix)
            {
                matrix = new Matrix();
                matrix.ReadData(binaryReader);
            }
            colorTransform = null;
            if (placeFlagHasColorTransform)
            {
                colorTransform = new CXFormWithAlphaData();
                colorTransform.ReadData(binaryReader);
            }
            ratio = 0;
            if (placeFlagHasRatio)
                ratio = binaryReader.ReadUInt16() / 65535.0f;
            name = null;
            if (placeFlagHasName)
                name = binaryReader.ReadString();
            clipDepth = 0;
            if (placeFlagHasClipDepth)
                clipDepth = binaryReader.ReadUInt16();

            // get bytecode actions
            clipActions = null;
            if (placeFlagHasClipActions)
            {
                // different behaviour for Flash 6+
                actionHead = (version>=6) ? binaryReader.ReadBytes(6) : binaryReader.ReadBytes(4);
                // read clip action records to list
                ArrayList clpAc = new ArrayList();
                //ClipActionRec a = null;
                bool res = true;
                do
                {
                    ClipActionRec action = new ClipActionRec();
                    res = action.ReadData(binaryReader, version);
                    if (res)
                        clpAc.Add(action);
                }
                while (res);
                // copy list to array
                clipActions = new ClipActionRec[clpAc.Count];
                clpAc.CopyTo(clipActions,0);
            }
        }