Example #1
0
void Wakeup::sendColor(uint8 r, uint8 g, uint8 b) {
    uint32 dx = 0;
 
    dx |= (uint32)0x03 << 30;             // highest two bits 1,flag bits
    dx |= (uint32)anti(b) << 28;
    dx |= (uint32)anti(g) << 26;	
    dx |= (uint32)anti(r) << 24;
 
    dx |= (uint32)b << 16;
    dx |= (uint32)g << 8;
    dx |= r;
 
    sendPacket(dx);
}
Example #2
0
 int totalNQueens(int n) {
     vector<bool> col(n, true);
     vector<bool> anti(2*n-1, true);
     vector<bool> main(2*n-1, true);
     vector<int> row(n, 0);
     int count = 0;
     dfs(0, row, col, main, anti, count);
     return count;
 }
Example #3
0
static uint64_t bishop_attacks(unsigned sq, uint64_t occ)
{
    occ &= ~board(sq);
    unsigned d = diag(sq), a = anti(sq);
    uint64_t d_occ = occ & (diag2board(d) & ~BOARD_EDGE);
    uint64_t a_occ = occ & (anti2board(a) & ~BOARD_EDGE);
    size_t d_idx = diag2index(d_occ);
    size_t a_idx = anti2index(a_occ);
    uint64_t d_attacks = diag_attacks_table[sq][d_idx];
    uint64_t a_attacks = anti_attacks_table[sq][a_idx];
    return d_attacks | a_attacks;
}
// Suggestion by Carlos Moreno
wxImage wxAntiAlias2(const wxImage& image)
{
    wxImage anti(image.GetWidth(), image.GetHeight());

  /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */

  for (int y = 1; y < image.GetHeight() - 1; y++)
    for (int x = 1; x < image.GetWidth() - 1; x++)
    {
       long red =
            ((int) image.GetRed( x-1, y-1 )) * 1 +
            ((int) image.GetRed( x, y-1 )) * 4 +
            ((int) image.GetRed( x+1, y-1 )) * 1 +
            ((int) image.GetRed( x+1, y )) * 4 +
            ((int) image.GetRed( x+1, y+1 )) * 1 +
            ((int) image.GetRed( x, y+1 )) * 4 +
            ((int) image.GetRed( x-1, y+1 )) * 1 +
            ((int) image.GetRed( x-1, y )) * 4 +
            ((int) image.GetRed( x, y )) * 20 ;

       red = red/40;

       long green =
            ((int) image.GetGreen( x-1, y-1 )) * 1 +
            ((int) image.GetGreen( x, y-1 )) * 4 +
            ((int) image.GetGreen( x+1, y-1 )) * 1 +
            ((int) image.GetGreen( x+1, y )) * 4 +
            ((int) image.GetGreen( x+1, y+1 )) * 1 +
            ((int) image.GetGreen( x, y+1 )) * 4 +
            ((int) image.GetGreen( x-1, y+1 )) * 1 +
            ((int) image.GetGreen( x-1, y )) * 4 +
            ((int) image.GetGreen( x, y )) * 20 ;

       green = green/40;

       long blue =
            ((int) image.GetBlue( x-1, y-1 )) * 1 +
            ((int) image.GetBlue( x, y-1 )) * 4 +
            ((int) image.GetBlue( x+1, y-1 )) * 1 +
            ((int) image.GetBlue( x+1, y )) * 4 +
            ((int) image.GetBlue( x+1, y+1 )) * 1 +
            ((int) image.GetBlue( x, y+1 )) * 4 +
            ((int) image.GetBlue( x-1, y+1 )) * 1 +
            ((int) image.GetBlue( x-1, y )) * 4 +
            ((int) image.GetBlue( x, y )) * 20 ;

       blue = blue/40;

       anti.SetRGB( x, y, (wxChar) red, (wxChar) green, (wxChar) blue );
    }
    return anti;
}
Example #5
0
void MyCanvas::CreateAntiAliasedBitmap()
{
    wxBitmap bitmap( 300, 300 );

    wxMemoryDC dc;

    dc.SelectObject( bitmap );

    dc.Clear();

    dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
    dc.SetTextForeground( wxT("RED") );
    dc.DrawText( wxT("This is anti-aliased Text."), 20, 5 );
    dc.DrawText( wxT("And a Rectangle."), 20, 45 );

    dc.SetBrush( *wxRED_BRUSH );
    dc.SetPen( *wxTRANSPARENT_PEN );
    dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );

    wxImage original= bitmap.ConvertToImage();
    wxImage anti( 150, 150 );

    /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */

    for (int y = 1; y < 149; y++)
        for (int x = 1; x < 149; x++)
        {
            int red = original.GetRed( x*2, y*2 ) +
                        original.GetRed( x*2-1, y*2 ) +
                        original.GetRed( x*2, y*2+1 ) +
                        original.GetRed( x*2+1, y*2+1 );
            red = red/4;

            int green = original.GetGreen( x*2, y*2 ) +
                        original.GetGreen( x*2-1, y*2 ) +
                        original.GetGreen( x*2, y*2+1 ) +
                        original.GetGreen( x*2+1, y*2+1 );
            green = green/4;

            int blue = original.GetBlue( x*2, y*2 ) +
                        original.GetBlue( x*2-1, y*2 ) +
                        original.GetBlue( x*2, y*2+1 ) +
                        original.GetBlue( x*2+1, y*2+1 );
            blue = blue/4;
            anti.SetRGB( x, y, (unsigned char)red, (unsigned char)green, (unsigned char)blue );
        }

    my_anti = wxBitmap(anti);
}
wxImage wxAntiAlias(const wxImage& image)
{
    wxImage anti(image.GetWidth(), image.GetHeight());
	
	/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
	
	for (int y = 0; y < image.GetHeight(); y++)
	{
		for (int x = 0; x < image.GetWidth(); x++)
		{
			if (y == 0 || x == 0 ||
				x == (image.GetWidth() - 1) ||
				y == (image.GetHeight() - 1))
			{
				anti.SetRGB(x, y, image.GetRed(x, y), image.GetGreen(x, y), image.GetBlue(x, y));
			}
			else
			{
				int red = (int) image.GetRed( x, y ) +
					(int) image.GetRed( x-1, y ) +
					(int) image.GetRed( x, y+1 ) +
					(int) image.GetRed( x+1, y+1 );
				red = red/4;
				
				int green = (int) image.GetGreen( x, y ) +
					(int) image.GetGreen( x-1, y ) +
					(int) image.GetGreen( x, y+1 ) +
					(int) image.GetGreen( x+1, y+1 );
				green = green/4;
				
				int blue = (int) image.GetBlue( x, y ) +
					(int) image.GetBlue( x-1, y ) +
					(int) image.GetBlue( x, y+1 ) +
					(int) image.GetBlue( x+1, y+1 );
				blue = blue/4;
				anti.SetRGB( x, y, red, green, blue );
			}
		}
	}
	return anti;
}