|
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/liboiltest.h> |
|
35 #include "jpeg.h" |
|
36 |
|
37 /** |
|
38 * oil_yuv2rgbx_u8: |
|
39 * @d_4xn: |
|
40 * @src1: Y component |
|
41 * @src2: U component |
|
42 * @src3: V component |
|
43 * @n: |
|
44 * |
|
45 * Converts YUV pixels to RGB pixels. Each YUV component is in a |
|
46 * separate source array, and are combined and converted to RGB. |
|
47 * |
|
48 * This function should be replaced by one that makes sense. |
|
49 */ |
|
50 OIL_DEFINE_CLASS (yuv2rgbx_u8, |
|
51 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n"); |
|
52 /** |
|
53 * oil_yuv2rgbx_sub2_u8: |
|
54 * @d_4xn: |
|
55 * @src1: Y component |
|
56 * @src2: U component |
|
57 * @src3: V component |
|
58 * @n: |
|
59 * |
|
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. |
|
64 * |
|
65 * This function should be replaced by one that makes sense. |
|
66 */ |
|
67 OIL_DEFINE_CLASS (yuv2rgbx_sub2_u8, |
|
68 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n"); |
|
69 /** |
|
70 * oil_yuv2rgbx_sub4_u8: |
|
71 * @d_4xn: |
|
72 * @src1: Y component |
|
73 * @src2: U component |
|
74 * @src3: V component |
|
75 * @n: |
|
76 * |
|
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. |
|
81 * |
|
82 * This function should be replaced by one that makes sense. |
|
83 */ |
|
84 OIL_DEFINE_CLASS (yuv2rgbx_sub4_u8, |
|
85 "uint8_t *d_4xn, uint8_t *src1, uint8_t *src2, uint8_t *src3, int n"); |
|
86 |
|
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)) |
|
90 |
|
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) |
|
95 |
|
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) |
|
99 |
|
100 |
|
101 static void |
|
102 yuv2rgbx_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n) |
|
103 { |
|
104 int i; |
|
105 |
|
106 for(i=0;i<n;i++){ |
|
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]); |
|
110 rgbp[3] = 0; |
|
111 rgbp+=4; |
|
112 yp++; |
|
113 up++; |
|
114 vp++; |
|
115 } |
|
116 } |
|
117 |
|
118 OIL_DEFINE_IMPL_REF (yuv2rgbx_u8_ref, yuv2rgbx_u8); |
|
119 |
|
120 #ifdef ENABLE_BROKEN_IMPLS |
|
121 static void |
|
122 yuv2rgbx_u8_int (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n) |
|
123 { |
|
124 int i; |
|
125 |
|
126 for(i=0;i<n;i++){ |
|
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]); |
|
130 rgbp[3] = 0; |
|
131 rgbp+=4; |
|
132 yp++; |
|
133 up++; |
|
134 vp++; |
|
135 } |
|
136 } |
|
137 |
|
138 OIL_DEFINE_IMPL (yuv2rgbx_u8_int, yuv2rgbx_u8); |
|
139 #endif |
|
140 |
|
141 static void |
|
142 yuv2rgbx_sub2_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n) |
|
143 { |
|
144 int i; |
|
145 |
|
146 for(i=0;i<n/2;i++){ |
|
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]); |
|
150 rgbp[3] = 0; |
|
151 rgbp+=4; |
|
152 yp++; |
|
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]); |
|
156 rgbp[3] = 0; |
|
157 rgbp+=4; |
|
158 yp++; |
|
159 up++; |
|
160 vp++; |
|
161 } |
|
162 } |
|
163 |
|
164 OIL_DEFINE_IMPL_REF (yuv2rgbx_sub2_u8_ref, yuv2rgbx_sub2_u8); |
|
165 |
|
166 static void |
|
167 yuv2rgbx_sub4_u8_ref (uint8_t *rgbp, uint8_t *yp, uint8_t *up, uint8_t *vp, int n) |
|
168 { |
|
169 int i; |
|
170 |
|
171 for(i=0;i<n/4;i++){ |
|
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]); |
|
175 rgbp[3] = 0; |
|
176 rgbp+=4; |
|
177 yp++; |
|
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]); |
|
181 rgbp[3] = 0; |
|
182 rgbp+=4; |
|
183 yp++; |
|
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]); |
|
187 rgbp[3] = 0; |
|
188 rgbp+=4; |
|
189 yp++; |
|
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]); |
|
193 rgbp[3] = 0; |
|
194 rgbp+=4; |
|
195 yp++; |
|
196 up++; |
|
197 vp++; |
|
198 } |
|
199 } |
|
200 |
|
201 OIL_DEFINE_IMPL_REF (yuv2rgbx_sub4_u8_ref, yuv2rgbx_sub4_u8); |
|
202 |
|
203 |
|
204 |
|
205 #ifdef __SYMBIAN32__ |
|
206 |
|
207 OilFunctionClass* __oil_function_class_yuv2rgbx_u8() { |
|
208 return &_oil_function_class_yuv2rgbx_u8; |
|
209 } |
|
210 #endif |
|
211 |
|
212 #ifdef __SYMBIAN32__ |
|
213 |
|
214 OilFunctionClass* __oil_function_class_yuv2rgbx_sub2_u8() { |
|
215 return &_oil_function_class_yuv2rgbx_sub2_u8; |
|
216 } |
|
217 #endif |
|
218 |
|
219 #ifdef __SYMBIAN32__ |
|
220 |
|
221 OilFunctionClass* __oil_function_class_yuv2rgbx_sub4_u8() { |
|
222 return &_oil_function_class_yuv2rgbx_sub4_u8; |
|
223 } |
|
224 #endif |
|
225 |
|
226 |
|
227 |
|
228 #ifdef __SYMBIAN32__ |
|
229 |
|
230 OilFunctionImpl* __oil_function_impl_yuv2rgbx_u8_ref() { |
|
231 return &_oil_function_impl_yuv2rgbx_u8_ref; |
|
232 } |
|
233 #endif |
|
234 |
|
235 |
|
236 |
|
237 #ifdef __SYMBIAN32__ |
|
238 |
|
239 OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub2_u8_ref() { |
|
240 return &_oil_function_impl_yuv2rgbx_sub2_u8_ref; |
|
241 } |
|
242 #endif |
|
243 |
|
244 #ifdef __SYMBIAN32__ |
|
245 |
|
246 OilFunctionImpl* __oil_function_impl_yuv2rgbx_sub4_u8_ref() { |
|
247 return &_oil_function_impl_yuv2rgbx_sub4_u8_ref; |
|
248 } |
|
249 #endif |
|
250 |
|
251 |
|
252 |
|
253 #ifdef __SYMBIAN32__ |
|
254 |
|
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; |
|
258 } |
|
259 #endif |
|
260 |
|
261 #ifdef __SYMBIAN32__ |
|
262 |
|
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; |
|
266 } |
|
267 #endif |
|
268 |
|
269 #ifdef __SYMBIAN32__ |
|
270 |
|
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; |
|
274 } |
|
275 #endif |
|
276 |