cancel
Showing results for 
Search instead for 
Did you mean: 

JPG Image with LIBJPEG (STM32F4)

Devashish_Lahariya
Associate II

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);
}
 
1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hello @Devashish_Lahariya,

 

It is possible you are linking decompression library into the transcoder. Note if an application links in jpeg_start_decompress(), it will end up linking in the entire decompressor. You thus must separate jdapistd.c file from jdapimin.c. For further details read LibJPEG documentaiton.
Also, make sure decompression initialization must be completed before calling jpeg_start_decompress(). 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

View solution in original post

2 REPLIES 2
FBL
ST Employee

Hello @Devashish_Lahariya,

 

It is possible you are linking decompression library into the transcoder. Note if an application links in jpeg_start_decompress(), it will end up linking in the entire decompressor. You thus must separate jdapistd.c file from jdapimin.c. For further details read LibJPEG documentaiton.
Also, make sure decompression initialization must be completed before calling jpeg_start_decompress(). 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Hello, I have the exact same problem and use the same MCU.

Indeed, I ended up with an executable of 182Kb because all the JPED library has been linked.

This is not a problem in itself but the solution asks to separate 2 specific jpeg files.

What do you mean?

Also where can we access the LibJPEG documentation?

Best regards.