Note that there are some explanatory texts on larger screens.

plurals
  1. POError reading .jpeg file using libjpeg
    primarykey
    data
    text
    <p>I am getting NULL pointer exception in the function <code>jpeg_read_header()</code> in following code while the input image file is successfully read by FILE object.</p> <pre><code>#include "jpeglib.h" #include &lt;iostream&gt; using namespace std; void decode_frame(char *filename) { unsigned char* raw_image; JSAMPROW row_pointer[1]; unsigned long location = 0; struct jpeg_error_mgr jerr; struct jpeg_decompress_struct cinfo ; FILE *infile = fopen(filename, "rb" ); if (infile == NULL ) { printf("Error opening jpeg file %s\n!", filename ); return -1; } cinfo.err = jpeg_std_error(&amp;jerr); /* create decompressor */ jpeg_create_decompress(&amp;cinfo); /* this makes the library read from infile */ jpeg_stdio_src(&amp;cinfo, infile ); /* read jpeg header */ jpeg_read_header(&amp;cinfo, TRUE); /* decompress */ jpeg_start_decompress(&amp;cinfo); /*allocate memory */ raw_image = (unsigned char*)malloc( cinfo.output_width*cinfo.output_height*cinfo.num_components ); /* now actually read the jpeg into the raw buffer */ row_pointer[0] = (unsigned char *)malloc( cinfo.output_width*cinfo.num_components ); /* read scanlines */ while (cinfo.output_scanline &lt; cinfo.output_height) { jpeg_read_scanlines( &amp;cinfo, row_pointer, 1 ); for( int i=0; i &lt; cinfo.image_width*cinfo.num_components;i++) raw_image[location++] = row_pointer[0][i]; } /* clean up */ jpeg_finish_decompress(&amp;cinfo); jpeg_destroy_decompress(&amp;cinfo); fclose( infile ); free( row_pointer[0] ); } int main(){ char *f = "Example.jpg"; decode_frame(f); return 0; } </code></pre> <p>The value of cinfo alfter <code>jpeg_stdio_src(&amp;cinfo, infile )</code> function call is :</p> <pre><code>cinfo{err=0x0020f8fc mem=0x021cb320 progress=0x00000000 ...} progress 0x00000000 {progress_monitor=??? pass_counter=??? pass_limit=??? ...} client_data 0xcccccccc void * is_decompressor 1 global_state 200 src 0x021c4480 {next_input_byte=0x00000000 &lt;Bad Ptr&gt; bytes_in_buffer=0 init_source=0x686ccb50 ...} image_width 0 image_height 0 num_components 0 jpeg_color_space JCS_UNKNOWN out_color_space JCS_UNKNOWN scale_num 0 scale_denom 0 output_gamma 0.00000000000000000 buffered_image 0 raw_data_out 0 dct_method JDCT_ISLOW </code></pre> <p>Where I am getting wrong? This is the first time I am using image library.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload