Skip to content

Commit 376baa2

Browse files
committed
Add gray conversion function
1 parent 18736b6 commit 376baa2

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

modules/VirtualPrototype/FreeRTOS/freertos_test.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,46 @@ static void task_test_sobel(void *pParameter)
273273
printf("Finished process of image with Sobel gradient\n");
274274
}
275275

276+
unsigned char compute_gray_value(unsigned char r_val, unsigned char g_val, unsigned char b_val)
277+
{
278+
return (unsigned char)((299 * (int)r_val + 587 * (int)g_val + 114 * (int)b_val) / 1000);
279+
}
280+
281+
void convert_to_grayscale()
282+
{
283+
unsigned char *source_ptr = (unsigned char *) IMG_INPUT_ADDRESS_LO;
284+
unsigned char *target_ptr = (unsigned char *) IMG_INPROCESS_A_ADDRESS_LO;
285+
unsigned char rgb_val[3];
286+
unsigned char gray_val;
287+
288+
printf("Starting process of image with grayscale conversion\n");
289+
290+
for (int i = 0; i < IMAG_ROWS; i++)
291+
{
292+
for (int j = 0; j < IMAG_COLS; j++)
293+
{
294+
memcpy(rgb_val, source_ptr + ((i * 3 * IMAG_COLS) + (j * 3)), 3 * sizeof(char));
295+
// if (i == 0 && j < 10)
296+
// {
297+
// printf("On pixel %0d %0d r %0d g %0d b %0d\n", i, j, rgb_val[0], rgb_val[1], rgb_val[2]);
298+
// }
299+
gray_val = compute_gray_value(rgb_val[0], rgb_val[1], rgb_val[2]);
300+
// if (i == 0 && j < 10)
301+
// {
302+
// printf("On pixel %0d %0d gray value %0d\n", i, j, gray_val);
303+
// }
304+
*(target_ptr + ((i * IMAG_COLS) + j)) = gray_val;
305+
}
306+
}
307+
308+
printf("Finished process of image with grayscale conversion\n");
309+
}
310+
311+
static void task_test_grayscale(void *pParameter)
312+
{
313+
convert_to_grayscale();
314+
}
315+
276316
int main( void )
277317
{
278318

@@ -285,7 +325,8 @@ int main( void )
285325
xTaskCreate(task_2, "Task2", 10000, NULL, tskIDLE_PRIORITY+1, NULL);
286326
xTaskCreate(task_3, "Task3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
287327

288-
xTaskCreate(task_test_sobel, "TaskSobel", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
328+
// xTaskCreate(task_test_sobel, "TaskSobel", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
329+
xTaskCreate(task_test_grayscale, "TaskGrayscale", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
289330
/* Start the kernel. From here on, only tasks and interrupts will run. */
290331
vTaskStartScheduler();
291332

0 commit comments

Comments
 (0)