aboutsummaryrefslogtreecommitdiff
path: root/pixman/test/utils.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-01-05 17:14:35 +0100
committermarha <marha@users.sourceforge.net>2014-01-05 17:14:35 +0100
commit1b37f71714e2ca4af60bd050adbbb7969534dfd6 (patch)
treefddb228ad86cd15742a6a05d3de3995e460f4bac /pixman/test/utils.c
parentf93b0a79de9ea56bea3e24797cc72625d9dcee3c (diff)
downloadvcxsrv-1b37f71714e2ca4af60bd050adbbb7969534dfd6.tar.gz
vcxsrv-1b37f71714e2ca4af60bd050adbbb7969534dfd6.tar.bz2
vcxsrv-1b37f71714e2ca4af60bd050adbbb7969534dfd6.zip
randrproto libXau libxcb mesa mkfontscale pixman git update 5 Jan 2014
xserver commit 2ea973e12f5d954211e1d10085a4c74581b43aca libxcb commit 3b72a2c9d1d656c74c691a45689e1d637f669e3a libxcb/xcb-proto commit 0d8f09b6469c45be08dae3665d352269ffcc7df2 xkeyboard-config commit 8f49a59f8cd118564ec1554d428177d681bc8b7f libX11 commit 3d69b0a83e62f8f6fbdd952fc49cdbdf8825e1e6 libXdmcp commit 089081dca4ba3598c6f9bf401c029378943b5854 libXext commit bb24f2970f2e425f4df90c9b73d078ad15a73fbb libfontenc commit 3acba630d8b57084f7e92c15732408711ed5137a libXinerama commit edd95182b26eb5d576d4878c559e0f17dddaa909 libXau commit 1e4635be11154dd8262f37b379511bd627defa2a xkbcomp commit e3e6e938535532bfad175c1635256ab7fb3ac943 pixman commit 82d094654a46bd97d47f1f132a01ae0a74b986f3 xextproto commit 66afec3f49e8eb0d4c2e9af7088fc3116d4bafd7 randrproto commit 19fc4c5a72eb9919d720ad66734029d9f8e313b1 glproto commit f84853d97d5749308992412a215fa518b6536eb3 mkfontscale commit eac564e0fc9052a39981ea47b271f7f3d2821944 xwininfo commit ba0d1b0da21d2dbdd81098ed5778f3792b472e13 libXft commit 4acfdaf95adb0a05c2a25550bdde036c865902f4 libXmu commit 22d9c590901e121936f50dee97dc60c4f7defb63 libxtrans commit 2c0a7840a28ae696e80e73157856d7a049fdf6c7 fontconfig commit 5c725f2f5829238d16116f782d00d8bb0defaf08 mesa commit a61ae2aa01c9b1976ba4107c1564e0c3f94aea4d
Diffstat (limited to 'pixman/test/utils.c')
-rw-r--r--pixman/test/utils.c184
1 files changed, 179 insertions, 5 deletions
diff --git a/pixman/test/utils.c b/pixman/test/utils.c
index ebe0ccc09..188841783 100644
--- a/pixman/test/utils.c
+++ b/pixman/test/utils.c
@@ -4,6 +4,7 @@
#include <math.h>
#include <signal.h>
#include <stdlib.h>
+#include <float.h>
#ifdef HAVE_GETTIMEOFDAY
#include <sys/time.h>
@@ -1099,6 +1100,152 @@ format_name (pixman_format_code_t format)
return "<unknown format>";
};
+#define IS_ZERO(f) (-DBL_MIN < (f) && (f) < DBL_MIN)
+
+typedef double (* blend_func_t) (double as, double s, double ad, double d);
+
+static force_inline double
+blend_multiply (double sa, double s, double da, double d)
+{
+ return d * s;
+}
+
+static force_inline double
+blend_screen (double sa, double s, double da, double d)
+{
+ return d * sa + s * da - s * d;
+}
+
+static force_inline double
+blend_overlay (double sa, double s, double da, double d)
+{
+ if (2 * d < da)
+ return 2 * s * d;
+ else
+ return sa * da - 2 * (da - d) * (sa - s);
+}
+
+static force_inline double
+blend_darken (double sa, double s, double da, double d)
+{
+ s = s * da;
+ d = d * sa;
+
+ if (s > d)
+ return d;
+ else
+ return s;
+}
+
+static force_inline double
+blend_lighten (double sa, double s, double da, double d)
+{
+ s = s * da;
+ d = d * sa;
+
+ if (s > d)
+ return s;
+ else
+ return d;
+}
+
+static force_inline double
+blend_color_dodge (double sa, double s, double da, double d)
+{
+ if (IS_ZERO (d))
+ return 0.0f;
+ else if (d * sa >= sa * da - s * da)
+ return sa * da;
+ else if (IS_ZERO (sa - s))
+ return sa * da;
+ else
+ return sa * sa * d / (sa - s);
+}
+
+static force_inline double
+blend_color_burn (double sa, double s, double da, double d)
+{
+ if (d >= da)
+ return sa * da;
+ else if (sa * (da - d) >= s * da)
+ return 0.0f;
+ else if (IS_ZERO (s))
+ return 0.0f;
+ else
+ return sa * (da - sa * (da - d) / s);
+}
+
+static force_inline double
+blend_hard_light (double sa, double s, double da, double d)
+{
+ if (2 * s < sa)
+ return 2 * s * d;
+ else
+ return sa * da - 2 * (da - d) * (sa - s);
+}
+
+static force_inline double
+blend_soft_light (double sa, double s, double da, double d)
+{
+ if (2 * s <= sa)
+ {
+ if (IS_ZERO (da))
+ return d * sa;
+ else
+ return d * sa - d * (da - d) * (sa - 2 * s) / da;
+ }
+ else
+ {
+ if (IS_ZERO (da))
+ {
+ return d * sa;
+ }
+ else
+ {
+ if (4 * d <= da)
+ return d * sa + (2 * s - sa) * d * ((16 * d / da - 12) * d / da + 3);
+ else
+ return d * sa + (sqrt (d * da) - d) * (2 * s - sa);
+ }
+ }
+}
+
+static force_inline double
+blend_difference (double sa, double s, double da, double d)
+{
+ double dsa = d * sa;
+ double sda = s * da;
+
+ if (sda < dsa)
+ return dsa - sda;
+ else
+ return sda - dsa;
+}
+
+static force_inline double
+blend_exclusion (double sa, double s, double da, double d)
+{
+ return s * da + d * sa - 2 * d * s;
+}
+
+static double
+clamp (double d)
+{
+ if (d > 1.0)
+ return 1.0;
+ else if (d < 0.0)
+ return 0.0;
+ else
+ return d;
+}
+
+static double
+blend_channel (double as, double s, double ad, double d,
+ blend_func_t blend)
+{
+ return clamp ((1 - ad) * s + (1 - as) * d + blend (as, s, ad, d));
+}
+
static double
calc_op (pixman_op_t op, double src, double dst, double srca, double dsta)
{
@@ -1336,6 +1483,21 @@ do_composite (pixman_op_t op,
{
color_t srcval, srcalpha;
+ static const blend_func_t blend_funcs[] =
+ {
+ blend_multiply,
+ blend_screen,
+ blend_overlay,
+ blend_darken,
+ blend_lighten,
+ blend_color_dodge,
+ blend_color_burn,
+ blend_hard_light,
+ blend_soft_light,
+ blend_difference,
+ blend_exclusion,
+ };
+
if (mask == NULL)
{
srcval = *src;
@@ -1370,10 +1532,22 @@ do_composite (pixman_op_t op,
srcalpha.a = src->a * mask->a;
}
- result->r = calc_op (op, srcval.r, dst->r, srcalpha.r, dst->a);
- result->g = calc_op (op, srcval.g, dst->g, srcalpha.g, dst->a);
- result->b = calc_op (op, srcval.b, dst->b, srcalpha.b, dst->a);
- result->a = calc_op (op, srcval.a, dst->a, srcalpha.a, dst->a);
+ if (op >= PIXMAN_OP_MULTIPLY)
+ {
+ blend_func_t func = blend_funcs[op - PIXMAN_OP_MULTIPLY];
+
+ result->a = srcalpha.a + dst->a - srcalpha.a * dst->a;
+ result->r = blend_channel (srcalpha.r, srcval.r, dst->a, dst->r, func);
+ result->g = blend_channel (srcalpha.g, srcval.g, dst->a, dst->g, func);
+ result->b = blend_channel (srcalpha.b, srcval.b, dst->a, dst->b, func);
+ }
+ else
+ {
+ result->r = calc_op (op, srcval.r, dst->r, srcalpha.r, dst->a);
+ result->g = calc_op (op, srcval.g, dst->g, srcalpha.g, dst->a);
+ result->b = calc_op (op, srcval.b, dst->b, srcalpha.b, dst->a);
+ result->a = calc_op (op, srcval.a, dst->a, srcalpha.a, dst->a);
+ }
}
static double
@@ -1580,7 +1754,7 @@ get_limits (const pixel_checker_t *checker, double limit,
/* The acceptable deviation in units of [0.0, 1.0]
*/
-#define DEVIATION (0.0064)
+#define DEVIATION (0.0128)
void
pixel_checker_get_max (const pixel_checker_t *checker, color_t *color,