1e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams/* 2e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * Copyright (C) 2012 The Android Open Source Project 3e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * 4e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * you may not use this file except in compliance with the License. 6e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * You may obtain a copy of the License at 7e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * 8e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 9e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * 10e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * Unless required by applicable law or agreed to in writing, software 11e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * See the License for the specific language governing permissions and 14e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams * limitations under the License. 15e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams */ 16e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 17e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 18e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 19e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint8_t uchar; 20e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint16_t ushort; 21e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint32_t uint; 22e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 23e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef float float2 __attribute__((ext_vector_type(2))); 24e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef float float3 __attribute__((ext_vector_type(3))); 25e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef float float4 __attribute__((ext_vector_type(4))); 26e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uchar uchar2 __attribute__((ext_vector_type(2))); 27e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uchar uchar3 __attribute__((ext_vector_type(3))); 28e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uchar uchar4 __attribute__((ext_vector_type(4))); 29e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef ushort ushort2 __attribute__((ext_vector_type(2))); 30e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef ushort ushort3 __attribute__((ext_vector_type(3))); 31e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef ushort ushort4 __attribute__((ext_vector_type(4))); 32e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint uint2 __attribute__((ext_vector_type(2))); 33e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint uint3 __attribute__((ext_vector_type(3))); 34e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef uint uint4 __attribute__((ext_vector_type(4))); 35e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef char char2 __attribute__((ext_vector_type(2))); 36e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef char char3 __attribute__((ext_vector_type(3))); 37e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef char char4 __attribute__((ext_vector_type(4))); 38e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef short short2 __attribute__((ext_vector_type(2))); 39e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef short short3 __attribute__((ext_vector_type(3))); 40e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef short short4 __attribute__((ext_vector_type(4))); 41e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef int int2 __attribute__((ext_vector_type(2))); 42e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef int int3 __attribute__((ext_vector_type(3))); 43e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef int int4 __attribute__((ext_vector_type(4))); 44e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef long long2 __attribute__((ext_vector_type(2))); 45e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef long long3 __attribute__((ext_vector_type(3))); 46e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samstypedef long long4 __attribute__((ext_vector_type(4))); 47e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 48e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsenum IntrinsicEnums { 49e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams INTRINSIC_UNDEFINED, 50e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams INTRINSIC_CONVOLVE_3x3, 51e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams INTRINXIC_COLORMATRIX 52e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 53e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams}; 54e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 55e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsstatic inline int4 convert_int4(uchar4 i) { 56e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams int4 f4 = {i.x, i.y, i.z, i.w}; 57e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams return f4; 58e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams} 59e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 60e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsstatic inline short4 convert_short4(uchar4 i) { 61e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams short4 f4 = {i.x, i.y, i.z, i.w}; 62e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams return f4; 63e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams} 64e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 65e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsstatic inline float4 convert_float4(uchar4 i) { 66e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams float4 f4 = {i.x, i.y, i.z, i.w}; 67e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams return f4; 6836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray} 6936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray 7036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murraystatic inline uchar4 convert_uchar4(short4 i) { 7136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w}; 7236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray return f4; 73e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams} 74e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 75e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsstatic inline uchar4 convert_uchar4(int4 i) { 76e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w}; 77e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams return f4; 78e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams} 79e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 80537c4411b57ba30b688f437a663120e7f9c4f4e0Jason Samsstatic inline uchar4 convert_uchar4(float4 i) { 81537c4411b57ba30b688f437a663120e7f9c4f4e0Jason Sams uchar4 f4 = {(uchar)i.x, (uchar)i.y, (uchar)i.z, (uchar)i.w}; 82537c4411b57ba30b688f437a663120e7f9c4f4e0Jason Sams return f4; 83537c4411b57ba30b688f437a663120e7f9c4f4e0Jason Sams} 84537c4411b57ba30b688f437a663120e7f9c4f4e0Jason Sams 85e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 86e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Samsstatic inline int4 clamp(int4 amount, int low, int high) { 87e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams int4 r; 88e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); 89e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); 90e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); 91e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams r.w = amount.w < low ? low : (amount.w > high ? high : amount.w); 92e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams return r; 93e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams} 94e1e08b4c9cc80c51224fdaf3aeab0804daf073e6Jason Sams 95d85e283087ecd00760a0d8d0c9d8482cda845efcJason Samsstatic inline float4 clamp(float4 amount, float low, float high) { 96d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams float4 r; 97d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); 98d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); 99d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); 100d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams r.w = amount.w < low ? low : (amount.w > high ? high : amount.w); 101d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams return r; 102d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams} 103d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams 104d85e283087ecd00760a0d8d0c9d8482cda845efcJason Sams 105