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, float)     \
42                         CVT_FUNC_2(type, double)
43 
44 CVT_FUNC(char)
45 CVT_FUNC(uchar)
46 CVT_FUNC(short)
47 CVT_FUNC(ushort)
48 CVT_FUNC(int)
49 CVT_FUNC(uint)
50 CVT_FUNC(long)
51 CVT_FUNC(ulong)
52 CVT_FUNC(float)
53 CVT_FUNC(double)
54 
55 
56 /*
57  * YUV float4 version
58  */
59 
60 static float4 yuv_U_values = {0.f, -0.392f * 0.003921569f, +2.02 * 0.003921569f, 0.f};
61 static float4 yuv_V_values = {1.603f * 0.003921569f, -0.815f * 0.003921569f, 0.f, 0.f};
62 
rsYuvToRGBA_float4(uchar y,uchar u,uchar v)63 extern float4 __attribute__((overloadable)) rsYuvToRGBA_float4(uchar y, uchar u, uchar v) {
64     float4 color = (float)y * 0.003921569f;
65     float4 fU = ((float)u) - 128.f;
66     float4 fV = ((float)v) - 128.f;
67 
68     color += fU * yuv_U_values;
69     color += fV * yuv_V_values;
70     color = clamp(color, 0.f, 1.f);
71     return color;
72 }
73 
74