gfx/cairo/libpixman/src/pixman-combine64.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* WARNING: This file is generated by combine.pl from combine.inc.
michael@0 2 Please edit one of those files rather than this one. */
michael@0 3
michael@0 4 #line 1 "pixman-combine.c.template"
michael@0 5
michael@0 6 #define COMPONENT_SIZE 16
michael@0 7 #define MASK 0xffffULL
michael@0 8 #define ONE_HALF 0x8000ULL
michael@0 9
michael@0 10 #define A_SHIFT 16 * 3
michael@0 11 #define R_SHIFT 16 * 2
michael@0 12 #define G_SHIFT 16
michael@0 13 #define A_MASK 0xffff000000000000ULL
michael@0 14 #define R_MASK 0xffff00000000ULL
michael@0 15 #define G_MASK 0xffff0000ULL
michael@0 16
michael@0 17 #define RB_MASK 0xffff0000ffffULL
michael@0 18 #define AG_MASK 0xffff0000ffff0000ULL
michael@0 19 #define RB_ONE_HALF 0x800000008000ULL
michael@0 20 #define RB_MASK_PLUS_ONE 0x10000000010000ULL
michael@0 21
michael@0 22 #define ALPHA_16(x) ((x) >> A_SHIFT)
michael@0 23 #define RED_16(x) (((x) >> R_SHIFT) & MASK)
michael@0 24 #define GREEN_16(x) (((x) >> G_SHIFT) & MASK)
michael@0 25 #define BLUE_16(x) ((x) & MASK)
michael@0 26
michael@0 27 /*
michael@0 28 * Helper macros.
michael@0 29 */
michael@0 30
michael@0 31 #define MUL_UN16(a, b, t) \
michael@0 32 ((t) = (a) * (uint32_t)(b) + ONE_HALF, ((((t) >> G_SHIFT ) + (t) ) >> G_SHIFT ))
michael@0 33
michael@0 34 #define DIV_UN16(a, b) \
michael@0 35 (((uint32_t) (a) * MASK + ((b) / 2)) / (b))
michael@0 36
michael@0 37 #define ADD_UN16(x, y, t) \
michael@0 38 ((t) = (x) + (y), \
michael@0 39 (uint64_t) (uint16_t) ((t) | (0 - ((t) >> G_SHIFT))))
michael@0 40
michael@0 41 #define DIV_ONE_UN16(x) \
michael@0 42 (((x) + ONE_HALF + (((x) + ONE_HALF) >> G_SHIFT)) >> G_SHIFT)
michael@0 43
michael@0 44 /*
michael@0 45 * The methods below use some tricks to be able to do two color
michael@0 46 * components at the same time.
michael@0 47 */
michael@0 48
michael@0 49 /*
michael@0 50 * x_rb = (x_rb * a) / 255
michael@0 51 */
michael@0 52 #define UN16_rb_MUL_UN16(x, a, t) \
michael@0 53 do \
michael@0 54 { \
michael@0 55 t = ((x) & RB_MASK) * (a); \
michael@0 56 t += RB_ONE_HALF; \
michael@0 57 x = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \
michael@0 58 x &= RB_MASK; \
michael@0 59 } while (0)
michael@0 60
michael@0 61 /*
michael@0 62 * x_rb = min (x_rb + y_rb, 255)
michael@0 63 */
michael@0 64 #define UN16_rb_ADD_UN16_rb(x, y, t) \
michael@0 65 do \
michael@0 66 { \
michael@0 67 t = ((x) + (y)); \
michael@0 68 t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); \
michael@0 69 x = (t & RB_MASK); \
michael@0 70 } while (0)
michael@0 71
michael@0 72 /*
michael@0 73 * x_rb = (x_rb * a_rb) / 255
michael@0 74 */
michael@0 75 #define UN16_rb_MUL_UN16_rb(x, a, t) \
michael@0 76 do \
michael@0 77 { \
michael@0 78 t = (x & MASK) * (a & MASK); \
michael@0 79 t |= (x & R_MASK) * ((a >> R_SHIFT) & MASK); \
michael@0 80 t += RB_ONE_HALF; \
michael@0 81 t = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \
michael@0 82 x = t & RB_MASK; \
michael@0 83 } while (0)
michael@0 84
michael@0 85 /*
michael@0 86 * x_c = (x_c * a) / 255
michael@0 87 */
michael@0 88 #define UN16x4_MUL_UN16(x, a) \
michael@0 89 do \
michael@0 90 { \
michael@0 91 uint64_t r1__, r2__, t__; \
michael@0 92 \
michael@0 93 r1__ = (x); \
michael@0 94 UN16_rb_MUL_UN16 (r1__, (a), t__); \
michael@0 95 \
michael@0 96 r2__ = (x) >> G_SHIFT; \
michael@0 97 UN16_rb_MUL_UN16 (r2__, (a), t__); \
michael@0 98 \
michael@0 99 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 100 } while (0)
michael@0 101
michael@0 102 /*
michael@0 103 * x_c = (x_c * a) / 255 + y_c
michael@0 104 */
michael@0 105 #define UN16x4_MUL_UN16_ADD_UN16x4(x, a, y) \
michael@0 106 do \
michael@0 107 { \
michael@0 108 uint64_t r1__, r2__, r3__, t__; \
michael@0 109 \
michael@0 110 r1__ = (x); \
michael@0 111 r2__ = (y) & RB_MASK; \
michael@0 112 UN16_rb_MUL_UN16 (r1__, (a), t__); \
michael@0 113 UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \
michael@0 114 \
michael@0 115 r2__ = (x) >> G_SHIFT; \
michael@0 116 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 117 UN16_rb_MUL_UN16 (r2__, (a), t__); \
michael@0 118 UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \
michael@0 119 \
michael@0 120 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 121 } while (0)
michael@0 122
michael@0 123 /*
michael@0 124 * x_c = (x_c * a + y_c * b) / 255
michael@0 125 */
michael@0 126 #define UN16x4_MUL_UN16_ADD_UN16x4_MUL_UN16(x, a, y, b) \
michael@0 127 do \
michael@0 128 { \
michael@0 129 uint64_t r1__, r2__, r3__, t__; \
michael@0 130 \
michael@0 131 r1__ = (x); \
michael@0 132 r2__ = (y); \
michael@0 133 UN16_rb_MUL_UN16 (r1__, (a), t__); \
michael@0 134 UN16_rb_MUL_UN16 (r2__, (b), t__); \
michael@0 135 UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \
michael@0 136 \
michael@0 137 r2__ = ((x) >> G_SHIFT); \
michael@0 138 r3__ = ((y) >> G_SHIFT); \
michael@0 139 UN16_rb_MUL_UN16 (r2__, (a), t__); \
michael@0 140 UN16_rb_MUL_UN16 (r3__, (b), t__); \
michael@0 141 UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \
michael@0 142 \
michael@0 143 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 144 } while (0)
michael@0 145
michael@0 146 /*
michael@0 147 * x_c = (x_c * a_c) / 255
michael@0 148 */
michael@0 149 #define UN16x4_MUL_UN16x4(x, a) \
michael@0 150 do \
michael@0 151 { \
michael@0 152 uint64_t r1__, r2__, r3__, t__; \
michael@0 153 \
michael@0 154 r1__ = (x); \
michael@0 155 r2__ = (a); \
michael@0 156 UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \
michael@0 157 \
michael@0 158 r2__ = (x) >> G_SHIFT; \
michael@0 159 r3__ = (a) >> G_SHIFT; \
michael@0 160 UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \
michael@0 161 \
michael@0 162 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 163 } while (0)
michael@0 164
michael@0 165 /*
michael@0 166 * x_c = (x_c * a_c) / 255 + y_c
michael@0 167 */
michael@0 168 #define UN16x4_MUL_UN16x4_ADD_UN16x4(x, a, y) \
michael@0 169 do \
michael@0 170 { \
michael@0 171 uint64_t r1__, r2__, r3__, t__; \
michael@0 172 \
michael@0 173 r1__ = (x); \
michael@0 174 r2__ = (a); \
michael@0 175 UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \
michael@0 176 r2__ = (y) & RB_MASK; \
michael@0 177 UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \
michael@0 178 \
michael@0 179 r2__ = ((x) >> G_SHIFT); \
michael@0 180 r3__ = ((a) >> G_SHIFT); \
michael@0 181 UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \
michael@0 182 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 183 UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \
michael@0 184 \
michael@0 185 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 186 } while (0)
michael@0 187
michael@0 188 /*
michael@0 189 * x_c = (x_c * a_c + y_c * b) / 255
michael@0 190 */
michael@0 191 #define UN16x4_MUL_UN16x4_ADD_UN16x4_MUL_UN16(x, a, y, b) \
michael@0 192 do \
michael@0 193 { \
michael@0 194 uint64_t r1__, r2__, r3__, t__; \
michael@0 195 \
michael@0 196 r1__ = (x); \
michael@0 197 r2__ = (a); \
michael@0 198 UN16_rb_MUL_UN16_rb (r1__, r2__, t__); \
michael@0 199 r2__ = (y); \
michael@0 200 UN16_rb_MUL_UN16 (r2__, (b), t__); \
michael@0 201 UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \
michael@0 202 \
michael@0 203 r2__ = (x) >> G_SHIFT; \
michael@0 204 r3__ = (a) >> G_SHIFT; \
michael@0 205 UN16_rb_MUL_UN16_rb (r2__, r3__, t__); \
michael@0 206 r3__ = (y) >> G_SHIFT; \
michael@0 207 UN16_rb_MUL_UN16 (r3__, (b), t__); \
michael@0 208 UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \
michael@0 209 \
michael@0 210 x = r1__ | (r2__ << G_SHIFT); \
michael@0 211 } while (0)
michael@0 212
michael@0 213 /*
michael@0 214 x_c = min(x_c + y_c, 255)
michael@0 215 */
michael@0 216 #define UN16x4_ADD_UN16x4(x, y) \
michael@0 217 do \
michael@0 218 { \
michael@0 219 uint64_t r1__, r2__, r3__, t__; \
michael@0 220 \
michael@0 221 r1__ = (x) & RB_MASK; \
michael@0 222 r2__ = (y) & RB_MASK; \
michael@0 223 UN16_rb_ADD_UN16_rb (r1__, r2__, t__); \
michael@0 224 \
michael@0 225 r2__ = ((x) >> G_SHIFT) & RB_MASK; \
michael@0 226 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 227 UN16_rb_ADD_UN16_rb (r2__, r3__, t__); \
michael@0 228 \
michael@0 229 x = r1__ | (r2__ << G_SHIFT); \
michael@0 230 } while (0)

mercurial