I am trying to write a small function that calculates difference for each pixel. However, seems like casting int to uint8_t ( (uint8_t)temp ) is causing problems on a microprocessor at the very first iteration and leads to a restart
abs_diff = (uint8_t*)malloc(320*240 * sizeof(uint8_t));
for (int i = 0; i < 320*240; i++){
int temp = abs((int)_jpg_buf[i] - (int)_jpg_buf_prev[i]);
Serial.printf("abs %d\n", temp);
abs_diff[i] = (uint8_t)temp; // <- fails
}
P.S. not a C expert here