2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
32 #include <liboil/liboil.h>
33 #include <liboil/liboilfunction.h>
34 #include <liboil/liboilcolorspace.h>
35 #include <liboil/liboildebug.h>
37 #define COMPOSITE_OVER(d,s,m) ((d) + (s) - oil_muldiv_255((d),(m)))
38 #define COMPOSITE_ADD(d,s) oil_clamp_255((d) + (s))
39 #define COMPOSITE_IN(s,m) oil_muldiv_255((s),(m))
41 OIL_DECLARE_CLASS (composite_over_argb);
44 composite_over_argb_noclamp (uint32_t *dest, const uint32_t *src, int n)
50 a = oil_argb_A(src[i]);
51 dest[i] = oil_argb_noclamp(
52 COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(src[i]),a),
53 COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(src[i]),a),
54 COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(src[i]),a),
55 COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(src[i]),a));
59 OIL_DEFINE_IMPL (composite_over_argb_noclamp, composite_over_argb);
61 #define oil_divide_255_2(x) ((((x)+128)*257)>>24)
62 #define oil_muldiv_255_2(a,b) oil_divide_255_2((a)*(b))
63 #define COMPOSITE_OVER_2(d,s,m) ((d) + (s) - oil_muldiv_255((d),(m)))
66 composite_over_argb_noclamp_2 (uint32_t *dest, const uint32_t *src, int n)
72 a = oil_argb_A(src[i]);
73 dest[i] = oil_argb_noclamp(
74 COMPOSITE_OVER_2(oil_argb_A(dest[i]),oil_argb_A(src[i]),a),
75 COMPOSITE_OVER_2(oil_argb_R(dest[i]),oil_argb_R(src[i]),a),
76 COMPOSITE_OVER_2(oil_argb_G(dest[i]),oil_argb_G(src[i]),a),
77 COMPOSITE_OVER_2(oil_argb_B(dest[i]),oil_argb_B(src[i]),a));
81 OIL_DEFINE_IMPL (composite_over_argb_noclamp_2, composite_over_argb);