Vampyre Imaging Library Forum

Imaging Category => Bugs And Other Insects => Topic started by: Bernd on 15 June 2010, 14:49:22

Title: JPG throws exception when it contains no resolution information
Post by: Bernd on 15 June 2010, 14:49:22
Version: current trunk from svn
Compiler: FPC 2.5.1/Lazarus
Operating system: Windows 7 (x64)

JPEG throws exception when loading thru

aJPEG: TImagingGraphic;
...
aJPEG := TImagingGraphic.Create;
aJPEG.LoadFromFile('TMP68830.jpg');
aJPEG.Free;

The exception is thrown in "imaging.pas" (TMetadata.TranslateUnits) in line 3934, because the image does not contain any x or y resolution. In this case the call

    XRes := UnitSize / XRes;
    YRes := UnitSize / YRes;     

causes an "div zero" exception. I recommend to check the content of "Xres" and "Yres" and if zero, set it to a default value (72 or 96dpi).

This is a working solution for the problem:

    if XRes <=0 then Xres := 96;
    if YRes <=0 then Yres := 96;
    XRes := UnitSize / XRes;
    YRes := UnitSize / YRes;

Regards
Bernd

Title: Re: JPG throws exception when it contains no resolution information
Post by: Galfar on 15 June 2010, 15:09:32
Thanks for reporting this, I'll fix it right away. 
New features in the trunk haven't been tested that much yet.