Standard error handler in gil jpeg_io extension calls exit()
Hi, I'm using the gil jpeg_io extension like this: gil::rgb8_image_t img; gil::jpeg_read_image("test.jpg",img); As it turned out, if "test.jpg" is not a jpeg the program will quit with the message: "Not a JPEG file: starts with 0x6b 0x6a" although I put a try-catch-block around it. Digging a bit deeper, I found, that this is because in boost/gil/extension/io/jpeg_io_private.hpp the jpeg_reader::init() function uses the standard error handler: _cinfo.err=jpeg_std_error(&_jerr); which calls the exit() function. I'd prefer to have an exception and handle the exception in my main program rather than in the library. Is there a way to do that? To me it seems there's no other way than modifying the jpeg_io_extension. Or am I missing something? Any help is very appreciated! Peter
Hi Peter, Digging a bit deeper, I found, that this is because in
boost/gil/extension/io/jpeg_io_private.hpp the jpeg_reader::init() function uses the standard error handler:
_cinfo.err=jpeg_std_error(&_jerr);
which calls the exit() function. I'd prefer to have an exception and handle the exception in my main program rather than in the library.
Is there a way to do that? To me it seems there's no other way than modifying the jpeg_io_extension. Or am I missing something?
some time ago I was faced with the same problem and modified gil/extension/io/jpeg_io_private.hpp to throw an exception in that case. I am not sure, but maybe it is worth trying to get this into boost? Cheers, Robert
Hi Robert,
some time ago I was faced with the same problem and modified gil/extension/io/jpeg_io_private.hpp to throw an exception in that case.
Thank you for the attached header file. I very much appreciate that I've got a working solution now, although I'd wish that it was already implemented in boost like this.
I am not sure, but maybe it is worth trying to get this into boost?
That's true. I wonder who's responsible for the GIL I/O extension stuff. Would that be Christian Henning or rather Lubomir Bourdev? Cheers, Peter
2010/2/2 Peter Goetz
Hi Robert,
some time ago I was faced with the same problem and modified gil/extension/io/jpeg_io_private.hpp to throw an exception in that case.
Thank you for the attached header file. I very much appreciate that I've got a working solution now, although I'd wish that it was already implemented in boost like this.
I am not sure, but maybe it is worth trying to get this into boost?
That's true. I wonder who's responsible for the GIL I/O extension stuff. Would that be Christian Henning or rather Lubomir Bourdev?
Cheers, Peter
Robert, 2 minor details: 1. Is there a reason you used io_error_if(true...) instead of io_error(...)? 2. I think the return is not necessary since we throw anyway. Cheers, Peter
Hi Peter, Robert, 2 minor details:
1. Is there a reason you used io_error_if(true...) instead of io_error(...)?
No, just my ignorance. This was my first real venture into boost code and io_error_if was the first appropriate function I found.
2. I think the return is not necessary since we throw anyway.
You are right. As to who is responsible for the code I have no idea. Should we just propose the changes on the boost development list? Cheers, Robert
Christian,
Can you handle, please ?
regards
On Thu, Feb 4, 2010 at 4:17 PM, Robert Franke
Hi Peter,
Robert, 2 minor details:
1. Is there a reason you used io_error_if(true...) instead of io_error(...)?
No, just my ignorance. This was my first real venture into boost code and io_error_if was the first appropriate function I found.
2. I think the return is not necessary since we throw anyway.
You are right.
As to who is responsible for the code I have no idea. Should we just propose the changes on the boost development list?
Cheers,
Robert
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Christian was already informed. Sorry, forgot to forward it. Here's the email from Lubomir:
Hi Christian,
Could you perhaps submit a fix? This is temporary until we get your gil.io in place... But be sure to fix this in your io too...
Lubomir
Thanks guys for handling this!
Peter
2010/2/4 Jose
Christian, Can you handle, please ? regards
On Thu, Feb 4, 2010 at 4:17 PM, Robert Franke
wrote: Hi Peter,
Robert, 2 minor details:
1. Is there a reason you used io_error_if(true...) instead of io_error(...)?
No, just my ignorance. This was my first real venture into boost code and io_error_if was the first appropriate function I found.
2. I think the return is not necessary since we throw anyway.
You are right.
As to who is responsible for the code I have no idea. Should we just propose the changes on the boost development list?
Cheers,
Robert
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello Peter, On 31.01.2010 19:28, Peter Goetz wrote:
Hi,
I'm using the gil jpeg_io extension
which calls the exit() function. I'd prefer to have an exception and handle the exception in my main program rather than in the library.
Is there a way to do that?
While new gil.io is not in boost distribution, you can use io_new available here: http://gil-contributions.googlecode.com/svn/trunk/gil_2/boost/gil/extension/... It can be used like this: gil::rgb8_image_t img; try { boost::gil::read_and_convert_image(filePath, img, boost::gil::jpeg_tag()); } catch (std::ios_base::failure&) { // oops } ----------- Sergey Mitsyn.
participants (4)
-
Jose
-
Peter Goetz
-
Robert Franke
-
Sergey Mitsyn