#ifndef CVD_PIXEL_OPERATIONS_H_ #define CVD_PIXEL_OPERATIONS_H_ #include #include #include #include #include namespace CVD { namespace Pixel { // operations::assign(dest,src) template ::count> struct operations { inline static void assign(T& lhs, const T& rhs) { memcpy(&lhs, &rhs, sizeof(T)); } template inline static void assign(T& lhs, const S& rhs) { for(unsigned int i = 0; i < N; i++) Component::get(lhs, i) = (typename Component::type)Component::get(rhs, i); } template inline static void add(T& lhs, const S& rhs) { for(unsigned int i = 0; i < N; ++i) Component::get(lhs, i) += Component::get(rhs, i); } template inline static void subtract(T& lhs, const S& rhs) { for(unsigned int i = 0; i < N; ++i) Component::get(lhs, i) -= Component::get(rhs, i); } template inline static void multiply(T& lhs, const S& rhs) { for(unsigned int i = 0; i < N; ++i) Component::get(lhs, i) = (typename Component::type)(Component::get(lhs, i) * rhs); } template inline static void divide(T& lhs, const S& rhs) { for(unsigned int i = 0; i < N; ++i) Component::get(lhs, i) = (typename Component::type)(Component::get(lhs, i) / rhs); } inline static bool equal(const T& a, const T& b) { return memcmp(&a, &b, sizeof(T)) == 0; } inline static void zero(T& t) { memset(&t, 0, sizeof(T)); } }; template struct operations { template inline static void assign(T& lhs, const S& rhs) { lhs = (T)rhs; } template inline static void add(T& lhs, const S& rhs) { lhs += rhs; } template inline static void subtract(T& lhs, const S& rhs) { lhs -= rhs; } template inline static void multiply(T& lhs, const S& rhs) { lhs = (T)(lhs * rhs); } template inline static void divide(T& lhs, const S& rhs) { lhs = (T)(lhs / rhs); } inline static bool equal(const T& a, const T& b) { return a == b; } inline static void zero(T& t) { t = T(); } }; }; }; #endif