FCL Image SIGSEGV Raised on run lazarus / 39-Graphics ---------------------------------------------------------------------- BeanzMaster · 2018-06-25 22:43 Hi to all can anyone explain me why the following code don't work Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Unit uMainForm; {$mode objfpc}{$H+} Interface Uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  FPImage, FPCanvas, FPImgCanv,  FPReadBMP, FPReadGIF; Type   { TMainForm }   TMainForm = Class(TForm)    Procedure FormActivate(Sender: TObject);    Procedure FormCreate(Sender: TObject);    Procedure FormDestroy(Sender: TObject);    Procedure FormDropFiles(Sender: TObject; Const FileNames: Array Of String);    Procedure FormPaint(Sender: TObject);  private  InDrawingMode : Boolean;  protected    FPCanvas : TFPcustomCanvas;    FPImage : TFPCustomImage;    FPReader : TFPCustomImageReader;  public     procedure DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);  End; Var  MainForm: TMainForm; Implementation {$R *.lfm} { TMainForm }Const  FPColorRed: TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535); procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);begin  Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),TCanvas(ACanvas) , Rect(0,0,ACanvas.Width,ACanvas.Height));end; Procedure TMainForm.FormActivate(Sender: TObject);Begin  InDrawingMode:= True;end; Procedure TMainForm.FormCreate(Sender: TObject);Begin  FPImage := TFPMemoryImage.Create (256, 256);  FPCanvas := TFPImageCanvas.Create (FPImage);  FPCanvas.Brush.FPColor := FPColorRed ;  FPCanvas.Brush.Style := bsSolid;  FPCanvas.Clear;  InDrawingMode:= False;end; Procedure TMainForm.FormDestroy(Sender: TObject);Begin  FreeAndNil(FPCanvas);  FreeAndNil(FPImage);end; Procedure TMainForm.FormDropFiles(Sender: TObject; Const FileNames: Array Of String);Var  ImageFileName : String;  FileExtension : String;Begin  ImageFileName := FileNames[0];  FileExtension := ExtractFileExt(ImageFileName);  showmessage(FileExtension);  if FIleExtension ='.bmp' then    FPReader := TFPReaderBMP.Create  else if FIleExtension ='.gif' then    FPReader := TFPReaderGIF.Create;   Try  Try      Screen.Cursor := crHourGlass;       FPImage.LoadFromFile(ImageFileName, FPReader);     Finally        Screen.Cursor := crDefault;    End;  Except    On E: FPImageException Do    Begin      MessageDlg(E.Message, mtWarning, [mbOK], 0);      Exit;    End    Else    Begin      MessageDlg('Unknown Error', mtError, [mbOK, mbAbort], 0);    End;  End; end; Procedure TMainForm.FormPaint(Sender: TObject);Begin  if InDrawingMode then DrawFPImageToCanvas(FPCanvas);end; End. Note :  TCanvas = class(TFPCustomCanvas) Thanks ---------------------------------------------------------------------- Blaazen · 2018-06-25 23:33 Method Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCanvas.CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect); has line Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SrcCanvas.RequiredState([csHandleValid]);but class TFPCustomCanvas has NOT this method. RequiredState is protected method of TCanvas. ---------------------------------------------------------------------- BeanzMaster · 2018-06-25 23:59 It's not help me and i use Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);begin  Canvas.CopyRect(Rect(0,0,Canvas.Width,Canvas.Height),TCanvas(ACanvas) , Rect(0,0,ACanvas.Width,ACanvas.Height));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 · 2018-06-26 00:35 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(). ---------------------------------------------------------------------- Jurassic Pork · 2018-06-26 00:38 hello, you can try this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);begin TFPCustomCanvas(Canvas).CopyRect(0,0,ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height)); //Canvas.CopyRect(Rect(0,0,Ca nvas.Width,Canvas.Height),ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       FPImage.LoadFromFile(ImageFileName, FPReader);      Invalidate;   Friendly, J.P ---------------------------------------------------------------------- BeanzMaster · 2018-06-26 13:06 Hello Quote from: Jurassic Pork on June 26, 2018, 02:38:34 amhello, you can try this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.DrawFPImageToCanvas(ACanvas: TFPCustomCanvas);begin TFPCustomCanvas(Canvas).CopyRect(0,0,ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height)); //Canvas.CopyRect(Rect(0,0,Ca nvas.Width,Canvas.Height),ACanvas , Rect(0,0,ACanvas.Width,ACanvas.Height));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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       FPImage.LoadFromFile(ImageFileName, FPReader);      Invalidate;   Friendly, J.P Thanks it work, but like i supposed TFPxxx is bugged see attached screenshots This is  the code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   FPImage := TFPMemoryImage.Create (256, 256);  FPCanvas := TFPImageCanvas.Create (FPImage);  FPCanvas.Pen.Style := psClear ;  FPCanvas.Brush.FPColor := FPColorRed ;  FPCanvas.Brush.Style := bsSolid;  FPCanvas.Clear; How work correctly in this case ????? the black lin on top and left normally not to be here ---------------------------------------------------------------------- BeanzMaster · 2018-06-26 13:34 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 ---------------------------------------------------------------------- BeanzMaster · 2018-06-26 13:34 Next part And those screenshot is just some problems. Many other BMP don't displayed correctly ---------------------------------------------------------------------- Jurassic Pork · 2018-06-27 04:44 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   { Account for restart interval (no-op if not using restarts) }//  Dec(entropy^.restarts_to_go); ---------------------------------------------------------------------- BeanzMaster · 2018-06-27 13:56 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 · 2018-06-27 14:55 Quote from: BeanzMaster on June 27, 2018, 03:56:42 pmI test FCL-Image cause of the message from wp in Annoucement/TGIfViewer topicMy 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? Quote from: BeanzMaster on June 27, 2018, 03:56:42 pm[...] 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 · 2018-06-27 21:53 Quote from: wp on June 27, 2018, 04:55:23 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 Quote from: wp on June 27, 2018, 04:55:23 pmI 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. Quote from: wp on June 27, 2018, 04:55:23 pmInstead 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 ---------------------------------------------------------------------- wp · 2018-06-29 10:25 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 · 2018-06-29 13:05 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. ---------------------------------------------------------------------- wp · 2018-06-30 11:31 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_TLazI ntfImage.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). ---------------------------------------------------------------------- BeanzMaster · 2018-06-30 13:02 Quote from: wp on June 30, 2018, 01:31:09 pmI have the feeling that something is missing here. You are working with a simple TFPMemoryImage. Loading bitmap is independant of the device display, it must be work. I must can load data information in a  TFPMemoryImage for working with it. Bitmaps are only a series of bytes that are grouped by 1, 3, 4 bytes or more depending on the color mode (1, 2, 4, 8, 16, 24, 32, 64, 128 bits) and sorted following the type (WB, BGR, GRBA, ABGR, ARGB, ect....) Quote from: wp on June 30, 2018, 01:31:09 pmDoes 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_TLazI ntfImage.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). If i just want use FCL in an application console (suppose i don't use Lazarus and LCL), how i can do  ? LCL is not FCL. they are two differents things. For information LCL override the BMP loading so this why you can load and see Lena-2.bmp The LCL graphic solution also have many "bugs" . Many thing are not manage correctly thrue TRawImage/ TRawImageDescription (many times is not fill correctly, like the pixelformat or the color masks) I take a look many times in code before began my project and this is the why. You can take a look in this topic (it's in french, but just see screenshot is enougth for make a comparation)  see here : https://www.developpez.net/forums/d1699554/autres- langages/pascal/lazarus/fichier-bmp-encodage-bitfield/ This discussion was when i began to decode Bmp and i've made some comparating tests with TBitmap (all bmp are in the imagetestsuite if you want make some test to with TRawImageDescription) TLazIntfImage is a good  for manipulating bitmap instead of use TRawImage/TBitmap, ( see bug in TGIFViewer and transparency with Linux) but not an easy way sometimes and it was not very optimized for speed. I see TLazIntfImage as a bridge with the LCL and that's it. Indeed the best way to load a bitmap with TLazIntfImage (so also for TBitmap) (only BMP, XPM, PNG and TIFF) This sample come from the IntfGraphics unit Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       var      BmpHnd,MaskHnd: HBitmap;        Bitmap1: TBitmap;        IntfImg1: TLazIntfImage;        Reader: TLazReaderBMP;       begin      // create a bitmap (or use an existing one)        Bitmap1:=TBitmap.Create;        // create the raw image for the screenformat you want        IntfImg1:=TLazIntfImage.Create(0,0,[riqfRGB, riqfAlpha, riqfMask]);      // create the XPM reader        Reader:=TLazReaderXPM.Create;      // load the image        IntfImg1.LoadFromFile('filename.xpm',Reader);        // create the bitmap handles         // do something with the IntfImg1         IntfImg1.CreateBitmap(BmpHnd,MaskHnd);        // apply handles to the Bitmap1        Bitmap1.Handle:=BmpHnd;        Bitmap1.MaskHandle:=MaskHnd;        // clean up        Reader.Free;      IntfImg1.Free;         // do something with the Bitmap1      end; Like you can see FPReadBMP is overrided by TLazReaderBMP but is not complete and also have some things wrong with the support of BMP formats. Cheers