1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "rs_core.rsh"
18
19
20 #define CVT_FUNC_2(typeout, typein) \
21 extern typeout##2 __attribute__((const, overloadable)) \
22 convert_##typeout##2(typein##2 i) { \
23 return __builtin_convertvector(i, typeout##2); \
24 } \
25 extern typeout##3 __attribute__((const, overloadable)) \
26 convert_##typeout##3(typein##3 i) { \
27 return __builtin_convertvector(i, typeout##3); \
28 } \
29 extern typeout##4 __attribute__((const, overloadable)) \
30 convert_##typeout##4(typein##4 i) { \
31 return __builtin_convertvector(i, typeout##4); \
32 }
33 #define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
34 CVT_FUNC_2(type, char) \
35 CVT_FUNC_2(type, ushort) \
36 CVT_FUNC_2(type, short) \
37 CVT_FUNC_2(type, uint) \
38 CVT_FUNC_2(type, int) \
39 CVT_FUNC_2(type, ulong) \
40 CVT_FUNC_2(type, long) \
41 CVT_FUNC_2(type, half) \
42 CVT_FUNC_2(type, float) \
43 CVT_FUNC_2(type, double)
44
45 CVT_FUNC(char)
46 CVT_FUNC(uchar)
47 CVT_FUNC(short)
48 CVT_FUNC(ushort)
49 CVT_FUNC(int)
50 CVT_FUNC(uint)
51 CVT_FUNC(long)
52 CVT_FUNC(ulong)
53 CVT_FUNC(half)
54 CVT_FUNC(float)
55 CVT_FUNC(double)
56
57
58 /*
59 * YUV float4 version
60 */
61
62 static float4 yuv_U_values = {0.f, -0.392f * 0.003921569f, +2.02 * 0.003921569f, 0.f};
63 static float4 yuv_V_values = {1.603f * 0.003921569f, -0.815f * 0.003921569f, 0.f, 0.f};
64
rsYuvToRGBA_float4(uchar y,uchar u,uchar v)65 extern float4 __attribute__((overloadable)) rsYuvToRGBA_float4(uchar y, uchar u, uchar v) {
66 float4 color = (float)y * 0.003921569f;
67 float4 fU = ((float)u) - 128.f;
68 float4 fV = ((float)v) - 128.f;
69
70 color += fU * yuv_U_values;
71 color += fV * yuv_V_values;
72 color = clamp(color, 0.f, 1.f);
73 return color;
74 }
75
76