blob: d6644cab9a2c1e7fbaa7edfa3262b85302755df4 [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
55static inline int4 convert_int4(uchar4 i) {
56 int4 f4 = {i.x, i.y, i.z, i.w};
57 return f4;
58}
59
Jason Sams7c4b8882013-01-04 10:50:05 -080060static inline uint4 convert_uint4(uchar4 i) {
61 uint4 f4 = {i.x, i.y, i.z, i.w};
62 return f4;
63}
64
65static inline int4 convert_int4(float4 i) {
66 int4 f4 = {i.x, i.y, i.z, i.w};
67 return f4;
68}
69
Jason Samse1e08b42012-09-04 16:49:19 -070070static inline short4 convert_short4(uchar4 i) {
71 short4 f4 = {i.x, i.y, i.z, i.w};
72 return f4;
73}
74
75static inline float4 convert_float4(uchar4 i) {
76 float4 f4 = {i.x, i.y, i.z, i.w};
77 return f4;
78}
79
Jason Sams7c4b8882013-01-04 10:50:05 -080080static inline float4 convert_float4(int4 i) {
81 float4 f4 = {i.x, i.y, i.z, i.w};
82 return f4;
83}
84
Tim Murray36889a02012-09-24 14:52:48 -070085static inline uchar4 convert_uchar4(short4 i) {
86 uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w};
87 return f4;
88}
89
Jason Samse1e08b42012-09-04 16:49:19 -070090static inline uchar4 convert_uchar4(int4 i) {
91 uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w};
92 return f4;
93}
94
Jason Sams7c4b8882013-01-04 10:50:05 -080095static inline uchar4 convert_uchar4(uint4 i) {
96 uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w};
97 return f4;
98}
99
Jason Sams537c4412012-09-04 19:55:55 -0700100static inline uchar4 convert_uchar4(float4 i) {
101 uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w};
102 return f4;
103}
104
Jason Samse1e08b42012-09-04 16:49:19 -0700105
106static inline int4 clamp(int4 amount, int low, int high) {
107 int4 r;
108 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
109 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
110 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
111 r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
112 return r;
113}
114
Jason Samsd85e2832012-09-11 16:04:27 -0700115static inline float4 clamp(float4 amount, float low, float high) {
116 float4 r;
117 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
118 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
119 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
120 r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
121 return r;
122}
123
124