/////////////////////////////////////////////////////////////////////////////
-// Name: bitmap.cpp
+// Name: src/mac/carbon/bitmap.cpp
// Purpose: wxBitmap
// Author: Stefan Csomor
// Modified by:
#include "wx/wxprec.h"
#include "wx/bitmap.h"
-#include "wx/icon.h"
-#include "wx/log.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/log.h"
+ #include "wx/dcmemory.h"
+ #include "wx/icon.h"
+#endif
+
#include "wx/image.h"
#include "wx/metafile.h"
#include "wx/xpmdecod.h"
#endif
#include "wx/mac/uma.h"
-#include "wx/dcmemory.h"
// Implementation Notes
// --------------------
*maskdest++ = 0xFF - *masksource++ ;
masksource++ ;
masksource++ ;
+ masksource++ ;
}
else if ( hasAlpha )
*maskdest++ = a ;
PicHandle pic = GetPictHandle() ;
SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ;
}
-
// transform into IconRef
-
+#ifdef __WXMAC_OSX__
+ // cleaner version existing from 10.3 upwards
+ HLock((Handle) iconFamily);
+ OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef );
+ HUnlock((Handle) iconFamily);
+ wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") );
+#else
static int iconCounter = 2 ;
OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ;
// we have to retain a reference, as Unregister will decrement it
AcquireIconRef( m_iconRef ) ;
UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ;
- DisposeHandle( (Handle) iconFamily ) ;
++iconCounter ;
+#endif
+ DisposeHandle( (Handle) iconFamily ) ;
}
return m_iconRef ;
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 ;
}
bit = x % 8 ;
mask = 1 << bit ;
- if ( linestart[index] & mask )
+ if ( !(linestart[index] & mask ) )
{
*destination++ = 0xFF ;
*destination++ = 0 ;
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);
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() ;
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 ) ;
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();
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 )
maskp++ ;
maskp++ ;
+ maskp++ ;
}
else if ( hasAlpha )
*alpha++ = a ;
}
// Construct a mask from a mono bitmap (copies the bitmap).
+
wxMask::wxMask( const wxMemoryBuffer& data, int width , int height , int bytesPerRow )
{
Init() ;
Rect rect = { 0 , 0 , m_height , m_width } ;
OSStatus err = NewGWorldFromPtr(
- (GWorldPtr*) &m_maskBitmap , k24RGBPixelFormat , &rect , NULL , NULL , 0 ,
+ (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 ;
{
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 ) ;
*destdata++ = 0xFF ;
*destdata++ = 0xFF ;
*destdata++ = 0xFF ;
+ *destdata++ = 0xFF ;
}
else
{
*destdata++ = 0x00 ;
*destdata++ = 0x00 ;
*destdata++ = 0x00 ;
+ *destdata++ = 0x00 ;
}
}
}
{
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 ) ;
*destdata++ = 0xFF ;
*destdata++ = 0xFF ;
*destdata++ = 0xFF ;
+ *destdata++ = 0xFF ;
}
else
{
*destdata++ = 0x00 ;
*destdata++ = 0x00 ;
*destdata++ = 0x00 ;
+ *destdata++ = 0x00 ;
}
}
}
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()