I just wrote my own, if anyone knows how to have qt do this internally or a better way to do this let me know, here's the code in case anyone else is having the same problem:
QImage CreateAlphaMask
( const QImage
& srcImage
) {
// QImage one only creates alpha mask for alpha values greater than 128... need it to be all alpha greater than 0
int nWidth = m_PatchSetImage.width();
int nHeight = m_PatchSetImage.height();
int nDepth = m_PatchSetImage.depth();
QImage alphaMask
( nWidth, nHeight,
QImage::Format_MonoLSB );
alphaMask.setColor( 0, 0xffffffff );
alphaMask.setColor( 1, 0xff000000 );
// initialize everything to 0 first
memset( alphaMask.bits(), 0, alphaMask.numBytes() );
switch ( nDepth )
{
case 32:
for ( int y = 0; y < nHeight; ++y )
{
unsigned char* pMaskData = alphaMask.scanLine( y );
unsigned int* pSrcData = (unsigned int*)srcImage.scanLine( y );
for ( int x = 0; x < nWidth; ++x )
{
if ( *pSrcData++ >> 24 )
{
pMaskData[x/8] |= 1 << (x % 8);
}
}
}
break;
default:
// Set mask to all 1's if not 32 bit depth
memset( alphaMask.bits(), 0xFF, alphaMask.numBytes() );
break;
}
return alphaMask;
}
QImage CreateAlphaMask( const QImage& srcImage )
{
// QImage one only creates alpha mask for alpha values greater than 128... need it to be all alpha greater than 0
int nWidth = m_PatchSetImage.width();
int nHeight = m_PatchSetImage.height();
int nDepth = m_PatchSetImage.depth();
QImage alphaMask( nWidth, nHeight, QImage::Format_MonoLSB );
alphaMask.setColor( 0, 0xffffffff );
alphaMask.setColor( 1, 0xff000000 );
// initialize everything to 0 first
memset( alphaMask.bits(), 0, alphaMask.numBytes() );
switch ( nDepth )
{
case 32:
for ( int y = 0; y < nHeight; ++y )
{
unsigned char* pMaskData = alphaMask.scanLine( y );
unsigned int* pSrcData = (unsigned int*)srcImage.scanLine( y );
for ( int x = 0; x < nWidth; ++x )
{
if ( *pSrcData++ >> 24 )
{
pMaskData[x/8] |= 1 << (x % 8);
}
}
}
break;
default:
// Set mask to all 1's if not 32 bit depth
memset( alphaMask.bits(), 0xFF, alphaMask.numBytes() );
break;
}
return alphaMask;
}
To copy to clipboard, switch view to plain text mode
Bookmarks