Move some macros from pixman-compose.c to pixman-private.h
authorSoren Sandmann Pedersen <ssp@dhcp83-218.boston.redhat.com>
Wed, 16 May 2007 15:03:09 +0000 (11:03 -0400)
committerSoren Sandmann Pedersen <ssp@dhcp83-218.boston.redhat.com>
Wed, 16 May 2007 15:03:09 +0000 (11:03 -0400)
pixman/pixman-compose.c
pixman/pixman-private.h

index 44963a9..ac9e2d0 100644 (file)
 #endif
 
 
-#if IMAGE_BYTE_ORDER == MSBFirst
-#define Fetch24(a)  ((unsigned long) (a) & 1 ?                       \
-                    ((READ(a) << 16) | READ((uint16_t *) ((a)+1))) : \
-                    ((READ((uint16_t *) (a)) << 8) | READ((a)+2)))
-#define Store24(a,v) ((unsigned long) (a) & 1 ?                \
-                     (WRITE(a, (uint8_t) ((v) >> 16)),               \
-                      WRITE((uint16_t *) ((a)+1), (uint16_t) (v))) :  \
-                     (WRITE((uint16_t *) (a), (uint16_t) ((v) >> 8)), \
-                      WRITE((a)+2, (uint8_t) (v))))
-#else
-#define Fetch24(a)  ((unsigned long) (a) & 1 ?                      \
-                    (READ(a) | (READ((uint16_t *) ((a)+1)) << 8)) : \
-                    (READ((uint16_t *) (a)) | (READ((a)+2) << 16)))
-#define Store24(a,v) ((unsigned long) (a) & 1 ? \
-                     (WRITE(a, (uint8_t) (v)),                         \
-                      WRITE((uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
-                     (WRITE((uint16_t *) (a), (uint16_t) (v)),         \
-                      WRITE((a)+2, (uint8_t) ((v) >> 16))))
-#endif
-#define Alpha(x) ((x) >> 24)
-#define Red(x) (((x) >> 16) & 0xff)
-#define Green(x) (((x) >> 8) & 0xff)
-#define Blue(x) ((x) & 0xff)
-
-#define CvtR8G8B8toY15(s)       (((((s) >> 16) & 0xff) * 153 + \
-                                  (((s) >>  8) & 0xff) * 301 +         \
-                                  (((s)      ) & 0xff) * 58) >> 2)
-#define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) |  \
-                           (((s) >> 6) & 0x03e0) |  \
-                           (((s) >> 9) & 0x7c00))
-#define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
-#define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
-
-#define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
-
-
-#define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
-#define FbIntDiv(a,b)   (((uint16_t) (a) * 255) / (b))
-
-#define FbGet8(v,i)   ((uint16_t) (uint8_t) ((v) >> i))
-
-
-/*
- * There are two ways of handling alpha -- either as a single unified value or
- * a separate value for each component, hence each macro must have two
- * versions.  The unified alpha version has a 'U' at the end of the name,
- * the component version has a 'C'.  Similarly, functions which deal with
- * this difference will have two versions using the same convention.
- */
-
-#define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i),        \
-                           (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
-
-#define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i),        \
-                           (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
-
-#define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
-
-#define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
-
-#define FbGen(x,y,i,ax,ay,t,u,v) ((t) = (FbIntMult(FbGet8(y,i),ay,(u)) + \
-                                        FbIntMult(FbGet8(x,i),ax,(v))), \
-                                 (uint32_t) ((uint8_t) ((t) |          \
-                                                        (0 - ((t) >> 8)))) << (i))
-
-#define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i),               \
-                        (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
-
-
-/*
-  The methods below use some tricks to be able to do two color
-  components at the same time.
-*/
-
-/*
-  x_c = (x_c * a) / 255
-*/
-#define FbByteMul(x, a) do {                                       \
-        uint32_t t = ((x & 0xff00ff) * a) + 0x800080;               \
-        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                      \
-        t &= 0xff00ff;                                             \
-                                                                   \
-        x = (((x >> 8) & 0xff00ff) * a) + 0x800080;                \
-        x = (x + ((x >> 8) & 0xff00ff));                           \
-        x &= 0xff00ff00;                                           \
-        x += t;                                                            \
-    } while (0)
-
-/*
-  x_c = (x_c * a) / 255 + y
-*/
-#define FbByteMulAdd(x, a, y) do {                                 \
-        uint32_t t = ((x & 0xff00ff) * a) + 0x800080;               \
-        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                      \
-        t &= 0xff00ff;                                             \
-        t += y & 0xff00ff;                                         \
-        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                            \
-        t &= 0xff00ff;                                             \
-                                                                   \
-        x = (((x >> 8) & 0xff00ff) * a) + 0x800080;                 \
-        x = (x + ((x >> 8) & 0xff00ff)) >> 8;                       \
-        x &= 0xff00ff;                                              \
-        x += (y >> 8) & 0xff00ff;                                   \
-        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                     \
-        x &= 0xff00ff;                                              \
-        x <<= 8;                                                    \
-        x += t;                                                     \
-    } while (0)
-
-/*
-  x_c = (x_c * a + y_c * b) / 255
-*/
-#define FbByteAddMul(x, a, y, b) do {                                   \
-        uint32_t t;                                                    \
-        uint32_t r = (x >> 24) * a + (y >> 24) * b + 0x80;             \
-        r += (r >> 8);                                                  \
-        r >>= 8;                                                        \
-                                                                       \
-        t = (x & 0xff00) * a + (y & 0xff00) * b;                        \
-        t += (t >> 8) + 0x8000;                                         \
-        t >>= 16;                                                       \
-                                                                       \
-        t |= r << 16;                                                   \
-        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
-        t &= 0xff00ff;                                                  \
-        t <<= 8;                                                        \
-                                                                       \
-        r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b + 0x80;     \
-        r += (r >> 8);                                                  \
-        r >>= 8;                                                        \
-                                                                       \
-        x = (x & 0xff) * a + (y & 0xff) * b + 0x80;                     \
-        x += (x >> 8);                                                  \
-        x >>= 8;                                                        \
-        x |= r << 16;                                                   \
-        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                         \
-        x &= 0xff00ff;                                                  \
-        x |= t;                                                         \
-    } while (0)
-
-/*
-  x_c = (x_c * a + y_c *b) / 256
-*/
-#define FbByteAddMul_256(x, a, y, b) do {                               \
-        uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;          \
-        t >>= 8;                                                        \
-        t &= 0xff00ff;                                                  \
-                                                                       \
-        x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;      \
-        x &= 0xff00ff00;                                                \
-        x += t;                                                         \
-    } while (0)
-/*
-  x_c = (x_c * a_c) / 255
-*/
-#define FbByteMulC(x, a) do {                            \
-        uint32_t t;                                       \
-        uint32_t r = (x & 0xff) * (a & 0xff);             \
-        r |= (x & 0xff0000) * ((a >> 16) & 0xff);        \
-       r += 0x800080;                                    \
-        r = (r + ((r >> 8) & 0xff00ff)) >> 8;            \
-        r &= 0xff00ff;                                   \
-                                                         \
-        x >>= 8;                                         \
-        t = (x & 0xff) * ((a >> 8) & 0xff);              \
-        t |= (x & 0xff0000) * (a >> 24);                 \
-        t += 0x800080;                                   \
-        t = t + ((t >> 8) & 0xff00ff);                   \
-        x = r | (t & 0xff00ff00);                        \
-                                                         \
-    } while (0)
-
-/*
-  x_c = (x_c * a) / 255 + y
-*/
-#define FbByteMulAddC(x, a, y) do {                                  \
-        uint32_t t;                                                   \
-        uint32_t r = (x & 0xff) * (a & 0xff);                         \
-        r |= (x & 0xff0000) * ((a >> 16) & 0xff);                    \
-       r += 0x800080;                                                \
-       r = (r + ((r >> 8) & 0xff00ff)) >> 8;                         \
-        r &= 0xff00ff;                                               \
-        r += y & 0xff00ff;                                           \
-        r |= 0x1000100 - ((r >> 8) & 0xff00ff);                              \
-        r &= 0xff00ff;                                               \
-                                                                     \
-        x >>= 8;                                                       \
-        t = (x & 0xff) * ((a >> 8) & 0xff);                            \
-        t |= (x & 0xff0000) * (a >> 24);                               \
-       t += 0x800080;                                                 \
-        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                         \
-        t &= 0xff00ff;                                                 \
-        t += (y >> 8) & 0xff00ff;                                      \
-        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                        \
-        t &= 0xff00ff;                                                 \
-        x = r | (t << 8);                                              \
-    } while (0)
-
-/*
-  x_c = (x_c * a_c + y_c * b) / 255
-*/
-#define FbByteAddMulC(x, a, y, b) do {                                  \
-        uint32_t t;                                                    \
-        uint32_t r = (x >> 24) * (a >> 24) + (y >> 24) * b;            \
-        r += (r >> 8) + 0x80;                                           \
-        r >>= 8;                                                        \
-                                                                       \
-        t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b;        \
-        t += (t >> 8) + 0x8000;                                         \
-        t >>= 16;                                                       \
-                                                                       \
-        t |= r << 16;                                                   \
-        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
-        t &= 0xff00ff;                                                  \
-        t <<= 8;                                                        \
-                                                                       \
-        r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b + 0x80; \
-        r += (r >> 8);                                                  \
-        r >>= 8;                                                        \
-                                                                       \
-        x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b + 0x80;            \
-        x += (x >> 8);                                                  \
-        x >>= 8;                                                        \
-        x |= r << 16;                                                   \
-        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                         \
-        x &= 0xff00ff;                                                  \
-        x |= t;                                                         \
-    } while (0)
-
-/*
-  x_c = min(x_c + y_c, 255)
-*/
-#define FbByteAdd(x, y) do {                                            \
-        uint32_t t;                                                    \
-        uint32_t r = (x & 0xff00ff) + (y & 0xff00ff);                  \
-        r |= 0x1000100 - ((r >> 8) & 0xff00ff);                         \
-        r &= 0xff00ff;                                                  \
-                                                                       \
-        t = ((x >> 8) & 0xff00ff) + ((y >> 8) & 0xff00ff);              \
-        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
-        r |= (t & 0xff00ff) << 8;                                       \
-        x = r;                                                          \
-    } while (0)
-
-#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
-
 /*   End of stuff added to get it to compile
  */ 
 
index dd1488c..e6f4e27 100644 (file)
@@ -208,6 +208,254 @@ union pixman_image
 void pixmanCompositeRect (const FbComposeData *data,
                          uint32_t *scanline_buffer);
 
+#if IMAGE_BYTE_ORDER == MSBFirst
+#define Fetch24(a)  ((unsigned long) (a) & 1 ?                       \
+                    ((READ(a) << 16) | READ((uint16_t *) ((a)+1))) : \
+                    ((READ((uint16_t *) (a)) << 8) | READ((a)+2)))
+#define Store24(a,v) ((unsigned long) (a) & 1 ?                \
+                     (WRITE(a, (uint8_t) ((v) >> 16)),               \
+                      WRITE((uint16_t *) ((a)+1), (uint16_t) (v))) :  \
+                     (WRITE((uint16_t *) (a), (uint16_t) ((v) >> 8)), \
+                      WRITE((a)+2, (uint8_t) (v))))
+#else
+#define Fetch24(a)  ((unsigned long) (a) & 1 ?                      \
+                    (READ(a) | (READ((uint16_t *) ((a)+1)) << 8)) : \
+                    (READ((uint16_t *) (a)) | (READ((a)+2) << 16)))
+#define Store24(a,v) ((unsigned long) (a) & 1 ? \
+                     (WRITE(a, (uint8_t) (v)),                         \
+                      WRITE((uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
+                     (WRITE((uint16_t *) (a), (uint16_t) (v)),         \
+                      WRITE((a)+2, (uint8_t) ((v) >> 16))))
+#endif
+
+#define Alpha(x) ((x) >> 24)
+#define Red(x) (((x) >> 16) & 0xff)
+#define Green(x) (((x) >> 8) & 0xff)
+#define Blue(x) ((x) & 0xff)
+
+#define CvtR8G8B8toY15(s)       (((((s) >> 16) & 0xff) * 153 + \
+                                  (((s) >>  8) & 0xff) * 301 +         \
+                                  (((s)      ) & 0xff) * 58) >> 2)
+#define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) |  \
+                           (((s) >> 6) & 0x03e0) |  \
+                           (((s) >> 9) & 0x7c00))
+#define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
+#define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
+
+#define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
+
+
+#define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
+#define FbIntDiv(a,b)   (((uint16_t) (a) * 255) / (b))
+
+#define FbGet8(v,i)   ((uint16_t) (uint8_t) ((v) >> i))
+
+
+/*
+ * There are two ways of handling alpha -- either as a single unified value or
+ * a separate value for each component, hence each macro must have two
+ * versions.  The unified alpha version has a 'U' at the end of the name,
+ * the component version has a 'C'.  Similarly, functions which deal with
+ * this difference will have two versions using the same convention.
+ */
+
+#define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i),        \
+                           (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
+
+#define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i),        \
+                           (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
+
+#define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
+
+#define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
+
+#define FbGen(x,y,i,ax,ay,t,u,v) ((t) = (FbIntMult(FbGet8(y,i),ay,(u)) + \
+                                        FbIntMult(FbGet8(x,i),ax,(v))), \
+                                 (uint32_t) ((uint8_t) ((t) |          \
+                                                        (0 - ((t) >> 8)))) << (i))
+
+#define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i),               \
+                        (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
+
+
+/*
+  The methods below use some tricks to be able to do two color
+  components at the same time.
+*/
+
+/*
+  x_c = (x_c * a) / 255
+*/
+#define FbByteMul(x, a) do {                                       \
+        uint32_t t = ((x & 0xff00ff) * a) + 0x800080;               \
+        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                      \
+        t &= 0xff00ff;                                             \
+                                                                   \
+        x = (((x >> 8) & 0xff00ff) * a) + 0x800080;                \
+        x = (x + ((x >> 8) & 0xff00ff));                           \
+        x &= 0xff00ff00;                                           \
+        x += t;                                                            \
+    } while (0)
+
+/*
+  x_c = (x_c * a) / 255 + y
+*/
+#define FbByteMulAdd(x, a, y) do {                                 \
+        uint32_t t = ((x & 0xff00ff) * a) + 0x800080;               \
+        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                      \
+        t &= 0xff00ff;                                             \
+        t += y & 0xff00ff;                                         \
+        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                            \
+        t &= 0xff00ff;                                             \
+                                                                   \
+        x = (((x >> 8) & 0xff00ff) * a) + 0x800080;                 \
+        x = (x + ((x >> 8) & 0xff00ff)) >> 8;                       \
+        x &= 0xff00ff;                                              \
+        x += (y >> 8) & 0xff00ff;                                   \
+        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                     \
+        x &= 0xff00ff;                                              \
+        x <<= 8;                                                    \
+        x += t;                                                     \
+    } while (0)
+
+/*
+  x_c = (x_c * a + y_c * b) / 255
+*/
+#define FbByteAddMul(x, a, y, b) do {                                   \
+        uint32_t t;                                                    \
+        uint32_t r = (x >> 24) * a + (y >> 24) * b + 0x80;             \
+        r += (r >> 8);                                                  \
+        r >>= 8;                                                        \
+                                                                       \
+        t = (x & 0xff00) * a + (y & 0xff00) * b;                        \
+        t += (t >> 8) + 0x8000;                                         \
+        t >>= 16;                                                       \
+                                                                       \
+        t |= r << 16;                                                   \
+        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
+        t &= 0xff00ff;                                                  \
+        t <<= 8;                                                        \
+                                                                       \
+        r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b + 0x80;     \
+        r += (r >> 8);                                                  \
+        r >>= 8;                                                        \
+                                                                       \
+        x = (x & 0xff) * a + (y & 0xff) * b + 0x80;                     \
+        x += (x >> 8);                                                  \
+        x >>= 8;                                                        \
+        x |= r << 16;                                                   \
+        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                         \
+        x &= 0xff00ff;                                                  \
+        x |= t;                                                         \
+    } while (0)
+
+/*
+  x_c = (x_c * a + y_c *b) / 256
+*/
+#define FbByteAddMul_256(x, a, y, b) do {                               \
+        uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;          \
+        t >>= 8;                                                        \
+        t &= 0xff00ff;                                                  \
+                                                                       \
+        x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;      \
+        x &= 0xff00ff00;                                                \
+        x += t;                                                         \
+    } while (0)
+
+/*
+  x_c = (x_c * a_c) / 255
+*/
+#define FbByteMulC(x, a) do {                            \
+        uint32_t t;                                       \
+        uint32_t r = (x & 0xff) * (a & 0xff);             \
+        r |= (x & 0xff0000) * ((a >> 16) & 0xff);        \
+       r += 0x800080;                                    \
+        r = (r + ((r >> 8) & 0xff00ff)) >> 8;            \
+        r &= 0xff00ff;                                   \
+                                                         \
+        x >>= 8;                                         \
+        t = (x & 0xff) * ((a >> 8) & 0xff);              \
+        t |= (x & 0xff0000) * (a >> 24);                 \
+        t += 0x800080;                                   \
+        t = t + ((t >> 8) & 0xff00ff);                   \
+        x = r | (t & 0xff00ff00);                        \
+                                                         \
+    } while (0)
+
+/*
+  x_c = (x_c * a) / 255 + y
+*/
+#define FbByteMulAddC(x, a, y) do {                                  \
+        uint32_t t;                                                   \
+        uint32_t r = (x & 0xff) * (a & 0xff);                         \
+        r |= (x & 0xff0000) * ((a >> 16) & 0xff);                    \
+       r += 0x800080;                                                \
+       r = (r + ((r >> 8) & 0xff00ff)) >> 8;                         \
+        r &= 0xff00ff;                                               \
+        r += y & 0xff00ff;                                           \
+        r |= 0x1000100 - ((r >> 8) & 0xff00ff);                              \
+        r &= 0xff00ff;                                               \
+                                                                     \
+        x >>= 8;                                                       \
+        t = (x & 0xff) * ((a >> 8) & 0xff);                            \
+        t |= (x & 0xff0000) * (a >> 24);                               \
+       t += 0x800080;                                                 \
+        t = (t + ((t >> 8) & 0xff00ff)) >> 8;                         \
+        t &= 0xff00ff;                                                 \
+        t += (y >> 8) & 0xff00ff;                                      \
+        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                        \
+        t &= 0xff00ff;                                                 \
+        x = r | (t << 8);                                              \
+    } while (0)
+
+/*
+  x_c = (x_c * a_c + y_c * b) / 255
+*/
+#define FbByteAddMulC(x, a, y, b) do {                                  \
+        uint32_t t;                                                    \
+        uint32_t r = (x >> 24) * (a >> 24) + (y >> 24) * b;            \
+        r += (r >> 8) + 0x80;                                           \
+        r >>= 8;                                                        \
+                                                                       \
+        t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b;        \
+        t += (t >> 8) + 0x8000;                                         \
+        t >>= 16;                                                       \
+                                                                       \
+        t |= r << 16;                                                   \
+        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
+        t &= 0xff00ff;                                                  \
+        t <<= 8;                                                        \
+                                                                       \
+        r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b + 0x80; \
+        r += (r >> 8);                                                  \
+        r >>= 8;                                                        \
+                                                                       \
+        x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b + 0x80;            \
+        x += (x >> 8);                                                  \
+        x >>= 8;                                                        \
+        x |= r << 16;                                                   \
+        x |= 0x1000100 - ((x >> 8) & 0xff00ff);                         \
+        x &= 0xff00ff;                                                  \
+        x |= t;                                                         \
+    } while (0)
+
+/*
+  x_c = min(x_c + y_c, 255)
+*/
+#define FbByteAdd(x, y) do {                                            \
+        uint32_t t;                                                    \
+        uint32_t r = (x & 0xff00ff) + (y & 0xff00ff);                  \
+        r |= 0x1000100 - ((r >> 8) & 0xff00ff);                         \
+        r &= 0xff00ff;                                                  \
+                                                                       \
+        t = ((x >> 8) & 0xff00ff) + ((y >> 8) & 0xff00ff);              \
+        t |= 0x1000100 - ((t >> 8) & 0xff00ff);                         \
+        r |= (t & 0xff00ff) << 8;                                       \
+        x = r;                                                          \
+    } while (0)
+
+#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
+
 #if 0
 typedef struct _Picture {
     DrawablePtr            pDrawable;