|
1 | 1 | #include <string.h> |
2 | 2 | #include <stdio.h> |
| 3 | +#include <../inc/address_map.hpp> |
3 | 4 |
|
4 | 5 | #define IPS_FILTER_KERNEL_SIZE 3 |
| 6 | +#define IMAG_ROWS 452 |
| 7 | +#define IMAG_COLS 640 |
5 | 8 |
|
| 9 | +// void extract_window(int i, int j, unsigned char *initial_address_ptr, unsigned char*& local_window_ptr) |
| 10 | +// { |
| 11 | +// unsigned char* read_ptr = new unsigned char[3]; |
| 12 | +// if ((i == 0) && (j == 0)) // Upper left corner of the image |
| 13 | +// { |
| 14 | +// // First row |
| 15 | +// *(local_window_ptr ) = 0; |
| 16 | +// *(local_window_ptr + 1) = 0; |
| 17 | +// *(local_window_ptr + 2) = 0; |
| 18 | +// // Second row |
| 19 | +// memcpy(read_ptr, initial_address_ptr, 2 * sizeof(char)); |
| 20 | +// *(local_window_ptr + 3) = 0; |
| 21 | +// *(local_window_ptr + 4) = *(read_ptr ); |
| 22 | +// *(local_window_ptr + 5) = *(read_ptr + 1); |
| 23 | +// // Third row |
| 24 | +// memcpy(read_ptr, initial_address_ptr + IMAG_COLS, 2 * sizeof(char)); |
| 25 | +// *(local_window_ptr + 6) = 0; |
| 26 | +// *(local_window_ptr + 7) = *(read_ptr ); |
| 27 | +// *(local_window_ptr + 8) = *(read_ptr + 1); |
| 28 | +// } |
| 29 | +// else if ((i == 0) && (j == IMAG_COLS - 1)) // Upper right corner of the image |
| 30 | +// { |
| 31 | +// // First row |
| 32 | +// *(local_window_ptr ) = 0; |
| 33 | +// *(local_window_ptr + 1) = 0; |
| 34 | +// *(local_window_ptr + 2) = 0; |
| 35 | +// // Second row |
| 36 | +// memcpy(read_ptr, initial_address_ptr + (IMAG_COLS - 2), 2 * sizeof(char)); |
| 37 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 38 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 39 | +// *(local_window_ptr + 5) = 0; |
| 40 | +// // Third row |
| 41 | +// memcpy(read_ptr, initial_address_ptr + (IMAG_COLS + (IMAG_COLS - 2)), 2 * sizeof(char)); |
| 42 | +// *(local_window_ptr + 6) = *(read_ptr ); |
| 43 | +// *(local_window_ptr + 7) = *(read_ptr + 1); |
| 44 | +// *(local_window_ptr + 8) = 0; |
| 45 | +// } |
| 46 | +// else if (i == 0) // Upper border |
| 47 | +// { |
| 48 | +// // First row |
| 49 | +// *(local_window_ptr ) = 0; |
| 50 | +// *(local_window_ptr + 1) = 0; |
| 51 | +// *(local_window_ptr + 2) = 0; |
| 52 | +// // Second row |
| 53 | +// memcpy(read_ptr, initial_address_ptr + (j - 1), 3 * sizeof(char)); |
| 54 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 55 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 56 | +// *(local_window_ptr + 5) = *(read_ptr + 2); |
| 57 | +// // Third row |
| 58 | +// memcpy(read_ptr, initial_address_ptr + (IMAG_COLS + (j - 1)), 3 * sizeof(char)); |
| 59 | +// *(local_window_ptr + 6) = *(read_ptr ); |
| 60 | +// *(local_window_ptr + 7) = *(read_ptr + 1); |
| 61 | +// *(local_window_ptr + 8) = *(read_ptr + 2); |
| 62 | +// } |
| 63 | +// else if ((i == IMAG_ROWS - 1) && (j == 0)) // Lower left corner of the image |
| 64 | +// { |
| 65 | +// // First row |
| 66 | +// memcpy(read_ptr, initial_address_ptr + ((IMAG_ROWS - 2) * IMAG_COLS), 2 * sizeof(char)); |
| 67 | +// *(local_window_ptr ) = 0; |
| 68 | +// *(local_window_ptr + 1) = *(read_ptr ); |
| 69 | +// *(local_window_ptr + 2) = *(read_ptr + 1); |
| 70 | +// // Second row |
| 71 | +// memcpy(read_ptr, initial_address_ptr + ((IMAG_ROWS - 1) * IMAG_COLS), 2 * sizeof(char)); |
| 72 | +// *(local_window_ptr + 3) = 0; |
| 73 | +// *(local_window_ptr + 4) = *(read_ptr ); |
| 74 | +// *(local_window_ptr + 5) = *(read_ptr + 1); |
| 75 | +// // Third row |
| 76 | +// *(local_window_ptr + 6) = 0; |
| 77 | +// *(local_window_ptr + 7) = 0; |
| 78 | +// *(local_window_ptr + 8) = 0; |
| 79 | +// } |
| 80 | +// else if ((i == IMAG_ROWS - 1) && (j == IMAG_COLS - 1)) // Lower right corner of the image |
| 81 | +// { |
| 82 | +// // First row |
| 83 | +// memcpy(read_ptr, initial_address_ptr + (((IMAG_ROWS - 2) * IMAG_COLS) + (IMAG_COLS - 2)), 2 * sizeof(char)); |
| 84 | +// *(local_window_ptr ) = *(read_ptr ); |
| 85 | +// *(local_window_ptr + 1) = *(read_ptr + 1); |
| 86 | +// *(local_window_ptr + 2) = 0; |
| 87 | +// // Second row |
| 88 | +// memcpy(read_ptr, initial_address_ptr + (((IMAG_ROWS - 1) * IMAG_COLS) + (IMAG_COLS - 2)), 2 * sizeof(char)); |
| 89 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 90 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 91 | +// *(local_window_ptr + 5) = 0; |
| 92 | +// // Third row |
| 93 | +// *(local_window_ptr + 6) = 0; |
| 94 | +// *(local_window_ptr + 7) = 0; |
| 95 | +// *(local_window_ptr + 8) = 0; |
| 96 | +// } |
| 97 | +// else if (i == IMAG_ROWS - 1) // Lower border of the image |
| 98 | +// { |
| 99 | +// // First row |
| 100 | +// memcpy(read_ptr, initial_address_ptr + (((IMAG_ROWS - 2) * IMAG_COLS) + (j - 1)), 3 * sizeof(char)); |
| 101 | +// *(local_window_ptr ) = *(read_ptr ); |
| 102 | +// *(local_window_ptr + 1) = *(read_ptr + 1); |
| 103 | +// *(local_window_ptr + 2) = *(read_ptr + 2); |
| 104 | +// // Second row |
| 105 | +// memcpy(read_ptr, initial_address_ptr + (((IMAG_ROWS - 1) * IMAG_COLS) + (j - 1)), 3 * sizeof(char)); |
| 106 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 107 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 108 | +// *(local_window_ptr + 5) = *(read_ptr + 2); |
| 109 | +// // Third row |
| 110 | +// *(local_window_ptr + 6) = 0; |
| 111 | +// *(local_window_ptr + 7) = 0; |
| 112 | +// *(local_window_ptr + 8) = 0; |
| 113 | +// } |
| 114 | +// else if (j == 0) // Left border of the image |
| 115 | +// { |
| 116 | +// // First row |
| 117 | +// memcpy(read_ptr, initial_address_ptr + ((i - 1) * IMAG_COLS), 2 * sizeof(char)); |
| 118 | +// *(local_window_ptr ) = 0; |
| 119 | +// *(local_window_ptr + 1) = *(read_ptr ); |
| 120 | +// *(local_window_ptr + 2) = *(read_ptr + 1); |
| 121 | +// // Second row |
| 122 | +// memcpy(read_ptr, initial_address_ptr + (i * IMAG_COLS), 2 * sizeof(char)); |
| 123 | +// *(local_window_ptr + 3) = 0; |
| 124 | +// *(local_window_ptr + 4) = *(read_ptr ); |
| 125 | +// *(local_window_ptr + 5) = *(read_ptr + 1); |
| 126 | +// // Third row |
| 127 | +// memcpy(read_ptr, initial_address_ptr + ((i + 1) * IMAG_COLS), 2 * sizeof(char)); |
| 128 | +// *(local_window_ptr + 6) = 0; |
| 129 | +// *(local_window_ptr + 7) = *(read_ptr ); |
| 130 | +// *(local_window_ptr + 8) = *(read_ptr + 1); |
| 131 | +// } |
| 132 | +// else if (j == IMAG_COLS - 1) // Right border of the image |
| 133 | +// { |
| 134 | +// // First row |
| 135 | +// memcpy(read_ptr, initial_address_ptr + (((i - 1) * IMAG_COLS) + (j - 1)), 2 * sizeof(char)); |
| 136 | +// *(local_window_ptr ) = *(read_ptr ); |
| 137 | +// *(local_window_ptr + 1) = *(read_ptr + 1); |
| 138 | +// *(local_window_ptr + 2) = 0; |
| 139 | +// // Second row |
| 140 | +// memcpy(read_ptr, initial_address_ptr + ((i * IMAG_COLS) + (j - 1)), 2 * sizeof(char)); |
| 141 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 142 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 143 | +// *(local_window_ptr + 5) = 0; |
| 144 | +// // Third row |
| 145 | +// memcpy(read_ptr, initial_address_ptr + (((i + 1) * IMAG_COLS) + (j - 1)), 2 * sizeof(char)); |
| 146 | +// *(local_window_ptr + 6) = *(read_ptr ); |
| 147 | +// *(local_window_ptr + 7) = *(read_ptr + 1); |
| 148 | +// *(local_window_ptr + 8) = 0; |
| 149 | +// } |
| 150 | +// else // Rest of the image |
| 151 | +// { |
| 152 | +// // First row |
| 153 | +// memcpy(read_ptr, initial_address_ptr + (((i - 1) * IMAG_COLS) + (j - 1)), 3 * sizeof(char)); |
| 154 | +// *(local_window_ptr ) = *(read_ptr ); |
| 155 | +// *(local_window_ptr + 1) = *(read_ptr + 1); |
| 156 | +// *(local_window_ptr + 2) = *(read_ptr + 2); |
| 157 | +// // Second row |
| 158 | +// memcpy(read_ptr, initial_address_ptr + ((i * IMAG_COLS) + (j - 1)), 3 * sizeof(char)); |
| 159 | +// *(local_window_ptr + 3) = *(read_ptr ); |
| 160 | +// *(local_window_ptr + 4) = *(read_ptr + 1); |
| 161 | +// *(local_window_ptr + 5) = *(read_ptr + 2); |
| 162 | +// // Third row |
| 163 | +// memcpy(read_ptr, initial_address_ptr + (((i + 1) * IMAG_COLS) + (j - 1)), 3 * sizeof(char)); |
| 164 | +// *(local_window_ptr + 6) = *(read_ptr ); |
| 165 | +// *(local_window_ptr + 7) = *(read_ptr + 1); |
| 166 | +// *(local_window_ptr + 8) = *(read_ptr + 2); |
| 167 | +// } |
| 168 | +// } |
6 | 169 |
|
7 | 170 | int main(void) { |
8 | 171 |
|
9 | | - unsigned char *local_window_ptr = new unsigned char[9]; |
10 | | - unsigned char *result_ptr = new unsigned char; |
11 | | - unsigned char *filter = (unsigned char*)0x40005003; |
| 172 | + // unsigned char *local_window_ptr = new unsigned char[9]; |
| 173 | + // unsigned char *result_ptr = new unsigned char; |
| 174 | + // unsigned char *filter = (unsigned char*)IMG_FILTER_KERNEL_ADDRESS_LO; |
| 175 | + // unsigned char *filter_output = (unsigned char*)IMG_FILTER_OUTPUT_ADDRESS_LO; |
| 176 | + unsigned char *img = (unsigned char*) IMG_INPUT_ADDRESS_LO; |
| 177 | + unsigned char *filtered_img = new unsigned char[IMAG_COLS*IMAG_ROWS]; |
| 178 | + unsigned char *img_result = (unsigned char*) IMG_OUTPUT_ADDRESS_LO; |
12 | 179 |
|
13 | | - for(int i = 0; i < IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE; i++) { |
14 | | - *(local_window_ptr+i) = i; |
15 | | - printf("Writing[%0d]: %0d \n", i, (int)*(local_window_ptr+i)); |
16 | | - } |
| 180 | + memcpy(img_result, img, IMAG_COLS*IMAG_ROWS*sizeof(char)); |
17 | 181 |
|
18 | | - memcpy(filter, local_window_ptr, IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE*sizeof(char)); |
19 | | - //Now Read |
20 | | - memcpy(result_ptr, filter, sizeof(char)); |
21 | | - printf("FILTER is %0d\n", (int)*result_ptr); |
| 182 | + // for(int i = 0; i < IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE; i++) { |
| 183 | + // *(local_window_ptr+i) = i; |
| 184 | + // printf("Writing[%0d]: %0d \n", i, (int)*(local_window_ptr+i)); |
| 185 | + // } |
22 | 186 |
|
| 187 | + //memcpy(filter, local_window_ptr, IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE*sizeof(char)); |
| 188 | + // //Now Read |
| 189 | + // memcpy(result_ptr, filter, sizeof(char)); |
| 190 | + // printf("FILTER is %0d\n", (int)*result_ptr); |
| 191 | + |
| 192 | + // memcpy(img_ptr, img, 289280*sizeof(char)); |
| 193 | + // int local_count = 0; |
| 194 | + // int current_number_of_pixels = 0; |
| 195 | + // int next_target_of_completion = 10.0; |
| 196 | + // int local_group_count = 0; |
| 197 | + // int total_number_of_pixels = IMAG_COLS*IMAG_ROWS; |
| 198 | + // unsigned char* local_results; |
| 199 | + // for (int i = 0; i < 100; i++) |
| 200 | + // { |
| 201 | + // local_group_count = 0; |
| 202 | + // for (int j = 0; j < 100; j++) |
| 203 | + // { |
| 204 | + // unsigned char* local_window_ptr = new unsigned char[9]; |
| 205 | + // unsigned char* data_returned_ptr; |
| 206 | + // unsigned char* write_ptr = new unsigned char[9]; |
| 207 | + // unsigned char* read_ptr = new unsigned char; |
| 208 | + // unsigned char data_returned; |
| 209 | + |
| 210 | + // extract_window(i, j, img, local_window_ptr); |
| 211 | + |
| 212 | + // write_ptr = local_window_ptr; |
| 213 | + // memcpy(filter, write_ptr, IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE*sizeof(char)); |
| 214 | + // memcpy(read_ptr, filter_output, sizeof(char)); |
| 215 | + // data_returned = *read_ptr; |
| 216 | + // printf("Data Returned: %0d\n", data_returned); |
| 217 | + |
| 218 | + // if (data_returned > 255) { |
| 219 | + // *(filtered_img + (i*IMAG_COLS)+j) = 255; |
| 220 | + // } |
| 221 | + // else { |
| 222 | + // *(filtered_img + (i*IMAG_COLS)+j) = data_returned; |
| 223 | + // } |
| 224 | + |
| 225 | + // if (local_count == 0) |
| 226 | + // { |
| 227 | + // local_results = new unsigned char[8]; |
| 228 | + // } |
| 229 | + |
| 230 | + // if (data_returned > 255) |
| 231 | + // { |
| 232 | + // *(local_results + local_count) = 255; |
| 233 | + // } |
| 234 | + // else { |
| 235 | + // *(local_results + local_count) = data_returned; |
| 236 | + // } |
| 237 | + |
| 238 | + // local_count++; |
| 239 | + // if (local_count == 8) |
| 240 | + // { |
| 241 | + // memcpy(img_result + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), local_results, 8 * sizeof(char)); |
| 242 | + // local_count = 0; |
| 243 | + // local_group_count++; |
| 244 | + // } |
| 245 | + |
| 246 | + // current_number_of_pixels++; |
| 247 | + // if(current_number_of_pixels*100/total_number_of_pixels >= next_target_of_completion) { |
| 248 | + // printf("Image processing completed at %d\n", next_target_of_completion); |
| 249 | + // next_target_of_completion += 10.0; |
| 250 | + // } |
| 251 | + // } |
| 252 | + // } |
| 253 | + // memcpy(img_result, filtered_img, total_number_of_pixels * sizeof(char)); |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + printf("FINISHED\n"); |
23 | 258 | asm volatile ("ecall"); |
24 | 259 | return 0; |
25 | 260 | } |
0 commit comments