I have a simple jpeg load function for normal jpeg files.
If I step through it with gdb I get
"Program received signal SIGSEGV, Segmentation fault.
0x1000b73a in ycc_rgb_convert ()"
The ycc_rgb_convert() is called by jpeg_read_scanlines()
I tried multiple jpg files and I always get that.
Am I totally missing out something here, or what could be wrong with it?
basically this is the function:
Code:
#include "libjpeg/jpeglib.h"
#include <setjmp.h>
int loadJPEG(char *filename, struct slideshow_img *img) {
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *fp;
int row_stride, state=0;
cinfo.err = jpeg_std_error(&jerr.pub); // ERROR CONTROL
jerr.pub.error_exit = my_error_exit;
if ((fp = fopen(filename, "rb")) == NULL) { //LOAD FILE
fprintf(errorlog, "Failed to open JPEG file %s\n", filename); return 1;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, fp);
jpeg_read_header(&cinfo, TRUE);
row_stride = cinfo.output_width * cinfo.output_components;
img->pixels = (void *)calloc(cinfo.output_height, row_stride); //Allocate Space for pixels
jpeg_calc_output_dimensions(&cinfo);
jpeg_start_decompress(&cinfo); printf(".");
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, (JSAMPARRAY)(img->pixels+state), 1);
state += row_stride; //Increment pointer offset
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(fp);
if (setjmp(jerr.setjmp_buffer)) { //Error
jpeg_destroy_decompress(&cinfo);
fclose(fp);
return 2;
}
return 0;