[Gdal-dev] how can i get the error msg

Frank Warmerdam warmerdam at pobox.com
Thu Apr 2 11:05:37 EDT 2009


mjollnir wrote:
> hi,
> 
> when i handle a bad jpg file, like this:
> eErr = GDALRasterIO(hBand, GF_Read, 0, 0, nXSize, nYSize,......)
> 
> i got this error message in console:
> Premature end of JPEG file
> 
> i'm wonder where the error msg come from. because i found that: eErr == CE_None
> 
> when i use this code the code quiet the msg:
> CPLPushErrorHandler( CPLQuietErrorHandler );
> eErr = GDALRasterIO(hBand, GF_Read, 0, 0, nXSize, nYSize,......)
> 
> the error msg still be there.
> 
> so, my question is:
> where the error msg come  from, how can i quiet it or handle it.
> and how can i know the image file is bad before i process it.

mjollnir,

It looks like this warning is issued by libjpeg in the fill_input_buffer
function:

fill_input_buffer (j_decompress_ptr cinfo)
{
   my_src_ptr src = (my_src_ptr) cinfo->src;
   size_t nbytes;

   nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);

   if (nbytes <= 0) {
     if (src->start_of_file)     /* Treat empty input file as fatal error */
       ERREXIT(cinfo, JERR_INPUT_EMPTY);
     WARNMS(cinfo, JWRN_JPEG_EOF);
     /* Insert a fake EOI marker */
     src->buffer[0] = (JOCTET) 0xFF;
     src->buffer[1] = (JOCTET) JPEG_EOI;
     nbytes = 2;
   }

   src->pub.next_input_byte = src->buffer;
   src->pub.bytes_in_buffer = nbytes;
   src->start_of_file = FALSE;

   return TRUE;
}

It appears that while we (GDAL) overrides the error exit
handler for the libjpeg library, we do not override the warning
handler so the warnings are just issued to stdout or stderr.

If you file a ticket on this, I can likely correct the warning
handling.  However, it is unlikely to be treated as a fatal error
since the authors of libjpeg have apparently decided that a
truncated file should not be treated as an error.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list