From d2c6d54928e7ba32b2bf6ddf0ca5f3dd4339758b Mon Sep 17 00:00:00 2001
From: Gilles Depeyrot <gilles_depeyrot@mac.com>
Date: Sun, 6 May 2001 18:51:22 +0000
Subject: [PATCH] applied correction from Marc Newsam in calculations of
 linesize tested with the image sample which now produces expected results

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10018 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 src/mac/bitmap.cpp        | 117 +++++++++++++++++---------------------
 src/mac/carbon/bitmap.cpp | 117 +++++++++++++++++---------------------
 2 files changed, 106 insertions(+), 128 deletions(-)

diff --git a/src/mac/bitmap.cpp b/src/mac/bitmap.cpp
index 1412aa925b..5d2b9fa638 100644
--- a/src/mac/bitmap.cpp
+++ b/src/mac/bitmap.cpp
@@ -263,73 +263,62 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     M_BITMAPDATA->m_height = the_height ;
     M_BITMAPDATA->m_depth = no_bits ;
     M_BITMAPDATA->m_numColors = 0;
-		if ( no_bits == 1 )
-		{
-	    	M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
-	    	M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
-			M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+    if ( no_bits == 1 )
+    {
+	M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
+	M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
+	M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
 	
-			CGrafPtr 	origPort ;
-			GDHandle	origDevice ;
-			
-			GetGWorld( &origPort , &origDevice ) ;
-			SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
-			LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
-
-#ifdef __UNIX__
-           // bits is a word aligned array?? Don't think so
-           // bits is a char array on MAC OS X however using the benefit of the
-           // doubt I replaced references to 16 with sizeof(unsigned char)*8
-           unsigned char* linestart = (unsigned char*) bits ;
-           int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
-           if ( the_width % (sizeof(unsigned char) * 8) ) {
-               linesize += sizeof(unsigned char);
-           }
-#else
-			// bits is a word aligned array
-			
-			unsigned char* linestart = (unsigned char*) bits ;
-			int linesize = ( the_width / 16 ) * 2  ;
-			if ( the_width % 16 )
-			{
-				linesize += 2 ;
-			}
-#endif
-			
-			RGBColor colors[2] = { 
-				{ 0xFFFF , 0xFFFF , 0xFFFF } ,
-				{ 0, 0 , 0 } 
-				} ;
-			
-			for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
-			{
-				for ( int x = 0 ; x < the_width ; ++x )
-				{
-					int index = x / 8 ;
-					int bit = x % 8 ;
-					int mask = 1 << bit ;
-					if ( linestart[index] & mask )
-					{
-						SetCPixel( x , y , &colors[1] ) ;
-					}
-					else
-					{
-						SetCPixel( x , y , &colors[0] ) ;
-					}
-				}
-				
-			}
-		UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	CGrafPtr 	origPort ;
+	GDHandle	origDevice ;
 	
-	   	SetGWorld( origPort , origDevice ) ;
-	   }
-	   else
-	   {
-         wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
-	   }
-
-    if ( wxTheBitmapList )
+	GetGWorld( &origPort , &origDevice ) ;
+	SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
+	LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	
+	// bits is a char array
+	
+	unsigned char* linestart = (unsigned char*) bits ;
+	int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
+	if ( the_width % (sizeof(unsigned char) * 8) ) {
+	    linesize += sizeof(unsigned char);
+	}
+	
+	RGBColor colors[2] = { 
+	    { 0xFFFF , 0xFFFF , 0xFFFF } ,
+	    { 0, 0 , 0 } 
+	} ;
+	
+	for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
+	{
+	    for ( int x = 0 ; x < the_width ; ++x )
+	    {
+		int index = x / 8 ;
+		int bit = x % 8 ;
+		int mask = 1 << bit ;
+		if ( linestart[index] & mask )
+		{
+		    SetCPixel( x , y , &colors[1] ) ;
+		}
+		else
+		{
+		    SetCPixel( x , y , &colors[0] ) ;
+		}
+	    }
+	    
+	}
+	UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	
+	SetGWorld( origPort , origDevice ) ;
+    }
+    else
+    {
+	wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
+    }
+    
+    if ( wxTheBitmapList ) {
         wxTheBitmapList->AddBitmap(this);
+    }
 }
 
 wxBitmap::wxBitmap(int w, int h, int d)
diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp
index 1412aa925b..5d2b9fa638 100644
--- a/src/mac/carbon/bitmap.cpp
+++ b/src/mac/carbon/bitmap.cpp
@@ -263,73 +263,62 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     M_BITMAPDATA->m_height = the_height ;
     M_BITMAPDATA->m_depth = no_bits ;
     M_BITMAPDATA->m_numColors = 0;
-		if ( no_bits == 1 )
-		{
-	    	M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
-	    	M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
-			M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+    if ( no_bits == 1 )
+    {
+	M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
+	M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
+	M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
 	
-			CGrafPtr 	origPort ;
-			GDHandle	origDevice ;
-			
-			GetGWorld( &origPort , &origDevice ) ;
-			SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
-			LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
-
-#ifdef __UNIX__
-           // bits is a word aligned array?? Don't think so
-           // bits is a char array on MAC OS X however using the benefit of the
-           // doubt I replaced references to 16 with sizeof(unsigned char)*8
-           unsigned char* linestart = (unsigned char*) bits ;
-           int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
-           if ( the_width % (sizeof(unsigned char) * 8) ) {
-               linesize += sizeof(unsigned char);
-           }
-#else
-			// bits is a word aligned array
-			
-			unsigned char* linestart = (unsigned char*) bits ;
-			int linesize = ( the_width / 16 ) * 2  ;
-			if ( the_width % 16 )
-			{
-				linesize += 2 ;
-			}
-#endif
-			
-			RGBColor colors[2] = { 
-				{ 0xFFFF , 0xFFFF , 0xFFFF } ,
-				{ 0, 0 , 0 } 
-				} ;
-			
-			for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
-			{
-				for ( int x = 0 ; x < the_width ; ++x )
-				{
-					int index = x / 8 ;
-					int bit = x % 8 ;
-					int mask = 1 << bit ;
-					if ( linestart[index] & mask )
-					{
-						SetCPixel( x , y , &colors[1] ) ;
-					}
-					else
-					{
-						SetCPixel( x , y , &colors[0] ) ;
-					}
-				}
-				
-			}
-		UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	CGrafPtr 	origPort ;
+	GDHandle	origDevice ;
 	
-	   	SetGWorld( origPort , origDevice ) ;
-	   }
-	   else
-	   {
-         wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
-	   }
-
-    if ( wxTheBitmapList )
+	GetGWorld( &origPort , &origDevice ) ;
+	SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ;
+	LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	
+	// bits is a char array
+	
+	unsigned char* linestart = (unsigned char*) bits ;
+	int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
+	if ( the_width % (sizeof(unsigned char) * 8) ) {
+	    linesize += sizeof(unsigned char);
+	}
+	
+	RGBColor colors[2] = { 
+	    { 0xFFFF , 0xFFFF , 0xFFFF } ,
+	    { 0, 0 , 0 } 
+	} ;
+	
+	for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
+	{
+	    for ( int x = 0 ; x < the_width ; ++x )
+	    {
+		int index = x / 8 ;
+		int bit = x % 8 ;
+		int mask = 1 << bit ;
+		if ( linestart[index] & mask )
+		{
+		    SetCPixel( x , y , &colors[1] ) ;
+		}
+		else
+		{
+		    SetCPixel( x , y , &colors[0] ) ;
+		}
+	    }
+	    
+	}
+	UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
+	
+	SetGWorld( origPort , origDevice ) ;
+    }
+    else
+    {
+	wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
+    }
+    
+    if ( wxTheBitmapList ) {
         wxTheBitmapList->AddBitmap(this);
+    }
 }
 
 wxBitmap::wxBitmap(int w, int h, int d)
-- 
2.47.2