I was recently trying to update my game to store graphics in compressed formats (JPEG and PNG).
Whilst I ended up settling on a different library, my initial attempt
here is a tested function
void test(char FileName[])
{
unsigned long x, y;
struct jpeg_decompress_struct info; //for our jpeg info
struct jpeg_error_mgr err; //the error handler
JSAMPARRAY buffer;
FILE* infile;
//initialize error handling
info.err = jpeg_std_error(& err);
infile = fopen(FileName, "rb"); //open the file
//if the jpeg file doesn't load
if(!infile) {
fprintf(stderr, "Error reading JPEG file %s!", FileName);
// printf("Error reading JPEG file %s!", FileName);
//return 0;
}
//initialize the decompression
jpeg_create_decompress(&info);
//specify the input
jpeg_stdio_src(&info, infile);
//read headers
jpeg_read_header(&info, TRUE); // read jpeg file header
jpeg_start_decompress(&info); // decompress the file
//set width and height
x = info.output_width;
y = info.output_height;
printf("x value is %ul", x);
printf("x value is %ul", y);
}