Jason Sams | e1e08b4 | 2012-09-04 16:49:19 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | typedef uint8_t uchar; |
| 20 | typedef uint16_t ushort; |
| 21 | typedef uint32_t uint; |
| 22 | |
| 23 | typedef float float2 __attribute__((ext_vector_type(2))); |
| 24 | typedef float float3 __attribute__((ext_vector_type(3))); |
| 25 | typedef float float4 __attribute__((ext_vector_type(4))); |
| 26 | typedef uchar uchar2 __attribute__((ext_vector_type(2))); |
| 27 | typedef uchar uchar3 __attribute__((ext_vector_type(3))); |
| 28 | typedef uchar uchar4 __attribute__((ext_vector_type(4))); |
| 29 | typedef ushort ushort2 __attribute__((ext_vector_type(2))); |
| 30 | typedef ushort ushort3 __attribute__((ext_vector_type(3))); |
| 31 | typedef ushort ushort4 __attribute__((ext_vector_type(4))); |
| 32 | typedef uint uint2 __attribute__((ext_vector_type(2))); |
| 33 | typedef uint uint3 __attribute__((ext_vector_type(3))); |
| 34 | typedef uint uint4 __attribute__((ext_vector_type(4))); |
| 35 | typedef char char2 __attribute__((ext_vector_type(2))); |
| 36 | typedef char char3 __attribute__((ext_vector_type(3))); |
| 37 | typedef char char4 __attribute__((ext_vector_type(4))); |
| 38 | typedef short short2 __attribute__((ext_vector_type(2))); |
| 39 | typedef short short3 __attribute__((ext_vector_type(3))); |
| 40 | typedef short short4 __attribute__((ext_vector_type(4))); |
| 41 | typedef int int2 __attribute__((ext_vector_type(2))); |
| 42 | typedef int int3 __attribute__((ext_vector_type(3))); |
| 43 | typedef int int4 __attribute__((ext_vector_type(4))); |
| 44 | typedef long long2 __attribute__((ext_vector_type(2))); |
| 45 | typedef long long3 __attribute__((ext_vector_type(3))); |
| 46 | typedef long long4 __attribute__((ext_vector_type(4))); |
| 47 | |
| 48 | enum IntrinsicEnums { |
| 49 | INTRINSIC_UNDEFINED, |
| 50 | INTRINSIC_CONVOLVE_3x3, |
| 51 | INTRINXIC_COLORMATRIX |
| 52 | |
| 53 | }; |
| 54 | |
| 55 | static inline int4 convert_int4(uchar4 i) { |
| 56 | int4 f4 = {i.x, i.y, i.z, i.w}; |
| 57 | return f4; |
| 58 | } |
| 59 | |
| 60 | static inline short4 convert_short4(uchar4 i) { |
| 61 | short4 f4 = {i.x, i.y, i.z, i.w}; |
| 62 | return f4; |
| 63 | } |
| 64 | |
| 65 | static inline float4 convert_float4(uchar4 i) { |
| 66 | float4 f4 = {i.x, i.y, i.z, i.w}; |
| 67 | return f4; |
| 68 | } |
| 69 | |
| 70 | static inline uchar4 convert_uchar4(int4 i) { |
| 71 | uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w}; |
| 72 | return f4; |
| 73 | } |
| 74 | |
Jason Sams | 537c441 | 2012-09-04 19:55:55 -0700 | [diff] [blame] | 75 | static inline uchar4 convert_uchar4(float4 i) { |
| 76 | uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w}; |
| 77 | return f4; |
| 78 | } |
| 79 | |
Jason Sams | e1e08b4 | 2012-09-04 16:49:19 -0700 | [diff] [blame] | 80 | |
| 81 | static inline int4 clamp(int4 amount, int low, int high) { |
| 82 | int4 r; |
| 83 | r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); |
| 84 | r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); |
| 85 | r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); |
| 86 | r.w = amount.w < low ? low : (amount.w > high ? high : amount.w); |
| 87 | return r; |
| 88 | } |
| 89 | |