00001
00002
00003
00004
00005
00006
00007 #ifndef __IM_MATH_OP_H
00008 #define __IM_MATH_OP_H
00009
00010 #include "im_complex.h"
00011
00012
00013
00014 template <class T>
00015 inline T crop_byte(const T& v)
00016 {
00017 return v < 0? 0: v > 255? 255: v;
00018 }
00019
00020
00021 template <class T1, class T2>
00022 inline T1 add_op(const T1& v1, const T2& v2)
00023 {
00024 return v2 + v1;
00025 }
00026
00027
00028 template <class T1, class T2>
00029 inline T1 sub_op(const T1& v1, const T2& v2)
00030 {
00031 return v2 - v1;
00032 }
00033
00034
00035 template <class T1, class T2>
00036 inline T1 mul_op(const T1& v1, const T2& v2)
00037 {
00038 return v2 * v1;
00039 }
00040
00041
00042 template <class T1, class T2>
00043 inline T1 div_op(const T1& v1, const T2& v2)
00044 {
00045 return v1 / v2;
00046 }
00047
00048
00049 template <class T>
00050 inline T inv_op(const T& v)
00051 {
00052 return 1/v;
00053 }
00054
00055
00056 template <class T1, class T2>
00057 inline T1 diff_op(const T1& v1, const T2& v2)
00058 {
00059 if (v1 < v2)
00060 return v2 - v1;
00061 return v1 - v2;
00062 }
00063
00064
00065 template <class T1, class T2>
00066 inline T1 min_op(const T1& v1, const T2& v2)
00067 {
00068 if (v1 < v2)
00069 return v1;
00070 return v2;
00071 }
00072
00073
00074 template <class T1, class T2>
00075 inline T1 max_op(const T1& v1, const T2& v2)
00076 {
00077 if (v1 < v2)
00078 return v2;
00079 return v1;
00080 }
00081
00082 inline imbyte pow_op(const imbyte& v1, const imbyte& v2)
00083 {
00084 return (imbyte)pow((float)v1, v2);
00085 }
00086
00087 inline imushort pow_op(const imushort& v1, const imushort& v2)
00088 {
00089 return (imushort)pow((float)v1, v2);
00090 }
00091
00092 inline int pow_op(const int& v1, const int& v2)
00093 {
00094 return (int)pow((float)v1, v2);
00095 }
00096
00097
00098 template <class T1, class T2>
00099 inline T1 pow_op(const T1& v1, const T2& v2)
00100 {
00101 return (T1)pow(v1, v2);
00102 }
00103
00104
00105 template <class T>
00106 inline T abs_op(const T& v)
00107 {
00108 if (v < 0)
00109 return -1*v;
00110 return v;
00111 }
00112
00113
00114 template <class T>
00115 inline T less_op(const T& v)
00116 {
00117 return -1*v;
00118 }
00119
00120
00121 template <class T>
00122 inline T sqr_op(const T& v)
00123 {
00124 return v*v;
00125 }
00126
00127 inline int sqrt(const int& C)
00128 {
00129 return (int)sqrt(float(C));
00130 }
00131
00132
00133 template <class T>
00134 inline T sqrt_op(const T& v)
00135 {
00136 return (T)sqrt(v);
00137 }
00138
00139 inline int exp(const int& v)
00140 {
00141 return (int)exp((float)v);
00142 }
00143
00144
00145 template <class T>
00146 inline T exp_op(const T& v)
00147 {
00148 return (T)exp(v);
00149 }
00150
00151 inline int log(const int& v)
00152 {
00153 return (int)log((float)v);
00154 }
00155
00156
00157 template <class T>
00158 inline T log_op(const T& v)
00159 {
00160 return (T)log(v);
00161 }
00162
00163
00164 inline imcfloat sin(const imcfloat& v)
00165 {
00166 return (v);
00167 }
00168
00169 inline int sin(const int& v)
00170 {
00171 return (int)sin((float)v);
00172 }
00173
00174
00175 template <class T>
00176 inline T sin_op(const T& v)
00177 {
00178 return (T)sin(v);
00179 }
00180
00181 inline int cos(const int& v)
00182 {
00183 return (int)cos((float)v);
00184 }
00185
00186
00187 inline imcfloat cos(const imcfloat& v)
00188 {
00189 return (v);
00190 }
00191
00192
00193 template <class T>
00194 inline T cos_op(const T& v)
00195 {
00196 return (T)cos(v);
00197 }
00198
00199
00200 inline void imDataBitSet(imbyte* data, int index, int bit)
00201 {
00202 if (bit)
00203 data[index / 8] |= (0x01 << (7 - (index % 8)));
00204 else
00205 data[index / 8] &= ~(0x01 << (7 - (index % 8)));
00206 }
00207
00208
00209 inline int imDataBitGet(imbyte* data, int index)
00210 {
00211 return (data[index / 8] >> (7 - (index % 8))) & 0x01;
00212 }
00213
00214 #endif