os/ossrv/genericopenlibs/liboil/src/ayuv2argb.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/ayuv2argb.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,192 @@
     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 "liboilfunction.h"
    1.38 +#include "liboil/liboilcolorspace.h"
    1.39 +#include "liboil/liboiltest.h"
    1.40 +#include <string.h>
    1.41 +
    1.42 +/**
    1.43 + * oil_ayuv2argb_u8:
    1.44 + * @d_4xn:
    1.45 + * @s_4xn:
    1.46 + * @n:
    1.47 + *
    1.48 + * Converts AYUV pixels to ARGB pixels.  AYUV pixels are in the
    1.49 + * JPEG colorspace.  Note that this function doesn't follow normal
    1.50 + * liboil pixel conventions.
    1.51 + *
    1.52 + * (This function should be replaced by one that handles other
    1.53 + * conversion factors.)
    1.54 + */
    1.55 +OIL_DEFINE_CLASS (ayuv2argb_u8, "uint8_t *d_4xn, uint8_t *s_4xn, int n");
    1.56 +
    1.57 +
    1.58 +#define clamp(x,a,b) clamp_lower(clamp_upper(x,b),a)
    1.59 +#define clamp_lower(x,a) ((x<a)?(a):(x))
    1.60 +#define clamp_upper(x,b) ((x>b)?(b):(x))
    1.61 +
    1.62 +/* from the JFIF spec */
    1.63 +#define YUV_TO_R(y,u,v) clamp((y) + 1.402*((v)-128.0),0,255)
    1.64 +#define YUV_TO_G(y,u,v) clamp((y) - 0.34414*((u)-128.0) - 0.71414*((v)-128.0),0,255)
    1.65 +#define YUV_TO_B(y,u,v) clamp((y) + 1.772*((u)-128.0),0,255)
    1.66 +
    1.67 +#define muldiv256(x,y) (((x)*(y) + 128)>>8)
    1.68 +#define YUV_TO_R_INT8(y,u,v) clamp((y) + muldiv256(359,(v)-128),0,255)
    1.69 +#define YUV_TO_G_INT8(y,u,v) clamp((y) + muldiv256(-88,(u)-128) + muldiv256(-183,(v)-128),0,255)
    1.70 +#define YUV_TO_B_INT8(y,u,v) clamp((y) + muldiv256(454,(u)-128),0,255)
    1.71 +
    1.72 +#define muldiv65536(x,y) (((x)*(y) + 32768)>>16)
    1.73 +#define YUV_TO_R_INT16(y,u,v) clamp((y) + muldiv65536(91881,(v)-128),0,255)
    1.74 +#define YUV_TO_G_INT16(y,u,v) clamp((y) - muldiv65536(22554,(u)-128) - muldiv65536(46802,(v)-128),0,255)
    1.75 +#define YUV_TO_B_INT16(y,u,v) clamp((y) + muldiv65536(116130,(u)-128),0,255)
    1.76 +
    1.77 +
    1.78 +#define SHIFT 6
    1.79 +#define MULT (1<<6)
    1.80 +#define X(x) ((int)((x)*(1<<(SHIFT+8)) + 0.5))
    1.81 +static int16_t jfif_matrix[][4] = {
    1.82 +  { 0,      0,      -8192,   -8192  },
    1.83 +  { 16384,  0,      0,       0      },
    1.84 +  { 0,      16384,  16384,   16384  },
    1.85 +  { 0,      0,      -5638,   29032  },
    1.86 +  { 0,      22970,  -11700,  0      },
    1.87 +  { 0, 0, 0, 0 }
    1.88 +};
    1.89 +
    1.90 +static void
    1.91 +colorspace_argb_test (OilTest *test)
    1.92 +{
    1.93 +  int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC2);
    1.94 +
    1.95 +  memcpy (data, jfif_matrix, 4*2*6);
    1.96 +}
    1.97 +
    1.98 +OIL_DEFINE_CLASS_FULL (colorspace_argb, "uint32_t *d, uint32_t *s, int16_t *s2_24, int n", colorspace_argb_test);
    1.99 +
   1.100 +static void
   1.101 +colorspace_argb_ref (uint32_t *dest, const uint32_t *src, const int16_t *matrix, int n)
   1.102 +{
   1.103 +  int i;
   1.104 +
   1.105 +  for(i=0;i<n;i++){
   1.106 +    int sa = (oil_argb_A(src[i])<<SHIFT) + matrix[0*4+0];
   1.107 +    int sr = (oil_argb_R(src[i])<<SHIFT) + matrix[0*4+1];
   1.108 +    int sg = (oil_argb_G(src[i])<<SHIFT) + matrix[0*4+2];
   1.109 +    int sb = (oil_argb_B(src[i])<<SHIFT) + matrix[0*4+3];
   1.110 +    int da, dr, dg, db;
   1.111 +
   1.112 +#define MUL(a,b) (((a)*(b))>>16)
   1.113 +    da = (MUL(sa,matrix[1*4+0]) + MUL(sr,matrix[2*4+0]) + MUL(sg,matrix[3*4+0]) +
   1.114 +        MUL(sb,matrix[4*4+0]) + matrix[5*4+0] + 8)>>(2*SHIFT - 8);
   1.115 +    dr = (MUL(sa,matrix[1*4+1]) + MUL(sr,matrix[2*4+1]) + MUL(sg,matrix[3*4+1]) +
   1.116 +        MUL(sb,matrix[4*4+1]) + matrix[5*4+1] + 8)>>(2*SHIFT - 8);
   1.117 +    dg = (MUL(sa,matrix[1*4+2]) + MUL(sr,matrix[2*4+2]) + MUL(sg,matrix[3*4+2]) +
   1.118 +        MUL(sb,matrix[4*4+2]) + matrix[5*4+2] + 8)>>(2*SHIFT - 8);
   1.119 +    db = (MUL(sa,matrix[1*4+3]) + MUL(sr,matrix[2*4+3]) + MUL(sg,matrix[3*4+3]) +
   1.120 +        MUL(sb,matrix[4*4+3]) + matrix[5*4+3] + 8)>>(2*SHIFT - 8);
   1.121 +    dest[i] = oil_argb(da, dr, dg, db);
   1.122 +  }
   1.123 +
   1.124 +}
   1.125 +OIL_DEFINE_IMPL_REF (colorspace_argb_ref, colorspace_argb);
   1.126 +
   1.127 +
   1.128 +static void
   1.129 +ayuv2argb_u8_ref (uint8_t *argb, const uint8_t *ayuv, int n)
   1.130 +{
   1.131 +  int i;
   1.132 +
   1.133 +  for(i=0;i<n;i++){
   1.134 +    argb[0] = ayuv[0];
   1.135 +    argb[1] = YUV_TO_R_INT8(ayuv[1], ayuv[2], ayuv[3]);
   1.136 +    argb[2] = YUV_TO_G_INT8(ayuv[1], ayuv[2], ayuv[3]);
   1.137 +    argb[3] = YUV_TO_B_INT8(ayuv[1], ayuv[2], ayuv[3]);
   1.138 +    argb+=4;
   1.139 +    ayuv+=4;
   1.140 +  }
   1.141 +
   1.142 +}
   1.143 +OIL_DEFINE_IMPL_REF (ayuv2argb_u8_ref, ayuv2argb_u8);
   1.144 +
   1.145 +
   1.146 +
   1.147 +
   1.148 +#ifdef	__SYMBIAN32__
   1.149 + 
   1.150 +OilFunctionClass* __oil_function_class_ayuv2argb_u8() {
   1.151 +		return &_oil_function_class_ayuv2argb_u8;
   1.152 +}
   1.153 +#endif
   1.154 +
   1.155 +#ifdef	__SYMBIAN32__
   1.156 + 
   1.157 +OilFunctionClass* __oil_function_class_colorspace_argb() {
   1.158 +		return &_oil_function_class_colorspace_argb;
   1.159 +}
   1.160 +#endif
   1.161 +
   1.162 +
   1.163 +
   1.164 +#ifdef	__SYMBIAN32__
   1.165 + 
   1.166 +OilFunctionImpl* __oil_function_impl_colorspace_argb_ref() {
   1.167 +		return &_oil_function_impl_colorspace_argb_ref;
   1.168 +}
   1.169 +#endif
   1.170 +
   1.171 +#ifdef	__SYMBIAN32__
   1.172 + 
   1.173 +OilFunctionImpl* __oil_function_impl_ayuv2argb_u8_ref() {
   1.174 +		return &_oil_function_impl_ayuv2argb_u8_ref;
   1.175 +}
   1.176 +#endif
   1.177 +
   1.178 +
   1.179 +
   1.180 +#ifdef	__SYMBIAN32__
   1.181 + 
   1.182 +EXPORT_C void** _oil_function_class_ptr_ayuv2argb_u8 ()	{
   1.183 +	oil_function_class_ptr_ayuv2argb_u8 = __oil_function_class_ayuv2argb_u8();
   1.184 +	return &oil_function_class_ptr_ayuv2argb_u8->func;
   1.185 +	}
   1.186 +#endif
   1.187 +
   1.188 +#ifdef	__SYMBIAN32__
   1.189 + 
   1.190 +EXPORT_C void** _oil_function_class_ptr_colorspace_argb ()	{
   1.191 +	oil_function_class_ptr_colorspace_argb = __oil_function_class_colorspace_argb();
   1.192 +	return &oil_function_class_ptr_colorspace_argb->func;
   1.193 +	}
   1.194 +#endif
   1.195 +