adding PICT conversion for IconRef

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32183 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2005-02-19 15:24:13 +00:00
parent fb3aacd727
commit 431c82e03e

View File

@@ -64,8 +64,8 @@ IconFamilyHandle wxMacCreateIconFamily(const wxBitmap& bitmap)
int h = bmp.GetHeight() ; int h = bmp.GetHeight() ;
int sz = wxMax( w , h ) ; int sz = wxMax( w , h ) ;
OSType dataType ; OSType dataType = 0 ;
OSType maskType ; OSType maskType = 0 ;
if ( sz == 64 ) if ( sz == 64 )
{ {
@@ -100,11 +100,9 @@ IconFamilyHandle wxMacCreateIconFamily(const wxBitmap& bitmap)
dataType = kSmall32BitData ; dataType = kSmall32BitData ;
maskType = kSmall8BitMask ; maskType = kSmall8BitMask ;
} }
else
{
return NULL ;
}
if ( dataType != 0 )
{
Handle data = NULL ; Handle data = NULL ;
Handle maskdata = NULL ; Handle maskdata = NULL ;
unsigned char * maskptr = NULL ; unsigned char * maskptr = NULL ;
@@ -162,6 +160,13 @@ IconFamilyHandle wxMacCreateIconFamily(const wxBitmap& bitmap)
HUnlock( maskdata ) ; HUnlock( maskdata ) ;
DisposeHandle( data ) ; DisposeHandle( data ) ;
DisposeHandle( maskdata ) ; DisposeHandle( maskdata ) ;
}
else
{
PicHandle pic = wxMacCreatePicHandle( bitmap ) ;
SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ;
KillPicture( pic ) ;
}
return iconFamily ; return iconFamily ;
} }
@@ -195,11 +200,40 @@ PicHandle wxMacCreatePicHandle( const wxBitmap &bmp )
PicHandle pict = NULL ; PicHandle pict = NULL ;
GWorldPtr wp = NULL ; GWorldPtr wp = NULL ;
GWorldPtr mask = NULL ; GWorldPtr mask = NULL ;
int height = bmp.GetHeight() ;
int width = bmp.GetWidth() ;
Rect rect = { 0 , 0 , height , width } ;
GetGWorld( &origPort , &origDev ) ; GetGWorld( &origPort , &origDev ) ;
wp = (GWorldPtr) bmp.GetHBITMAP( (WXHBITMAP*) &mask ) ; wp = (GWorldPtr) bmp.GetHBITMAP( (WXHBITMAP*) &mask ) ;
RgnHandle clipRgn = NULL ;
if ( mask )
{
GWorldPtr monoworld ;
clipRgn = NewRgn() ;
OSStatus err = NewGWorld( &monoworld , 1 , &rect , NULL , NULL , 0 ) ;
LockPixels( GetGWorldPixMap( monoworld ) ) ;
LockPixels( GetGWorldPixMap( mask ) ) ;
SetGWorld( monoworld , NULL ) ;
RGBColor white = { 0xffff ,0xffff , 0xffff } ;
RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
RGBForeColor( &black ) ;
RGBBackColor( &white ) ;
CopyBits(GetPortBitMapForCopyBits(mask),
GetPortBitMapForCopyBits(monoworld),
&rect,
&rect,
srcCopy,NULL);
BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( monoworld ) ) ;
UnlockPixels( GetGWorldPixMap( monoworld ) ) ;
UnlockPixels( GetGWorldPixMap( mask ) ) ;
DisposeGWorld( monoworld ) ;
}
SetGWorld( wp , NULL ) ; SetGWorld( wp , NULL ) ;
Rect portRect ; Rect portRect ;
GetPortBounds( wp , &portRect ) ; GetPortBounds( wp , &portRect ) ;
@@ -212,16 +246,21 @@ PicHandle wxMacCreatePicHandle( const wxBitmap &bmp )
RGBForeColor( &black ) ; RGBForeColor( &black ) ;
RGBBackColor( &white ) ; RGBBackColor( &white ) ;
if ( clipRgn )
SetClip( clipRgn ) ;
LockPixels( GetGWorldPixMap( wp ) ) ; LockPixels( GetGWorldPixMap( wp ) ) ;
CopyBits(GetPortBitMapForCopyBits(wp), CopyBits(GetPortBitMapForCopyBits(wp),
GetPortBitMapForCopyBits(wp), GetPortBitMapForCopyBits(wp),
&portRect, &portRect,
&portRect, &portRect,
srcCopy,NULL); srcCopy,clipRgn);
UnlockPixels( GetGWorldPixMap( wp ) ) ; UnlockPixels( GetGWorldPixMap( wp ) ) ;
ClosePicture(); ClosePicture();
} }
SetGWorld( origPort , origDev ) ; SetGWorld( origPort , origDev ) ;
if ( clipRgn )
DisposeRgn( clipRgn ) ;
return pict; return pict;
} }
@@ -329,13 +368,13 @@ void wxBitmapRefData::UseAlpha( bool use )
{ {
int width = GetWidth() ; int width = GetWidth() ;
int height = GetHeight() ; int height = GetHeight() ;
m_maskBytesPerRow = ( width + 3 ) & 0xFFFFFFC ; m_maskBytesPerRow = ( width * 4 + 3 ) & 0xFFFFFFC ;
size_t size = height * m_maskBytesPerRow ; size_t size = height * m_maskBytesPerRow ;
unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ; unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ;
memset( data , 0 , size ) ; memset( data , 0 , size ) ;
wxASSERT( m_hMaskBitmap == NULL ) ; wxASSERT( m_hMaskBitmap == NULL ) ;
Rect rect = { 0 , 0 , height , width } ; Rect rect = { 0 , 0 , height , width } ;
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 , verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
(char*) data , m_maskBytesPerRow ) ) ; (char*) data , m_maskBytesPerRow ) ) ;
wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ; wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
m_maskMemBuf.UngetWriteBuf(size) ; m_maskMemBuf.UngetWriteBuf(size) ;
@@ -498,9 +537,13 @@ void wxBitmapRefData::UpdateAlphaMask() const
for ( int y = 0 ; y < h ; ++y , destalphabase += m_maskBytesPerRow ) for ( int y = 0 ; y < h ; ++y , destalphabase += m_maskBytesPerRow )
{ {
unsigned char* destalpha = destalphabase ; unsigned char* destalpha = destalphabase ;
for( int x = 0 ; x < w ; ++x , sourcemask += 4, ++destalpha ) for( int x = 0 ; x < w ; ++x , sourcemask += 4 )
{ {
*destalpha = *sourcemask ; // we must have 24 bit depth for non quartz smooth alpha
*destalpha++ = 255 ;
*destalpha++ = 255 - *sourcemask ;
*destalpha++ = 255 - *sourcemask ;
*destalpha++ = 255 - *sourcemask ;
} }
} }
} }
@@ -1184,6 +1227,9 @@ void *wxMask::GetRawAccess() const
return m_memBuf.GetData() ; return m_memBuf.GetData() ;
} }
// this can be a k8IndexedGrayPixelFormat GWorld, because it never stores other values than black or white
// so no rainbox colors will be created by QD when blitting
void wxMask::RealizeNative() void wxMask::RealizeNative()
{ {
if ( m_maskBitmap ) if ( m_maskBitmap )