Forum > Graphics

FPReadGif possible bug?

(1/1)

KodeZwerg:
Based on an example done by wp I've extended his version to support all graphic formats that FP brings in a detection method that should give back dimensions and format.

Here is the used code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  FPImage, FPReadBMP, FPReadGif, FPReadJPEG, FPReadPCX, FPReadPNG, FPReadPNM, FPReadPSD, FPReadTGA, FPReadTiff, FPReadXPM, FPReadXWD, type  TImageFormat = (ifUnknown, ifBmp, ifGif, ifJpg, ifPcx, ifPng, ifPnm, ifPsd, ifTga, ifTiff, ifXpm, ifXwd);  function GetImageSize(const AFilename: string; out AWidth, AHeight: dword): TImageFormat;var  stream: TFileStream;  imgSize: TPoint;  readerClass: TFPCustomImageReaderClass;begin  Result := ifUnknown;  stream := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyNone);  try    readerClass := TFPCustomImage.FindReaderFromStream(stream);    if readerClass <> nil then      begin        if readerClass = TFPReaderBMP then          Result := ifBmp        else        if readerClass = TFPReaderGif then          Result := ifGif        else        if readerClass = TFPReaderJPEG then          Result := ifJpg        else        if readerClass = TFPReaderPCX then          Result := ifPcx        else        if readerClass = TFPReaderPNG then          Result := ifPng        else        if readerClass = TFPReaderPNM then          Result := ifPnm        else        if readerClass = TFPReaderPSD then          Result := ifPsd        else        if readerClass = TFPReaderTarga then          Result := ifTga        else        if readerClass = TFPReaderTiff then          Result := ifTiff        else        if readerClass = TFPReaderXPM then          Result := ifXpm        else        if readerClass = TFPReaderXWD then          Result := ifXwd;        imgSize := readerClass.ImageSize(stream);        AWidth := imgSize.X;        AHeight := imgSize.Y;      end;  finally    stream.Free;  end;end;
For GIF files it returns -1 for Width and Height property.
Is that a bug or do I use it wrong?

wp:
In order to return the image size by the ImageSize method a reader must implement the virtual InternalSize class function. TFPReaderGIF does not do this and thus returns the default width and height, -1.

Reported in https://gitlab.com/freepascal.org/fpc/source/-/issues/40630

The attached project uses the patched fpreadgif unit of the bug report in a small console program.

[EDIT]
The patch has already been applied.

KodeZwerg:
First of all, thank very much for your patch!!
Building your example does flawless work, compile and run with fetching dimensions out works also.

Put the patched file in my projects folder, at build I do get error that the checksum from graphics in belonging to your unit does not match.
So I'd thought, "okay, I guess I need to put it into my c:\Tools\FreePascal\fpcsrc\packages\fcl-image\src\ folder and rebuild my installation."
Before I do this, it's a good time to update via FPUP(deluxe) to latest Lazarus trunk. Done.
Check in folder if it has replaced the patched unit, no it does not, it is yours.
Removed from your example folder the patched file to proof it uses/show the new version in the IDE, it does.
Pressed Build, Compile, Run, it does not complain but it seems that it still uses the old pre-compiled and not the new patched one.
I did pressed on "clean build IDE", after that IDE closes and starts, no errors.
Tried to rebuild, recompile, run your demo, again -1 displayed.

So my question is, how do I compile/integrate it into my Lazarus/FPC installation please?
Sorry for this beginner question, rebuild IDE was for my little patches always enough to do.

Lazarus 3.99 (rev main_3_99-1410-g1b863d612c) FPC 3.2.2 x86_64-win64-win32/win64

wp:
Since a registered file format reader/writer (FCL) is used by the graphics unit (LCL) it is not possible to just copy the modified fpreadgif into your project directory. And this caused me to demonstrate the fixed issue in a console application which does not need the LCL.

You should install FPC/main in which the changed unit is already contained - and you actually did this by using fpcupdeluxe.

Basically you could also use the modified unit in you current fpc 3.2.2 (copy it into the corresponding fpc/packages/fcl-image folder), but then you must recompile FPC. Rebuilding the Lazarus IDE from the tools menu has no effect because it does not rebuild FPC...

In the attachment you can find a batch file which I am routinely using in several modifications to recompile FPC. Adjust the directory names to your situation and run the script from a console (you may want to skip copying the compiled files to a "bin" directory)

But sincerely, gif is a rarely used file format today, and the necessity to get the image size without reading the full file is not an every-day task either. Therefore, I would not take the risk of damaging my compiler setup this way (The exercise of recompiling FPC may be better reason, though, but then do it with a secondary, separate installation).

Navigation

[0] Message Index

Go to full version