X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/93a2b888fcbc81aa1c97df976ff0b151b2233abd..55f5548f782e57d1067cf0ab10c51d7ec5af61ac:/src/mac/carbon/bitmap.cpp diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 5d6d012951..89f0d0e127 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -367,6 +367,7 @@ IconRef wxBitmapRefData::GetIconRef() *maskdest++ = 0xFF - *masksource++ ; masksource++ ; masksource++ ; + masksource++ ; } else if ( hasAlpha ) *maskdest++ = a ; @@ -522,7 +523,7 @@ CGImageRef wxBitmapRefData::CGImageCreate() const for ( int y = 0 ; y < h ; ++y , sourcemaskstart += maskrowbytes) { unsigned char *sourcemask = sourcemaskstart ; - for ( int x = 0 ; x < w ; ++x , sourcemask+=3 , destalpha += 4 ) + for ( int x = 0 ; x < w ; ++x , sourcemask += 4 , destalpha += 4 ) { *destalpha = 0xFF - *sourcemask ; } @@ -801,7 +802,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits bit = x % 8 ; mask = 1 << bit ; - if ( linestart[index] & mask ) + if ( !(linestart[index] & mask ) ) { *destination++ = 0xFF ; *destination++ = 0 ; @@ -875,11 +876,11 @@ void wxBitmap::EndRawAccess() bool wxBitmap::CreateFromXpm(const char **bits) { #if wxUSE_IMAGE - wxCHECK_MSG( bits != NULL, false, wxT("invalid bitmap data") ) + wxCHECK_MSG( bits != NULL, false, wxT("invalid bitmap data") ); wxXPMDecoder decoder; wxImage img = decoder.ReadData(bits); - wxCHECK_MSG( img.Ok(), false, wxT("invalid bitmap data") ) + wxCHECK_MSG( img.Ok(), false, wxT("invalid bitmap data") ); *this = wxBitmap(img); @@ -935,23 +936,22 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const if ( M_BITMAPDATA->m_bitmapMask ) { wxMemoryBuffer maskbuf ; - int rowBytes = ( destwidth + 3 ) & 0xFFFFFFC ; + int rowBytes = ( destwidth * 4 + 3 ) & 0xFFFFFFC ; size_t maskbufsize = rowBytes * destheight ; - int sourcelinesize = M_BITMAPDATA->m_bitmapMask->GetBytesPerRow() ; + int sourcelinesize = M_BITMAPDATA->m_bitmapMask->GetBytesPerRow() ; int destlinesize = rowBytes ; unsigned char *source = (unsigned char *) M_BITMAPDATA->m_bitmapMask->GetRawAccess() ; unsigned char *destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ; wxASSERT( (source != NULL) && (destdata != NULL) ) ; - source += rect.x + rect.y * sourcelinesize ; + source += rect.x * 4 + rect.y * sourcelinesize ; unsigned char *dest = destdata ; for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize) { - for (int xx = 0; xx < destlinesize; xx++ ) - *(dest+xx) = 0xFF - *(source+xx*3) ; + memcpy( dest , source , destlinesize ) ; } maskbuf.UngetWriteBuf( maskbufsize ) ; @@ -1027,7 +1027,7 @@ bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int wxBitmap::wxBitmap(const wxImage& image, int depth) { - wxCHECK_RET( image.Ok(), wxT("invalid image") ) + wxCHECK_RET( image.Ok(), wxT("invalid image") ); // width and height of the device-dependent bitmap int width = image.GetWidth(); @@ -1131,7 +1131,7 @@ wxImage wxBitmap::ConvertToImage() const // The following masking algorithm is the same as well in msw/gtk: // the colour used as transparent one in wxImage and the one it is - // replaced with when it really occurs in the bitmap + // replaced with when it actually occurs in the bitmap static const int MASK_RED = 1; static const int MASK_GREEN = 2; static const int MASK_BLUE = 3; @@ -1146,11 +1146,17 @@ wxImage wxBitmap::ConvertToImage() const for (int xx = 0; xx < width; xx++) { color = *((long*) source) ; +#ifdef WORDS_BIGENDIAN a = ((color&0xFF000000) >> 24) ; r = ((color&0x00FF0000) >> 16) ; g = ((color&0x0000FF00) >> 8) ; b = (color&0x000000FF); - +#else + b = ((color&0xFF000000) >> 24) ; + g = ((color&0x00FF0000) >> 16) ; + r = ((color&0x0000FF00) >> 8) ; + a = (color&0x000000FF); +#endif if ( hasMask ) { if ( *maskp++ == 0xFF ) @@ -1161,6 +1167,8 @@ wxImage wxBitmap::ConvertToImage() const } else if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE ) b = MASK_BLUE_REPLACEMENT ; + + maskp++ ; maskp++ ; maskp++ ; } @@ -1184,8 +1192,8 @@ wxImage wxBitmap::ConvertToImage() const #endif //wxUSE_IMAGE -bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, - const wxPalette *palette) const +bool wxBitmap::SaveFile( const wxString& filename, + wxBitmapType type, const wxPalette *palette ) const { bool success = false; wxBitmapHandler *handler = FindHandler(type); @@ -1334,31 +1342,32 @@ wxMask::wxMask() // Construct a mask from a bitmap and a colour indicating // the transparent area -wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) +wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour ) { Init() ; - Create(bitmap, colour); + Create( bitmap, colour ); } // Construct a mask from a mono bitmap (copies the bitmap). -wxMask::wxMask(const wxBitmap& bitmap) +wxMask::wxMask( const wxBitmap& bitmap ) { Init() ; - Create(bitmap); + Create( bitmap ); } // Construct a mask from a mono bitmap (copies the bitmap). + wxMask::wxMask( const wxMemoryBuffer& data, int width , int height , int bytesPerRow ) { Init() ; - Create(data, width , height , bytesPerRow ); + Create( data, width , height , bytesPerRow ); } wxMask::~wxMask() { if ( m_maskBitmap ) { - DisposeGWorld( (GWorldPtr) m_maskBitmap ) ; + DisposeGWorld( (GWorldPtr)m_maskBitmap ) ; m_maskBitmap = NULL ; } } @@ -1374,24 +1383,27 @@ void *wxMask::GetRawAccess() const return m_memBuf.GetData() ; } -// The default ColorTable for k8IndexedGrayPixelFormat in Intel seems to be broken, so we'll use an non-indexed -// bitmap mask instead, in order to keep the code simple, the change is done for ppc implementations as well +// The default ColorTable for k8IndexedGrayPixelFormat in Intel appears to be broken, so we'll use an non-indexed +// bitmap mask instead; in order to keep the code simple, the change applies to PowerPC implementations as well void wxMask::RealizeNative() { if ( m_maskBitmap ) { - DisposeGWorld( (GWorldPtr) m_maskBitmap ) ; + DisposeGWorld( (GWorldPtr)m_maskBitmap ) ; m_maskBitmap = NULL ; } Rect rect = { 0 , 0 , m_height , m_width } ; - verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_maskBitmap , k24RGBPixelFormat , &rect , NULL , NULL , 0 , - (char*) m_memBuf.GetData() , m_bytesPerRow ) ) ; + OSStatus err = NewGWorldFromPtr( + (GWorldPtr*) &m_maskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 , + (char*) m_memBuf.GetData() , m_bytesPerRow ) ; + verify_noerr( err ) ; } // Create a mask from a mono bitmap (copies the bitmap). + bool wxMask::Create(const wxMemoryBuffer& data,int width , int height , int bytesPerRow) { m_memBuf = data ; @@ -1411,7 +1423,7 @@ bool wxMask::Create(const wxBitmap& bitmap) { m_width = bitmap.GetWidth() ; m_height = bitmap.GetHeight() ; - m_bytesPerRow = ( m_width * 3 + 3 ) & 0xFFFFFFC ; + m_bytesPerRow = ( m_width * 4 + 3 ) & 0xFFFFFFC ; size_t size = m_bytesPerRow * m_height ; unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ; @@ -1437,12 +1449,14 @@ bool wxMask::Create(const wxBitmap& bitmap) *destdata++ = 0xFF ; *destdata++ = 0xFF ; *destdata++ = 0xFF ; + *destdata++ = 0xFF ; } else { *destdata++ = 0x00 ; *destdata++ = 0x00 ; *destdata++ = 0x00 ; + *destdata++ = 0x00 ; } } } @@ -1459,7 +1473,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) { m_width = bitmap.GetWidth() ; m_height = bitmap.GetHeight() ; - m_bytesPerRow = ( m_width * 3 + 3 ) & 0xFFFFFFC ; + m_bytesPerRow = ( m_width * 4 + 3 ) & 0xFFFFFFC ; size_t size = m_bytesPerRow * m_height ; unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ; @@ -1480,17 +1494,19 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) g = *srcdata++ ; b = *srcdata++ ; - if ( colour == wxColour( r , g , b) ) + if ( colour == wxColour( r , g , b ) ) { *destdata++ = 0xFF ; *destdata++ = 0xFF ; *destdata++ = 0xFF ; + *destdata++ = 0xFF ; } else { *destdata++ = 0x00 ; *destdata++ = 0x00 ; *destdata++ = 0x00 ; + *destdata++ = 0x00 ; } } } @@ -1549,6 +1565,7 @@ public: virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, int desiredWidth, int desiredHeight); }; + IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler) @@ -1563,6 +1580,7 @@ bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, lon if ( thePict ) { wxMetafile mf ; + mf.SetHMETAFILE( (WXHMETAFILE) thePict ) ; bitmap->Create( mf.GetWidth() , mf.GetHeight() ) ; wxMemoryDC dc ; @@ -1572,7 +1590,7 @@ bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, lon return true ; } -#endif //wxUSE_METAFILE +#endif return false ; } @@ -1597,53 +1615,12 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) data.m_height = GetHeight() ; data.m_stride = GetWidth() * 4 ; - return GetRawAccess() ; + return BeginRawAccess() ; } void wxBitmap::UngetRawData(wxPixelDataBase& dataBase) { - if ( !Ok() ) - return; - - // TODO : if we have some information about the API we should check - // this code looks strange... - - if ( !M_BITMAPDATA->HasAlpha() ) - return; - - wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase; - int w = data.GetWidth(); - int h = data.GetHeight(); - - wxBitmap bmpMask( GetWidth(), GetHeight(), 32 ); - wxAlphaPixelData dataMask( bmpMask, data.GetOrigin(), wxSize( w, h ) ); - wxAlphaPixelData::Iterator pMask( dataMask ), p( data ); - - for ( int y = 0; y < h; y++ ) - { - wxAlphaPixelData::Iterator rowStartMask = pMask; - wxAlphaPixelData::Iterator rowStart = p; - - for ( int x = 0; x < w; x++ ) - { - const wxAlphaPixelData::Iterator::ChannelType alpha = p.Alpha(); - - pMask.Red() = alpha; - pMask.Green() = alpha; - pMask.Blue() = alpha; - - ++p; - ++pMask; - } - - p = rowStart; - p.OffsetY( data, 1 ); - - pMask = rowStartMask; - pMask.OffsetY( dataMask, 1 ); - } - - SetMask( new wxMask( bmpMask ) ); + EndRawAccess() ; } void wxBitmap::UseAlpha()