29inline float IAbs(
float a) {
return a < 0.f ? -a : a; }
30inline int IAbs(
int a) {
return a < 0 ? -a : a; }
31inline double IAbs(
double a) {
return a < 0.0 ? -a : a; }
35inline float IDiv(
float a,
float b) {
return ((b != 0.f) ? (a / b) : 1.0f); }
36inline float IDiv(
float a,
int b) {
37 return ((b != 0) ? (a /
static_cast<float>(b)) : 1.0f);
39inline float IDiv(
float a,
unsigned int b) {
42 result = a /
static_cast<float>(b);
46inline double IDiv(
int a,
int b) {
47 return ((b != 0) ? (
static_cast<double>(a) / b) : 1.0);
49inline double IDiv(
unsigned int a,
unsigned int b) {
52 result =
static_cast<double>(a) / b;
56inline double IDiv(
double a,
double b) {
return ((b != 0.0) ? (a / b) : 1.0); }
57inline double IDiv(
double a,
int b) {
return ((b != 0) ? (a / b) : 1.0); }
58inline double IDiv(
double a,
unsigned int b) {
69inline float IRec(
float a) {
return ((a != 0.0f) ? ((1.0f) / a) : 1.0f); }
70inline double IRec(
int a) {
return ((a != 0) ? ((1.0) / a) : 1.0); }
71inline double IRec(
unsigned int a) {
return ((a != 0) ? ((1.0) / a) : 1.0); }
72inline double IRec(
double a) {
return ((a != 0.0) ? ((1.0) / a) : 1.0); }
76inline float ISqrt(
float a) {
return (a >= 0.0f) ? (sqrtf(a)) : 0.0f; }
78 return (a > 0) ? (sqrt(
static_cast<double>(a))) : 0.0;
80inline double ISqrt(
unsigned int a) {
81 return (a > 0) ? (sqrt(
static_cast<double>(a))) : 0.0;
83inline double ISqrt(
double a) {
return (a >= 0.0) ? (sqrt(a)) : 0.0; }
88 return (a >= 0.f) ? powf(a, 1.f / 3) : -powf(-a, 1.f / 3);
91 return (a >= 0) ? pow(
static_cast<double>(a), 1.0 / 3)
92 : -pow(-
static_cast<double>(a), 1.0 / 3);
94inline double ICbrt(
unsigned int a) {
95 return pow(
static_cast<double>(a), 1.0 / 3);
98 return (a >= 0.0) ? pow(a, 1.0 / 3) : -pow(-a, 1.0 / 3);
103inline float ISqr(
float a) {
return (a * a); }
104inline int ISqr(
int a) {
return (a * a); }
105inline unsigned int ISqr(
unsigned int a) {
return (a * a); }
106inline double ISqr(
double a) {
return (a * a); }
107inline int ISqr(
char a) {
return (
static_cast<int>(a) *
static_cast<int>(a)); }
108inline int ISqr(
unsigned char a) {
109 return (
static_cast<int>(a) *
static_cast<int>(a));
114inline float ICub(
float a) {
return (a * a * a); }
115inline int ICub(
int a) {
return (a * a * a); }
116inline unsigned int ICub(
unsigned int a) {
return (a * a * a); }
117inline double ICub(
double a) {
return (a * a * a); }
119 return (
static_cast<int>(a) *
static_cast<int>(a) *
static_cast<int>(a));
121inline int ICub(
unsigned char a) {
122 return (
static_cast<int>(a) *
static_cast<int>(a) *
static_cast<int>(a));
126inline float ILog(
float x) {
return ((x > 0.f) ? logf(x) : 0.f); }
128 return ((x > 0) ? log(
static_cast<double>(x)) : 0.0);
130inline double ILog(
unsigned int x) {
131 return ((x > 0) ? log(
static_cast<double>(x)) : 0.0);
133inline double ILog(
double x) {
return ((x > 0.0) ? log(x) : 0.0); }
136inline float IExp(
float x) {
return (expf(x)); }
137inline double IExp(
int x) {
return exp(
static_cast<double>(x)); }
138inline double IExp(
unsigned int x) {
return exp(
static_cast<double>(x)); }
139inline double IExp(
double x) {
return exp(x); }
142inline float IPow(
float a,
float b) {
return powf(a, b); }
143inline float IPow(
float a,
int b) {
return powf(a,
static_cast<float>(b)); }
144inline double IPow(
int a,
int b) {
145 return pow(
static_cast<double>(a),
static_cast<double>(b));
147inline double IPow(
unsigned int a,
unsigned int b) {
148 return pow(
static_cast<double>(a),
static_cast<double>(b));
150inline double IPow(
double a,
double b) {
return pow(a, b); }
151inline double IPow(
double a,
int b) {
return pow(a,
static_cast<double>(b)); }
156 return ((a <= b) ? a : b);
162 return ((a >= b) ? a : b);
199 return ((a >= 0.f) ? (
static_cast<int>(a + 0.5f))
200 : (
static_cast<int>(a - 0.5f)));
203 return ((a >= 0.0) ? (
static_cast<int>(a + 0.5))
204 : (
static_cast<int>(a - 0.5)));
209inline int ICeil(
int a) {
return (a); }
210inline int ICeil(
float a) {
return static_cast<int>(ceilf(a)); }
211inline int ICeil(
double a) {
return static_cast<int>(ceil(a)); }
214inline float ISin(
float alpha) {
return sinf(alpha); }
215inline double ISin(
double alpha) {
return sin(alpha); }
216inline float ICos(
float alpha) {
return cosf(alpha); }
217inline double ICos(
double alpha) {
return cos(alpha); }
218inline float ITan(
float alpha) {
return tanf(alpha); }
219inline double ITan(
double alpha) {
return tan(alpha); }
257inline float IAtan2(
float y,
float x) {
return atan2f(y, x); }
258inline double IAtan2(
double y,
double x) {
return atan2(y, x); }
275inline unsigned int IHamming(
unsigned int a,
unsigned int b) {
276 unsigned int distance = 0;
277 unsigned int val = a ^ b;
288 unsigned int distance = 0;
289 unsigned int val = a ^ b;
290 unsigned char *p = (
unsigned char *)&val;
292 distance = kIUByteBitCountLut[p[0]] + kIUByteBitCountLut[p[1]] +
293 kIUByteBitCountLut[p[2]] + kIUByteBitCountLut[p[3]];
306inline void ISwap(T *a, T *b,
int n) {
307 for (
int i = 0; i < n; i++) {
350 return (max_val - 1);
358 for (
int i = 0; i < m; i++) {
425 for (
int i = 0; i < m; i++) {
494 for (
int i = 0; i < l; i++) {
495 for (
int j = 0; j < m; j++) {
505 for (
int i = 0; i < n; i++) {
506 a[i] =
static_cast<T
>(i);
515 const float cen = (
static_cast<float>(n - 1)) / 2;
517 IDiv(0.5f, (sigma * sigma));
518 float dr, drsqr, dc, dcsqr, v, ksum = 0.f;
520 for (r = 0; r < n; ++r) {
521 dr =
static_cast<float>(r) - cen;
523 for (c = 0; c < n; ++c) {
524 dc =
static_cast<float>(c) - cen;
526 v =
IExp(-(drsqr + dcsqr) * nf);
532 v =
IDiv(1.0f, ksum);
533 for (i = 0; i < n * n; ++i) {
538inline void IGaussian2D(
double *kernel,
int n,
const double sigma) {
540 const double cen = (
static_cast<double>(n - 1)) / 2;
542 IDiv(0.5, (sigma * sigma));
543 double dr, drsqr, dc, dcsqr, v, ksum = 0.0;
545 for (r = 0; r < n; ++r) {
546 dr =
static_cast<double>(r) - cen;
548 for (c = 0; c < n; ++c) {
549 dc =
static_cast<double>(c) - cen;
551 v =
IExp(-(drsqr + dcsqr) * nf);
558 for (i = 0; i < n * n; ++i) {
566inline void IMove(
const T &a, T *b) {
573inline bool IWithin1D(
const T x,
const T start,
const T length) {
574 return (x >= start && x < (length + start));
582inline bool IWithin2D(
const T p[2],
const T x_upper_left,
const T y_upper_left,
583 const T width,
const T height) {
584 return (p[0] >= x_upper_left && p[1] >= y_upper_left &&
585 p[0] < width + x_upper_left && p[1] < height + y_upper_left);
592inline bool IWithin2D(
const T x,
const T y,
const T x_upper_left,
593 const T y_upper_left,
const T width,
const T height) {
594 return (x >= x_upper_left && y >= y_upper_left && x < width + x_upper_left &&
595 y < height + y_upper_left);
void IMakeReference4x9(T a[36], T *p[4])
float IDegreeToRadians(float d)
void IMakeReference(T *a, T **p, int m, int n)
void IMakeConstReference4x4(const T a[16], const T *p[4])
float IRadiansToDegree(float r)
void IMove(const T &a, T *b)
void IMakeConstReference2x2(const T a[4], const T *p[2])
void IMakeReference12x12(T a[144], T *p[12])
void IMakeConstReference12x12(const T a[144], const T *p[12])
void IMakeConstReference9x9(const T a[81], const T *p[9])
void IGaussian2D(float *kernel, int n, const float sigma)
T IIntervalHalfopen(T a, T min_val, T max_val)
float IDiv(float a, float b)
T IInterval(T a, T min_val, T max_val)
void IMakeReference5x9(T a[45], T *p[5])
unsigned int IHammingLut(unsigned int a, unsigned int b)
void IMakeConstReference3x3(const T a[9], const T *p[3])
bool IWithin2D(const T p[2], const T x_upper_left, const T y_upper_left, const T width, const T height)
void IMakeConstReference(const T *a, const T **p, int m, int n)
void IMakeConstReference5x9(const T a[45], const T *p[5])
float IPow(float a, float b)
float IAtan2(float y, float x)
void IMakeReference3x3(T a[9], T *p[3])
void IMakeReference2x2(T a[4], T *p[2])
bool IWithin1D(const T x, const T start, const T length)
unsigned int IHamming(unsigned int a, unsigned int b)
void IMakeReference4x4(T a[16], T *p[4])
void IMakeReference9x9(T a[81], T *p[9])
void IMakeConstReference4x9(const T a[36], const T *p[4])