Skip to main content
Visitor II
August 3, 2023
Solved

JPG Image with LIBJPEG (STM32F4)

  • August 3, 2023
  • 2 replies
  • 3090 views

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);
}
 
    This topic has been closed for replies.
    Best answer by FBL

    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(). 

     

    2 replies

    FBLAnswer
    Technical Moderator
    August 3, 2023

    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(). 

     

    Visitor II
    June 14, 2024

    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.

    Explorer
    April 6, 2025

    Hi 

     

    Indeed, where is the LibJPEG documentation?

    Ofer