os/ossrv/genericopenlibs/liboil/src/ref/resample.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
 * LIBOIL - Library of Optimized Inner Loops
sl@0
     3
 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
sl@0
     4
 * All rights reserved.
sl@0
     5
 *
sl@0
     6
 * Redistribution and use in source and binary forms, with or without
sl@0
     7
 * modification, are permitted provided that the following conditions
sl@0
     8
 * are met:
sl@0
     9
 * 1. Redistributions of source code must retain the above copyright
sl@0
    10
 *    notice, this list of conditions and the following disclaimer.
sl@0
    11
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    12
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    13
 *    documentation and/or other materials provided with the distribution.
sl@0
    14
 * 
sl@0
    15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
sl@0
    16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sl@0
    17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
sl@0
    19
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sl@0
    20
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sl@0
    21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    23
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sl@0
    24
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
sl@0
    25
 * POSSIBILITY OF SUCH DAMAGE.
sl@0
    26
 */
sl@0
    27
//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
sl@0
    28
sl@0
    29
#ifdef HAVE_CONFIG_H
sl@0
    30
#include "config.h"
sl@0
    31
#endif
sl@0
    32
sl@0
    33
#include <liboil/liboil.h>
sl@0
    34
#include <liboil/liboilfunction.h>
sl@0
    35
#include <liboil/liboiltest.h>
sl@0
    36
#include <liboil/liboilrandom.h>
sl@0
    37
sl@0
    38
sl@0
    39
/**
sl@0
    40
 * oil_resample_linear_u8:
sl@0
    41
 * @d_n:
sl@0
    42
 * @s_2xn:
sl@0
    43
 * @n:
sl@0
    44
 * @i_2:
sl@0
    45
 *
sl@0
    46
 * Linearly resamples a row of pixels.  FIXME.
sl@0
    47
 */
sl@0
    48
static void
sl@0
    49
resample_linear_u8_test (OilTest *test)
sl@0
    50
{
sl@0
    51
  uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
sl@0
    52
sl@0
    53
  in[0] = 0;
sl@0
    54
  in[1] = 65536;
sl@0
    55
}
sl@0
    56
OIL_DEFINE_CLASS_FULL (resample_linear_u8,
sl@0
    57
    "uint8_t *d_n, uint8_t *s_2xn, int n, uint32_t *i_2",
sl@0
    58
    resample_linear_u8_test);
sl@0
    59
sl@0
    60
/**
sl@0
    61
 * oil_resample_linear_argb:
sl@0
    62
 * @d_n:
sl@0
    63
 * @s_2xn:
sl@0
    64
 * @n:
sl@0
    65
 * @i_2:
sl@0
    66
 *
sl@0
    67
 * Linearly resamples a row of pixels.  FIXME.
sl@0
    68
 */
sl@0
    69
static void
sl@0
    70
resample_linear_argb_test (OilTest *test)
sl@0
    71
{
sl@0
    72
  uint32_t *in = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_INPLACE1);
sl@0
    73
sl@0
    74
  in[0] = 0;
sl@0
    75
  in[1] = 65536;
sl@0
    76
}
sl@0
    77
OIL_DEFINE_CLASS_FULL (resample_linear_argb,
sl@0
    78
    "uint32_t *d_n, uint32_t *s_2xn, int n, uint32_t *i_2",
sl@0
    79
    resample_linear_argb_test);
sl@0
    80
sl@0
    81
static void
sl@0
    82
resample_linear_u8_ref (uint8_t *dest, uint8_t *src, int n,
sl@0
    83
    uint32_t *in)
sl@0
    84
{
sl@0
    85
  int acc = in[0];
sl@0
    86
  int increment = in[1];
sl@0
    87
  int i;
sl@0
    88
  int j;
sl@0
    89
  int x;
sl@0
    90
sl@0
    91
  for(i=0;i<n;i++){
sl@0
    92
    j = acc>>16;
sl@0
    93
    x = (acc&0xffff)>>8;
sl@0
    94
    dest[i] = (src[j]*(256-x) + src[j+1]*x) >> 8;
sl@0
    95
sl@0
    96
    acc += increment;
sl@0
    97
  }
sl@0
    98
sl@0
    99
  in[0] = acc;
sl@0
   100
}
sl@0
   101
OIL_DEFINE_IMPL_REF (resample_linear_u8_ref, resample_linear_u8);
sl@0
   102
sl@0
   103
static void
sl@0
   104
resample_linear_argb_ref (uint32_t *d, uint32_t *s, int n, uint32_t *in)
sl@0
   105
{
sl@0
   106
  uint8_t *src = (uint8_t *)s;
sl@0
   107
  uint8_t *dest = (uint8_t *)d;
sl@0
   108
  int acc = in[0];
sl@0
   109
  int increment = in[1];
sl@0
   110
  int i;
sl@0
   111
  int j;
sl@0
   112
  int x;
sl@0
   113
sl@0
   114
  for(i=0;i<n;i++){
sl@0
   115
    j = acc>>16;
sl@0
   116
    x = (acc&0xffff)>>8;
sl@0
   117
    dest[4*i+0] = (src[4*j+0]*(256-x) + src[4*j+4]*x) >> 8;
sl@0
   118
    dest[4*i+1] = (src[4*j+1]*(256-x) + src[4*j+5]*x) >> 8;
sl@0
   119
    dest[4*i+2] = (src[4*j+2]*(256-x) + src[4*j+6]*x) >> 8;
sl@0
   120
    dest[4*i+3] = (src[4*j+3]*(256-x) + src[4*j+7]*x) >> 8;
sl@0
   121
sl@0
   122
    acc += increment;
sl@0
   123
  }
sl@0
   124
sl@0
   125
  in[0] = acc;
sl@0
   126
}
sl@0
   127
OIL_DEFINE_IMPL_REF (resample_linear_argb_ref, resample_linear_argb);
sl@0
   128
sl@0
   129
sl@0
   130
static void
sl@0
   131
merge_linear_test (OilTest *test)
sl@0
   132
{
sl@0
   133
  uint32_t *src3 = (uint32_t *) oil_test_get_source_data (test, OIL_ARG_SRC3);
sl@0
   134
sl@0
   135
  do {
sl@0
   136
    src3[0] = oil_rand_u16() & 0x1ff;
sl@0
   137
  } while (src3[0] > 256);
sl@0
   138
}
sl@0
   139
OIL_DEFINE_CLASS_FULL (merge_linear_argb,
sl@0
   140
    "uint32_t *d_n, uint32_t *s_n, uint32_t *s2_n, uint32_t *s3_1, int n",
sl@0
   141
    merge_linear_test);
sl@0
   142
OIL_DEFINE_CLASS_FULL (merge_linear_u8,
sl@0
   143
    "uint8_t *d_n, uint8_t *s_n, uint8_t *s2_n, uint32_t *s3_1, int n",
sl@0
   144
    merge_linear_test);
sl@0
   145
sl@0
   146
/**
sl@0
   147
 * oil_merge_linear_argb:
sl@0
   148
 * @d_n:
sl@0
   149
 * @s_n:
sl@0
   150
 * @s2_n:
sl@0
   151
 * @s3_1:
sl@0
   152
 * @n:
sl@0
   153
 *
sl@0
   154
 * Linearly interpolate the @s_n and @s2_n arrays using the scale
sl@0
   155
 * factor in @s3_1.  The value @s3_1 must be in the range [0, 256]
sl@0
   156
 * A value of 0 indicates weights of 1.0 and 0.0 for
sl@0
   157
 * the s_n and s2_n arrays respectively.  A value of 256 indicates
sl@0
   158
 * weights of 0.0 and 1.0 respectively.
sl@0
   159
 *
sl@0
   160
 * This function is not intended for alpha blending; use one of the
sl@0
   161
 * compositing functions instead.
sl@0
   162
 */
sl@0
   163
static void
sl@0
   164
merge_linear_argb_ref (uint32_t *d, uint32_t *s1, uint32_t *s2,
sl@0
   165
    uint32_t *src3, int n)
sl@0
   166
{
sl@0
   167
  uint8_t *src1 = (uint8_t *)s1;
sl@0
   168
  uint8_t *src2 = (uint8_t *)s2;
sl@0
   169
  uint8_t *dest = (uint8_t *)d;
sl@0
   170
  int i;
sl@0
   171
  int x = src3[0];
sl@0
   172
sl@0
   173
  for(i=0;i<n;i++){
sl@0
   174
    dest[4*i+0] = (src1[4*i+0]*(256-x) + src2[4*i+0]*x) >> 8;
sl@0
   175
    dest[4*i+1] = (src1[4*i+1]*(256-x) + src2[4*i+1]*x) >> 8;
sl@0
   176
    dest[4*i+2] = (src1[4*i+2]*(256-x) + src2[4*i+2]*x) >> 8;
sl@0
   177
    dest[4*i+3] = (src1[4*i+3]*(256-x) + src2[4*i+3]*x) >> 8;
sl@0
   178
  }
sl@0
   179
}
sl@0
   180
OIL_DEFINE_IMPL_REF (merge_linear_argb_ref, merge_linear_argb);
sl@0
   181
sl@0
   182
sl@0
   183
/**
sl@0
   184
 * oil_merge_linear_u8:
sl@0
   185
 * @d_n:
sl@0
   186
 * @s_n:
sl@0
   187
 * @s2_n:
sl@0
   188
 * @s3_1:
sl@0
   189
 * @n:
sl@0
   190
 *
sl@0
   191
 * Linearly interpolate the @s_n and @s2_n arrays using the scale
sl@0
   192
 * factor in @s3_1.  The value @s3_1 must be in the range [0, 255].
sl@0
   193
 * The value translates into weights of 1.0-(value/256.0) and
sl@0
   194
 * (value/256.0) for the s_n and s2_n arrays respectively.
sl@0
   195
 *
sl@0
   196
 * This function is not intended for alpha blending; use one of the
sl@0
   197
 * compositing functions instead.
sl@0
   198
 */
sl@0
   199
static void
sl@0
   200
merge_linear_u8_ref (uint8_t *dest, uint8_t *src1, uint8_t *src2,
sl@0
   201
    uint32_t *src3, int n)
sl@0
   202
{
sl@0
   203
  int i;
sl@0
   204
  int x = src3[0];
sl@0
   205
sl@0
   206
  for(i=0;i<n;i++){
sl@0
   207
    dest[i] = (src1[i]*(256-x) + src2[i]*x) >> 8;
sl@0
   208
  }
sl@0
   209
}
sl@0
   210
OIL_DEFINE_IMPL_REF (merge_linear_u8_ref, merge_linear_u8);
sl@0
   211
sl@0
   212
sl@0
   213
sl@0
   214
sl@0
   215
#ifdef	__SYMBIAN32__
sl@0
   216
 
sl@0
   217
OilFunctionClass* __oil_function_class_resample_linear_u8() {
sl@0
   218
        return &_oil_function_class_resample_linear_u8;
sl@0
   219
}
sl@0
   220
#endif
sl@0
   221
sl@0
   222
#ifdef	__SYMBIAN32__
sl@0
   223
 
sl@0
   224
OilFunctionClass* __oil_function_class_resample_linear_argb() {
sl@0
   225
        return &_oil_function_class_resample_linear_argb;
sl@0
   226
}
sl@0
   227
#endif
sl@0
   228
sl@0
   229
#ifdef	__SYMBIAN32__
sl@0
   230
 
sl@0
   231
OilFunctionClass* __oil_function_class_merge_linear_argb() {
sl@0
   232
        return &_oil_function_class_merge_linear_argb;
sl@0
   233
}
sl@0
   234
#endif
sl@0
   235
sl@0
   236
#ifdef	__SYMBIAN32__
sl@0
   237
 
sl@0
   238
OilFunctionClass* __oil_function_class_merge_linear_u8() {
sl@0
   239
        return &_oil_function_class_merge_linear_u8;
sl@0
   240
}
sl@0
   241
#endif
sl@0
   242
sl@0
   243
sl@0
   244
sl@0
   245
#ifdef	__SYMBIAN32__
sl@0
   246
 
sl@0
   247
OilFunctionImpl* __oil_function_impl_resample_linear_u8_ref() {
sl@0
   248
        return &_oil_function_impl_resample_linear_u8_ref;
sl@0
   249
}
sl@0
   250
#endif
sl@0
   251
sl@0
   252
#ifdef	__SYMBIAN32__
sl@0
   253
 
sl@0
   254
OilFunctionImpl* __oil_function_impl_resample_linear_argb_ref() {
sl@0
   255
        return &_oil_function_impl_resample_linear_argb_ref;
sl@0
   256
}
sl@0
   257
#endif
sl@0
   258
sl@0
   259
#ifdef	__SYMBIAN32__
sl@0
   260
 
sl@0
   261
OilFunctionImpl* __oil_function_impl_merge_linear_argb_ref() {
sl@0
   262
        return &_oil_function_impl_merge_linear_argb_ref;
sl@0
   263
}
sl@0
   264
#endif
sl@0
   265
sl@0
   266
#ifdef	__SYMBIAN32__
sl@0
   267
 
sl@0
   268
OilFunctionImpl* __oil_function_impl_merge_linear_u8_ref() {
sl@0
   269
        return &_oil_function_impl_merge_linear_u8_ref;
sl@0
   270
}
sl@0
   271
#endif
sl@0
   272
sl@0
   273
sl@0
   274
sl@0
   275
sl@0
   276
#ifdef	__SYMBIAN32__
sl@0
   277
 
sl@0
   278
EXPORT_C void** _oil_function_class_ptr_resample_linear_u8 ()	{
sl@0
   279
	oil_function_class_ptr_resample_linear_u8 = __oil_function_class_resample_linear_u8();
sl@0
   280
	return &oil_function_class_ptr_resample_linear_u8->func;
sl@0
   281
	}
sl@0
   282
#endif
sl@0
   283
sl@0
   284
#ifdef	__SYMBIAN32__
sl@0
   285
 
sl@0
   286
EXPORT_C void** _oil_function_class_ptr_resample_linear_argb ()	{
sl@0
   287
	oil_function_class_ptr_resample_linear_argb = __oil_function_class_resample_linear_argb();
sl@0
   288
	return &oil_function_class_ptr_resample_linear_argb->func;
sl@0
   289
	}
sl@0
   290
#endif
sl@0
   291
sl@0
   292
#ifdef	__SYMBIAN32__
sl@0
   293
 
sl@0
   294
EXPORT_C void** _oil_function_class_ptr_merge_linear_argb ()	{
sl@0
   295
	oil_function_class_ptr_merge_linear_argb = __oil_function_class_merge_linear_argb();
sl@0
   296
	return &oil_function_class_ptr_merge_linear_argb->func;
sl@0
   297
	}
sl@0
   298
#endif
sl@0
   299
sl@0
   300
#ifdef	__SYMBIAN32__
sl@0
   301
 
sl@0
   302
EXPORT_C void** _oil_function_class_ptr_merge_linear_u8 ()	{
sl@0
   303
	oil_function_class_ptr_merge_linear_u8 = __oil_function_class_merge_linear_u8();
sl@0
   304
	return &oil_function_class_ptr_merge_linear_u8->func;
sl@0
   305
	}
sl@0
   306
#endif
sl@0
   307