Recent

Author Topic: FCL Image SIGSEGV Raised on run  (Read 7742 times)

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
FCL Image SIGSEGV Raised on run
« on: June 26, 2018, 12:43:48 am »
Hi to all
can anyone explain me why the following code don't work

Code: Pascal  [Select][+][-]
  1. Unit uMainForm;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. Interface
  6.  
  7. Uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   FPImage, FPCanvas, FPImgCanv,
  10.   FPReadBMP, FPReadGIF;
  11.  
  12. Type
  13.  
  14.   { TMainForm }
  15.  
  16.   TMainForm = Class(TForm)
  17.     Procedure FormActivate(Sender: TObject);
  18.     Procedure FormCreate(Sender: TObject);
  19.     Procedure FormDestroy(Sender: TObject);
  20.     Procedure FormDropFiles(Sender: TObject; Const FileNames: Array Of String);
  21.     Procedure FormPaint(Sender: TObject);
  22.   private
  23.     InDrawingMode : Boolean;
  24.   protected
  25.     FPCanvas : TFPcustomCanvas;
  26.     FPImage : TFPCustomImage;
  27.     FPReader : TFPCustomImageReader;
  28.   public
  29.  
  30.     procedure DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);
  31.   End;
  32.  
  33. Var
  34.   MainForm: TMainForm;
  35.  
  36. Implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TMainForm }
  41. Const
  42.   FPColorRed: TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535);
  43.  
  44. procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);
  45. begin
  46.   Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),TCanvas(ACanvas) , Rect(0,0,ACanvas.Width,ACanvas.Height));
  47. end;
  48.  
  49. Procedure TMainForm.FormActivate(Sender: TObject);
  50. Begin
  51.   InDrawingMode:= True;
  52. end;
  53.  
  54. Procedure TMainForm.FormCreate(Sender: TObject);
  55. Begin
  56.   FPImage := TFPMemoryImage.Create (256, 256);
  57.   FPCanvas := TFPImageCanvas.Create (FPImage);
  58.   FPCanvas.Brush.FPColor := FPColorRed ;
  59.   FPCanvas.Brush.Style := bsSolid;
  60.   FPCanvas.Clear;
  61.   InDrawingMode:= False;
  62. end;
  63.  
  64. Procedure TMainForm.FormDestroy(Sender: TObject);
  65. Begin
  66.   FreeAndNil(FPCanvas);
  67.   FreeAndNil(FPImage);
  68. end;
  69.  
  70. Procedure TMainForm.FormDropFiles(Sender: TObject; Const FileNames: Array Of String);
  71. Var
  72.   ImageFileName : String;
  73.   FileExtension : String;
  74. Begin
  75.   ImageFileName := FileNames[0];
  76.   FileExtension := ExtractFileExt(ImageFileName);
  77.   showmessage(FileExtension);
  78.   if FIleExtension ='.bmp' then
  79.     FPReader := TFPReaderBMP.Create
  80.   else if FIleExtension ='.gif' then
  81.     FPReader := TFPReaderGIF.Create;
  82.  
  83.   Try
  84.     Try
  85.       Screen.Cursor := crHourGlass;
  86.  
  87.       FPImage.LoadFromFile(ImageFileName, FPReader);
  88.  
  89.     Finally
  90.         Screen.Cursor := crDefault;
  91.     End;
  92.   Except
  93.     On E: FPImageException Do
  94.     Begin
  95.       MessageDlg(E.Message, mtWarning, [mbOK], 0);
  96.       Exit;
  97.     End
  98.     Else
  99.     Begin
  100.       MessageDlg('Unknown Error', mtError, [mbOK, mbAbort], 0);
  101.     End;
  102.   End;
  103.  
  104. end;
  105.  
  106. Procedure TMainForm.FormPaint(Sender: TObject);
  107. Begin
  108.   if InDrawingMode then DrawFPImageToCanvas(FPCanvas);
  109. end;
  110.  
  111. End.

Note :  TCanvas = class(TFPCustomCanvas)

Thanks
« Last Edit: June 26, 2018, 01:09:17 am by BeanzMaster »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: FCL Image SIGSEGV Raised on run
« Reply #1 on: June 26, 2018, 01:33:48 am »
Method
Code: Pascal  [Select][+][-]
  1. procedure TCanvas.CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect);
has line
Code: Pascal  [Select][+][-]
  1. SrcCanvas.RequiredState([csHandleValid]);
but class TFPCustomCanvas has NOT this method. RequiredState is protected method of TCanvas.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #2 on: June 26, 2018, 01:59:40 am »
It's not help me

and i use

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);
  2. begin
  3.   Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),TCanvas(ACanvas) , Rect(0,0,ACanvas.Width,ACanvas.Height));
  4. end;

If i not uses the form's paint event i don't any SIGSEGV but Image (bmp or gif) is not displayed at loading, and no SIGSEV raised.

What wrong with this code or how can i display directly the FPImage

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: FCL Image SIGSEGV Raised on run
« Reply #3 on: June 26, 2018, 02:35:09 am »
I usually use TBitmap and its Canvas. Also, I'm not sure if it is possible to paint to Form.Canvas directly. Qt does not support it, for example. I have to use TPaintBox or TImage. You can then draw via PaintBox.CopyRect() or PaintBox.Draw().
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: FCL Image SIGSEGV Raised on run
« Reply #4 on: June 26, 2018, 02:38:34 am »
hello,
you can try this :
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);
  2. begin
  3.  TFPCustomCanvas(Canvas).CopyRect(0,0,ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));
  4.  //Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));
  5. end;
have a look to this message : Re: Mixing Between FCL and LCL

Edit : in your code, an invalidate is missing after the FPImage.LoadFromFile  to redraw the canvas. Try this :
Code: Pascal  [Select][+][-]
  1.       FPImage.LoadFromFile(ImageFileName, FPReader);
  2.       Invalidate;  
  3.  

Friendly, J.P
« Last Edit: June 26, 2018, 03:36:22 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #5 on: June 26, 2018, 03:06:37 pm »
Hello
hello,
you can try this :
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);
  2. begin
  3.  TFPCustomCanvas(Canvas).CopyRect(0,0,ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));
  4.  //Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));
  5. end;
have a look to this message : Re: Mixing Between FCL and LCL

Edit : in your code, an invalidate is missing after the FPImage.LoadFromFile  to redraw the canvas. Try this :
Code: Pascal  [Select][+][-]
  1.       FPImage.LoadFromFile(ImageFileName, FPReader);
  2.       Invalidate;  
  3.  

Friendly, J.P

Thanks it work, but like i supposed TFPxxx is bugged see attached screenshots :(

This is  the code

Code: Pascal  [Select][+][-]
  1.   FPImage := TFPMemoryImage.Create (256, 256);
  2.   FPCanvas := TFPImageCanvas.Create (FPImage);
  3.   FPCanvas.Pen.Style := psClear ;
  4.   FPCanvas.Brush.FPColor := FPColorRed ;
  5.   FPCanvas.Brush.Style := bsSolid;
  6.   FPCanvas.Clear;

How work correctly in this case ????? the black lin on top and left normally not to be here :(


BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #6 on: June 26, 2018, 03:34:25 pm »
Like i said :

here are some screenshots wherer we can see that the BMP format is not supported correctly.

Test under Windows. Thumbnails are those of the file explorer

The BMP provide from my BMP-ImageTestSuite here : https://github.com/jdelauney/BMP-ImageTestSuite

The worst is that no error message appears or is raised

FCL/LCL Bitmap management really need a big update
« Last Edit: June 26, 2018, 03:49:33 pm by BeanzMaster »

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #7 on: June 26, 2018, 03:34:57 pm »
Next part

And those screenshot is just some problems. Many other BMP don't displayed correctly
« Last Edit: June 26, 2018, 03:38:04 pm by BeanzMaster »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: FCL Image SIGSEGV Raised on run
« Reply #8 on: June 27, 2018, 06:44:10 am »
hello,
you can also try to use the last version of vampyre imaging library to read images in lazarus :

1 - The last version is here
2 - Download the zip file and uncompress it.
3 - Install the packages vampyreimagingpackage.lpk and vampyreimagingpackage_ext.lpk  from the folder Extras\IdePackages\Lazarus
4 - Try the demo lclimager in the folder Demos\ObjectPascal\LCLImager
Note : it seems that there is problem to read jpeg with this version of the library (rangecheck error in the file imjdhuff.pas). So to run the demo :
1 - Disable the automatic load of the tiger.jpg image in the create of the mainform unit.
2 - Don't try to load jpeg file or correct the range check error (and say to us how  ).
i have tried this on Windows 10 Lazarus 1.8.2 32 bits.
See screenshots in attachments (load a gif and a bmp image).

Friendly, J.P

[EDIT] if i put the line Dec(entropy^.restarts_to_go); in comment in the function decode_mcu of the file imjdhuff.pas no more range check error :
Code: Pascal  [Select][+][-]
  1.   { Account for restart interval (no-op if not using restarts) }
  2. //  Dec(entropy^.restarts_to_go);
« Last Edit: June 27, 2018, 07:07:26 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #9 on: June 27, 2018, 03:56:42 pm »
Hi JP thanks but i don't use. I test FCL-Image cause of the message from wp in Annoucement/TGIfViewer topic

I already can open all of those file in my project.

Graphics is not a priority for dev team. I regret it because this bug I am sure it causes many others downstream. Dev team must do a brainstorming around graphics with FPC and LCL. It's a very important part, but it seems not actually. This kind of bug can really cause great instability over time

Thanks

I come back to my own solution it work better

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FCL Image SIGSEGV Raised on run
« Reply #10 on: June 27, 2018, 04:55:23 pm »
I test FCL-Image cause of the message from wp in Annoucement/TGIfViewer topic
My comment refered to the drawing of the GIF images. I don't believe that it is needed to provide a dedicated "fastbitmap" class. FCL-image can paint other formats, so why shouldn't it be able to paint animated GIF?

[...] because this bug I am sure it causes many others downstream. Dev team must do a brainstorming around graphics with FPC and LCL. It's a very important part, but it seems not actually. This kind of bug can really cause great instability over time
I always have been able to load all my bmp files without any error using the LCL/FPC routines. I could imagine that the BMP specification contains a variety of options which are not supported by the bmp reader because they were not considered to be relevant when the units were written. But of course, if your collection contains all these corner cases the bmp reader will appear like crap.

Instead of lamenting about the bugginess of the bmp reader you should write patches which address all these issues. You seem to be a programmer who has good knowledge of the graphics formats, and it appears to be a waste of resources if you write your own image library instead of improving the existing one.

But of course, you can do what you want...

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #11 on: June 27, 2018, 11:53:00 pm »

My comment refered to the drawing of the GIF images. I don't believe that it is needed to provide a dedicated "fastbitmap" class. FCL-image can paint other formats, so why shouldn't it be able to paint animated GIF?


It's exactly what i want and for understing how work FCL-Image i begining from the start with simple code



I always have been able to load all my bmp files without any error using the LCL/FPC routines. I could imagine that the BMP specification contains a variety of options which are not supported by the bmp reader because they were not considered to be relevant when the units were written. But of course, if your collection contains all these corner cases the bmp reader will appear like crap.

Just test image in my imagetestsuite and you'll see by yourself
 Sorry not understanding well.
 BMP is one the most old image format it will be supported correctly
In the case of 512x128x16.bmp and 512x128x32 those two images was made by me in gimp (see the screen shoot) More standard of that you can't.

Instead of lamenting about the bugginess of the bmp reader you should write patches which address all these issues. You seem to be a programmer who has good knowledge of the graphics formats, and it appears to be a waste of resources if you write your own image library instead of improving the existing one.

But of course, you can do what you want...

What i tell is the bug with black line can produce error code in others part like in widgets and it's not good.
Yes i 'm developping my own solution. Like you said to me Graphics is actually not a priority. I think that that's too bad.

It's my opinion that FCL-Image did not go in the right direction. Modified all this part of the FCL is not my responsibility. I do not know enough about the content of the code. Moreover, doing or adding things to something that is not working properly is not a long-term solution.
But it is clear that I can provide solutions for reading support for several image formats. And that's why I need to know the functioning of the FCL-Image and this first bug can cause serious problem to the display.

and this why i posted this : http://forum.lazarus.freepascal.org/index.php/topic,41706.msg289856/boardseen.html#new. But you already see it  :D

« Last Edit: June 28, 2018, 12:16:04 am by BeanzMaster »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FCL Image SIGSEGV Raised on run
« Reply #12 on: June 29, 2018, 12:25:32 pm »
I don't know what's going on here. I wrote a test application to easily load your test images (see attachment), and all of them seem to be displayed correctly except for the "bmp_*.bmp" pictures which do not show up at all. In the attachment you see the screenshot lena_02.bmp which you cannot display. I normally use Win10/64bit and Laz-trunk/fpc3.0.4-32bit, but the 64-bit is working here too, as well as Laz-1.8.4/fpc3.0.4-32bit/Win10 and Laz-trunk/fpc 3.0.4/Win 7

Please post your code in a compilable project. You must be doing something severely wrong.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: FCL Image SIGSEGV Raised on run
« Reply #13 on: June 29, 2018, 03:05:02 pm »
Hi wp

My test code is very basic and normally  it must be work as is.

Tested on win10/64 with lazarus 1.8.5 FPC 3.0.4 and lazarus 1.9 FPC 3.1.1 same result

Note i beginning to patch the FPReadBMP unit. When i'll find how to recompil fpc source correctly. I'll test.
I'll also prepare some little report for  bugtraker. i found very minor bugs in FCL-Image. 
« Last Edit: June 29, 2018, 03:10:38 pm by BeanzMaster »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FCL Image SIGSEGV Raised on run
« Reply #14 on: June 30, 2018, 01:31:09 pm »
I have the feeling that something is missing here. You are working with a simple TFPMemoryImage. Does it do all the required adaptions to the device format? Lazarus introduced TLazIntfImage for this purpose. There is an example in the wiki:
http://wiki.freepascal.org/Developing_with_Graphics#Working_with_TLazIntfImage.2C_TRawImage_and_TLazCanvas. This is similar to what the LCL is doing when reading an image. And the LCL can read all your test bmp images without any problems (I reported above that the bmp*.bmp images cannot be read - this is not true, I just did not see them due to their small size; with the gifs there are some issues, though).

 

TinyPortal © 2005-2018