gfx/cairo/libpixman/src/pixman-combine.h.template

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 #define COMPONENT_SIZE
michael@0 3 #define MASK
michael@0 4 #define ONE_HALF
michael@0 5
michael@0 6 #define A_SHIFT
michael@0 7 #define R_SHIFT
michael@0 8 #define G_SHIFT
michael@0 9 #define A_MASK
michael@0 10 #define R_MASK
michael@0 11 #define G_MASK
michael@0 12
michael@0 13 #define RB_MASK
michael@0 14 #define AG_MASK
michael@0 15 #define RB_ONE_HALF
michael@0 16 #define RB_MASK_PLUS_ONE
michael@0 17
michael@0 18 #define ALPHA_c(x) ((x) >> A_SHIFT)
michael@0 19 #define RED_c(x) (((x) >> R_SHIFT) & MASK)
michael@0 20 #define GREEN_c(x) (((x) >> G_SHIFT) & MASK)
michael@0 21 #define BLUE_c(x) ((x) & MASK)
michael@0 22
michael@0 23 /*
michael@0 24 * Helper macros.
michael@0 25 */
michael@0 26
michael@0 27 #define MUL_UNc(a, b, t) \
michael@0 28 ((t) = (a) * (comp2_t)(b) + ONE_HALF, ((((t) >> G_SHIFT ) + (t) ) >> G_SHIFT ))
michael@0 29
michael@0 30 #define DIV_UNc(a, b) \
michael@0 31 (((comp2_t) (a) * MASK + ((b) / 2)) / (b))
michael@0 32
michael@0 33 #define ADD_UNc(x, y, t) \
michael@0 34 ((t) = (x) + (y), \
michael@0 35 (comp4_t) (comp1_t) ((t) | (0 - ((t) >> G_SHIFT))))
michael@0 36
michael@0 37 #define DIV_ONE_UNc(x) \
michael@0 38 (((x) + ONE_HALF + (((x) + ONE_HALF) >> G_SHIFT)) >> G_SHIFT)
michael@0 39
michael@0 40 /*
michael@0 41 * The methods below use some tricks to be able to do two color
michael@0 42 * components at the same time.
michael@0 43 */
michael@0 44
michael@0 45 /*
michael@0 46 * x_rb = (x_rb * a) / 255
michael@0 47 */
michael@0 48 #define UNc_rb_MUL_UNc(x, a, t) \
michael@0 49 do \
michael@0 50 { \
michael@0 51 t = ((x) & RB_MASK) * (a); \
michael@0 52 t += RB_ONE_HALF; \
michael@0 53 x = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \
michael@0 54 x &= RB_MASK; \
michael@0 55 } while (0)
michael@0 56
michael@0 57 /*
michael@0 58 * x_rb = min (x_rb + y_rb, 255)
michael@0 59 */
michael@0 60 #define UNc_rb_ADD_UNc_rb(x, y, t) \
michael@0 61 do \
michael@0 62 { \
michael@0 63 t = ((x) + (y)); \
michael@0 64 t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); \
michael@0 65 x = (t & RB_MASK); \
michael@0 66 } while (0)
michael@0 67
michael@0 68 /*
michael@0 69 * x_rb = (x_rb * a_rb) / 255
michael@0 70 */
michael@0 71 #define UNc_rb_MUL_UNc_rb(x, a, t) \
michael@0 72 do \
michael@0 73 { \
michael@0 74 t = (x & MASK) * (a & MASK); \
michael@0 75 t |= (x & R_MASK) * ((a >> R_SHIFT) & MASK); \
michael@0 76 t += RB_ONE_HALF; \
michael@0 77 t = (t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT; \
michael@0 78 x = t & RB_MASK; \
michael@0 79 } while (0)
michael@0 80
michael@0 81 /*
michael@0 82 * x_c = (x_c * a) / 255
michael@0 83 */
michael@0 84 #define UNcx4_MUL_UNc(x, a) \
michael@0 85 do \
michael@0 86 { \
michael@0 87 comp4_t r1__, r2__, t__; \
michael@0 88 \
michael@0 89 r1__ = (x); \
michael@0 90 UNc_rb_MUL_UNc (r1__, (a), t__); \
michael@0 91 \
michael@0 92 r2__ = (x) >> G_SHIFT; \
michael@0 93 UNc_rb_MUL_UNc (r2__, (a), t__); \
michael@0 94 \
michael@0 95 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 96 } while (0)
michael@0 97
michael@0 98 /*
michael@0 99 * x_c = (x_c * a) / 255 + y_c
michael@0 100 */
michael@0 101 #define UNcx4_MUL_UNc_ADD_UNcx4(x, a, y) \
michael@0 102 do \
michael@0 103 { \
michael@0 104 comp4_t r1__, r2__, r3__, t__; \
michael@0 105 \
michael@0 106 r1__ = (x); \
michael@0 107 r2__ = (y) & RB_MASK; \
michael@0 108 UNc_rb_MUL_UNc (r1__, (a), t__); \
michael@0 109 UNc_rb_ADD_UNc_rb (r1__, r2__, t__); \
michael@0 110 \
michael@0 111 r2__ = (x) >> G_SHIFT; \
michael@0 112 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 113 UNc_rb_MUL_UNc (r2__, (a), t__); \
michael@0 114 UNc_rb_ADD_UNc_rb (r2__, r3__, t__); \
michael@0 115 \
michael@0 116 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 117 } while (0)
michael@0 118
michael@0 119 /*
michael@0 120 * x_c = (x_c * a + y_c * b) / 255
michael@0 121 */
michael@0 122 #define UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc(x, a, y, b) \
michael@0 123 do \
michael@0 124 { \
michael@0 125 comp4_t r1__, r2__, r3__, t__; \
michael@0 126 \
michael@0 127 r1__ = (x); \
michael@0 128 r2__ = (y); \
michael@0 129 UNc_rb_MUL_UNc (r1__, (a), t__); \
michael@0 130 UNc_rb_MUL_UNc (r2__, (b), t__); \
michael@0 131 UNc_rb_ADD_UNc_rb (r1__, r2__, t__); \
michael@0 132 \
michael@0 133 r2__ = ((x) >> G_SHIFT); \
michael@0 134 r3__ = ((y) >> G_SHIFT); \
michael@0 135 UNc_rb_MUL_UNc (r2__, (a), t__); \
michael@0 136 UNc_rb_MUL_UNc (r3__, (b), t__); \
michael@0 137 UNc_rb_ADD_UNc_rb (r2__, r3__, t__); \
michael@0 138 \
michael@0 139 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 140 } while (0)
michael@0 141
michael@0 142 /*
michael@0 143 * x_c = (x_c * a_c) / 255
michael@0 144 */
michael@0 145 #define UNcx4_MUL_UNcx4(x, a) \
michael@0 146 do \
michael@0 147 { \
michael@0 148 comp4_t r1__, r2__, r3__, t__; \
michael@0 149 \
michael@0 150 r1__ = (x); \
michael@0 151 r2__ = (a); \
michael@0 152 UNc_rb_MUL_UNc_rb (r1__, r2__, t__); \
michael@0 153 \
michael@0 154 r2__ = (x) >> G_SHIFT; \
michael@0 155 r3__ = (a) >> G_SHIFT; \
michael@0 156 UNc_rb_MUL_UNc_rb (r2__, r3__, t__); \
michael@0 157 \
michael@0 158 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 159 } while (0)
michael@0 160
michael@0 161 /*
michael@0 162 * x_c = (x_c * a_c) / 255 + y_c
michael@0 163 */
michael@0 164 #define UNcx4_MUL_UNcx4_ADD_UNcx4(x, a, y) \
michael@0 165 do \
michael@0 166 { \
michael@0 167 comp4_t r1__, r2__, r3__, t__; \
michael@0 168 \
michael@0 169 r1__ = (x); \
michael@0 170 r2__ = (a); \
michael@0 171 UNc_rb_MUL_UNc_rb (r1__, r2__, t__); \
michael@0 172 r2__ = (y) & RB_MASK; \
michael@0 173 UNc_rb_ADD_UNc_rb (r1__, r2__, t__); \
michael@0 174 \
michael@0 175 r2__ = ((x) >> G_SHIFT); \
michael@0 176 r3__ = ((a) >> G_SHIFT); \
michael@0 177 UNc_rb_MUL_UNc_rb (r2__, r3__, t__); \
michael@0 178 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 179 UNc_rb_ADD_UNc_rb (r2__, r3__, t__); \
michael@0 180 \
michael@0 181 (x) = r1__ | (r2__ << G_SHIFT); \
michael@0 182 } while (0)
michael@0 183
michael@0 184 /*
michael@0 185 * x_c = (x_c * a_c + y_c * b) / 255
michael@0 186 */
michael@0 187 #define UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc(x, a, y, b) \
michael@0 188 do \
michael@0 189 { \
michael@0 190 comp4_t r1__, r2__, r3__, t__; \
michael@0 191 \
michael@0 192 r1__ = (x); \
michael@0 193 r2__ = (a); \
michael@0 194 UNc_rb_MUL_UNc_rb (r1__, r2__, t__); \
michael@0 195 r2__ = (y); \
michael@0 196 UNc_rb_MUL_UNc (r2__, (b), t__); \
michael@0 197 UNc_rb_ADD_UNc_rb (r1__, r2__, t__); \
michael@0 198 \
michael@0 199 r2__ = (x) >> G_SHIFT; \
michael@0 200 r3__ = (a) >> G_SHIFT; \
michael@0 201 UNc_rb_MUL_UNc_rb (r2__, r3__, t__); \
michael@0 202 r3__ = (y) >> G_SHIFT; \
michael@0 203 UNc_rb_MUL_UNc (r3__, (b), t__); \
michael@0 204 UNc_rb_ADD_UNc_rb (r2__, r3__, t__); \
michael@0 205 \
michael@0 206 x = r1__ | (r2__ << G_SHIFT); \
michael@0 207 } while (0)
michael@0 208
michael@0 209 /*
michael@0 210 x_c = min(x_c + y_c, 255)
michael@0 211 */
michael@0 212 #define UNcx4_ADD_UNcx4(x, y) \
michael@0 213 do \
michael@0 214 { \
michael@0 215 comp4_t r1__, r2__, r3__, t__; \
michael@0 216 \
michael@0 217 r1__ = (x) & RB_MASK; \
michael@0 218 r2__ = (y) & RB_MASK; \
michael@0 219 UNc_rb_ADD_UNc_rb (r1__, r2__, t__); \
michael@0 220 \
michael@0 221 r2__ = ((x) >> G_SHIFT) & RB_MASK; \
michael@0 222 r3__ = ((y) >> G_SHIFT) & RB_MASK; \
michael@0 223 UNc_rb_ADD_UNc_rb (r2__, r3__, t__); \
michael@0 224 \
michael@0 225 x = r1__ | (r2__ << G_SHIFT); \
michael@0 226 } while (0)

mercurial