Beispiel #1
0
wxImage ThemeBase::MaskedImage( char const ** pXpm, char const ** pMask )
{
   wxBitmap Bmp1( pXpm );
   wxBitmap Bmp2( pMask );

//   wxLogDebug( wxT("Image 1: %i Image 2: %i"), 
//      Bmp1.GetDepth(), Bmp2.GetDepth() );

   // We want a 24-bit-depth bitmap if all is working, but on some
   // platforms it might just return -1 (which means best available
   // or not relevant).
   // JKC: \todo check that we're not relying on 24 bit elsewhere.
   wxASSERT( Bmp1.GetDepth()==-1 || Bmp1.GetDepth()==24);
   wxASSERT( Bmp1.GetDepth()==-1 || Bmp2.GetDepth()==24);

   int i,nBytes;
   nBytes = Bmp1.GetWidth() * Bmp1.GetHeight();
   wxImage Img1( Bmp1.ConvertToImage());
   wxImage Img2( Bmp2.ConvertToImage());

//   unsigned char *src = Img1.GetData();
   unsigned char *mk = Img2.GetData();
   unsigned char *alpha = (unsigned char*)malloc( nBytes );

   // Extract alpha channel from second XPM.
   for(i=0;i<nBytes;i++)
   {
      alpha[i] = mk[0];
      mk+=3;
   }

   Img1.SetAlpha( alpha);

   //dmazzoni: the top line does not work on wxGTK
   //wxBitmap Result( Img1, 32 );
   //wxBitmap Result( Img1 );

   return Img1;
}
Beispiel #2
0
void Test3::rgbimage( const char* Directory)
{
    printf( "Start RGBImage Test\n");
    // create 3 images
    RGBImage Img1( 800, 600);
    RGBImage Img2( 800, 600);
    RGBImage Img3( 800, 600);
    
    
    TEST( "Invalid Image Width\n", Img1.width()==800);
    TEST( "Invalid Image Height\n", Img1.height()==600);
    /*
    Img1.setPixelColor( 800, 100, Color());
    Color c = Img1.getPixelColor(800, 100);
    Img2.setPixelColor( 100, 600, Color());
    c = Img1.getPixelColor(100, 600);
    */
    Color c0(0,0,0);
    Color c1(1,0,0);
    Color c2(0,1,0);
    Color c3(0,0,1);

    for( unsigned int i=0; i<Img1.height(); i++ )
    {
        for( unsigned int j=0; j<Img1.width(); j++ )
        {
            float u = (float)j/(float)Img1.width();
            float v = (float)i/(float)Img1.height();
			Color cu0 = c0 *(1.0f-u) + c1*u;
            Color cu1 = c2 *(1.0f-u) + c3*u;
            Color co = cu0 *(1.0f-v) + cu1*v;

			if ((j == 0 || j==400) && i%50 == 0) {
				std::cout << " : i =" << i*j << "\n" << "Floats RGB:( " << co.R << " | " << co.G << " | " << co.B << " )" << std::endl;
			}

            Img1.setPixelColor(j, i, co);
            TEST( "Different colors for identical get/setPixelColor calls\n", equals(co, Img1.getPixelColor(j,i)));
        }
    }

    
    char Path[512];
    char CompletePath[512];
    size_t len = strlen( Directory );
    assert(len<=256);
    strcpy(Path, Directory);
    
    if(len>0 && Path[len-1] != '/' && Path[len-1] != '\\')
        strcat( Path, "/");
    
    strcpy( CompletePath, Path);
    strcat( CompletePath, "rgbtestimage1.bmp");
    TEST( "Unable to save Image!\n", Img1.saveToDisk(CompletePath));
    
    for( unsigned int i=0; i<Img1.height(); i++ )
    {
        for( unsigned int j=0; j<Img1.width(); j++ )
        {
            float cx = ((float)j-400.0f);
            float cy = ((float)i-300.0f);
            float r = sqrt(cx*cx + cy*cy);
            if(r<300)
            {
                r = 300-r;
                float rcx = cx * cos( r * 0.015f) - cy * sin(r* 0.015f);
                float rcy = cx * sin( r * 0.015f) + cy * cos(r* 0.015f);
                Color co = Img1.getPixelColor(400 + (int)rcx, 300 + (int)rcy);
                Img2.setPixelColor(j,i, co);
            }
            else
            {
                Color co = Img1.getPixelColor(j, i );
                Img2.setPixelColor(j,i, co);
            }
        }
    }
    
    strcpy( CompletePath, Path);
    strcat( CompletePath, "rgbtestimage2.bmp");
    TEST( "Unable to save Image!\n", Img2.saveToDisk(CompletePath));

    
    for( unsigned int i=0; i<Img2.height(); i++ )
    {
        for( unsigned int j=0; j<Img2.width(); j++ )
        {
            if( ((j/40)%2)==(i/40)%2 )
            {
                Color c = Color(1,1,1);
                c.R = c.R - Img2.getPixelColor(j,i).R;
                c.G = c.G - Img2.getPixelColor(j,i).G;
                c.B = c.B - Img2.getPixelColor(j,i).B;
                
                Img3.setPixelColor(j,i, c);
            }
            else
            {
                Img3.setPixelColor(j,i, Img2.getPixelColor(j,i));
            }

        }
    }
    
    strcpy( CompletePath, Path);
    strcat( CompletePath, "rgbtestimage3.bmp");
    TEST( "Unable to save Image!\n", Img3.saveToDisk(CompletePath));
    printf( "RGBImage Test succeeded if the saved bmp-images are equal to the reference images!\n");
}