genericopenlibs/liboil/src/ref/resample.c
changeset 18 47c74d1534e1
equal deleted inserted replaced
0:e4d67989cc36 18:47c74d1534e1
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
       
     4  * All rights reserved.
       
     5  *
       
     6  * Redistribution and use in source and binary forms, with or without
       
     7  * modification, are permitted provided that the following conditions
       
     8  * are met:
       
     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.
       
    14  * 
       
    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.
       
    26  */
       
    27 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
       
    28 
       
    29 #ifdef HAVE_CONFIG_H
       
    30 #include "config.h"
       
    31 #endif
       
    32 
       
    33 #include <liboil/liboil.h>
       
    34 #include <liboil/liboilfunction.h>
       
    35 #include <liboil/liboiltest.h>
       
    36 #include <liboil/liboilrandom.h>
       
    37 
       
    38 
       
    39 /**
       
    40  * oil_resample_linear_u8:
       
    41  * @d_n:
       
    42  * @s_2xn:
       
    43  * @n:
       
    44  * @i_2:
       
    45  *
       
    46  * Linearly resamples a row of pixels.  FIXME.
       
    47  */
       
    48 static void
       
    49 resample_linear_u8_test (OilTest *test)
       
    50 {
       
    51   uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
       
    52 
       
    53   in[0] = 0;
       
    54   in[1] = 65536;
       
    55 }
       
    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);
       
    59 
       
    60 /**
       
    61  * oil_resample_linear_argb:
       
    62  * @d_n:
       
    63  * @s_2xn:
       
    64  * @n:
       
    65  * @i_2:
       
    66  *
       
    67  * Linearly resamples a row of pixels.  FIXME.
       
    68  */
       
    69 static void
       
    70 resample_linear_argb_test (OilTest *test)
       
    71 {
       
    72   uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
       
    73 
       
    74   in[0] = 0;
       
    75   in[1] = 65536;
       
    76 }
       
    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);
       
    80 
       
    81 static void
       
    82 resample_linear_u8_ref (uint8_t *dest, uint8_t *src, int n,
       
    83     uint32_t *in)
       
    84 {
       
    85   int acc = in[0];
       
    86   int increment = in[1];
       
    87   int i;
       
    88   int j;
       
    89   int x;
       
    90 
       
    91   for(i=0;i<n;i++){
       
    92     j = acc>>16;
       
    93     x = (acc&0xffff)>>8;
       
    94     dest[i] = (src[j]*(256-x) + src[j+1]*x) >> 8;
       
    95 
       
    96     acc += increment;
       
    97   }
       
    98 
       
    99   in[0] = acc;
       
   100 }
       
   101 OIL_DEFINE_IMPL_REF (resample_linear_u8_ref, resample_linear_u8);
       
   102 
       
   103 static void
       
   104 resample_linear_argb_ref (uint32_t *d, uint32_t *s, int n, uint32_t *in)
       
   105 {
       
   106   uint8_t *src = (uint8_t *)s;
       
   107   uint8_t *dest = (uint8_t *)d;
       
   108   int acc = in[0];
       
   109   int increment = in[1];
       
   110   int i;
       
   111   int j;
       
   112   int x;
       
   113 
       
   114   for(i=0;i<n;i++){
       
   115     j = acc>>16;
       
   116     x = (acc&0xffff)>>8;
       
   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;
       
   121 
       
   122     acc += increment;
       
   123   }
       
   124 
       
   125   in[0] = acc;
       
   126 }
       
   127 OIL_DEFINE_IMPL_REF (resample_linear_argb_ref, resample_linear_argb);
       
   128 
       
   129 
       
   130 static void
       
   131 merge_linear_test (OilTest *test)
       
   132 {
       
   133   uint32_t *src3 = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_SRC3);
       
   134 
       
   135   do {
       
   136     src3[0] = oil_rand_u16() & 0x1ff;
       
   137   } while (src3[0] > 256);
       
   138 }
       
   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",
       
   141     merge_linear_test);
       
   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",
       
   144     merge_linear_test);
       
   145 
       
   146 /**
       
   147  * oil_merge_linear_argb:
       
   148  * @d_n:
       
   149  * @s_n:
       
   150  * @s2_n:
       
   151  * @s3_1:
       
   152  * @n:
       
   153  *
       
   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.
       
   159  *
       
   160  * This function is not intended for alpha blending; use one of the
       
   161  * compositing functions instead.
       
   162  */
       
   163 static void
       
   164 merge_linear_argb_ref (uint32_t *d, uint32_t *s1, uint32_t *s2,
       
   165     uint32_t *src3, int n)
       
   166 {
       
   167   uint8_t *src1 = (uint8_t *)s1;
       
   168   uint8_t *src2 = (uint8_t *)s2;
       
   169   uint8_t *dest = (uint8_t *)d;
       
   170   int i;
       
   171   int x = src3[0];
       
   172 
       
   173   for(i=0;i<n;i++){
       
   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;
       
   178   }
       
   179 }
       
   180 OIL_DEFINE_IMPL_REF (merge_linear_argb_ref, merge_linear_argb);
       
   181 
       
   182 
       
   183 /**
       
   184  * oil_merge_linear_u8:
       
   185  * @d_n:
       
   186  * @s_n:
       
   187  * @s2_n:
       
   188  * @s3_1:
       
   189  * @n:
       
   190  *
       
   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.
       
   195  *
       
   196  * This function is not intended for alpha blending; use one of the
       
   197  * compositing functions instead.
       
   198  */
       
   199 static void
       
   200 merge_linear_u8_ref (uint8_t *dest, uint8_t *src1, uint8_t *src2,
       
   201     uint32_t *src3, int n)
       
   202 {
       
   203   int i;
       
   204   int x = src3[0];
       
   205 
       
   206   for(i=0;i<n;i++){
       
   207     dest[i] = (src1[i]*(256-x) + src2[i]*x) >> 8;
       
   208   }
       
   209 }
       
   210 OIL_DEFINE_IMPL_REF (merge_linear_u8_ref, merge_linear_u8);
       
   211 
       
   212 
       
   213 
       
   214 
       
   215 #ifdef	__SYMBIAN32__
       
   216  
       
   217 OilFunctionClass* __oil_function_class_resample_linear_u8() {
       
   218         return &_oil_function_class_resample_linear_u8;
       
   219 }
       
   220 #endif
       
   221 
       
   222 #ifdef	__SYMBIAN32__
       
   223  
       
   224 OilFunctionClass* __oil_function_class_resample_linear_argb() {
       
   225         return &_oil_function_class_resample_linear_argb;
       
   226 }
       
   227 #endif
       
   228 
       
   229 #ifdef	__SYMBIAN32__
       
   230  
       
   231 OilFunctionClass* __oil_function_class_merge_linear_argb() {
       
   232         return &_oil_function_class_merge_linear_argb;
       
   233 }
       
   234 #endif
       
   235 
       
   236 #ifdef	__SYMBIAN32__
       
   237  
       
   238 OilFunctionClass* __oil_function_class_merge_linear_u8() {
       
   239         return &_oil_function_class_merge_linear_u8;
       
   240 }
       
   241 #endif
       
   242 
       
   243 
       
   244 
       
   245 #ifdef	__SYMBIAN32__
       
   246  
       
   247 OilFunctionImpl* __oil_function_impl_resample_linear_u8_ref() {
       
   248         return &_oil_function_impl_resample_linear_u8_ref;
       
   249 }
       
   250 #endif
       
   251 
       
   252 #ifdef	__SYMBIAN32__
       
   253  
       
   254 OilFunctionImpl* __oil_function_impl_resample_linear_argb_ref() {
       
   255         return &_oil_function_impl_resample_linear_argb_ref;
       
   256 }
       
   257 #endif
       
   258 
       
   259 #ifdef	__SYMBIAN32__
       
   260  
       
   261 OilFunctionImpl* __oil_function_impl_merge_linear_argb_ref() {
       
   262         return &_oil_function_impl_merge_linear_argb_ref;
       
   263 }
       
   264 #endif
       
   265 
       
   266 #ifdef	__SYMBIAN32__
       
   267  
       
   268 OilFunctionImpl* __oil_function_impl_merge_linear_u8_ref() {
       
   269         return &_oil_function_impl_merge_linear_u8_ref;
       
   270 }
       
   271 #endif
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 #ifdef	__SYMBIAN32__
       
   277  
       
   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;
       
   281 	}
       
   282 #endif
       
   283 
       
   284 #ifdef	__SYMBIAN32__
       
   285  
       
   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;
       
   289 	}
       
   290 #endif
       
   291 
       
   292 #ifdef	__SYMBIAN32__
       
   293  
       
   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;
       
   297 	}
       
   298 #endif
       
   299 
       
   300 #ifdef	__SYMBIAN32__
       
   301  
       
   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;
       
   305 	}
       
   306 #endif
       
   307