Esempio n. 1
0
        public static ColorBlend[] ReadGradient(BinaryFlashReader reader, bool bWithAlpha, bool morph)
        {
            ColorBlend[] clrs = new ColorBlend[2];

            int        nNumRecords = reader.ReadByte();
            ColorBlend clrBlend    = new ColorBlend(nNumRecords);
            ColorBlend clrBlendEnd = null;

            if (morph)
            {
                clrBlendEnd = new ColorBlend(nNumRecords);
            }

            for (int i = 0; i < nNumRecords; i++)
            {
                Color clr;
                byte  ratio;
                ReadRecord(reader, bWithAlpha, out clr, out ratio);
                clrBlend.Colors[i]    = clr;
                clrBlend.Positions[i] = (float)ratio / 255;

                if (morph)
                {
                    ReadRecord(reader, bWithAlpha, out clr, out ratio);
                    clrBlendEnd.Colors[i]    = clr;
                    clrBlendEnd.Positions[i] = (float)ratio / 255;
                }
            }
            return(clrs);
        }
Esempio n. 2
0
        public ColorMatrix(BinaryFlashReader reader, bool hasAlpha)
        {
            bool bHasAddTerms  = reader.ReadBoolean();
            bool bHasMultTerms = reader.ReadBoolean();
            int  nNumBits      = (int)reader.ReadBits(4);

            this.AlphaMultiply = this.RedMultiply = this.GreenMultiply = this.BlueMultiply = 256;
            this.AlphaAdd      = this.RedAdd = this.GreenAdd = this.BlueAdd = 0;

            if (bHasMultTerms)
            {
                this.RedMultiply   = (short)reader.ReadBits(nNumBits);
                this.GreenMultiply = (short)reader.ReadBits(nNumBits);
                this.BlueMultiply  = (short)reader.ReadBits(nNumBits);
                if (hasAlpha)
                {
                    this.AlphaMultiply = (short)reader.ReadBits(nNumBits);
                }
            }
            if (bHasAddTerms)
            {
                this.RedAdd   = (short)reader.ReadBits(nNumBits);
                this.GreenAdd = (short)reader.ReadBits(nNumBits);
                this.BlueAdd  = (short)reader.ReadBits(nNumBits);
                if (hasAlpha)
                {
                    this.AlphaAdd = (short)reader.ReadBits(nNumBits);
                }
            }
            reader.JumpToNextByteStart();
        }
Esempio n. 3
0
        public ColorMatrix(BinaryFlashReader reader, bool hasAlpha)
        {
            bool bHasAddTerms = reader.ReadBoolean();
            bool bHasMultTerms = reader.ReadBoolean();
            int nNumBits = (int)reader.ReadBits(4);

            this.AlphaMultiply = this.RedMultiply = this.GreenMultiply = this.BlueMultiply = 256;
            this.AlphaAdd = this.RedAdd = this.GreenAdd = this.BlueAdd = 0;

            if (bHasMultTerms)
            {
                this.RedMultiply = (short) reader.ReadBits(nNumBits);
                this.GreenMultiply = (short) reader.ReadBits(nNumBits);
                this.BlueMultiply = (short) reader.ReadBits(nNumBits);
                if (hasAlpha)
                    this.AlphaMultiply = (short) reader.ReadBits(nNumBits);
            }
            if (bHasAddTerms)
            {
                this.RedAdd = (short) reader.ReadBits(nNumBits);
                this.GreenAdd = (short) reader.ReadBits(nNumBits);
                this.BlueAdd = (short) reader.ReadBits(nNumBits);
                if (hasAlpha)
                    this.AlphaAdd = (short) reader.ReadBits(nNumBits);
            }
            reader.JumpToNextByteStart();
        }
Esempio n. 4
0
        public static ColorBlend[] ReadGradient(BinaryFlashReader reader, bool bWithAlpha, bool morph)
        {
            ColorBlend[] clrs = new ColorBlend[2];

            int nNumRecords = reader.ReadByte();
            ColorBlend clrBlend = new ColorBlend(nNumRecords);
            ColorBlend clrBlendEnd = null;
            if (morph)
                clrBlendEnd = new ColorBlend(nNumRecords);

            for (int i = 0; i < nNumRecords; i++)
            {
                Color clr;
                byte ratio;
                ReadRecord(reader, bWithAlpha, out clr, out ratio);
                clrBlend.Colors[i] = clr;
                clrBlend.Positions[i] = (float)ratio/255;

                if (morph)
                {
                    ReadRecord(reader, bWithAlpha, out clr, out ratio);
                    clrBlendEnd.Colors[i] = clr;
                    clrBlendEnd.Positions[i] = (float)ratio/255;
                }
            }
            return clrs;
        }
Esempio n. 5
0
        private void ReadShapeWithStyle(BinaryFlashReader reader)
        {
            this.FillStyles = reader.ReadFillStyleArray(this.UseAlpha, this._extended, false);
            this.LineStyles = reader.ReadLineStyleArray(this.UseAlpha, this._extended, false, this._hasX);

            this.CommandList = ReadShapeCommands(reader, this.FillStyles, this.LineStyles, this.UseAlpha, this._extended, false, this._hasX);

            reader.JumpToNextByteStart();
        }
Esempio n. 6
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = this.GetDataReader();
            ushort            id     = reader.ReadUInt16();

            ((Font)record.Owner.Characters[id]).ReadFontInfo(this);
        }
Esempio n. 7
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            if (record.Tag == Flash.Tags.RemoveObject2)
            {
                this.Depth = (int)reader.ReadUInt16();
            }
            else
            {
                throw new Exception("Placement version not implemented");
            }
        }
Esempio n. 8
0
        public LineStyle(BinaryFlashReader reader, bool useAlpha, bool morph, bool bHasX)
        {
            reader.JumpToNextByteStart();
            this.Width = reader.ReadUInt16();
            if (morph)
                this.WidthEnd = reader.ReadUInt16();
            //this.Width = this.WidthEnd = 60;

            this.Color = reader.ReadColor(useAlpha);
            if (morph)
                this.ColorEnd = reader.ReadColor(useAlpha);

            if (bHasX)
                reader.ReadUInt16(); //TODO: what's this for? Shape4 and 5.
        }
Esempio n. 9
0
        public FillStyle(BinaryFlashReader reader, bool useAlpha, bool morph)
        {
            reader.JumpToNextByteStart();
            this.FillStyleType = (FillStyleTypes)(int)reader.ReadByte();

            switch (this.FillStyleType)
            {
            case FillStyleTypes.Solid:
                this.Color = reader.ReadColor(useAlpha);
                if (morph)
                {
                    this.ColorEnd = reader.ReadColor(useAlpha);
                }
                break;

            case FillStyleTypes.LinearGradient:
            case FillStyleTypes.RadialGradient:
                this.Matrix = new Basic.Matrix(reader);
                if (morph)
                {
                    this.MatrixEnd = new Basic.Matrix(reader);
                }
                ColorBlend[] gradients = Style.Gradient.ReadGradient(reader, useAlpha, morph);
                this.Gradient = gradients[0];
                if (morph)
                {
                    this.GradientEnd = gradients[1];
                }
                break;

            case FillStyleTypes.RepeatingBitmap:
            case FillStyleTypes.ClippedBitmap:
            case FillStyleTypes.NonSmoothedRepeatingBitmap:
            case FillStyleTypes.NonSmoothedClippedBitmap:
                this.CharacterId      = reader.ReadUInt16();
                this.BitmapFillMatrix = new Basic.Matrix(reader);
                if (morph)
                {
                    this.BitmapFillMatrixEnd = new Basic.Matrix(reader);
                }
                break;
            }
        }
Esempio n. 10
0
        public Matrix(BinaryFlashReader reader)
        {
            bool bHasScale = reader.ReadBoolean();

            if (bHasScale)
            {
                int    nNumBits = (int)reader.ReadBits(5);
                long[] vals     = reader.ReadBitArray(2, nNumBits, true);
                //TODO: scale is 16.16 fixed!?! Why numbits in that case? MM doc error as usual...
                //matrix.Scale((float)vals[0]/65536, (float)vals[1]/65536);
                this.A = (int)vals[0];
                this.D = (int)vals[1];
            }
            else
            {
                this.A = this.D = 0x00010000;
            }

            bool bHasRotateSkew = reader.ReadBoolean();

            if (bHasRotateSkew)
            {
                int    nNumBits = (int)reader.ReadBits(5);
                long[] vals     = reader.ReadBitArray(2, nNumBits, true);
                //matrix.Shear((float)vals[0]/65536, (float)vals[1]/65536);
                this.B = (int)vals[0];
                this.C = (int)vals[1];
            }

            //Translate info is always included:
            if (true)
            {
                int    nNumBits = (int)reader.ReadBits(5);
                long[] vals     = reader.ReadBitArray(2, nNumBits, true);
                //matrix.Translate((float)vals[0]/20,(float)vals[1]/20);
                this.Tx = (int)vals[0];
                this.Ty = (int)vals[1];
            }

            reader.JumpToNextByteStart();
        }
Esempio n. 11
0
        public void ReadFontInfo(FontInfo fi)
        {
            BinaryFlashReader reader = fi.GetDataReader();

            this.Name = reader.ReadUnicodePascalString();

            byte flags = reader.ReadByte();

            this.Small = (flags & 32) != 0;
            bool shiftJIS = (flags & 16) != 0;

            this.Ansi       = (flags & 8) != 0;
            this.Italic     = (flags & 4) != 0;
            this.Bold       = (flags & 2) != 0;
            this.DoubleByte = (flags & 1) != 0;

            if (fi.Tag == Flash.Tags.DefineFontInfo2)
            {
                this.LanguageCode = reader.ReadByte();
            }

            int nNumChars = (int)reader.BaseStream.Length - (int)reader.BaseStream.Position;             //number of bytes left

            if (this.DoubleByte)
            {
                nNumChars /= 2;
            }
            ArrayList codes = new ArrayList();

            for (int charNum = 0; charNum < nNumChars; charNum++)
            {
                if (this.DoubleByte)
                {
                    codes.Add(reader.ReadUInt16());
                }
                else
                {
                    codes.Add((ushort)reader.ReadByte());
                }
            }
        }
Esempio n. 12
0
        public LineStyle(BinaryFlashReader reader, bool useAlpha, bool morph, bool bHasX)
        {
            reader.JumpToNextByteStart();
            this.Width = reader.ReadUInt16();
            if (morph)
            {
                this.WidthEnd = reader.ReadUInt16();
            }
            //this.Width = this.WidthEnd = 60;

            this.Color = reader.ReadColor(useAlpha);
            if (morph)
            {
                this.ColorEnd = reader.ReadColor(useAlpha);
            }

            if (bHasX)
            {
                reader.ReadUInt16();                 //TODO: what's this for? Shape4 and 5.
            }
        }
Esempio n. 13
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            //TODO: Is this a correct assumption about DefineShape5?
            this.UseAlpha  = (this.Tag == Flash.Tags.DefineShape3 || this.Tag == Flash.Tags.DefineShape5)?true:false;
            this._extended = (this.Tag == Flash.Tags.DefineShape)?false:true;
            this._hasX     = (this.Tag == Flash.Tags.DefineShape4 || this.Tag == Flash.Tags.DefineShape5)?true:false;
            this.Id        = reader.ReadUInt16();
            this.Bounds    = reader.ReadRect();

            if (this.Tag == Flash.Tags.DefineShape4)
            {
                reader.ReadRect();                 //TODO: what's this rect for?
            }
            this.ReadShapeWithStyle(reader);

            this.InitDone();
        }
Esempio n. 14
0
        public Matrix(BinaryFlashReader reader)
        {
            bool bHasScale = reader.ReadBoolean();
            if (bHasScale)
            {
                int nNumBits = (int)reader.ReadBits(5);
                long[] vals = reader.ReadBitArray(2, nNumBits, true);
                //TODO: scale is 16.16 fixed!?! Why numbits in that case? MM doc error as usual...
                //matrix.Scale((float)vals[0]/65536, (float)vals[1]/65536);
                this.A = (int)vals[0];
                this.D = (int)vals[1];
            }
            else
                this.A = this.D = 0x00010000;

            bool bHasRotateSkew = reader.ReadBoolean();
            if (bHasRotateSkew)
            {
                int nNumBits = (int)reader.ReadBits(5);
                long[] vals = reader.ReadBitArray(2, nNumBits, true);
                //matrix.Shear((float)vals[0]/65536, (float)vals[1]/65536);
                this.B = (int)vals[0];
                this.C = (int)vals[1];
            }

            //Translate info is always included:
            if (true)
            {
                int nNumBits = (int)reader.ReadBits(5);
                long[] vals = reader.ReadBitArray(2, nNumBits, true);
                //matrix.Translate((float)vals[0]/20,(float)vals[1]/20);
                this.Tx = (int)vals[0];
                this.Ty = (int)vals[1];
            }

            reader.JumpToNextByteStart();
        }
Esempio n. 15
0
 public static void ReadRecord(BinaryFlashReader reader, bool useAlpha, out Color color, out byte ratio)
 {
     ratio = reader.ReadByte();
     color = reader.ReadColor(useAlpha);
 }
Esempio n. 16
0
 public static ColorBlend ReadGradient(BinaryFlashReader reader, bool bWithAlpha)
 {
     ColorBlend[] clrBlends = ReadGradient(reader, bWithAlpha, false);
     return clrBlends[0];
 }
Esempio n. 17
0
        public static ArrayList ReadShapeCommands(BinaryFlashReader reader, ArrayList fillStyles, ArrayList lineStyles, bool useAlpha, bool extended, bool morph, bool hasX)
        {
            reader.JumpToNextByteStart();
            ArrayList commands = new ArrayList();

            Byte val = reader.ReadByte();
            int numFillBits = val >> 4; //this.NumFillBits
            int numLineBits = val & 15; //this.NumLineBits

            while (true)
            {
                //Debugging
            //				ArrayList types = new ArrayList();
            //				foreach (ShapeCommand.Base cmd in commands)
            //				{
            //					string name = cmd.GetType().ToString();
            //					types.Add(name.Remove(0,name.LastIndexOf(".")+1) + ":"+cmd.ToString());
            //				}

                bool bIsEdge = reader.ReadBoolean();

                if (!bIsEdge)
                {
                    int nFlags = (int)reader.ReadBits(5);
                    if (nFlags == 0)
                        break;

                    bool bStateNewStyles = (nFlags & 16) > 0;
                    bool bStateLineStyle = (nFlags & 8) > 0;
                    bool bStateFillStyle1 = (nFlags & 4) > 0;
                    bool bStateFillStyle0 = (nFlags & 2) > 0;
                    bool bStateMoveTo = (nFlags & 1) > 0;

                    if (bStateMoveTo)
                    {
                        int nMoveBits = (int)reader.ReadBits(5);
                        EPoint pntMove = new EPoint(
                            (int)reader.ReadBits(nMoveBits,true),
                            (int)reader.ReadBits(nMoveBits,true));
                        commands.Add(new ShapeCommand.Move(pntMove));
                    }
                    if (bStateFillStyle0)
                        commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 0));
                    if (bStateFillStyle1)
                        commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 1));
                    if (bStateLineStyle)
                        commands.Add(new ShapeCommand.LineStyle((int)reader.ReadBits(numLineBits)));
                    if (bStateNewStyles)
                    {
                        fillStyles.AddRange(reader.ReadFillStyleArray(useAlpha, extended, morph));
                        lineStyles.AddRange(reader.ReadLineStyleArray(useAlpha, extended, morph, hasX));
                        numFillBits = (int)reader.ReadBits(4);
                        numLineBits = (int)reader.ReadBits(4);
                    }
                }
                else
                {
                    bool bIsStraight = reader.ReadBoolean();
                    if (bIsStraight)
                    {
                        int nNumBits = (int)reader.ReadBits(4)+2;
                        bool bGeneralLineFlag = reader.ReadBoolean();
                        //0 = horizontal/vertical, 1 = general (ie both X and Y)
                        EPoint pntMove = new EPoint();
                        if (bGeneralLineFlag)
                        {
                            pntMove.X = (int)reader.ReadBits(nNumBits,true);
                            pntMove.Y = (int)reader.ReadBits(nNumBits,true);
                        }
                        else
                        {
                            //error in MMs documentation: either X or Y in here, not both!
                            bool bVertical = reader.ReadBoolean();
                            int nVal = (int)reader.ReadBits(nNumBits, true);
                            if (bVertical)
                                pntMove.Y = nVal;
                            else
                                pntMove.X = nVal;
                        }
                        commands.Add(new ShapeCommand.Line(pntMove));
                    }
                    else
                    {
                        //it's a curve
                        int nNumBits = (int)reader.ReadBits(4)+2;
                        long[] vals = reader.ReadBitArray(4, nNumBits, true);
                        commands.Add(new ShapeCommand.Curve(new EPoint(vals[0], vals[1]), new EPoint(vals[2], vals[3])));
                    }
                }
            }
            return commands;
        }
Esempio n. 18
0
        private void ReadShapeWithStyle(BinaryFlashReader reader)
        {
            this.FillStyles = reader.ReadFillStyleArray(this.UseAlpha, this._extended, false);
            this.LineStyles = reader.ReadLineStyleArray(this.UseAlpha, this._extended, false, this._hasX);

            this.CommandList = ReadShapeCommands(reader, this.FillStyles, this.LineStyles, this.UseAlpha, this._extended, false, this._hasX);

            reader.JumpToNextByteStart();
        }
Esempio n. 19
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            if (this.Tag == Flash.Tags.DoInitAction)
            {
                this.Sprite = reader.ReadUInt16();
            }

            this.Actions = new ArrayList();
            while (true)
            {
                ActionTypes actionType = (ActionTypes)reader.ReadByte();
                //int nDataLength = 0;
                switch (actionType)
                {
                case ActionTypes.StoreRegister:
                    byte register = reader.ReadByte();
                    break;

                case ActionTypes.WaitForFrame_Dyn:
                    byte skip = reader.ReadByte();
                    break;

                case ActionTypes.GetURL2:
                    byte method = reader.ReadByte();
                    break;

                case ActionTypes.GotoFrame:
                    ushort frameNo = reader.ReadUInt16();
                    break;

                case ActionTypes.BranchAlways:
                    short offset = reader.ReadInt16();
                    break;

                case ActionTypes.BranchIfTrue:
                    short offsetX = reader.ReadInt16();
                    break;

                case ActionTypes.GotoExpression:
                    //TODO: error in documentation. Says 2 bytes but declares a byte...
                    byte play = reader.ReadByte();
                    break;

                case ActionTypes.WaitForFrame:
                    ushort frame = reader.ReadUInt16();
                    byte   skipX = reader.ReadByte();
                    break;

                case ActionTypes.GetURL:
                    string URL    = reader.ReadPascalString();
                    string Target = reader.ReadPascalString();
                    break;

                case ActionTypes.DeclareDictionary:
                    int      nCount     = reader.ReadUInt16();
                    string[] Dictionary = new string[nCount];
                    for (int i = 0; i < nCount; i++)
                    {
                        reader.ReadPascalString();
                    }
                    break;

                case ActionTypes.SetTarget:
                    string TargetX = reader.ReadPascalString();
                    break;

                case ActionTypes.GotoLabel:
                    string Label = reader.ReadPascalString();
                    break;

                case ActionTypes.DeclareFunction_V7:
                    string Name     = reader.ReadPascalString();
                    ushort argCount = reader.ReadUInt16();
                    byte   regCount = reader.ReadByte();
                    //TODO: 7 bits?
                    ushort declareFunction2_reserved = reader.ReadUInt16();               //:7
                    //TODO: booleans?
                    ushort preloadGlobal     = reader.ReadUInt16();                       //:1
                    ushort preloadParent     = reader.ReadUInt16();                       //:1
                    ushort preloadRoot       = reader.ReadUInt16();                       //:1
                    ushort suppressSuper     = reader.ReadUInt16();                       //:1
                    ushort preloadSuper      = reader.ReadUInt16();                       //:1
                    ushort suppressArguments = reader.ReadUInt16();                       //:1
                    ushort preloadArguments  = reader.ReadUInt16();                       //:1
                    ushort suppressThis      = reader.ReadUInt16();                       //:1
                    ushort preloadThis       = reader.ReadUInt16();                       //:1
                    //ArrayList parameters = new ArrayList();
                    for (int i = 0; i < argCount; i++)
                    {
                        byte   paramRegister = reader.ReadByte();
                        string paramName     = reader.ReadPascalString();
                    }
                    ushort functionLength = reader.ReadUInt16();
                    break;

                case ActionTypes.Try:
                    //TODO: 5 bits and 1-bit bools?
                    byte   tryReserved     = reader.ReadByte();                   //: 5;
                    byte   catchInRegister = reader.ReadByte();                   //: 1;
                    byte   useFinally      = reader.ReadByte();                   //: 1;
                    byte   useCatch        = reader.ReadByte();                   //: 1;
                    ushort trySize         = reader.ReadUInt16();
                    ushort catchSize       = reader.ReadUInt16();
                    ushort finallySize     = reader.ReadUInt16();
                    string catchName;
                    byte   catchRegister;
                    if (catchInRegister == 0)
                    {
                        catchName = reader.ReadPascalString();
                    }
                    else
                    {
                        catchRegister = reader.ReadByte();
                    }
                    break;

                case ActionTypes.PushData:
                    byte type = reader.ReadByte();
                    //TODO: read data depending on type
                    break;

                case ActionTypes.DeclareFunction:
                    string   NameX     = reader.ReadPascalString();
                    ushort   argCountX = reader.ReadUInt16();
                    string[] argNames  = new string[argCountX];
                    for (int i = 0; i < argCountX; i++)
                    {
                        argNames[i] = reader.ReadPascalString();
                    }
                    ushort functionLengthX = reader.ReadUInt16();
                    break;
                }
            }
        }
Esempio n. 20
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            if (this.Tag == Flash.Tags.PlaceObject)
            {
                this.CharacterId = reader.ReadUInt16();
                this.Depth       = reader.ReadUInt16();
                this.Matrix      = new Basic.Matrix(reader);
                this.ColorMatrix = new Basic.ColorMatrix(reader, false);                 //reader.ReadColorMatrix();
            }
            else
            {
                int nPlaceInfo = reader.ReadByte();

                bool bPlaceFlagHasClipActions    = (nPlaceInfo & 128) > 0;
                bool bPlaceFlagHasClipDepth      = (nPlaceInfo & 64) > 0;
                bool bPlaceFlagHasName           = (nPlaceInfo & 32) > 0;
                bool bPlaceFlagHasRatio          = (nPlaceInfo & 16) > 0;
                bool bPlaceFlagHasColorTransform = (nPlaceInfo & 8) > 0;
                bool bPlaceFlagHasMatrix         = (nPlaceInfo & 4) > 0;
                bool bPlaceFlagHasCharacter      = (nPlaceInfo & 2) > 0;
                bool bPlaceFlagMove = (nPlaceInfo & 1) > 0;

                this.Depth = reader.ReadUInt16();
                if (bPlaceFlagHasCharacter)
                {
                    this.CharacterId = reader.ReadUInt16();
                }
                if (bPlaceFlagHasMatrix)
                {
                    this.Matrix = new Basic.Matrix(reader);
                }
                if (bPlaceFlagHasColorTransform)
                {
                    this.ColorMatrix = new Basic.ColorMatrix(reader, true);
                }
                if (bPlaceFlagHasRatio)
                {
                    this.Ratio = reader.ReadUInt16();
                }
                if (bPlaceFlagHasName)
                {
                    this.Name = reader.ReadPascalString();                     //readNullString
                }
                if (bPlaceFlagHasClipDepth)
                {
                    this.ClipDepth = reader.ReadUInt16();
                }
                if (bPlaceFlagHasClipActions)
                {
                    //TODO:!!!
                }

                bool bFilters = false;
                bool bBlend   = false;
                bool bCache   = false;
                if (this.Tag == Flash.Tags.PlaceObject3)
                {
                    nPlaceInfo = reader.ReadByte();
                    bFilters   = (nPlaceInfo & 1) > 0;             //TODO: reverse order? 128,64,32?
                    bBlend     = (nPlaceInfo & 2) > 0;             //TODO: implement blend&cache
                    bCache     = (nPlaceInfo & 4) > 0;
                }
                if (bFilters)
                {
                    byte nNumFilters = reader.ReadByte();
                    for (int i = 0; i < nNumFilters; i++)
                    {
                        byte        filterId = reader.ReadByte();
                        Filter.Base filter   = null;
                        switch (filterId)
                        {
                        case 0:
                            filter = new Filter.DropShadow();
                            break;

                        case 1:
                            filter = new Filter.Blue();
                            break;

                        case 2:
                            filter = new Filter.Glow();
                            break;

                        case 3:
                            filter = new Filter.Bevel();
                            break;

                        case 4:
                            filter = new Filter.GradientGlow();
                            break;

                        case 6:
                            filter = new Filter.AdjustColor();
                            break;

                        case 7:
                            filter = new Filter.GradientBevel();
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        public override void Init(Record record)
        {
            base.CopyRecord(record);              //wheww, this is ugly.

            BinaryFlashReader reader = record.GetDataReader();

            //I don't need these (start/end bounds):
            this.Id = reader.ReadUInt16();
            reader.ReadRect();
            reader.ReadRect();


            // Offset to EndEdges
            uint offset       = reader.ReadUInt32();
            int  posForShape2 = (int)(reader.BaseStream.Position + offset);

            this.FillStyles = reader.ReadFillStyleArray(true, true, true);
            this.LineStyles = reader.ReadLineStyleArray(true, true, true, false);

            this.CommandList = ReadShapeCommands(reader, this.FillStyles, this.LineStyles, true, true, true, false);

            if (posForShape2 > reader.BaseStream.Position)
            {
                throw new Exception("Morph target error");
            }
            //make sure we're at the right position
            reader.BaseStream.Position = posForShape2;

            this._morphCommandList = ReadShapeCommands(reader, this.FillStyles, this.LineStyles, true, true, true, false);

            //Style changes are defined only in start shape - copy them to end shape!
            object      carry     = null;
            EPoint      ptCurrent = new EPoint();
            ArrayList   corrected = new ArrayList();
            IEnumerator enTarget  = this._morphCommandList.GetEnumerator();

            foreach (ShapeCommand.Base cmd in this.CommandList)
            {
                if (cmd.IsStyle)
                {
                    continue;
                }

                if (carry != null)
                {
                    corrected.Add(carry);
                    carry = null;
                }
                else
                {
                    if (!enTarget.MoveNext())
                    {
                        throw new Exception("Morph target is missing edges");
                    }

                    ShapeCommand.Base cmdTo = (ShapeCommand.Base)enTarget.Current;
                    if (cmd is ShapeCommand.Move)
                    {
                        if (cmdTo is ShapeCommand.Move)
                        {
                            corrected.Add(cmdTo);
                        }
                        else
                        {
                            carry = cmdTo;
                            corrected.Add(new ShapeCommand.Move(ptCurrent));
                        }
                    }
                    else
                    {
                        corrected.Add(cmdTo);
                    }

                    if (cmdTo is ShapeCommand.Move)
                    {
                        ptCurrent = ((ShapeCommand.Move)cmdTo).GetNewLoc(ptCurrent);
                    }
                    else if (cmdTo is ShapeCommand.Draw)
                    {
                        ptCurrent = ((ShapeCommand.Draw)cmdTo).GetNewLoc(ptCurrent);
                    }
                }
            }
            this._morphCommandList = corrected;

            string s = this.WriteCommands(this._morphCommandList);

            Endogine.Files.FileReadWrite.Write("MS" + this.Id + ".txt", s);

            this.InitDone();
        }
Esempio n. 22
0
 public static ColorBlend ReadGradient(BinaryFlashReader reader, bool bWithAlpha)
 {
     ColorBlend[] clrBlends = ReadGradient(reader, bWithAlpha, false);
     return(clrBlends[0]);
 }
Esempio n. 23
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = this.GetDataReader();

            this.Id = reader.ReadUInt16();

            bool      wideOffsets = false;
            ArrayList offsets     = new ArrayList();
            int       nNumChars;
            bool      hasLayout = false;

            if (this.Tag == Flash.Tags.DefineFont2)
            {
                byte flags = reader.ReadByte();
                hasLayout = (flags & 128) > 0;
                bool shiftJIS = (flags & 64) > 0;
                this.Small      = (flags & 32) > 0;
                this.Ansi       = (flags & 16) > 0;
                wideOffsets     = (flags & 8) > 0;
                this.DoubleByte = (flags & 4) > 0;
                this.Italic     = (flags & 2) > 0;
                this.Bold       = (flags & 1) > 0;

                this.LanguageCode = reader.ReadByte();
                this.Name         = reader.ReadPascalString();
                nNumChars         = reader.ReadUInt16();
            }
            else
            {
                ushort firstOffset = reader.ReadUInt16();
                offsets.Add(firstOffset);
                nNumChars = firstOffset / 2;
            }

            for (int charNum = offsets.Count; charNum < nNumChars; charNum++)
            {
                if (wideOffsets)
                {
                    offsets.Add(reader.ReadUInt32());
                }
                else
                {
                    offsets.Add((uint)reader.ReadUInt16());
                }
            }

            foreach (uint offset in offsets)
            {
                Record      recordX = new Record(reader, this.Owner);
                Shape.Shape shape   = new Endogine.Serialization.Flash.Shape.Shape();
                shape.Init(recordX);
            }

            if (this.Tag == Flash.Tags.DefineFont2)
            {
                ArrayList codeTable = new ArrayList();
                for (int charNum = 0; charNum < nNumChars; charNum++)
                {
                    if (this.DoubleByte)
                    {
                        codeTable.Add(reader.ReadUInt16());
                    }
                    else
                    {
                        codeTable.Add((ushort)reader.ReadByte());
                    }
                }

                if (hasLayout)
                {
                    short     ascent       = reader.ReadInt16();
                    short     descent      = reader.ReadInt16();
                    short     leading      = reader.ReadInt16();
                    ArrayList advanceTable = new ArrayList();
                    for (int i = 0; i < nNumChars; i++)
                    {
                        advanceTable.Add(reader.ReadInt16());
                    }
                    ArrayList boundsTable = new ArrayList();
                    for (int i = 0; i < nNumChars; i++)
                    {
                        ERectangle rect = reader.ReadRect();
                        boundsTable.Add(rect);
                    }
                    ushort kerningCount = reader.ReadUInt16();
                    for (int i = 0; i < kerningCount; i++)
                    {
                        //Kerning record
                    }
                }
            }
        }
Esempio n. 24
0
        public static ArrayList ReadShapeCommands(BinaryFlashReader reader, ArrayList fillStyles, ArrayList lineStyles, bool useAlpha, bool extended, bool morph, bool hasX)
        {
            reader.JumpToNextByteStart();
            ArrayList commands = new ArrayList();

            Byte val         = reader.ReadByte();
            int  numFillBits = val >> 4;            //this.NumFillBits
            int  numLineBits = val & 15;            //this.NumLineBits

            while (true)
            {
                //Debugging
//				ArrayList types = new ArrayList();
//				foreach (ShapeCommand.Base cmd in commands)
//				{
//					string name = cmd.GetType().ToString();
//					types.Add(name.Remove(0,name.LastIndexOf(".")+1) + ":"+cmd.ToString());
//				}

                bool bIsEdge = reader.ReadBoolean();

                if (!bIsEdge)
                {
                    int nFlags = (int)reader.ReadBits(5);
                    if (nFlags == 0)
                    {
                        break;
                    }

                    bool bStateNewStyles  = (nFlags & 16) > 0;
                    bool bStateLineStyle  = (nFlags & 8) > 0;
                    bool bStateFillStyle1 = (nFlags & 4) > 0;
                    bool bStateFillStyle0 = (nFlags & 2) > 0;
                    bool bStateMoveTo     = (nFlags & 1) > 0;

                    if (bStateMoveTo)
                    {
                        int    nMoveBits = (int)reader.ReadBits(5);
                        EPoint pntMove   = new EPoint(
                            (int)reader.ReadBits(nMoveBits, true),
                            (int)reader.ReadBits(nMoveBits, true));
                        commands.Add(new ShapeCommand.Move(pntMove));
                    }
                    if (bStateFillStyle0)
                    {
                        commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 0));
                    }
                    if (bStateFillStyle1)
                    {
                        commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 1));
                    }
                    if (bStateLineStyle)
                    {
                        commands.Add(new ShapeCommand.LineStyle((int)reader.ReadBits(numLineBits)));
                    }
                    if (bStateNewStyles)
                    {
                        fillStyles.AddRange(reader.ReadFillStyleArray(useAlpha, extended, morph));
                        lineStyles.AddRange(reader.ReadLineStyleArray(useAlpha, extended, morph, hasX));
                        numFillBits = (int)reader.ReadBits(4);
                        numLineBits = (int)reader.ReadBits(4);
                    }
                }
                else
                {
                    bool bIsStraight = reader.ReadBoolean();
                    if (bIsStraight)
                    {
                        int  nNumBits         = (int)reader.ReadBits(4) + 2;
                        bool bGeneralLineFlag = reader.ReadBoolean();
                        //0 = horizontal/vertical, 1 = general (ie both X and Y)
                        EPoint pntMove = new EPoint();
                        if (bGeneralLineFlag)
                        {
                            pntMove.X = (int)reader.ReadBits(nNumBits, true);
                            pntMove.Y = (int)reader.ReadBits(nNumBits, true);
                        }
                        else
                        {
                            //error in MMs documentation: either X or Y in here, not both!
                            bool bVertical = reader.ReadBoolean();
                            int  nVal      = (int)reader.ReadBits(nNumBits, true);
                            if (bVertical)
                            {
                                pntMove.Y = nVal;
                            }
                            else
                            {
                                pntMove.X = nVal;
                            }
                        }
                        commands.Add(new ShapeCommand.Line(pntMove));
                    }
                    else
                    {
                        //it's a curve
                        int    nNumBits = (int)reader.ReadBits(4) + 2;
                        long[] vals     = reader.ReadBitArray(4, nNumBits, true);
                        commands.Add(new ShapeCommand.Curve(new EPoint(vals[0], vals[1]), new EPoint(vals[2], vals[3])));
                    }
                }
            }
            return(commands);
        }
Esempio n. 25
0
 public static void ReadRecord(BinaryFlashReader reader, bool useAlpha, out Color color, out byte ratio)
 {
     ratio = reader.ReadByte();
     color = reader.ReadColor(useAlpha);
 }
Esempio n. 26
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            this.Id = reader.ReadUInt16();

            Bitmap bmp = null;

            byte[] alphaData = null;

            if (record.Tag == Flash.Tags.DefineBits)             //Jpeg with separate jpeg table
            {
                ushort start = reader.ReadUInt16();
                if (start != 0xd8ff)
                {
                    throw new Exception("JPEG start error");
                }


                MemoryStream stream = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(stream);
                writer.Write(this._jpegTables);
                writer.Write(reader.ReadBytes((int)record.TagLength));
                this._jpegTables = null;
                writer.Close();
                stream.Close();
                byte[] data = stream.ToArray();

                stream = new MemoryStream(data);
                bmp    = new Bitmap(stream);
                stream.Close();
            }
            else if (record.Tag == Flash.Tags.DefineBitsJPEG2)             //Jpeg with included jpeg table
            {
                byte[]       data   = reader.ReadBytes((int)record.TagLength);
                MemoryStream stream = new MemoryStream(data);
                bmp = new Bitmap(stream);
                stream.Close();
            }
            else if (record.Tag == Flash.Tags.DefineBitsJPEG3)             //Jpeg with alpha
            {
                uint         alphaDataOffset = reader.ReadUInt32();
                byte[]       data            = reader.ReadBytes((int)alphaDataOffset);
                MemoryStream stream          = new MemoryStream(data);
                bmp = new Bitmap(stream);
                stream.Close();
                byte[] alphaDataZCompressed = reader.ReadBytes((int)reader.BytesToEnd);
                //TODO: unpack zlib compressed data
            }
            else
            {
                //ZLib-compressed
                bool   UseAlpha = (record.Tag == Flash.Tags.DefineBitsLossless2?true:false);
                byte   format   = reader.ReadByte();
                ushort width    = reader.ReadUInt16();
                ushort height   = reader.ReadUInt16();
                int    stride   = ((width + 3) / 4) * 4;

                int  numPaletteEntries = 0;
                long size = 0;
                int  bpp  = 1;
                int  bytesPerPaletteEntry = 3;

                if (format == 3)
                {
                    numPaletteEntries = reader.ReadByte();
                    if (UseAlpha)
                    {
                        bytesPerPaletteEntry = 4;
                    }
                    size = stride * height + bytesPerPaletteEntry * numPaletteEntries;
                }
                else
                {
                    if (format == 4)
                    {
                        bpp = 2;
                    }
                    else if (format == 5)
                    {
                        bpp = 3;
                    }
                    size = bpp * width * height;
                }

                size += 248 + 1024;             //Don't know why...

                byte[] compressed   = reader.ReadBytes((int)reader.BytesToEnd);
                byte[] decompressed = null;                 //zlib.decompress(compressed);

                if (format == 3)
                {
                    Color[] palette = new Color[numPaletteEntries];
                    for (int i = 0; i < numPaletteEntries; i++)
                    {
                        Color clr = Color.White;
                        int   ptr = i * bytesPerPaletteEntry;
                        if (bytesPerPaletteEntry == 3)
                        {
                            clr = Color.FromArgb(decompressed[ptr], decompressed[ptr + 1], decompressed[ptr + 2]);
                        }
                        else
                        {
                            clr = Color.FromArgb(decompressed[ptr], decompressed[ptr + 1], decompressed[ptr + 2], decompressed[ptr + 3]);
                        }
                        palette[i] = clr;
                    }
                    int pixelPtr = numPaletteEntries * bytesPerPaletteEntry;
                    bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    //TODO:
                }
                else
                {
                    //TODO:
                }
            }

            if (bmp != null)
            {
                if (alphaData != null)
                {
                    //TODO: write to bmp's alpha channel
                }
                MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp);
                mb.Name = "Flash_" + this.Id.ToString();
            }

            this.InitDone();
        }