[cairo-commit] src/cairo-ft-font.c src/cairoint.h

Carl Worth cworth at kemper.freedesktop.org
Tue Jun 20 11:10:53 PDT 2006


 src/cairo-ft-font.c |    9 +++------
 src/cairoint.h      |   12 ++++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)

New commits:
diff-tree b806b50cfe890b534dbf86f0b4d2cc0c22b880ff (from 3465ae1c58a87382c33117f6c5dec52403c9694e)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Jun 20 10:59:22 2006 -0700

    Add new CAIRO_BITSWAP8 macro for swapping the bits within a byte.
    
    This uses a technique devised by Sean Anderson, July 13, 2001 as found
    at http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
    This technique uses 3 multiplies rather than just shifts and masks, but
    performance seems comparable to the old approach, (but more significantly,
    the new approach is easier to implement as a macro, and I plan to start
    using this bit-swapping elsewhere very soon).

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 0bc9f00..9a30cc8 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -753,15 +753,12 @@ _get_bitmap_surface (FT_Bitmap		     *bi
 
 	if (_native_byte_order_lsb())
 	{
-	    unsigned char   *d = data, c;
+	    unsigned char   *d = data;
 	    int		count = stride * height;
 
 	    while (count--) {
-		c = *d;
-		c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
-		c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
-		c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
-		*d++ = c;
+		*d = CAIRO_BITSWAP8 (*d);
+		*d++;
 	    }
 	}
 	format = CAIRO_FORMAT_A1;
diff --git a/src/cairoint.h b/src/cairoint.h
index ff71d35..103873f 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -206,6 +206,18 @@ typedef cairo_fixed_16_16_t cairo_fixed_
 #define CAIRO_ALPHA_IS_OPAQUE(alpha) ((alpha) >= ((double)0xff00 / (double)0xffff))
 #define CAIRO_ALPHA_IS_ZERO(alpha) ((alpha) <= 0.0)
 
+/* Reverse the bits in a byte with 7 operations (no 64-bit):
+ * Devised by Sean Anderson, July 13, 2001.
+ * Source: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
+ */
+#define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
+
+#ifdef WORDS_BIGENDIAN
+#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) (c)
+#else
+#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) CAIRO_BITSWAP8(c)
+#endif
+
 #include "cairo-hash-private.h"
 #include "cairo-cache-private.h"
 


More information about the cairo-commit mailing list