예제 #1
0
        public void Read( Stream ins, String PackName )
        {
            if (ins.ReadByte() != (byte)'R' ) return;
            if (ins.ReadByte() != (byte)'B' ) return;
            if (ins.ReadByte() != (byte)'S' ) return;
            if (ins.ReadByte() != (byte)'P' ) return;

            int nSprites = ReadWord( ins );
            ReadDword( ins );
            ReadDword( ins );

            int firstSprite = Sprites.Count;

            //  read header
            for (int i = 0; i < nSprites; i++)
            {
                Sprite sp = new Sprite();
                sp.Width = ReadWord( ins );
                sp.Height = ReadWord( ins );
                sp.ClrFormat = (ColorFormat)ReadWord( ins );
                sp.Frame.x = ReadWord( ins );
                sp.Frame.y = ReadWord( ins );
                sp.Frame.w = ReadWord( ins );
                sp.Frame.h = ReadWord( ins );
                sp.Name    = PackName + i;
                int bFiltered = ReadWord( ins );
                if (bFiltered == 1) sp.Filtered = true; else sp.Filtered = false;
                int nRects = ReadWord( ins );
                sp.PivotX  = (short)ReadWord( ins );
                sp.PivotY  = (short)ReadWord( ins );
                sp.ShiftX  = (short)ReadWord( ins );
                sp.ShiftY  = (short)ReadWord( ins );

                for (int j = 0; j < nRects; j++)
                {
                    Frame rc = new Frame();
                    rc.x = ReadWord( ins );
                    rc.y = ReadWord( ins );
                    rc.w = ReadWord( ins );
                    rc.h = rc.w;
                    ReadWord( ins );
                    sp.Partition.Rects.Add( rc );
                }
                Sprites.Add( sp );
            }

            //  read pixels
            for (int i = firstSprite; i < Sprites.Count; i++)
            {
                Sprite sprite = (Sprite)Sprites[i];
                int nBytes = sprite.GetNumBytes();
                sprite.Bytes = new byte[nBytes];
                ins.Read( sprite.Bytes, 0, nBytes );
            }
        }
예제 #2
0
        public void Subtract( ref Sprite sp )
        {
            if (sp.Width  != Width ||
                sp.Height != Height)
            {
                return;
            }

            Bitmap sbmp = sp.GetBitmap( false );
            Bitmap dbmp = GetBitmap( false );

            int nPixels     = Width*Height;
            int nSame       = 0;
            int nNonTransp  = 0;
            unchecked
            {
                for (int i = 0; i < nPixels; i++)
                {
                    int x = i%Width;
                    int y = i/Width;
                    Color dclr = dbmp.GetPixel( x, y );
                    Color sclr = sbmp.GetPixel( x, y );
                    if (sclr.A != 0)
                    {
                        nNonTransp++;
                    }
                    Color clr = dclr;
                    if (sclr == dclr)
                    {
                        clr = Color.FromArgb( 0, 0, 0, 0 );
                        nSame++;
                    }
                    sbmp.SetPixel( x, y, clr );
                }
            }

            const int c_SubtractBias = 30;
            if (nSame > nNonTransp*c_SubtractBias/100)
            {
                Difference = true;
                CreatePartition( sbmp );
            }
        }