[Pixman] [PATCH] When storing 4 bit pixels, make sure only the low 4 bits are stored.

Søren Sandmann sandmann at daimi.au.dk
Mon Mar 15 09:37:36 PDT 2010


From: Søren Sandmann Pedersen <ssp at redhat.com>

In some cases we end up trying to use the STORE_4 macro with an 8 bit
values, which resulted in other pixels getting overwritten. Fix this
by always masking away the high 4 bits.
---
 pixman/pixman-access.c |   22 ++++++++++++++--------
 test/blitters-test.c   |    2 +-
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/pixman/pixman-access.c b/pixman/pixman-access.c
index 389cf2a..fa0a267 100644
--- a/pixman/pixman-access.c
+++ b/pixman/pixman-access.c
@@ -2445,9 +2445,12 @@ store_scanline_x4a4 (bits_image_t *  image,
     do									\
     {									\
 	int bo = 4 * (o);						\
-	STORE_8 (img, l, bo, (bo & 4 ?					\
-			      (FETCH_8 (img, l, bo) & 0xf0) | (v) :	\
-			      (FETCH_8 (img, l, bo) & 0x0f) | ((v) << 4))); \
+	int v4 = (v) & 0x0f;						\
+									\
+	STORE_8 (img, l, bo, (						\
+		     bo & 4 ?						\
+		     (FETCH_8 (img, l, bo) & 0xf0) | (v4) :		\
+		     (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4)));	\
     } while (0)
 #else
 
@@ -2455,9 +2458,12 @@ store_scanline_x4a4 (bits_image_t *  image,
     do									\
     {									\
 	int bo = 4 * (o);						\
-	STORE_8 (img, l, bo, (bo & 4 ?					\
-			      (FETCH_8 (img, l, bo) & 0x0f) | ((v) << 4) : \
-			      (FETCH_8 (img, l, bo) & 0xf0) | (v)));	\
+	int v4 = (v) & 0x0f;						\
+									\
+	STORE_8 (img, l, bo, (						\
+		     bo & 4 ?						\
+		     (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4) :	\
+		     (FETCH_8 (img, l, bo) & 0xf0) | (v4)));		\
     } while (0)
 #endif
 
@@ -2484,11 +2490,11 @@ store_scanline_r1g2b1 (bits_image_t *  image,
 {
     uint32_t *bits = image->bits + image->rowstride * y;
     int i;
-    
+
     for (i = 0; i < width; ++i)
     {
 	uint32_t pixel;
-	
+
 	SPLIT (values[i]);
 	pixel = (((r >> 4) & 0x8) |
 	         ((g >> 5) & 0x6) |
diff --git a/test/blitters-test.c b/test/blitters-test.c
index c11917d..5e33031 100644
--- a/test/blitters-test.c
+++ b/test/blitters-test.c
@@ -482,7 +482,7 @@ main (int argc, char *argv[])
 	    /* Predefined value for running with all the fastpath functions
 	       disabled. It needs to be updated every time when changes are
 	       introduced to this program or behavior of pixman changes! */
-	    if (crc == 0xEF7A1179)
+	    if (crc == 0xA058F792)
 	    {
 		printf ("blitters test passed\n");
 	    }
-- 
1.6.0.6



More information about the Pixman mailing list