Recent

Author Topic: What's wrong with my code?  (Read 5668 times)

wp

  • Hero Member
  • *****
  • Posts: 8408
Re: What's wrong with my code?
« Reply #15 on: March 06, 2021, 06:30:12 pm »
Did you run EXACTLY my project, or did you insert the Progressbar and Application.ProcessMessages, too? When I do so the calculation time increases 10fold.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #16 on: March 06, 2021, 06:31:44 pm »
My guess is you make Application.ProcessMessages too responsive.

If you call it on an X-Y loop of 300 x 300 then it will be called 90 thousands times. You should reduce it's responsiveness.
I put the ProgressBar in afterwards, so it has nothing to do with the horrible time-interval.
With or without it, speed is extreme slow.

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #17 on: March 06, 2021, 06:34:42 pm »
Did you run EXACTLY my project, or did you insert the Progressbar and Application.ProcessMessages, too? When I do so the calculation time increases 10fold.
To be honest, I tried to run your project, but couldn't. (I opened it as a project, run, but nothing happened. Thre was no form at all.)
So, I take your Button1Click procedure and put into my code.

Handoko

  • Hero Member
  • *****
  • Posts: 4214
  • My goal: build my own game engine using Lazarus
Re: What's wrong with my code?
« Reply #18 on: March 06, 2021, 06:39:23 pm »
I opened it as a project, run, but nothing happened. Thre was no form at all.

If you opened the project but saw nothing, you should read this:
https://forum.lazarus.freepascal.org/index.php/topic,53535.msg396098.html#msg396098

... speed is extreme slow.

Maybe nothing wrong with your code. Can it be virus, antivirus, OS, hardware, etc issue? Can you try to run the code on different machine?
« Last Edit: March 06, 2021, 06:43:16 pm by Handoko »

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #19 on: March 06, 2021, 06:44:53 pm »
Maybe nothing wrong with your code. Can it be virus, antivirus, OS, hardware, etc issue? Can you try to run the code on different machine?
I don't think so. Linux + powerful hardware.

Handoko

  • Hero Member
  • *****
  • Posts: 4214
  • My goal: build my own game engine using Lazarus
Re: What's wrong with my code?
« Reply #20 on: March 06, 2021, 06:46:25 pm »
Can you provide the compile-able source code, in a zip format? I use Linux too. I'm interested to test it myself.

wp

  • Hero Member
  • *****
  • Posts: 8408
Re: What's wrong with my code?
« Reply #21 on: March 06, 2021, 06:50:45 pm »
Did you run EXACTLY my project, or did you insert the Progressbar and Application.ProcessMessages, too? When I do so the calculation time increases 10fold.
To be honest, I tried to run your project, but couldn't. (I opened it as a project, run, but nothing happened. Thre was no form at all.)
So, I take your Button1Click procedure and put into my code.
Sorry, I probably forgot to set the compatibility flag (I am on Laz trunk). This one should be correct for you:
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #22 on: March 06, 2021, 06:57:44 pm »
Can you provide the compile-able source code, in a zip format? I use Linux too. I'm interested to test it myself.
Here you are, thanks Handoko.

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #23 on: March 06, 2021, 07:04:41 pm »
@wp:
Now it worked, time is horrible, see attached.

Handoko

  • Hero Member
  • *****
  • Posts: 4214
  • My goal: build my own game engine using Lazarus
Re: What's wrong with my code?
« Reply #24 on: March 06, 2021, 07:15:50 pm »
Your MyProject needs 21 seconds to process a 450 x 300 pixels image on my Ubuntu Mate G2020 2-cores computer.

Now inspecting to see if there is anything can be done to improved the performance.

wp

  • Hero Member
  • *****
  • Posts: 8408
Re: What's wrong with my code?
« Reply #25 on: March 06, 2021, 07:20:06 pm »
OK. Here is a version which avoids the Pixels property. It is still based on the units which come with Lazarus/FPC, in this case IntfGraphics. Unlike using ScanLine it does not require knowledge of the color structure of the pixels. In my tests the previous demo runs in a few milliseconds:
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

wp

  • Hero Member
  • *****
  • Posts: 8408
Re: What's wrong with my code?
« Reply #26 on: March 06, 2021, 07:24:21 pm »
I see from your demo that you are planning to write a variety of image processing routines. Then you really should move to an optimized library such as BGRABitmap or Graphics32.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #27 on: March 06, 2021, 07:25:07 pm »
OK. Here is a version which avoids the Pixels property. It is still based on the units which come with Lazarus/FPC, in this case IntfGraphics. Unlike using ScanLine it does not require knowledge of the color structure of the pixels. In my tests the previous demo runs in a few milliseconds:
Got this error:

justnewbie

  • Sr. Member
  • ****
  • Posts: 273
Re: What's wrong with my code?
« Reply #28 on: March 06, 2021, 07:28:54 pm »
I see from your demo that you are planning to write a variety of image processing routines. Then you really should move to an optimized library such as BGRABitmap or Graphics32.
It's just a little playing, nothing serious.
I no need for great optimization, just wanted to try some pixel modifications.
But, around 40 seconds it is a bit unplayable. It should be much faster, but cannot see the reason of this horrible speed.
As I said, exactly the same code ran with Delphi within milliseconds.

Handoko

  • Hero Member
  • *****
  • Posts: 4214
  • My goal: build my own game engine using Lazarus
Re: What's wrong with my code?
« Reply #29 on: March 06, 2021, 07:38:16 pm »
Accessing pixel information using Pixel[x,y] command is low, using ScanLine is much faster.

But why Delphi faster? I think for cross platform reason it is not properly optimized. You can try Graphics32. I heard it is several times faster than traditional canvas and it supports both Delphi and Lazarus.

Quote
Fast per-pixel access up to 100 times faster compared to standard TBitmap
Source: https://en.wikipedia.org/wiki/Graphics32

https://github.com/graphics32/

 

TinyPortal © 2005-2018