Fixed warning in jpeg loader by replacing longjmp with throw/catch.
This commit is contained in:
parent
525cd9292d
commit
79855cf669
@ -4,9 +4,7 @@ include $(TOPDIR)/Make/makedefs
|
|||||||
CXXFILES =\
|
CXXFILES =\
|
||||||
ReaderWriterJPEG.cpp\
|
ReaderWriterJPEG.cpp\
|
||||||
|
|
||||||
ifneq ($(OS),HP-UX)
|
ifeq ($(OS),HP-UX)
|
||||||
INC += -I/usr/local/include/
|
|
||||||
else
|
|
||||||
INC += $(JPEG_INCLUDE)
|
INC += $(JPEG_INCLUDE)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -59,48 +59,10 @@ extern "C"
|
|||||||
|
|
||||||
static int jpegerror = ERR_NO_ERROR;
|
static int jpegerror = ERR_NO_ERROR;
|
||||||
|
|
||||||
int
|
|
||||||
simage_jpeg_error(char * buffer, int buflen)
|
|
||||||
{
|
|
||||||
switch (jpegerror)
|
|
||||||
{
|
|
||||||
case ERR_OPEN:
|
|
||||||
strncpy(buffer, "JPEG loader: Error opening file", buflen);
|
|
||||||
break;
|
|
||||||
case ERR_MEM:
|
|
||||||
strncpy(buffer, "JPEG loader: Out of memory error", buflen);
|
|
||||||
break;
|
|
||||||
case ERR_JPEGLIB:
|
|
||||||
strncpy(buffer, "JPEG loader: Illegal jpeg file", buflen);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return jpegerror;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct my_error_mgr
|
|
||||||
{
|
|
||||||
struct jpeg_error_mgr pub; /* "public" fields */
|
|
||||||
|
|
||||||
jmp_buf setjmp_buffer; /* for return to caller */
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct my_error_mgr * my_error_ptr;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
my_error_exit (j_common_ptr cinfo)
|
my_error_exit (j_common_ptr cinfo)
|
||||||
{
|
{
|
||||||
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
throw cinfo;
|
||||||
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
|
||||||
|
|
||||||
/* Always display the message. */
|
|
||||||
/* We could postpone this until after returning, if we chose. */
|
|
||||||
/*(*cinfo->err->output_message) (cinfo);*/
|
|
||||||
|
|
||||||
/* FIXME: get error messahe from jpeglib */
|
|
||||||
|
|
||||||
/* Return control to the setjmp point */
|
|
||||||
longjmp(myerr->setjmp_buffer, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,7 +106,8 @@ int *numComponents_ret)
|
|||||||
* Note that this struct must live as long as the main JPEG parameter
|
* Note that this struct must live as long as the main JPEG parameter
|
||||||
* struct, to avoid dangling-pointer problems.
|
* struct, to avoid dangling-pointer problems.
|
||||||
*/
|
*/
|
||||||
struct my_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
|
|
||||||
/* More stuff */
|
/* More stuff */
|
||||||
FILE * infile; /* source file */
|
FILE * infile; /* source file */
|
||||||
JSAMPARRAY rowbuffer; /* Output row buffer */
|
JSAMPARRAY rowbuffer; /* Output row buffer */
|
||||||
@ -166,25 +129,16 @@ int *numComponents_ret)
|
|||||||
|
|
||||||
/* Step 1: allocate and initialize JPEG decompression object */
|
/* Step 1: allocate and initialize JPEG decompression object */
|
||||||
|
|
||||||
/* We set up the normal JPEG error routines, then override error_exit. */
|
|
||||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
|
||||||
jerr.pub.error_exit = my_error_exit;
|
|
||||||
/* Establish the setjmp return context for my_error_exit to use. */
|
|
||||||
if (setjmp(jerr.setjmp_buffer))
|
|
||||||
{
|
|
||||||
/* If we get here, the JPEG code has signaled an error.
|
|
||||||
* We need to clean up the JPEG object, close the input file, and return.
|
|
||||||
*/
|
|
||||||
jpegerror = ERR_JPEGLIB;
|
|
||||||
jpeg_destroy_decompress(&cinfo);
|
|
||||||
fclose(infile);
|
|
||||||
//if (buffer) delete [] buffer;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// used to be before setjump above, but have moved to after to avoid compile warnings.
|
// used to be before setjump above, but have moved to after to avoid compile warnings.
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
|
|
||||||
|
/* We set up the normal JPEG error routines, then override error_exit. */
|
||||||
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
|
jerr.error_exit = my_error_exit;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
/* Now we can initialize the JPEG decompression object. */
|
/* Now we can initialize the JPEG decompression object. */
|
||||||
jpeg_create_decompress(&cinfo);
|
jpeg_create_decompress(&cinfo);
|
||||||
|
|
||||||
@ -296,6 +250,23 @@ int *numComponents_ret)
|
|||||||
jpegerror = ERR_MEM;
|
jpegerror = ERR_MEM;
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
|
}
|
||||||
|
catch (j_common_ptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::cout << " Here we are"<<std::endl;
|
||||||
|
|
||||||
|
/* If we get here, the JPEG code has signaled an error.
|
||||||
|
* We need to clean up the JPEG object, close the input file, and return.
|
||||||
|
*/
|
||||||
|
jpegerror = ERR_JPEGLIB;
|
||||||
|
jpeg_destroy_decompress(&cinfo);
|
||||||
|
fclose(infile);
|
||||||
|
if (buffer) delete [] buffer;
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -318,7 +289,17 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
|||||||
|
|
||||||
imageData = simage_jpeg_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
imageData = simage_jpeg_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||||
|
|
||||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
if (imageData==NULL)
|
||||||
|
{
|
||||||
|
switch (jpegerror)
|
||||||
|
{
|
||||||
|
case ERR_OPEN: return ReadResult("JPEG loader: Error opening file");
|
||||||
|
case ERR_MEM: return ReadResult("JPEG loader: Out of memory error");
|
||||||
|
case ERR_JPEGLIB: return ReadResult("JPEG loader: Illegal jpeg file");
|
||||||
|
}
|
||||||
|
return ReadResult::FILE_NOT_HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int s = width_ret;
|
int s = width_ret;
|
||||||
int t = height_ret;
|
int t = height_ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user