Ooops
April 02, 2020, 11:20:37 AM

Author Topic: ReadPixel WritePixel speed  (Read 870 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
ReadPixel WritePixel speed
« on: February 28, 2020, 03:22:10 PM »
Hi, Im using Xors3D and I use Writepixel and readpixel commands.
the writepixel is much slower than readpixel.. in xors3d
is it the same in blitzmax read write pixel?

also is there anything that can be done to make it faster?

Cheers
Happy New Year

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #1 on: March 01, 2020, 01:59:40 PM »
I guess no one has a clue
Happy New Year

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 476
Re: ReadPixel WritePixel speed
« Reply #2 on: March 01, 2020, 02:22:34 PM »
ReadPixel and WritePixel commands themselves are actually quite fast.  The problem comes when you need to display the imgae.  The image is modified in the CPU's memory, so must be transfered over the bus to the GPU's memory before it can be displayed.  This actually takes time.  That is why it takes so much longer to write to an image than read from it.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #3 on: March 01, 2020, 04:56:56 PM »
But when im writing pixel i dont display it..
so i dont understand why its slow
Happy New Year

Online Matty

  • Hero Member
  • *****
  • Posts: 923
    • MattiesGames
Re: ReadPixel WritePixel speed
« Reply #4 on: March 01, 2020, 05:58:36 PM »
How many pixels are you writing?

A full screen or a handful?

How many functions, calculations are you doing per pixel?

 Are you performing any slow operations per pixel such as square roots or trig functions?

Are you calculating rgb values with a function call or a calculation?

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #5 on: March 01, 2020, 07:52:23 PM »
I do no function calculation on the pixel i just read a pixel from one image and and write on another and it can start from 1000 and get to million approx..

Happy New Year

Online Matty

  • Hero Member
  • *****
  • Posts: 923
    • MattiesGames
Re: ReadPixel WritePixel speed
« Reply #6 on: March 01, 2020, 09:22:23 PM »
Well if there are no calculations or processing why not use a copyrect method instead of pixel writing and reading?

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #7 on: March 01, 2020, 10:22:00 PM »
because i need to read pixel by pixel for what im doing.. :)
but thanks for the suggestion :) here is what  im working on https://1drv.ms/u/s!ArSvOuhm7L3ko51b1gpP7GPIeBy8bw?e=HXdnj7
Happy New Year

Online Matty

  • Hero Member
  • *****
  • Posts: 923
    • MattiesGames
Re: ReadPixel WritePixel speed
« Reply #8 on: March 01, 2020, 11:47:06 PM »
Okay.  Here is another suggestion.

Do all your readpixels in one set.

Then all the writepixels.

In otherwords dont alternate between reading 1 pixel then writing 1 pixel.

Do them all at once.

Also if you can do multithreading then read each channel r g b and a in a thread each and process each colour channel on a separate thread.

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #9 on: March 02, 2020, 04:44:09 AM »
very interesting idea! ill give it a try! thanks

 i have no clue about multi threading.. never dealed with it
Happy New Year

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: ReadPixel WritePixel speed
« Reply #10 on: March 02, 2020, 07:27:59 AM »
Have a data portion to work on ... and use a Mutex to protect write accesses to it. Unlock the mutex everytime you are done.

For "numbers" this is not problematic as you can simple have threads eg do
pixels 0-99
pixels 100-199
pixels 200-299
...

So none of these groups overlap. They do not change memory addresses - but straight content of "numbers" in the number array (a pixmap is a row of integers containing RGB(A)).

So perfect for threaded processing.


Yet it is better to describe what you actually are doing - as a pixmap of 2k*2k is not that "slow" to compute each frame, but if you compute a 8k*8k 20 times a frame, then you might run into trouble.


Another idea is to make it "async" - so give it to a thread to process and use the old one until the thread is done (so it might be there in the same frame - or 1000 seconds later).


bye
Ron

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 476
Re: ReadPixel WritePixel speed
« Reply #11 on: March 02, 2020, 09:06:59 AM »
Unfortunately your link is asking me for a password for some reason.  But is it possible to do what you want using shaders?  This will allow you to process your images directly on the GPU, which means fast.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: ReadPixel WritePixel speed
« Reply #12 on: March 02, 2020, 10:23:42 AM »
I clicked on the link and it downloaded a PNGSplitter.rar (automatically) and it was able to unpack it.

According to the name he wants to read parts from a pixmap and create a new pixmap out of it. But maybe it is for some live preview or so.

Would be good to know in "abstract" what Hardcoal wants to do exactly.


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: ReadPixel WritePixel speed
« Reply #13 on: March 02, 2020, 10:59:07 AM »
Ill fix the link soon

What im doing is taking a tile set single png and turning it into separate pngs
Happy New Year

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: ReadPixel WritePixel speed
« Reply #14 on: March 02, 2020, 11:13:12 AM »
Yes - and this should be "blazing fast" - exception is if you need to find the sprites on your own (eg minimum island size) and then do auto-crop etc.

But this is not strictly readpixel/writepixel slowness then but also the algorithm you use.


So ... assume we have 10 sprites on an image - and you know the coords + dimension of each. Extracting this data into new PNGs, is this then slow for you? I doubt it.

As said _read_ access to TPixmap can be multithreaded without much hassle.


Next to classic "threading" you could use what @Brucey once wrote: some "Workers" (you then just pass your task "split images" to the workers and they spawn as much as required, and once done they spawn new ones if there are still images to strip from the image). Means you do not have a fixed amount of threads you send out to strip image slices but a flexible amount of runners utilizing threads - more on this if interested.

So the more you explain (without loosing yourself in too much implementation details) the more easily we could help and spot issues.


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal