blob: 81f36c929106f1a030786d190bf0f18f0176b64a [file] [log] [blame]
Jason Samse1e08b42012-09-04 16:49:19 -07001/*
2 * Copyright (C) 2012 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
18
19typedef uint8_t uchar;
20typedef uint16_t ushort;
21typedef uint32_t uint;
22
23typedef float float2 __attribute__((ext_vector_type(2)));
24typedef float float3 __attribute__((ext_vector_type(3)));
25typedef float float4 __attribute__((ext_vector_type(4)));
26typedef uchar uchar2 __attribute__((ext_vector_type(2)));
27typedef uchar uchar3 __attribute__((ext_vector_type(3)));
28typedef uchar uchar4 __attribute__((ext_vector_type(4)));
29typedef ushort ushort2 __attribute__((ext_vector_type(2)));
30typedef ushort ushort3 __attribute__((ext_vector_type(3)));
31typedef ushort ushort4 __attribute__((ext_vector_type(4)));
32typedef uint uint2 __attribute__((ext_vector_type(2)));
33typedef uint uint3 __attribute__((ext_vector_type(3)));
34typedef uint uint4 __attribute__((ext_vector_type(4)));
35typedef char char2 __attribute__((ext_vector_type(2)));
36typedef char char3 __attribute__((ext_vector_type(3)));
37typedef char char4 __attribute__((ext_vector_type(4)));
38typedef short short2 __attribute__((ext_vector_type(2)));
39typedef short short3 __attribute__((ext_vector_type(3)));
40typedef short short4 __attribute__((ext_vector_type(4)));
41typedef int int2 __attribute__((ext_vector_type(2)));
42typedef int int3 __attribute__((ext_vector_type(3)));
43typedef int int4 __attribute__((ext_vector_type(4)));
44typedef long long2 __attribute__((ext_vector_type(2)));
45typedef long long3 __attribute__((ext_vector_type(3)));
46typedef long long4 __attribute__((ext_vector_type(4)));
47
48enum IntrinsicEnums {
49 INTRINSIC_UNDEFINED,
50 INTRINSIC_CONVOLVE_3x3,
51 INTRINXIC_COLORMATRIX
52
53};
54
Jason Sams3b35d772013-06-25 17:47:02 -070055#define CVT_FUNC_2(typeout, typein) \
56static inline typeout##2 __attribute__((const, overloadable)) \
57 convert_##typeout##2(typein##2 i) { \
Jason Sams70404fa2014-05-05 14:31:22 -070058 return __builtin_convertvector(i, typeout##2); \
Jason Sams3b35d772013-06-25 17:47:02 -070059 } \
60static inline typeout##3 __attribute__((const, overloadable)) \
61 convert_##typeout##3(typein##3 i) { \
Jason Sams70404fa2014-05-05 14:31:22 -070062 return __builtin_convertvector(i, typeout##3); \
Jason Sams3b35d772013-06-25 17:47:02 -070063 } \
64static inline typeout##4 __attribute__((const, overloadable)) \
65 convert_##typeout##4(typein##4 i) { \
Jason Sams70404fa2014-05-05 14:31:22 -070066 return __builtin_convertvector(i, typeout##4); \
Jason Sams3b35d772013-06-25 17:47:02 -070067 }
68#define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
69 CVT_FUNC_2(type, char) \
70 CVT_FUNC_2(type, ushort) \
71 CVT_FUNC_2(type, short) \
72 CVT_FUNC_2(type, uint) \
73 CVT_FUNC_2(type, int) \
74 CVT_FUNC_2(type, float)
Jason Sams70404fa2014-05-05 14:31:22 -070075
Jason Sams3b35d772013-06-25 17:47:02 -070076CVT_FUNC(char)
77CVT_FUNC(uchar)
78CVT_FUNC(short)
79CVT_FUNC(ushort)
80CVT_FUNC(int)
81CVT_FUNC(uint)
82CVT_FUNC(float)
Jason Sams537c4412012-09-04 19:55:55 -070083
Jason Samse1e08b42012-09-04 16:49:19 -070084
85static inline int4 clamp(int4 amount, int low, int high) {
86 int4 r;
87 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
88 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
89 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
90 r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
91 return r;
92}
93
Jason Samsd85e2832012-09-11 16:04:27 -070094static inline float4 clamp(float4 amount, float low, float high) {
95 float4 r;
96 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
97 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
98 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
99 r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
100 return r;
101}
102
Jason Sams3b35d772013-06-25 17:47:02 -0700103static inline int2 clamp(int2 amount, int low, int high) {
104 int2 r;
105 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
106 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
107 return r;
108}
109
110static inline float2 clamp(float2 amount, float low, float high) {
111 float2 r;
112 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
113 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
114 return r;
115}
116
117static inline int clamp(int amount, int low, int high) {
118 return amount < low ? low : (amount > high ? high : amount);
119}
120
121static inline float clamp(float amount, float low, float high) {
122 return amount < low ? low : (amount > high ? high : amount);
123}
Jason Samsd85e2832012-09-11 16:04:27 -0700124