Esempio n. 1
0
 static void CheckShadowTexture( IGraphicsApi graphics )
 {
     if( shadowTex != -1 ) return;
     const int size = 128, half = size / 2;
     using( Bitmap bmp = new Bitmap( size, size ) )
         using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
     {
         int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
         int outPix = new FastColour( 0, 0, 0, 0 ).ToArgb();
         for( int y = 0; y < fastBmp.Height; y++ ) {
             int* row = fastBmp.GetRowPtr( y );
             for( int x = 0; x < fastBmp.Width; x++ ) {
                 double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
                     (half - (y + 0.5)) * (half - (y + 0.5));
                 row[x] = dist < half * half ? inPix : outPix;
             }
         }
         shadowTex = graphics.CreateTexture( fastBmp );
     }
 }
Esempio n. 2
0
        static unsafe void ClearHat( Bitmap bmp, SkinType skinType )
        {
            using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) ) {
                int sizeX = (bmp.Width / 64) * 32;
                int yScale = skinType == SkinType.Type64x32 ? 32 : 64;
                int sizeY = (bmp.Height / yScale) * 16;

                // determine if we actually need filtering
                for( int y = 0; y < sizeY; y++ ) {
                    int* row = fastBmp.GetRowPtr( y );
                    row += sizeX;
                    for( int x = 0; x < sizeX; x++ ) {
                        byte alpha = (byte)(row[x] >> 24);
                        if( alpha != 255 ) return;
                    }
                }

                // only perform filtering when the entire hat is opaque
                int fullWhite = FastColour.White.ToArgb();
                int fullBlack = FastColour.Black.ToArgb();
                for( int y = 0; y < sizeY; y++ ) {
                    int* row = fastBmp.GetRowPtr( y );
                    row += sizeX;
                    for( int x = 0; x < sizeX; x++ ) {
                        int pixel = row[x];
                        if( pixel == fullWhite || pixel == fullBlack ) row[x] = 0;
                    }
                }
            }
        }