I'm trying to read a .JPG image file from my SD Card (FATFS) and want to use LIBJPEG for decoding it. Everything seems to be fine until I execute the **jpeg_start_decompress()** function. As soon as this ifunction is executed a UsageFault is generated on the MCU, does anyone know why would this be happening?
Here is my code for loading the jpg image:
void read_JPG_image(FIL* _fptr, uint32_t _width, uint8_t* buff)
{
JSAMPROW buffer[2] = {0};
uint32_t row_stride = 0;
buffer[0] = buff;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, _fptr);
jpeg_read_header(&cinfo, TRUE);
cinfo.dct_method = JDCT_FLOAT;
jpeg_start_decompress(&cinfo);
row_stride = _width * 3;
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
// put_scanline_someplace;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
f_close(_fptr);
}