if ((infile = fopen(jpg_filename, "rb")) == NULL)
{
fprintf(stderr, "open %s failed/n", jpg_filename);
return(-1);
}
/*
init jpeg decompress object error handler
*/
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
/*
* bind jpeg decompress object to infile
*/
jpeg_stdio_src(&cinfo, infile);
/*
* read jpeg header
*/
jpeg_read_header(&cinfo, TRUE);
/*
* decompress process.
* note: after jpeg_start_decompress() is called
* the dimension infomation will be known,
* so allocate memory buffer for scanline immediately
*/
jpeg_start_decompress(&cinfo);
if ((cinfo.output_width > 320) ||
(cinfo.output_height > 240)) {
printf("too large JPEG file,cannot display/n");
return (-1);
}