1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/ref/resample.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,307 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
1.7 + * All rights reserved.
1.8 + *
1.9 + * Redistribution and use in source and binary forms, with or without
1.10 + * modification, are permitted provided that the following conditions
1.11 + * are met:
1.12 + * 1. Redistributions of source code must retain the above copyright
1.13 + * notice, this list of conditions and the following disclaimer.
1.14 + * 2. Redistributions in binary form must reproduce the above copyright
1.15 + * notice, this list of conditions and the following disclaimer in the
1.16 + * documentation and/or other materials provided with the distribution.
1.17 + *
1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.28 + * POSSIBILITY OF SUCH DAMAGE.
1.29 + */
1.30 +//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.31 +
1.32 +#ifdef HAVE_CONFIG_H
1.33 +#include "config.h"
1.34 +#endif
1.35 +
1.36 +#include <liboil/liboil.h>
1.37 +#include <liboil/liboilfunction.h>
1.38 +#include <liboil/liboiltest.h>
1.39 +#include <liboil/liboilrandom.h>
1.40 +
1.41 +
1.42 +/**
1.43 + * oil_resample_linear_u8:
1.44 + * @d_n:
1.45 + * @s_2xn:
1.46 + * @n:
1.47 + * @i_2:
1.48 + *
1.49 + * Linearly resamples a row of pixels. FIXME.
1.50 + */
1.51 +static void
1.52 +resample_linear_u8_test (OilTest *test)
1.53 +{
1.54 + uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
1.55 +
1.56 + in[0] = 0;
1.57 + in[1] = 65536;
1.58 +}
1.59 +OIL_DEFINE_CLASS_FULL (resample_linear_u8,
1.60 + "uint8_t *d_n, uint8_t *s_2xn, int n, uint32_t *i_2",
1.61 + resample_linear_u8_test);
1.62 +
1.63 +/**
1.64 + * oil_resample_linear_argb:
1.65 + * @d_n:
1.66 + * @s_2xn:
1.67 + * @n:
1.68 + * @i_2:
1.69 + *
1.70 + * Linearly resamples a row of pixels. FIXME.
1.71 + */
1.72 +static void
1.73 +resample_linear_argb_test (OilTest *test)
1.74 +{
1.75 + uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
1.76 +
1.77 + in[0] = 0;
1.78 + in[1] = 65536;
1.79 +}
1.80 +OIL_DEFINE_CLASS_FULL (resample_linear_argb,
1.81 + "uint32_t *d_n, uint32_t *s_2xn, int n, uint32_t *i_2",
1.82 + resample_linear_argb_test);
1.83 +
1.84 +static void
1.85 +resample_linear_u8_ref (uint8_t *dest, uint8_t *src, int n,
1.86 + uint32_t *in)
1.87 +{
1.88 + int acc = in[0];
1.89 + int increment = in[1];
1.90 + int i;
1.91 + int j;
1.92 + int x;
1.93 +
1.94 + for(i=0;i<n;i++){
1.95 + j = acc>>16;
1.96 + x = (acc&0xffff)>>8;
1.97 + dest[i] = (src[j]*(256-x) + src[j+1]*x) >> 8;
1.98 +
1.99 + acc += increment;
1.100 + }
1.101 +
1.102 + in[0] = acc;
1.103 +}
1.104 +OIL_DEFINE_IMPL_REF (resample_linear_u8_ref, resample_linear_u8);
1.105 +
1.106 +static void
1.107 +resample_linear_argb_ref (uint32_t *d, uint32_t *s, int n, uint32_t *in)
1.108 +{
1.109 + uint8_t *src = (uint8_t *)s;
1.110 + uint8_t *dest = (uint8_t *)d;
1.111 + int acc = in[0];
1.112 + int increment = in[1];
1.113 + int i;
1.114 + int j;
1.115 + int x;
1.116 +
1.117 + for(i=0;i<n;i++){
1.118 + j = acc>>16;
1.119 + x = (acc&0xffff)>>8;
1.120 + dest[4*i+0] = (src[4*j+0]*(256-x) + src[4*j+4]*x) >> 8;
1.121 + dest[4*i+1] = (src[4*j+1]*(256-x) + src[4*j+5]*x) >> 8;
1.122 + dest[4*i+2] = (src[4*j+2]*(256-x) + src[4*j+6]*x) >> 8;
1.123 + dest[4*i+3] = (src[4*j+3]*(256-x) + src[4*j+7]*x) >> 8;
1.124 +
1.125 + acc += increment;
1.126 + }
1.127 +
1.128 + in[0] = acc;
1.129 +}
1.130 +OIL_DEFINE_IMPL_REF (resample_linear_argb_ref, resample_linear_argb);
1.131 +
1.132 +
1.133 +static void
1.134 +merge_linear_test (OilTest *test)
1.135 +{
1.136 + uint32_t *src3 = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_SRC3);
1.137 +
1.138 + do {
1.139 + src3[0] = oil_rand_u16() & 0x1ff;
1.140 + } while (src3[0] > 256);
1.141 +}
1.142 +OIL_DEFINE_CLASS_FULL (merge_linear_argb,
1.143 + "uint32_t *d_n, uint32_t *s_n, uint32_t *s2_n, uint32_t *s3_1, int n",
1.144 + merge_linear_test);
1.145 +OIL_DEFINE_CLASS_FULL (merge_linear_u8,
1.146 + "uint8_t *d_n, uint8_t *s_n, uint8_t *s2_n, uint32_t *s3_1, int n",
1.147 + merge_linear_test);
1.148 +
1.149 +/**
1.150 + * oil_merge_linear_argb:
1.151 + * @d_n:
1.152 + * @s_n:
1.153 + * @s2_n:
1.154 + * @s3_1:
1.155 + * @n:
1.156 + *
1.157 + * Linearly interpolate the @s_n and @s2_n arrays using the scale
1.158 + * factor in @s3_1. The value @s3_1 must be in the range [0, 256]
1.159 + * A value of 0 indicates weights of 1.0 and 0.0 for
1.160 + * the s_n and s2_n arrays respectively. A value of 256 indicates
1.161 + * weights of 0.0 and 1.0 respectively.
1.162 + *
1.163 + * This function is not intended for alpha blending; use one of the
1.164 + * compositing functions instead.
1.165 + */
1.166 +static void
1.167 +merge_linear_argb_ref (uint32_t *d, uint32_t *s1, uint32_t *s2,
1.168 + uint32_t *src3, int n)
1.169 +{
1.170 + uint8_t *src1 = (uint8_t *)s1;
1.171 + uint8_t *src2 = (uint8_t *)s2;
1.172 + uint8_t *dest = (uint8_t *)d;
1.173 + int i;
1.174 + int x = src3[0];
1.175 +
1.176 + for(i=0;i<n;i++){
1.177 + dest[4*i+0] = (src1[4*i+0]*(256-x) + src2[4*i+0]*x) >> 8;
1.178 + dest[4*i+1] = (src1[4*i+1]*(256-x) + src2[4*i+1]*x) >> 8;
1.179 + dest[4*i+2] = (src1[4*i+2]*(256-x) + src2[4*i+2]*x) >> 8;
1.180 + dest[4*i+3] = (src1[4*i+3]*(256-x) + src2[4*i+3]*x) >> 8;
1.181 + }
1.182 +}
1.183 +OIL_DEFINE_IMPL_REF (merge_linear_argb_ref, merge_linear_argb);
1.184 +
1.185 +
1.186 +/**
1.187 + * oil_merge_linear_u8:
1.188 + * @d_n:
1.189 + * @s_n:
1.190 + * @s2_n:
1.191 + * @s3_1:
1.192 + * @n:
1.193 + *
1.194 + * Linearly interpolate the @s_n and @s2_n arrays using the scale
1.195 + * factor in @s3_1. The value @s3_1 must be in the range [0, 255].
1.196 + * The value translates into weights of 1.0-(value/256.0) and
1.197 + * (value/256.0) for the s_n and s2_n arrays respectively.
1.198 + *
1.199 + * This function is not intended for alpha blending; use one of the
1.200 + * compositing functions instead.
1.201 + */
1.202 +static void
1.203 +merge_linear_u8_ref (uint8_t *dest, uint8_t *src1, uint8_t *src2,
1.204 + uint32_t *src3, int n)
1.205 +{
1.206 + int i;
1.207 + int x = src3[0];
1.208 +
1.209 + for(i=0;i<n;i++){
1.210 + dest[i] = (src1[i]*(256-x) + src2[i]*x) >> 8;
1.211 + }
1.212 +}
1.213 +OIL_DEFINE_IMPL_REF (merge_linear_u8_ref, merge_linear_u8);
1.214 +
1.215 +
1.216 +
1.217 +
1.218 +#ifdef __SYMBIAN32__
1.219 +
1.220 +OilFunctionClass* __oil_function_class_resample_linear_u8() {
1.221 + return &_oil_function_class_resample_linear_u8;
1.222 +}
1.223 +#endif
1.224 +
1.225 +#ifdef __SYMBIAN32__
1.226 +
1.227 +OilFunctionClass* __oil_function_class_resample_linear_argb() {
1.228 + return &_oil_function_class_resample_linear_argb;
1.229 +}
1.230 +#endif
1.231 +
1.232 +#ifdef __SYMBIAN32__
1.233 +
1.234 +OilFunctionClass* __oil_function_class_merge_linear_argb() {
1.235 + return &_oil_function_class_merge_linear_argb;
1.236 +}
1.237 +#endif
1.238 +
1.239 +#ifdef __SYMBIAN32__
1.240 +
1.241 +OilFunctionClass* __oil_function_class_merge_linear_u8() {
1.242 + return &_oil_function_class_merge_linear_u8;
1.243 +}
1.244 +#endif
1.245 +
1.246 +
1.247 +
1.248 +#ifdef __SYMBIAN32__
1.249 +
1.250 +OilFunctionImpl* __oil_function_impl_resample_linear_u8_ref() {
1.251 + return &_oil_function_impl_resample_linear_u8_ref;
1.252 +}
1.253 +#endif
1.254 +
1.255 +#ifdef __SYMBIAN32__
1.256 +
1.257 +OilFunctionImpl* __oil_function_impl_resample_linear_argb_ref() {
1.258 + return &_oil_function_impl_resample_linear_argb_ref;
1.259 +}
1.260 +#endif
1.261 +
1.262 +#ifdef __SYMBIAN32__
1.263 +
1.264 +OilFunctionImpl* __oil_function_impl_merge_linear_argb_ref() {
1.265 + return &_oil_function_impl_merge_linear_argb_ref;
1.266 +}
1.267 +#endif
1.268 +
1.269 +#ifdef __SYMBIAN32__
1.270 +
1.271 +OilFunctionImpl* __oil_function_impl_merge_linear_u8_ref() {
1.272 + return &_oil_function_impl_merge_linear_u8_ref;
1.273 +}
1.274 +#endif
1.275 +
1.276 +
1.277 +
1.278 +
1.279 +#ifdef __SYMBIAN32__
1.280 +
1.281 +EXPORT_C void** _oil_function_class_ptr_resample_linear_u8 () {
1.282 + oil_function_class_ptr_resample_linear_u8 = __oil_function_class_resample_linear_u8();
1.283 + return &oil_function_class_ptr_resample_linear_u8->func;
1.284 + }
1.285 +#endif
1.286 +
1.287 +#ifdef __SYMBIAN32__
1.288 +
1.289 +EXPORT_C void** _oil_function_class_ptr_resample_linear_argb () {
1.290 + oil_function_class_ptr_resample_linear_argb = __oil_function_class_resample_linear_argb();
1.291 + return &oil_function_class_ptr_resample_linear_argb->func;
1.292 + }
1.293 +#endif
1.294 +
1.295 +#ifdef __SYMBIAN32__
1.296 +
1.297 +EXPORT_C void** _oil_function_class_ptr_merge_linear_argb () {
1.298 + oil_function_class_ptr_merge_linear_argb = __oil_function_class_merge_linear_argb();
1.299 + return &oil_function_class_ptr_merge_linear_argb->func;
1.300 + }
1.301 +#endif
1.302 +
1.303 +#ifdef __SYMBIAN32__
1.304 +
1.305 +EXPORT_C void** _oil_function_class_ptr_merge_linear_u8 () {
1.306 + oil_function_class_ptr_merge_linear_u8 = __oil_function_class_merge_linear_u8();
1.307 + return &oil_function_class_ptr_merge_linear_u8->func;
1.308 + }
1.309 +#endif
1.310 +