First public contribution.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboil.h>
34 #include <liboil/liboiltest.h>
45 * Converts YUV pixels to RGB pixels. Each YUV component is in a
46 * separate source array, and are combined and converted to RGB.
48 * This function should be replaced by one that makes sense.
50 OIL_DEFINE_CLASS (yuv2rgbx_u8,
51 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
53 * oil_yuv2rgbx_sub2_u8:
60 * Converts YUV pixels to RGB pixels. Each YUV component is in a
61 * separate source array, and are combined and converted to RGB.
62 * The U and V arrays are subsampled by a factor of 2, so only
63 * half of each array is used.
65 * This function should be replaced by one that makes sense.
67 OIL_DEFINE_CLASS (yuv2rgbx_sub2_u8,
68 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
70 * oil_yuv2rgbx_sub4_u8:
77 * Converts YUV pixels to RGB pixels. Each YUV component is in a
78 * separate source array, and are combined and converted to RGB.
79 * The U and V arrays are subsampled by a factor of 4, so only
80 * a quarter of each array is used.
82 * This function should be replaced by one that makes sense.
84 OIL_DEFINE_CLASS (yuv2rgbx_sub4_u8,
85 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n");
87 #define clamp(x,a,b) clamp_lower(clamp_upper(x,b),a)
88 #define clamp_lower(x,a) ((x<a)?(a):(x))
89 #define clamp_upper(x,b) ((x>b)?(b):(x))
91 /* from the JFIF spec */
92 #define YUV_TO_R(y,u,v) clamp((y) + 1.402*((v)-128),0,255)
93 #define YUV_TO_G(y,u,v) clamp((y) - 0.34414*((u)-128) - 0.71414*((v)-128),0,255)
94 #define YUV_TO_B(y,u,v) clamp((y) + 1.772*((u)-128),0,255)
96 #define YUV_TO_R_INT(y,u,v) clamp(((y)*256 + 358*((v)-128))>>8,0,255)
97 #define YUV_TO_G_INT(y,u,v) clamp(((y)*256 - 88*((u)-128) - 183*((v)-128))>>8,0,255)
98 #define YUV_TO_B_INT(y,u,v) clamp(((y)*256 + 454*((u)-128))>>8,0,255)
102 yuv2rgbx_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
107 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
108 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
109 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
118 OIL_DEFINE_IMPL_REF (yuv2rgbx_u8_ref, yuv2rgbx_u8);
120 #ifdef ENABLE_BROKEN_IMPLS
122 yuv2rgbx_u8_int (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
127 rgbp[0] = YUV_TO_R_INT(yp[0], up[0], vp[0]);
128 rgbp[1] = YUV_TO_G_INT(yp[0], up[0], vp[0]);
129 rgbp[2] = YUV_TO_B_INT(yp[0], up[0], vp[0]);
138 OIL_DEFINE_IMPL (yuv2rgbx_u8_int, yuv2rgbx_u8);
142 yuv2rgbx_sub2_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
147 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
148 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
149 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
153 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
154 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
155 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
164 OIL_DEFINE_IMPL_REF (yuv2rgbx_sub2_u8_ref, yuv2rgbx_sub2_u8);
167 yuv2rgbx_sub4_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n)
172 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
173 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
174 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
178 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
179 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
180 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
184 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
185 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
186 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
190 rgbp[0] = YUV_TO_R(yp[0], up[0], vp[0]);
191 rgbp[1] = YUV_TO_G(yp[0], up[0], vp[0]);
192 rgbp[2] = YUV_TO_B(yp[0], up[0], vp[0]);
201 OIL_DEFINE_IMPL_REF (yuv2rgbx_sub4_u8_ref, yuv2rgbx_sub4_u8);
207 OilFunctionClass* __oil_function_class_yuv2rgbx_u8() {
208 return &_oil_function_class_yuv2rgbx_u8;
214 OilFunctionClass* __oil_function_class_yuv2rgbx_sub2_u8() {
215 return &_oil_function_class_yuv2rgbx_sub2_u8;
221 OilFunctionClass* __oil_function_class_yuv2rgbx_sub4_u8() {
222 return &_oil_function_class_yuv2rgbx_sub4_u8;
230 OilFunctionImpl* __oil_function_impl_yuv2rgbx_u8_ref() {
231 return &_oil_function_impl_yuv2rgbx_u8_ref;
239 OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub2_u8_ref() {
240 return &_oil_function_impl_yuv2rgbx_sub2_u8_ref;
246 OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub4_u8_ref() {
247 return &_oil_function_impl_yuv2rgbx_sub4_u8_ref;
255 EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_u8 () {
256 oil_function_class_ptr_yuv2rgbx_u8 = __oil_function_class_yuv2rgbx_u8();
257 return &oil_function_class_ptr_yuv2rgbx_u8->func;
263 EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_sub2_u8 () {
264 oil_function_class_ptr_yuv2rgbx_sub2_u8 = __oil_function_class_yuv2rgbx_sub2_u8();
265 return &oil_function_class_ptr_yuv2rgbx_sub2_u8->func;
271 EXPORT_C void** _oil_function_class_ptr_yuv2rgbx_sub4_u8 () {
272 oil_function_class_ptr_yuv2rgbx_sub4_u8 = __oil_function_class_yuv2rgbx_sub4_u8();
273 return &oil_function_class_ptr_yuv2rgbx_sub4_u8->func;