michael@0: /* WARNING: This file is generated by combine.pl from combine.inc. michael@0: Please edit one of those files rather than this one. */ michael@0: michael@0: #line 1 "pixman-combine.c.template" michael@0: michael@0: #define COMPONENT_SIZE 16 michael@0: #define MASK 0xffffULL michael@0: #define ONE_HALF 0x8000ULL michael@0: michael@0: #define A_SHIFT 16 * 3 michael@0: #define R_SHIFT 16 * 2 michael@0: #define G_SHIFT 16 michael@0: #define A_MASK 0xffff000000000000ULL michael@0: #define R_MASK 0xffff00000000ULL michael@0: #define G_MASK 0xffff0000ULL michael@0: michael@0: #define RB_MASK 0xffff0000ffffULL michael@0: #define AG_MASK 0xffff0000ffff0000ULL michael@0: #define RB_ONE_HALF 0x800000008000ULL michael@0: #define RB_MASK_PLUS_ONE 0x10000000010000ULL michael@0: michael@0: #define ALPHA_16(x) ((x) >> A_SHIFT) michael@0: #define RED_16(x) (((x) >> R_SHIFT) & MASK) michael@0: #define GREEN_16(x) (((x) >> G_SHIFT) & MASK) michael@0: #define BLUE_16(x) ((x) & MASK) michael@0: michael@0: /* michael@0: * Helper macros. michael@0: */ michael@0: michael@0: #define MUL_UN16(a, b, t) \ michael@0: ((t) = (a) * (uint32_t)(b) + ONE_HALF, ((((t) >> G_SHIFT ) + (t) ) >> G_SHIFT )) michael@0: michael@0: #define DIV_UN16(a, b) \ michael@0: (((uint32_t) (a) * MASK + ((b) / 2)) / (b)) michael@0: michael@0: #define ADD_UN16(x, y, t) \ michael@0: ((t) = (x) + (y), \ michael@0: (uint64_t) (uint16_t) ((t) | (0 - ((t) >> G_SHIFT)))) michael@0: michael@0: #define DIV_ONE_UN16(x) \ michael@0: (((x) + ONE_HALF + (((x) + ONE_HALF) >> G_SHIFT)) >> G_SHIFT) michael@0: michael@0: /* michael@0: * The methods below use some tricks to be able to do two color michael@0: * components at the same time. michael@0: */ michael@0: michael@0: /* michael@0: * x_rb = (x_rb * a) / 255 michael@0: */ michael@0: #define UN16_rb_MUL_UN16(x, a, t) \ michael@0: do \ michael@0: { \ michael@0: t = ((x) & RB_MASK) * (a); \ michael@0: t += RB_ONE_HALF; \ michael@0: x = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \ michael@0: x &= RB_MASK; \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_rb = min (x_rb + y_rb, 255) michael@0: */ michael@0: #define UN16_rb_ADD_UN16_rb(x, y, t) \ michael@0: do \ michael@0: { \ michael@0: t = ((x) + (y)); \ michael@0: t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); \ michael@0: x = (t & RB_MASK); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_rb = (x_rb * a_rb) / 255 michael@0: */ michael@0: #define UN16_rb_MUL_UN16_rb(x, a, t) \ michael@0: do \ michael@0: { \ michael@0: t = (x & MASK) * (a & MASK); \ michael@0: t |= (x & R_MASK) * ((a >> R_SHIFT) & MASK); \ michael@0: t += RB_ONE_HALF; \ michael@0: t = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \ michael@0: x = t & RB_MASK; \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a) / 255 michael@0: */ michael@0: #define UN16x4_MUL_UN16(x, a) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: UN16_rb_MUL_UN16 (r1__, (a), t__); \ michael@0: \ michael@0: r2__ = (x) >> G_SHIFT; \ michael@0: UN16_rb_MUL_UN16 (r2__, (a), t__); \ michael@0: \ michael@0: (x) = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a) / 255 + y_c michael@0: */ michael@0: #define UN16x4_MUL_UN16_ADD_UN16x4(x, a, y) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: r2__ = (y) & RB_MASK; \ michael@0: UN16_rb_MUL_UN16 (r1__, (a), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = (x) >> G_SHIFT; \ michael@0: r3__ = ((y) >> G_SHIFT) & RB_MASK; \ michael@0: UN16_rb_MUL_UN16 (r2__, (a), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: (x) = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a + y_c * b) / 255 michael@0: */ michael@0: #define UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16(x, a, y, b) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: r2__ = (y); \ michael@0: UN16_rb_MUL_UN16 (r1__, (a), t__); \ michael@0: UN16_rb_MUL_UN16 (r2__, (b), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = ((x) >> G_SHIFT); \ michael@0: r3__ = ((y) >> G_SHIFT); \ michael@0: UN16_rb_MUL_UN16 (r2__, (a), t__); \ michael@0: UN16_rb_MUL_UN16 (r3__, (b), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: (x) = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a_c) / 255 michael@0: */ michael@0: #define UN16x4_MUL_UN16x4(x, a) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: r2__ = (a); \ michael@0: UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = (x) >> G_SHIFT; \ michael@0: r3__ = (a) >> G_SHIFT; \ michael@0: UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: (x) = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a_c) / 255 + y_c michael@0: */ michael@0: #define UN16x4_MUL_UN16x4_ADD_UN16x4(x, a, y) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: r2__ = (a); \ michael@0: UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \ michael@0: r2__ = (y) & RB_MASK; \ michael@0: UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = ((x) >> G_SHIFT); \ michael@0: r3__ = ((a) >> G_SHIFT); \ michael@0: UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \ michael@0: r3__ = ((y) >> G_SHIFT) & RB_MASK; \ michael@0: UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: (x) = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: * x_c = (x_c * a_c + y_c * b) / 255 michael@0: */ michael@0: #define UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16(x, a, y, b) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x); \ michael@0: r2__ = (a); \ michael@0: UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \ michael@0: r2__ = (y); \ michael@0: UN16_rb_MUL_UN16 (r2__, (b), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = (x) >> G_SHIFT; \ michael@0: r3__ = (a) >> G_SHIFT; \ michael@0: UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \ michael@0: r3__ = (y) >> G_SHIFT; \ michael@0: UN16_rb_MUL_UN16 (r3__, (b), t__); \ michael@0: UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: x = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0) michael@0: michael@0: /* michael@0: x_c = min(x_c + y_c, 255) michael@0: */ michael@0: #define UN16x4_ADD_UN16x4(x, y) \ michael@0: do \ michael@0: { \ michael@0: uint64_t r1__, r2__, r3__, t__; \ michael@0: \ michael@0: r1__ = (x) & RB_MASK; \ michael@0: r2__ = (y) & RB_MASK; \ michael@0: UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \ michael@0: \ michael@0: r2__ = ((x) >> G_SHIFT) & RB_MASK; \ michael@0: r3__ = ((y) >> G_SHIFT) & RB_MASK; \ michael@0: UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \ michael@0: \ michael@0: x = r1__ | (r2__ << G_SHIFT); \ michael@0: } while (0)