Skip to content

Commit b298f84

Browse files
committed
Add unification sw
1 parent 91e316a commit b298f84

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
#include <../inc/address_map.hpp>
4+
#include <math.h>
5+
6+
#define IPS_FILTER_KERNEL_SIZE 3
7+
#define IMAG_ROWS 452
8+
#define IMAG_COLS 640
9+
10+
// Non Efficient implementation of Integer SQRT. But compatible with RV32 instructions.
11+
int intSqrt(int x)
12+
{
13+
unsigned int s = 0;
14+
for (unsigned int i = (1 << 15); i > 0; i >>= 1){
15+
if (((s+i) * (s+i)) <= x){
16+
s += i;
17+
}
18+
}
19+
return s;
20+
}
21+
22+
int norm(int a, int b)
23+
{
24+
int norm_result = 0;
25+
26+
norm_result = intSqrt(a*a+b*b); //sqrt(pow(a, 2) + pow(b, 2));
27+
28+
return norm_result;
29+
}
30+
31+
void unificate_img(unsigned char *x_img, unsigned char *y_img, unsigned char *unificated_img, int img_size, int channels)
32+
{
33+
//Iterate over image
34+
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+=channels, y+=channels, u+=channels){
35+
int pixel_magnitude;
36+
int pixel_x = (int) *x;
37+
int pixel_y = (int) *y;
38+
39+
pixel_magnitude = norm(pixel_x, pixel_y);
40+
41+
if (pixel_magnitude > 255) {pixel_magnitude = 255;};
42+
*u = (unsigned char) pixel_magnitude;
43+
}
44+
}
45+
46+
int main(void) {
47+
48+
// unsigned char *local_window_ptr = new unsigned char[9];
49+
// unsigned char *result_ptr = new unsigned char;
50+
// unsigned char *filter = (unsigned char*)IMG_FILTER_KERNEL_ADDRESS_LO;
51+
// unsigned char *filter_output = (unsigned char*)IMG_FILTER_OUTPUT_ADDRESS_LO;
52+
int img_size = 452*640;
53+
int channels = 1;
54+
55+
unsigned char *img_x = (unsigned char*) IMG_INPUT_ADDRESS_LO;
56+
unsigned char *img_y = (unsigned char*) IMG_INPUT_ADDRESS_LO + img_size;
57+
unsigned char *img_result = (unsigned char*) IMG_OUTPUT_ADDRESS_LO;
58+
59+
unificate_img(img_x, img_y, img_result, img_size, channels);
60+
61+
printf("FINISHED\n");
62+
asm volatile ("ecall");
63+
return 0;
64+
}

0 commit comments

Comments
 (0)