summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2009-09-23 09:32:21 +0200
committerBenjamin Otte <otte@gnome.org>2009-11-02 12:59:53 +0100
commit96f8691fa0ce83b2e5c219b7b272a33fcc746a2c (patch)
tree4e80b01e2594ebcb299c4938f73f104c0f8502b0
parentc18596807c53380ecd3d8f63f5662b06b2533090 (diff)
Add bswap() macros and use them
Code taken from Cairo.
-rw-r--r--configure.ac1
-rw-r--r--pixman/pixman-access.c35
-rw-r--r--pixman/pixman-private.h18
3 files changed, 28 insertions, 26 deletions
diff --git a/configure.ac b/configure.ac
index 12c7f75..6856b82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,6 +73,7 @@ test_CFLAGS=${CFLAGS+set} # We may override autoconf default CFLAGS.
AC_PROG_CC
AC_PROG_LIBTOOL
AC_CHECK_FUNCS([getisax])
+AC_CHECK_HEADERS(byteswap.h)
AC_C_BIGENDIAN
AC_C_INLINE
diff --git a/pixman/pixman-access.c b/pixman/pixman-access.c
index 5a824cf..7dceee9 100644
--- a/pixman/pixman-access.c
+++ b/pixman/pixman-access.c
@@ -184,11 +184,8 @@ fetch_scanline_b8g8r8a8 (pixman_image_t *image,
while (pixel < end)
{
uint32_t p = READ (image, pixel++);
-
- *buffer++ = (((p & 0xff000000) >> 24) |
- ((p & 0x00ff0000) >> 8) |
- ((p & 0x0000ff00) << 8) |
- ((p & 0x000000ff) << 24));
+
+ *buffer++ = bswap_32 (p);
}
}
@@ -209,10 +206,7 @@ fetch_scanline_b8g8r8x8 (pixman_image_t *image,
{
uint32_t p = READ (image, pixel++);
- *buffer++ = (0xff000000 |
- ((p & 0xff000000) >> 24) |
- ((p & 0x00ff0000) >> 8) |
- ((p & 0x0000ff00) << 8));
+ *buffer++ = 0xff000000 | bswap_32 (p);
}
}
@@ -1414,10 +1408,7 @@ fetch_pixel_b8g8r8a8 (bits_image_t *image,
uint32_t *bits = image->bits + line * image->rowstride;
uint32_t pixel = READ (image, (uint32_t *)bits + offset);
- return ((pixel & 0xff000000) >> 24 |
- (pixel & 0x00ff0000) >> 8 |
- (pixel & 0x0000ff00) << 8 |
- (pixel & 0x000000ff) << 24);
+ return bswap_32 (pixel);
}
static uint32_t
@@ -1428,10 +1419,7 @@ fetch_pixel_b8g8r8x8 (bits_image_t *image,
uint32_t *bits = image->bits + line * image->rowstride;
uint32_t pixel = READ (image, (uint32_t *)bits + offset);
- return ((0xff000000) |
- (pixel & 0xff000000) >> 24 |
- (pixel & 0x00ff0000) >> 8 |
- (pixel & 0x0000ff00) << 8);
+ return 0xff000000 | bswap_32 (pixel);
}
static uint32_t
@@ -2194,11 +2182,8 @@ store_scanline_b8g8r8a8 (bits_image_t * image,
for (i = 0; i < width; ++i)
{
- WRITE (image, pixel++,
- ((values[i] >> 24) & 0x000000ff) |
- ((values[i] >> 8) & 0x0000ff00) |
- ((values[i] << 8) & 0x00ff0000) |
- ((values[i] << 24) & 0xff000000));
+ uint32_t p = bswap_32 (values[i]);
+ WRITE (image, pixel++, p);
}
}
@@ -2215,10 +2200,8 @@ store_scanline_b8g8r8x8 (bits_image_t * image,
for (i = 0; i < width; ++i)
{
- WRITE (image, pixel++,
- ((values[i] >> 8) & 0x0000ff00) |
- ((values[i] << 8) & 0x00ff0000) |
- ((values[i] << 24) & 0xff000000));
+ uint32_t p = bswap_32 (values[i]);
+ WRITE (image, pixel++, p);
}
}
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 7822c54..a1cd66c 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -666,6 +666,24 @@ pixman_region16_copy_from_region32 (pixman_region16_t *dst,
# define MAX(a, b) ((a > b) ? a : b)
#endif
+/* Byte swapping */
+#if HAVE_BYTESWAP_H
+# include <byteswap.h>
+#endif
+#ifndef bswap_16
+# define bswap_16(p) \
+ (((((uint16_t)(p)) & 0x00ff) << 8) | \
+ (((uint16_t)(p)) >> 8));
+#endif
+#ifndef bswap_32
+# define bswap_32(p) \
+ (((((uint32_t)(p)) & 0x000000ff) << 24) | \
+ ((((uint32_t)(p)) & 0x0000ff00) << 8) | \
+ ((((uint32_t)(p)) & 0x00ff0000) >> 8) | \
+ ((((uint32_t)(p))) >> 24));
+#endif
+
+
/* Integer division that rounds towards -infinity */
#define DIV(a, b) \
((((a) < 0) == ((b) < 0)) ? (a) / (b) : \