Question
Problem with time delay when decoding jpeg via libjpeg
Hi.
It took a long time to decoder JPEG images, so I measured the time.
[My code]
...
// Allocate and initialize JPEG decompression object. We set up the normal JPEG error routines.
cinfo.err = jpeg_std_error( &jerr );
// Now we can initialize the JPEG decompression object.
jpeg_create_decompress( &cinfo );
// Specify data source (eg, a file)
jpeg_stdio_src( &cinfo, &SDFile );
// Read file parameters with jpeg_read_header()
jpeg_read_header( &cinfo, TRUE );
// Start decompressor
jpeg_start_decompress( &cinfo );
// allocation memory
unsigned char* buffer = (unsigned char*) calloc( cinfo.output_width * cinfo.output_components, 1 );
static uint32_t time = 0;
static uint32_t index = 0;
static uint32_t laps[1024] = {0, };
// scan lines
while( cinfo.output_scanline < cinfo.output_height )
{
// get current tick time
time = HAL_GetTick();
// scan line
jpeg_read_scanlines( &cinfo, buffer, 1 );
// get lap time
laps[ index++ ] = HAL_GetTick() - time;
}
// Finish decompression
jpeg_finish_decompress( &cinfo );
// Release JPEG decompression object
jpeg_destroy_decompress( &cinfo );
...
Time required each time the function jpeg_read_scanlines is called.
As you can see, it takes 25 ms to 35 ms for every 16 lines.
For this reason, it takes more than 1 second to load the 800 x 480 size image.
How can we solve this time delay?