Thread: libjpeg sgefault on jpeg_read_scanlines()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    42
    Join Date
    May 2005
    Location
    Estonia
    Posts
    7

    Unhappy libjpeg segfault on jpeg_read_scanlines()

    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;
    Last edited by Syko; 11-25-2005 at 04:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linker error when using libjpeg
    By s-men in forum C++ Programming
    Replies: 2
    Last Post: 08-21-2008, 10:02 AM
  2. libjpeg problems linking in cpp
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2008, 04:29 PM
  3. Lib issues: undefined references (libjpeg)
    By psychopath in forum Linux Programming
    Replies: 3
    Last Post: 04-17-2006, 01:28 PM
  4. Compiler errors when using libjpeg.
    By Nikanoru in forum C++ Programming
    Replies: 11
    Last Post: 08-07-2003, 06:46 AM