[SOLVED] Three questions regarding fcl-image package lazarus / 62-General ---------------------------------------------------------------------- lagprogramming · 2023-03-01 09:43 I'd like to reduce the dependencies of an application and one step forward would be to avoid LCL to the maximum. I want to replace some uses of the graphics unit with units found in the fcl-image package. I have three questions: 1/3)Is this package having the exact same license as fpc? I mean applications that use fpc-image may be distributed or sold without additional licenses headaches. 2/3)Can the pascal code that involves fpc-image be compiled also by Delphi? The graphics unit provides the same functionality between Lazarus and Delphi, but fpc-image is available only in fpc. Somebody that has both Lazarus and Delphi, can you copy the fpc-image package in the Delphi environment and check that the following code works in Delphi, too? The test.bmp file should contain the text "Test" written with red on a white background. I don't want to trade the LCL dependency with being forced to use only fpc. 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 TForm1.Button1Click(Sender: TObject);//append to uses: fpimage, fpimgCanv, ftfontvar   AFont: TFreeTypeFont;  Img: TFPMemoryImage;  ImgCanvas: TFPImageCanvas;  w,h: integer;begin  //initialize free type font manager  ftfont.InitEngine;  FontMgr.SearchPath:='/usr/share/fonts/dejavu/';  AFont:=TFreeTypeFont.Create;   //create an image  Img:=TFPMemoryImage.Create(0,0);  Img.UsePalette:=false;    //create the canvas with the drawing operations  ImgCanvas:=TFPImageCanvas.create(Img);   //paint white background  ImgCanvas.Brush.FPColor:=colWhite;  ImgCanvas.Brush.Style:=bsSolid;  ImgCanvas.Rectangle(-1,-1,Img.Width,Img.Height);   //prepare to paint the text  ImgCanvas.Font:=AFont;  ImgCanvas.Font.Name:='DejaVuSans';  ImgCanvas.Font.Size:=20;  ImgCanvas.Font.FPColor:=colred;   //update the size to match the text size and paint white background  w:=0;h:=0;  ImgCanvas.GetTextSize('Test',w,h);  Img.SetSize(w,h);  ImgCanvas.Rectangle(-1,-1,Img.Width,Img.Height);   //Write Test text with red on a white background and save to a bitmap file  ImgCanvas.TextOut(0,h,'Test');  Img.SaveToFile('test.bmp');   AFont.Free;ImgCanvas.Free;Img.Free;  ftfont.DoneEngine;end;  3/3)Take a look at the following code, which can be found in packages/fcl-image/src/fpcanvas.inc. Is there a bug at "if (ym<0) or (y>width) then exit;"? 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 TFPCustomCanvas.Draw (x,y:integer; image:TFPCustomImage);var xx,xi,yi,xm,ym,r,t : integer;begin  xm := x + image.width-1;  if (xm<0) or (x>width) then exit;  if xm >= width then    xm := width - 1;  ym := y + image.height-1;  if (ym<0) or (y>width) then exit;  if ym >= height then    ym := height - 1;  xi := x;  yi := y;  if clipping then    if not CheckRectClipping (ClipRect, xi,yi, xm,ym) then      exit;  for r := xi to xm do    begin    xx := r - x;    for t := yi to ym do      DrawPixel(r,t, image.colors[xx,t-y]);    end;end; ---------------------------------------------------------------------- KodeZwerg · 2023-03-01 10:39 Code that does do the same and is to 100% delphi compatible (tested with delphi alexandria) and not need anything beside what it already got: 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 TForm1.Button1Click(Sender: TObject);var  LFont: TFont;  LBmp: TBitmap;  w,h: integer;begin  LFont := TFont.Create;  try    LBmp := TBitmap.Create;    try      LBmp.Width := Image1.Width;      LBmp.Height := Image1.Height;      LBmp.Canvas.Brush.Color := clWhite;      LBmp.Canvas.Brush.Style := bsSolid;      LBmp.Canvas.Rectangle(0, 0, LBmp.Width, LBmp.Height);      LFont.Name := 'Arial';      LFont.Size := 20;      LFont.Color := clRed;      LBmp.Canvas.Font := LFont;      w:=0;      h:=0;      h := LBmp.Canvas.TextHeight('Test');      w := LBmp.Canvas.TextWidth('Test');      LBmp.Canvas.TextOut(10, h, 'Test');      Image1.Picture.Bitmap.Assign(LBmp);    finally      LBmp.Free;    end;  finally    LFont.Free;  end;end; ---------------------------------------------------------------------- wp · 2023-03-01 11:02 /1/ I am not a laywer... But the file headers refer to a file COPYING.FPC - which cannot be found anywhere, but there is a LICENSE file reading like the LGLP with linking exception of Lazarus. And in https://wiki.lazarus.freepascal.org/licensing it is said that "[ ...] anything that is linked into end users programs should be usable in commercial programs in the classical sense, without heaps of additional clauses that make licensing a puzzle." /2/ Just try it yourself, but I am rather sure that it will not work to use fcl-image in Delphi (maybe only after adding tons of other libraries). /3/ I think this line is wrong (you mean the part "y > Width"?). I think "width" should be replaced by "height". Please file a bug report. ---------------------------------------------------------------------- lagprogramming · 2023-03-01 15:40 @KodeZwerg  Your code uses LCL/VCL and this is exactly what I want to avoid at this moment. Here is why. In Linux, if you compile your code using gtk widgetset everything looks fine, but if go to the project options and change the LCLWidgetType to customdrawn, run the application and you'll notice that the text is not written with red. It's just an example. I want to avoid useless dependencies on gtk and qt which means I have to build the application using customdrawn or fpgui. LCL implementation of fpgui is so bad, you can't build an empty form with it, it's unusable. Customdrawn is the only way for me but it's development stopped very early. So, the only solution I can see is to use fcl-image and use the LCL to very basic operations, like showing bitmaps. But I still want the source code to be compatible with Delphi, too. This is why I want to know if the code presented by me at point 2/3 can be compiled by Delphi. @wp Yes, it's that comparison between the "y" and "width" variables. It doesn't look right, does it!? ---------------------------------------------------------------------- PascalDragon · 2023-03-01 21:56 Quote from: lagprogramming on March 01, 2023, 10:43:58 am1/3)Is this package having the exact same license as fpc? I mean applications that use fpc-image may be distributed or sold without additional licenses headaches. FCL-Image is licensed the same as the RTL. Quote from: lagprogramming on March 01, 2023, 10:43:58 am2/3)Can the pascal code that involves fpc-image be compiled also by Delphi? The graphics unit provides the same functionality between Lazarus and Delphi, but fpc-image is available only in fpc. Somebody that has both Lazarus and Delphi, can you copy the fpc-image package in the Delphi environment and check that the following code works in Delphi, too? The test.bmp file should contain the text "Test" written with red on a white background. I don't want to trade the LCL dependency with being forced to use only fpc. The package is not written with Delphi compatibility in mind. If you need it you might take a look at the Vampyre Imaging Library instead. ---------------------------------------------------------------------- wp · 2023-03-01 23:05 Quote from: lagprogramming on March 01, 2023, 04:40:36 pmYes, it's that comparison between the "y" and "width" variables. It doesn't look right, does it!? Yes. I submitted a bugreport: https://gitlab.com/freepascal.org/fpc/source/-/issues/40176 ---------------------------------------------------------------------- Fred vS · 2023-03-01 23:44 Quote from: lagprogramming on March 01, 2023, 04:40:36 pm want to avoid useless dependencies on gtk and qt which means I have to build the application using customdrawn or fpgui. LCL implementation of fpgui is so bad, you can't build an empty form with it, it's unusable. Customdrawn is the only way for me but it's development stopped very early. Fortunately there is the solution: MSEgui widgetset. ---------------------------------------------------------------------- lagprogramming · 2023-03-03 16:19 Quote from: PascalDragon on March 01, 2023, 10:56:46 pmThe package is not written with Delphi compatibility in mind. That may be true, but it's not a guarantee that fcl-image can't be used by Delphi. The only way we can find out is to copy the fcl-image directory, add its unit files in the path and try to compile the code presented in my first post at point 2/3 with Delphi. ---------------------------------------------------------------------- wp · 2023-03-03 17:41 Just for the fun of it, I copied the FPC directory packages/fcl- image/src into a separate folder and added it to the search path of the following Delphi commandline application: 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 program Project2;{$APPTYPE CONSOLE}{$R *.res}uses  System.SysUtils,  fpimage;var  img: TFPMemoryImage;begin  img := TFPMemoryImage.Create(100, 100);end. Trying to compile this I ran into the following complications: Delphi does not reckognize the FPC file extension .pp --> Renamed to .pasDelphi complains about the directive {$mode objfpc} --> Commented it outDelphi stops at the type "qword": "undeclared identifier" --> Added type declaration "qword = UInt64" Delphi detects the unidentified identifier TRect which forces me to add unit "windows" to uses.TFPCustomImage.LoadFromStream is rejected because it is not marked as "overload" (there is a second procedure of the same name in the preceeding line.) --> Added "overload"After some more fixes of the missing "overload", I was blocked by the instruction "operator = (const c,d:TFPColor) : boolean;" which is not allowed in delphi (at least not in this way). Since I don't know how this could be circumvented I gave up...This short exercise shows: It probably is possible to use the fcl-image units in Delphi, but this requires a massive change and enormous work which has to be repeated with every new FPC release. I would not do this... ---------------------------------------------------------------------- wp · 2023-03-03 21:23 Quote from: wp on March 02, 2023, 12:05:12 amQuote from: lagprogramming on March 01, 2023, 04:40:36 pmYes, it's that comparison between the "y" and "width" variables. It doesn't look right, does it!? Yes. I submitted a bugreport: https://gitlab.com/freepascal.org/fpc/source/-/issues/40176 The patch now has been committed for fpc 3.3.1 ---------------------------------------------------------------------- jamie · 2023-03-03 22:49 That error appeared in 3.3.x but not earlier ? Wonder how that happened? ---------------------------------------------------------------------- TRon · 2023-03-03 22:59 Quote from: jamie on March 03, 2023, 11:49:20 pmWonder how that happened? It happens on occasion when trying to fix something else. ---------------------------------------------------------------------- jamie · 2023-03-03 23:18 really.. ---------------------------------------------------------------------- lagprogramming · 2023-03-04 11:16 Thank you, wp. Now the situation is crystal clear. Nice going with that bug report.