Update contrib.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboil.h>
34 #include <liboil/liboilfunction.h>
35 #include <liboil/liboiltest.h>
36 #include <liboil/liboilrandom.h>
40 * oil_resample_linear_u8:
46 * Linearly resamples a row of pixels. FIXME.
49 resample_linear_u8_test (OilTest *test)
51 uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
56 OIL_DEFINE_CLASS_FULL (resample_linear_u8,
57 "uint8_t *d_n, uint8_t *s_2xn, int n, uint32_t *i_2",
58 resample_linear_u8_test);
61 * oil_resample_linear_argb:
67 * Linearly resamples a row of pixels. FIXME.
70 resample_linear_argb_test (OilTest *test)
72 uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
77 OIL_DEFINE_CLASS_FULL (resample_linear_argb,
78 "uint32_t *d_n, uint32_t *s_2xn, int n, uint32_t *i_2",
79 resample_linear_argb_test);
82 resample_linear_u8_ref (uint8_t *dest, uint8_t *src, int n,
86 int increment = in[1];
94 dest[i] = (src[j]*(256-x) + src[j+1]*x) >> 8;
101 OIL_DEFINE_IMPL_REF (resample_linear_u8_ref, resample_linear_u8);
104 resample_linear_argb_ref (uint32_t *d, uint32_t *s, int n, uint32_t *in)
106 uint8_t *src = (uint8_t *)s;
107 uint8_t *dest = (uint8_t *)d;
109 int increment = in[1];
117 dest[4*i+0] = (src[4*j+0]*(256-x) + src[4*j+4]*x) >> 8;
118 dest[4*i+1] = (src[4*j+1]*(256-x) + src[4*j+5]*x) >> 8;
119 dest[4*i+2] = (src[4*j+2]*(256-x) + src[4*j+6]*x) >> 8;
120 dest[4*i+3] = (src[4*j+3]*(256-x) + src[4*j+7]*x) >> 8;
127 OIL_DEFINE_IMPL_REF (resample_linear_argb_ref, resample_linear_argb);
131 merge_linear_test (OilTest *test)
133 uint32_t *src3 = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_SRC3);
136 src3[0] = oil_rand_u16() & 0x1ff;
137 } while (src3[0] > 256);
139 OIL_DEFINE_CLASS_FULL (merge_linear_argb,
140 "uint32_t *d_n, uint32_t *s_n, uint32_t *s2_n, uint32_t *s3_1, int n",
142 OIL_DEFINE_CLASS_FULL (merge_linear_u8,
143 "uint8_t *d_n, uint8_t *s_n, uint8_t *s2_n, uint32_t *s3_1, int n",
147 * oil_merge_linear_argb:
154 * Linearly interpolate the @s_n and @s2_n arrays using the scale
155 * factor in @s3_1. The value @s3_1 must be in the range [0, 256]
156 * A value of 0 indicates weights of 1.0 and 0.0 for
157 * the s_n and s2_n arrays respectively. A value of 256 indicates
158 * weights of 0.0 and 1.0 respectively.
160 * This function is not intended for alpha blending; use one of the
161 * compositing functions instead.
164 merge_linear_argb_ref (uint32_t *d, uint32_t *s1, uint32_t *s2,
165 uint32_t *src3, int n)
167 uint8_t *src1 = (uint8_t *)s1;
168 uint8_t *src2 = (uint8_t *)s2;
169 uint8_t *dest = (uint8_t *)d;
174 dest[4*i+0] = (src1[4*i+0]*(256-x) + src2[4*i+0]*x) >> 8;
175 dest[4*i+1] = (src1[4*i+1]*(256-x) + src2[4*i+1]*x) >> 8;
176 dest[4*i+2] = (src1[4*i+2]*(256-x) + src2[4*i+2]*x) >> 8;
177 dest[4*i+3] = (src1[4*i+3]*(256-x) + src2[4*i+3]*x) >> 8;
180 OIL_DEFINE_IMPL_REF (merge_linear_argb_ref, merge_linear_argb);
184 * oil_merge_linear_u8:
191 * Linearly interpolate the @s_n and @s2_n arrays using the scale
192 * factor in @s3_1. The value @s3_1 must be in the range [0, 255].
193 * The value translates into weights of 1.0-(value/256.0) and
194 * (value/256.0) for the s_n and s2_n arrays respectively.
196 * This function is not intended for alpha blending; use one of the
197 * compositing functions instead.
200 merge_linear_u8_ref (uint8_t *dest, uint8_t *src1, uint8_t *src2,
201 uint32_t *src3, int n)
207 dest[i] = (src1[i]*(256-x) + src2[i]*x) >> 8;
210 OIL_DEFINE_IMPL_REF (merge_linear_u8_ref, merge_linear_u8);
217 OilFunctionClass* __oil_function_class_resample_linear_u8() {
218 return &_oil_function_class_resample_linear_u8;
224 OilFunctionClass* __oil_function_class_resample_linear_argb() {
225 return &_oil_function_class_resample_linear_argb;
231 OilFunctionClass* __oil_function_class_merge_linear_argb() {
232 return &_oil_function_class_merge_linear_argb;
238 OilFunctionClass* __oil_function_class_merge_linear_u8() {
239 return &_oil_function_class_merge_linear_u8;
247 OilFunctionImpl* __oil_function_impl_resample_linear_u8_ref() {
248 return &_oil_function_impl_resample_linear_u8_ref;
254 OilFunctionImpl* __oil_function_impl_resample_linear_argb_ref() {
255 return &_oil_function_impl_resample_linear_argb_ref;
261 OilFunctionImpl* __oil_function_impl_merge_linear_argb_ref() {
262 return &_oil_function_impl_merge_linear_argb_ref;
268 OilFunctionImpl* __oil_function_impl_merge_linear_u8_ref() {
269 return &_oil_function_impl_merge_linear_u8_ref;
278 EXPORT_C void** _oil_function_class_ptr_resample_linear_u8 () {
279 oil_function_class_ptr_resample_linear_u8 = __oil_function_class_resample_linear_u8();
280 return &oil_function_class_ptr_resample_linear_u8->func;
286 EXPORT_C void** _oil_function_class_ptr_resample_linear_argb () {
287 oil_function_class_ptr_resample_linear_argb = __oil_function_class_resample_linear_argb();
288 return &oil_function_class_ptr_resample_linear_argb->func;
294 EXPORT_C void** _oil_function_class_ptr_merge_linear_argb () {
295 oil_function_class_ptr_merge_linear_argb = __oil_function_class_merge_linear_argb();
296 return &oil_function_class_ptr_merge_linear_argb->func;
302 EXPORT_C void** _oil_function_class_ptr_merge_linear_u8 () {
303 oil_function_class_ptr_merge_linear_u8 = __oil_function_class_merge_linear_u8();
304 return &oil_function_class_ptr_merge_linear_u8->func;