[pHash-support] throwing exceptions from the binding code into the java glue

Alexander Kjäll - alaTest alex at alatest.com
Thu May 20 06:12:23 PDT 2010


Hi

This is the error that i get:

[java] Not a JPEG file: starts with 0x47 0x49

and then the libjpeg code does a exit(1).

You should be able to reproduce this error by renaming a .gif image to 
.jpg and try to calculate a hash for them.

I tried the code in my last patch (with the try {...} catch) and the 
latest CImg version from cvs and I got memory corruption errors when i 
tried to do an hash for a grayscale jpeg.

I'll try to hunt down where the problem lies, my current guess is that 
it's a problem with CImg.

thanks for the feedback, if I manage to solve the memory corruption 
error I'll try to write a patch without try {} catch {} for the illegal 
jpeg error.

best regards
Alexander Kjäll

On 2010-05-19 19:25, Evan Klinger wrote:
> Currently we disable all exceptions through a #define in the source.
> So it's hardcoded. But after looking at the CImg source again the
> macro may have been renamed so I need to look into that again to make
> sure we are using the correct name.
> What was the result of the JPEG error, did it cause the application to
> crash? It may be sufficient to check the CImg instance after your load
> call to be sure it was correctly loaded. I believe you can use
> img.is_empty() to check for that condition. So the first step is to
> determine if it was CImg that caused the crash or your application.
>
> Evan
>
> 2010/5/19 Alexander Kjäll - alaTest<alex at alatest.com>:
>> Hi
>>
>> Sounds like a good thing to disable exceptions, is this an option to the
>> configure script?
>>
>> I looked at the code in the CVS version of CImg:
>>
>> if (setjmp(jerr.setjmp_buffer)) { // JPEG error
>>   throw CImgIOException(_cimg_instance
>>            "load_jpeg() : Error message returned by libjpeg : %s.",
>>            cimg_instance,jerr.message);
>> }
>>
>> (around line 30766 in CImg.h)
>>
>> And it doesn't look like the throwing of the exception is optional, but it
>> was a pretty long time since I programmed c++ seriously, so I might be
>> totally out on this one.
>>
>> When I have had some more time to look at how this work I try to think up a
>> good structure for sending the error's into java.
>>
>> best regards
>> Alexander Kjäll
>>
>> On 2010-05-17 18:04, Evan Klinger wrote:
>>>
>>> Hello,
>>> Currently we disable CImg exceptions during compilation since they add
>>> considerable overhead. I understand the value they provide, but I'm
>>> wondering if it's possible to have them disabled in CImg/pHash and
>>> simply check the return code from CImg functions and throw exceptions
>>> in the Java code only. For example, if the CImg jpeg load function
>>> fails, the returned pointer will be NULL which can be tested and then
>>> throw your IllegalImageException in Java.
>>>
>>> Evan
>>>
>>> 2010/5/17 Alexander Kjäll - alaTest<alex at alatest.com>:
>>>>
>>>> Hi again
>>>>
>>>> I solved my problem with libjpeg by upgrading my installation of the CImg
>>>> library to the latest version.
>>>>
>>>> The next step is to make the exceptions that the CImg library throws
>>>> visible
>>>> to the java code, i wrote a small patch and a corresponding java
>>>> exception
>>>> class as a testcase on how it would be possible to do this.
>>>>
>>>> the exception class should be placed in
>>>> bindings/java/org/pHash/exceptions/
>>>>
>>>> This is a rather incomplete patch, and I don't think it should be
>>>> included
>>>> right away.
>>>>
>>>> But I would like to get some feedback if you think this is the right
>>>> direction to take the java bindings, before I spend more time on it.
>>>>
>>>> Any feedback is greatly appreciated.
>>>>
>>>> best regards
>>>> Alexander Kjäll
>>>>
>>>>
>>>> --
>>>> Developer
>>>> alex at alatest.com
>>>> +468343115
>>>>
>>>> _______________________________________________
>>>> pHash-support mailing list
>>>> pHash-support at lists.phash.org
>>>> http://lists.phash.org/listinfo.cgi/phash-support-phash.org
>>>>
>>>>
>>
>>
>> --
>> Developer
>> alex at alatest.com
>> +468343115
>>


-- 
Developer
alex at alatest.com
+468343115



More information about the pHash-support mailing list