Recent

Author Topic: CopyRect not working under Linux?  (Read 3616 times)

han

  • Jr. Member
  • **
  • Posts: 96
CopyRect not working under Linux?
« on: December 07, 2017, 11:37:29 pm »
I working on a code conversion from Windows to Linux and have an odd problem I can't fix. The program works with images and requires a horizontal and vertical flip of an Timage. It works in Window but not under Linux (fpc 3.0.2 and 3.0.4). I have impression the CopyRect doesn't work. Below my routine. Why doesn't it work in Linux and how to fix?

procedure Tmainwindow.Fliphorizontal1Click(Sender: TObject);
var src, dest: TRect;
    bmp: TBitmap;
    w, h: integer;
begin
  w:=image1.Picture.Width; h:=image1.Picture.Height;
  dest:=bounds(0, 0, w, h);
  //src:=rect(0, h, w, 0); // Vertical flip
  src:=rect(w, 0, 0, h); // Horizontal flip
  //src:=rect(w, h, 0, 0); // Both flip
  bmp:=TBitmap.Create;
  bmp.PixelFormat:=pf24bit;
  bmp.SetSize(w, h);
  bmp.Canvas.Draw(0, 0, image1.Picture.Bitmap);
  image1.Picture.Bitmap.Canvas.CopyRect(dest, bmp.Canvas, src);
  bmp.Free;
end;

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: CopyRect not working under Linux?
« Reply #1 on: December 08, 2017, 12:22:30 am »
Hi, this works under Linux (Qt):
Code: Pascal  [Select][+][-]
  1.   ...
  2.   dest:=rect(w, 0, 0, h);
  3.   image1.Picture.Bitmap.Canvas.StretchDraw(dest, bmp);
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/

han

  • Jr. Member
  • **
  • Posts: 96
Re: CopyRect not working under Linux?
« Reply #2 on: December 08, 2017, 08:53:07 am »
Yes that works!. I'm not a fan of StrechDraw since it can result in distortions. The application is an astronomical application and should be correct on subpixel level.

Later, I found a way to fix the CopyRect routine:

This works only in MS-Windows
Code: Pascal  [Select][+][-]
  1.  src:=rect(w, 0, 0, h);
  2.  dest:=bounds(0, 0, w, h);

This works both in MS-Windows and Linux:
Code: Pascal  [Select][+][-]
  1. src:=rect(0, 0, w, h);
  2. dest:=rect(w, 0, 0, h);//horizontal flip

Weird, is this a bug?

This is the new procedure working both in MS-Windows and Linux:
Code: Pascal  [Select][+][-]
  1. procedure Tmainwindow.Fliphorizontal1Click(Sender: TObject);
  2. var src, dest: TRect;
  3.     bmp: TBitmap;
  4.     w, h: integer;
  5. begin
  6.   w:=image1.Picture.Width; h:=image1.Picture.Height;
  7.   src:=rect(0, 0, w, h);
  8.   dest:=rect(w, 0, 0, h);//horizontal flip
  9.   bmp:=TBitmap.Create;
  10.   bmp.PixelFormat:=pf24bit;
  11.   bmp.SetSize(w, h);
  12.   bmp.Canvas.Draw(0, 0, image1.Picture.Bitmap);
  13.   image1.Picture.Bitmap.Canvas.CopyRect(dest, bmp.Canvas, src);
  14.   bmp.Free;
  15. end;
« Last Edit: December 08, 2017, 10:06:18 am by han »

han

  • Jr. Member
  • **
  • Posts: 96
Re: CopyRect not working under Linux?
« Reply #3 on: December 08, 2017, 10:33:14 am »
The same effect with StretchDraw if line 13 is replaced with:

     image1.Picture.Bitmap.Canvas.StretchDraw(dest, bmp);     

Is this a different behavior inside Linux?

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: CopyRect not working under Linux?
« Reply #4 on: December 08, 2017, 05:27:21 pm »
Yes, both CopyRect and StrechDraw work in Linux now. I don't if that trick of swapping Src and Dest rectangles is a bug, although.
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/

 

TinyPortal © 2005-2018