[Mono-winforms-list] Patches for 64-bit stride calculations in libgdiplus

eckzow eckzow <eckzow@gmail.com>
Tue, 22 Feb 2005 01:39:22 -0500


------=_Part_7236_10484148.1109054362111
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hey all,

Browsing through gdip, pdb and I noticed that strides weren't being
calculated properly for 64-bit machines due to hardcoded byte
alignments.  He (pdb) has submitted a couple patches already but this
one cleans a few more of the trouble spots up.  Thanks,

AJ "Eckzow" Frantz

------=_Part_7236_10484148.1109054362111
Content-Type: application/octet-stream; name=64bitstrides.patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="64bitstrides.patch"

Index: libgdiplus/libpixman/src/pixman.h
===================================================================
--- libgdiplus/src/bitmap.c	(revision 40971)
+++ libgdiplus/src/bitmap.c	(working copy)
@@ -357,7 +357,7 @@
 	if (destData->Scan0 == NULL) {
 		GpBitmap *data;
 
-		destData->Stride = (((( destRect->Width * dest_components * dest_deph) /8)  + 3) & ~3);
+		destData->Stride = (((( destRect->Width * dest_components * dest_deph) /8)  + (sizeof(pixman_bits_t)-1)) & ~(sizeof(pixman_bits_t)-1));
 
 		data = GdipAlloc (destData->Stride * destRect->Height);
 		if (data == NULL) {
@@ -459,7 +459,7 @@
 
 		if (destData->Scan0 == NULL) {
 			outStride = bytesPerPixel * destRect->Width;
-			while (outStride % 4)
+			while (outStride % sizeof(pixman_bits_t))
 				outStride++;		/* dword-align each row */
 
 			/* Allocate the output buffer */
@@ -502,7 +502,7 @@
 
 		if (destData->Scan0 == NULL) {
 			outStride = destBytesPerPixel * destRect->Width;
-			while (outStride % 4)
+			while (outStride % sizeof(pixman_bits_t))
 				outStride++;		/* dword-align each row */
 
 			/* Allocate the output buffer */
@@ -589,7 +589,7 @@
 	
 	*dest_stride = dest_components * 8;
 	*dest_stride = (*dest_stride * width) / 8;
-	*dest_stride = (*dest_stride + 3) & ~3;		
+	*dest_stride = (*dest_stride + (sizeof(pixman_bits_t)-1)) & ~(sizeof(pixman_bits_t)-1);		
 	
 	result = GdipAlloc (*dest_stride * height);
 	if (result == NULL)
@@ -622,7 +622,7 @@
 	
 	*dest_stride = dest_components * 8;
 	*dest_stride = (*dest_stride * width) / 8;
-	*dest_stride = (*dest_stride + 3) & ~3;		
+	*dest_stride = (*dest_stride + (sizeof(pixman_bits_t)-1)) & ~(sizeof(pixman_bits_t)-1);		
 	
 	result = GdipAlloc (*dest_stride * height);
 	if (result == NULL)


------=_Part_7236_10484148.1109054362111--