os/ossrv/genericopenlibs/liboil/src/jpeg/yuv2rgb_c.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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/liboiltest.h>
sl@0
    35
#include "jpeg.h"
sl@0
    36
sl@0
    37
/**
sl@0
    38
 * oil_yuv2rgbx_u8:
sl@0
    39
 * @d_4xn:
sl@0
    40
 * @src1: Y component
sl@0
    41
 * @src2: U component
sl@0
    42
 * @src3: V component
sl@0
    43
 * @n:
sl@0
    44
 *
sl@0
    45
 * Converts YUV pixels to RGB pixels.  Each YUV component is in a
sl@0
    46
 * separate source array, and are combined and converted to RGB.
sl@0
    47
 *
sl@0
    48
 * This function should be replaced by one that makes sense.
sl@0
    49
 */
sl@0
    50
OIL_DEFINE_CLASS (yuv2rgbx_u8,
sl@0
    51
    "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
sl@0
    52
/**
sl@0
    53
 * oil_yuv2rgbx_sub2_u8:
sl@0
    54
 * @d_4xn:
sl@0
    55
 * @src1: Y component
sl@0
    56
 * @src2: U component
sl@0
    57
 * @src3: V component
sl@0
    58
 * @n:
sl@0
    59
 *
sl@0
    60
 * Converts YUV pixels to RGB pixels.  Each YUV component is in a
sl@0
    61
 * separate source array, and are combined and converted to RGB.
sl@0
    62
 * The U and V arrays are subsampled by a factor of 2, so only
sl@0
    63
 * half of each array is used.
sl@0
    64
 *
sl@0
    65
 * This function should be replaced by one that makes sense.
sl@0
    66
 */
sl@0
    67
OIL_DEFINE_CLASS (yuv2rgbx_sub2_u8,
sl@0
    68
    "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
sl@0
    69
/**
sl@0
    70
 * oil_yuv2rgbx_sub4_u8:
sl@0
    71
 * @d_4xn:
sl@0
    72
 * @src1: Y component
sl@0
    73
 * @src2: U component
sl@0
    74
 * @src3: V component
sl@0
    75
 * @n:
sl@0
    76
 *
sl@0
    77
 * Converts YUV pixels to RGB pixels.  Each YUV component is in a
sl@0
    78
 * separate source array, and are combined and converted to RGB.
sl@0
    79
 * The U and V arrays are subsampled by a factor of 4, so only
sl@0
    80
 * a quarter of each array is used.
sl@0
    81
 *
sl@0
    82
 * This function should be replaced by one that makes sense.
sl@0
    83
 */
sl@0
    84
OIL_DEFINE_CLASS (yuv2rgbx_sub4_u8,
sl@0
    85
    "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
sl@0
    86
sl@0
    87
#define clamp(x,a,b) clamp_lower(clamp_upper(x,b),a)
sl@0
    88
#define clamp_lower(x,a) ((x<a)?(a):(x))
sl@0
    89
#define clamp_upper(x,b) ((x>b)?(b):(x))
sl@0
    90
sl@0
    91
/* from the JFIF spec */
sl@0
    92
#define YUV_TO_R(y,u,v) clamp((y) + 1.402*((v)-128),0,255)
sl@0
    93
#define YUV_TO_G(y,u,v) clamp((y) - 0.34414*((u)-128) - 0.71414*((v)-128),0,255)
sl@0
    94
#define YUV_TO_B(y,u,v) clamp((y) + 1.772*((u)-128),0,255)
sl@0
    95
sl@0
    96
#define YUV_TO_R_INT(y,u,v) clamp(((y)*256 + 358*((v)-128))>>8,0,255)
sl@0
    97
#define YUV_TO_G_INT(y,u,v) clamp(((y)*256 - 88*((u)-128) - 183*((v)-128))>>8,0,255)
sl@0
    98
#define YUV_TO_B_INT(y,u,v) clamp(((y)*256 + 454*((u)-128))>>8,0,255)
sl@0
    99
sl@0
   100
sl@0
   101
static void
sl@0
   102
yuv2rgbx_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
sl@0
   103
{
sl@0
   104
	int i;
sl@0
   105
sl@0
   106
	for(i=0;i<n;i++){
sl@0
   107
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   108
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   109
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   110
		rgbp[3] = 0;
sl@0
   111
		rgbp+=4;
sl@0
   112
		yp++;
sl@0
   113
		up++;
sl@0
   114
		vp++;
sl@0
   115
	}
sl@0
   116
}
sl@0
   117
sl@0
   118
OIL_DEFINE_IMPL_REF (yuv2rgbx_u8_ref, yuv2rgbx_u8);
sl@0
   119
sl@0
   120
#ifdef ENABLE_BROKEN_IMPLS
sl@0
   121
static void
sl@0
   122
yuv2rgbx_u8_int (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
sl@0
   123
{
sl@0
   124
	int i;
sl@0
   125
sl@0
   126
	for(i=0;i<n;i++){
sl@0
   127
		rgbp[0] = YUV_TO_R_INT(yp[0], up[0], vp[0]);
sl@0
   128
		rgbp[1] = YUV_TO_G_INT(yp[0], up[0], vp[0]);
sl@0
   129
		rgbp[2] = YUV_TO_B_INT(yp[0], up[0], vp[0]);
sl@0
   130
		rgbp[3] = 0;
sl@0
   131
		rgbp+=4;
sl@0
   132
		yp++;
sl@0
   133
		up++;
sl@0
   134
		vp++;
sl@0
   135
	}
sl@0
   136
}
sl@0
   137
sl@0
   138
OIL_DEFINE_IMPL (yuv2rgbx_u8_int, yuv2rgbx_u8);
sl@0
   139
#endif
sl@0
   140
sl@0
   141
static void
sl@0
   142
yuv2rgbx_sub2_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
sl@0
   143
{
sl@0
   144
	int i;
sl@0
   145
sl@0
   146
	for(i=0;i<n/2;i++){
sl@0
   147
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   148
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   149
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   150
		rgbp[3] = 0;
sl@0
   151
		rgbp+=4;
sl@0
   152
		yp++;
sl@0
   153
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   154
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   155
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   156
		rgbp[3] = 0;
sl@0
   157
		rgbp+=4;
sl@0
   158
		yp++;
sl@0
   159
		up++;
sl@0
   160
		vp++;
sl@0
   161
	}
sl@0
   162
}
sl@0
   163
sl@0
   164
OIL_DEFINE_IMPL_REF (yuv2rgbx_sub2_u8_ref, yuv2rgbx_sub2_u8);
sl@0
   165
sl@0
   166
static void
sl@0
   167
yuv2rgbx_sub4_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
sl@0
   168
{
sl@0
   169
	int i;
sl@0
   170
sl@0
   171
	for(i=0;i<n/4;i++){
sl@0
   172
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   173
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   174
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   175
		rgbp[3] = 0;
sl@0
   176
		rgbp+=4;
sl@0
   177
		yp++;
sl@0
   178
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   179
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   180
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   181
		rgbp[3] = 0;
sl@0
   182
		rgbp+=4;
sl@0
   183
		yp++;
sl@0
   184
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   185
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   186
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   187
		rgbp[3] = 0;
sl@0
   188
		rgbp+=4;
sl@0
   189
		yp++;
sl@0
   190
		rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
sl@0
   191
		rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
sl@0
   192
		rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
sl@0
   193
		rgbp[3] = 0;
sl@0
   194
		rgbp+=4;
sl@0
   195
		yp++;
sl@0
   196
		up++;
sl@0
   197
		vp++;
sl@0
   198
	}
sl@0
   199
}
sl@0
   200
sl@0
   201
OIL_DEFINE_IMPL_REF (yuv2rgbx_sub4_u8_ref, yuv2rgbx_sub4_u8);
sl@0
   202
sl@0
   203
sl@0
   204
sl@0
   205
#ifdef	__SYMBIAN32__
sl@0
   206
 
sl@0
   207
OilFunctionClass* __oil_function_class_yuv2rgbx_u8() {
sl@0
   208
		return &_oil_function_class_yuv2rgbx_u8;
sl@0
   209
}
sl@0
   210
#endif
sl@0
   211
sl@0
   212
#ifdef	__SYMBIAN32__
sl@0
   213
 
sl@0
   214
OilFunctionClass* __oil_function_class_yuv2rgbx_sub2_u8() {
sl@0
   215
		return &_oil_function_class_yuv2rgbx_sub2_u8;
sl@0
   216
}
sl@0
   217
#endif
sl@0
   218
sl@0
   219
#ifdef	__SYMBIAN32__
sl@0
   220
 
sl@0
   221
OilFunctionClass* __oil_function_class_yuv2rgbx_sub4_u8() {
sl@0
   222
		return &_oil_function_class_yuv2rgbx_sub4_u8;
sl@0
   223
}
sl@0
   224
#endif
sl@0
   225
sl@0
   226
sl@0
   227
sl@0
   228
#ifdef	__SYMBIAN32__
sl@0
   229
 
sl@0
   230
OilFunctionImpl* __oil_function_impl_yuv2rgbx_u8_ref() {
sl@0
   231
		return &_oil_function_impl_yuv2rgbx_u8_ref;
sl@0
   232
}
sl@0
   233
#endif
sl@0
   234
sl@0
   235
sl@0
   236
sl@0
   237
#ifdef	__SYMBIAN32__
sl@0
   238
 
sl@0
   239
OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub2_u8_ref() {
sl@0
   240
		return &_oil_function_impl_yuv2rgbx_sub2_u8_ref;
sl@0
   241
}
sl@0
   242
#endif
sl@0
   243
sl@0
   244
#ifdef	__SYMBIAN32__
sl@0
   245
 
sl@0
   246
OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub4_u8_ref() {
sl@0
   247
		return &_oil_function_impl_yuv2rgbx_sub4_u8_ref;
sl@0
   248
}
sl@0
   249
#endif
sl@0
   250
sl@0
   251
sl@0
   252
sl@0
   253
#ifdef	__SYMBIAN32__
sl@0
   254
 
sl@0
   255
EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_u8 ()	{
sl@0
   256
	oil_function_class_ptr_yuv2rgbx_u8 = __oil_function_class_yuv2rgbx_u8();
sl@0
   257
	return &oil_function_class_ptr_yuv2rgbx_u8->func;
sl@0
   258
	}
sl@0
   259
#endif
sl@0
   260
sl@0
   261
#ifdef	__SYMBIAN32__
sl@0
   262
 
sl@0
   263
EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_sub2_u8 ()	{
sl@0
   264
	oil_function_class_ptr_yuv2rgbx_sub2_u8 = __oil_function_class_yuv2rgbx_sub2_u8();
sl@0
   265
	return &oil_function_class_ptr_yuv2rgbx_sub2_u8->func;
sl@0
   266
	}
sl@0
   267
#endif
sl@0
   268
sl@0
   269
#ifdef	__SYMBIAN32__
sl@0
   270
 
sl@0
   271
EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_sub4_u8 ()	{
sl@0
   272
	oil_function_class_ptr_yuv2rgbx_sub4_u8 = __oil_function_class_yuv2rgbx_sub4_u8();
sl@0
   273
	return &oil_function_class_ptr_yuv2rgbx_sub4_u8->func;
sl@0
   274
	}
sl@0
   275
#endif
sl@0
   276