Skip to content

Commit f0a8d5c

Browse files
committed
Add img unification to freeRTOS sw
1 parent 66a9b4d commit f0a8d5c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef IMG_UNIFICATION_CPP
2+
#define IMG_UNIFICATION_CPP
3+
4+
#include <../inc/address_map.hpp>
5+
#include <math.h>
6+
7+
//Test Unificate in FreeRTOS
8+
int intSqrt(int x)
9+
{
10+
unsigned int s = 0;
11+
for (unsigned int i = (1 << 15); i > 0; i >>= 1){
12+
if (((s+i) * (s+i)) <= x){
13+
s += i;
14+
}
15+
}
16+
return s;
17+
}
18+
19+
int norm(int a, int b)
20+
{
21+
int norm_result = 0;
22+
23+
norm_result = intSqrt(a*a+b*b); //sqrt(pow(a, 2) + pow(b, 2));
24+
25+
26+
return norm_result;
27+
}
28+
29+
void unificate_img(unsigned char *x_img, unsigned char *y_img, unsigned char *unificated_img, int img_size)
30+
{
31+
//Iterate over image
32+
for(unsigned char *x = x_img, *y = y_img, *u = unificated_img; x < x_img + img_size && y < y_img + img_size && u < unificated_img + img_size; x++, y++, u++){
33+
int pixel_magnitude;
34+
int pixel_x = (int) *x;
35+
int pixel_y = (int) *y;
36+
37+
pixel_magnitude = norm(pixel_x, pixel_y);
38+
39+
if (pixel_magnitude > 255) {pixel_magnitude = 255;};
40+
*u = (unsigned char) pixel_magnitude;
41+
}
42+
}
43+
44+
#endif // IMG_UNIFICATION_CPP

0 commit comments

Comments
 (0)