ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
#ifndef _ISP_MATH_UTIL_H_
#define _ISP_MATH_UTIL_H_
 
#include "../include/isp_type.h"
#include "matrix.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define square(x)    ((x) * (x))
#define clear(x)    memset (&(x), 0, sizeof (x))
 
#define array_size(array)    (sizeof(array) / sizeof((array)[0]))
 
#define min(a, b) ({                \
   typeof(a) __a = (a);            \
   typeof(b) __b = (b);            \
   __a < __b ? __a : __b;            \
})
 
#define min_t(type, a, b) ({            \
   type __a = (a);                \
   type __b = (b);                \
   __a < __b ? __a : __b;            \
})
 
#define max(a, b) ({                \
   typeof(a) __a = (a);            \
   typeof(b) __b = (b);            \
   __a > __b ? __a : __b;            \
})
 
#define max_t(type, a, b) ({            \
   type __a = (a);                \
   type __b = (b);                \
   __a > __b ? __a : __b;            \
})
 
#define clamp(val, min, max) ({            \
   typeof(val) __val = (val);        \
   typeof(min) __min = (min);        \
   typeof(max) __max = (max);        \
   __val = __val < __min ? __min : __val;    \
   __val > __max ? __max : __val;        \
})
 
#define clamp_t(type, val, min, max) ({        \
   type __val = (val);            \
   type __min = (min);            \
   type __max = (max);            \
   __val = __val < __min ? __min : __val;    \
   __val > __max ? __max : __val;        \
})
 
#define div_round_up(num, denom)    (((num) + (denom) - 1) / (denom))
#define div_round(num, denom)    (((num) + ((denom) >> 1)) / (denom))
 
#define Q4        16
#define Q8        256
#define Q10        1024
 
#define SHIFT_Q4    4
#define SHIFT_Q8    8
#define SHIFT_Q10    10
 
#define R_SHIFT_N(x,n)        (((x) + (1 << (n-1)))>>(n))
#define L_SHIFT_N(x,n)        ((x)<<(n))
#define IS_BETWEEN(x,a,b)    (((x)>=(a)) && ((x)<=(b)))
 
#define N_ROUND(x,y)        (((x)/(y))*(y))
 
#define ABS(x) ({                        \
       long ret;                    \
       if (sizeof(x) == sizeof(long)) {        \
           long __x = (x);                \
           ret = (__x < 0) ? -__x : __x;        \
       } else {                    \
           int __x = (x);                \
           ret = (__x < 0) ? -__x : __x;        \
       }                        \
       ret;                        \
   })
 
void HorizontalMirror(int arr[64]);
void VerticalMirror(int arr[64]);
 
int ValueInterp(int curr, int x_low,int x_high,int y_low,int y_high);
void Conv(int u[],int v[],int w[], int m, int n);
 
int ArrayFindMinIndex(int array[], int num);
int ArrayFindSecondMinIndex(int array[], int num, int exclude);
int ArrayFindMaxIndex(int array[],int num);
int ArrayFindSecondMaxIndex(int array[], int num, int exclude);
 
int ArraySum(int *array,int len);
int ArrayStdVar(int x[], int n);
 
void ShellSort(int *a,int *sub, int n);
 
int SqrtM(unsigned int a);
 
int RoundQ4(int x);
 
struct matrix {
   float value[3][3];
};
 
void matrix_zero(struct matrix *m);
void matrix_invert(struct matrix *m);
void matrix_multiply(struct matrix *a, const struct matrix *b);
void matrix_float_to_s2q8(HW_S8Q8 out [3][3], const struct matrix *in);
void matrix_float_to_s4q8(HW_S8Q8 out[3][3], const struct matrix *in);
void matrix_float_to_s8q8(HW_S8Q8 out[3][3], const struct matrix *in);
 
void spline(double x[], double y[], int n, double yp1,double ypn, double y2[]);
void splint(double xa[], double ya[], double y2a[], int n, double x, double *y);
void spline_interp_u16(unsigned short x[], unsigned short y[], int n,
               unsigned short x2[], unsigned short y2[], int n2);
 
#endif /*_ISP_MATH_UTIL_H_*/