gfx/cairo/libpixman/src/pixman-combine16.c

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 #ifdef HAVE_CONFIG_H
michael@0 2 #include <config.h>
michael@0 3 #endif
michael@0 4
michael@0 5 #include <math.h>
michael@0 6 #include <string.h>
michael@0 7
michael@0 8 #include "pixman-private.h"
michael@0 9
michael@0 10 #include "pixman-combine32.h"
michael@0 11
michael@0 12 static force_inline uint32_t
michael@0 13 combine_mask (const uint32_t src, const uint32_t mask)
michael@0 14 {
michael@0 15 uint32_t s, m;
michael@0 16
michael@0 17 m = mask >> A_SHIFT;
michael@0 18
michael@0 19 if (!m)
michael@0 20 return 0;
michael@0 21 s = src;
michael@0 22
michael@0 23 UN8x4_MUL_UN8 (s, m);
michael@0 24
michael@0 25 return s;
michael@0 26 }
michael@0 27
michael@0 28 static void
michael@0 29 combine_src_u (pixman_implementation_t *imp,
michael@0 30 pixman_op_t op,
michael@0 31 uint32_t * dest,
michael@0 32 const uint32_t * src,
michael@0 33 const uint32_t * mask,
michael@0 34 int width)
michael@0 35 {
michael@0 36 int i;
michael@0 37
michael@0 38 if (!mask)
michael@0 39 memcpy (dest, src, width * sizeof (uint16_t));
michael@0 40 else
michael@0 41 {
michael@0 42 uint16_t *d = (uint16_t*)dest;
michael@0 43 uint16_t *src16 = (uint16_t*)src;
michael@0 44 for (i = 0; i < width; ++i)
michael@0 45 {
michael@0 46 if ((*mask & 0xff000000) == 0xff000000) {
michael@0 47 // it's likely worth special casing
michael@0 48 // fully opaque because it avoids
michael@0 49 // the cost of conversion as well the multiplication
michael@0 50 *(d + i) = *src16;
michael@0 51 } else {
michael@0 52 // the mask is still 32bits
michael@0 53 uint32_t s = combine_mask (convert_0565_to_8888(*src16), *mask);
michael@0 54 *(d + i) = convert_8888_to_0565(s);
michael@0 55 }
michael@0 56 mask++;
michael@0 57 src16++;
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 }
michael@0 62
michael@0 63 static void
michael@0 64 combine_over_u (pixman_implementation_t *imp,
michael@0 65 pixman_op_t op,
michael@0 66 uint32_t * dest,
michael@0 67 const uint32_t * src,
michael@0 68 const uint32_t * mask,
michael@0 69 int width)
michael@0 70 {
michael@0 71 int i;
michael@0 72
michael@0 73 if (!mask)
michael@0 74 memcpy (dest, src, width * sizeof (uint16_t));
michael@0 75 else
michael@0 76 {
michael@0 77 uint16_t *d = (uint16_t*)dest;
michael@0 78 uint16_t *src16 = (uint16_t*)src;
michael@0 79 for (i = 0; i < width; ++i)
michael@0 80 {
michael@0 81 if ((*mask & 0xff000000) == 0xff000000) {
michael@0 82 // it's likely worth special casing
michael@0 83 // fully opaque because it avoids
michael@0 84 // the cost of conversion as well the multiplication
michael@0 85 *(d + i) = *src16;
michael@0 86 } else if ((*mask & 0xff000000) == 0x00000000) {
michael@0 87 // keep the dest the same
michael@0 88 } else {
michael@0 89 // the mask is still 32bits
michael@0 90 uint32_t s = combine_mask (convert_0565_to_8888(*src16), *mask);
michael@0 91 uint32_t ia = ALPHA_8 (~s);
michael@0 92 uint32_t d32 = convert_0565_to_8888(*(d + i));
michael@0 93 UN8x4_MUL_UN8_ADD_UN8x4 (d32, ia, s);
michael@0 94 *(d + i) = convert_8888_to_0565(d32);
michael@0 95 }
michael@0 96 mask++;
michael@0 97 src16++;
michael@0 98 }
michael@0 99 }
michael@0 100
michael@0 101 }
michael@0 102
michael@0 103
michael@0 104 void
michael@0 105 _pixman_setup_combiner_functions_16 (pixman_implementation_t *imp)
michael@0 106 {
michael@0 107 int i;
michael@0 108 for (i = 0; i < PIXMAN_N_OPERATORS; i++) {
michael@0 109 imp->combine_16[i] = NULL;
michael@0 110 }
michael@0 111 imp->combine_16[PIXMAN_OP_SRC] = combine_src_u;
michael@0 112 imp->combine_16[PIXMAN_OP_OVER] = combine_over_u;
michael@0 113 }
michael@0 114

mercurial