From 30746b1e1e5101fd1502c676e777e27953772f75 Mon Sep 17 00:00:00 2001 From: Aaron Plattner Date: Mon, 31 Mar 2008 16:09:44 -0700 Subject: [PATCH] Move combining macros into pixman-combine.c. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Søren Sandmann --- pixman/pixman-combine.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++ pixman/pixman-private.h | 182 ---------------------------------------------- 2 files changed, 188 insertions(+), 182 deletions(-) diff --git a/pixman/pixman-combine.c b/pixman/pixman-combine.c index d201736..f6023e6 100644 --- a/pixman/pixman-combine.c +++ b/pixman/pixman-combine.c @@ -5,6 +5,194 @@ #include #include "pixman-private.h" + +/* + * Helper macros. + */ + +#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)) + + +/* + 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) + + /* * 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 diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index e236767..714a6a5 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -441,191 +441,9 @@ union pixman_image #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) #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b)) -- 2.7.4