| 290 | } |
| 291 | |
| 292 | wxImage ThemeBase::MaskedImage( char const ** pXpm, char const ** pMask ) |
| 293 | { |
| 294 | wxBitmap Bmp1( pXpm ); |
| 295 | wxBitmap Bmp2( pMask ); |
| 296 | |
| 297 | // wxLogDebug( wxT("Image 1: %i Image 2: %i"), |
| 298 | // Bmp1.GetDepth(), Bmp2.GetDepth() ); |
| 299 | |
| 300 | // We want a 24-bit-depth bitmap if all is working, but on some |
| 301 | // platforms it might just return -1 (which means best available |
| 302 | // or not relevant). |
| 303 | // JKC: \todo check that we're not relying on 24 bit elsewhere. |
| 304 | wxASSERT( Bmp1.GetDepth()==-1 || Bmp1.GetDepth()==24); |
| 305 | wxASSERT( Bmp1.GetDepth()==-1 || Bmp2.GetDepth()==24); |
| 306 | |
| 307 | int i,nBytes; |
| 308 | nBytes = Bmp1.GetWidth() * Bmp1.GetHeight(); |
| 309 | wxImage Img1( Bmp1.ConvertToImage()); |
| 310 | wxImage Img2( Bmp2.ConvertToImage()); |
| 311 | |
| 312 | // unsigned char *src = Img1.GetData(); |
| 313 | unsigned char *mk = Img2.GetData(); |
| 314 | //wxImage::setAlpha requires memory allocated with malloc, not NEW |
| 315 | MallocString<unsigned char> alpha{ |
| 316 | static_cast<unsigned char*>(malloc( nBytes )) }; |
| 317 | |
| 318 | // Extract alpha channel from second XPM. |
| 319 | for(i=0;i<nBytes;i++) |
| 320 | { |
| 321 | alpha[i] = mk[0]; |
| 322 | mk+=3; |
| 323 | } |
| 324 | |
| 325 | Img1.SetAlpha( alpha.release() ); |
| 326 | |
| 327 | //dmazzoni: the top line does not work on wxGTK |
| 328 | //wxBitmap Result( Img1, 32 ); |
| 329 | //wxBitmap Result( Img1 ); |
| 330 | |
| 331 | return Img1; |
| 332 | } |
| 333 | |
| 334 | // Legacy function to allow use of an XPM where no theme image was defined. |
| 335 | // Bit depth and mask needs review. |