Where are readpixel() and writepixel()?
BlitzMax Forums/BlitzMax Beginners Area/Where are readpixel() and writepixel()?
| ||
Is there any way i can just get/write a pixel from the screen? |
| ||
there isn't one. If you want to share what you are trying to do, someone might be able to help you with a work around. you can grab an area from the back buffer with GrabPixmap & GrabImage. You can 'ReadPixel' s from a Pixmap and from images through their pixmap. |
| ||
oh ok thanks. |
| ||
You mean something like this for reading the colour of a pixel at the x and y position on the screen. 'Old Blitz Style GetPixel Function Function GetPixel:Int(pixelX:Int, pixelY:Int) Local tempPixmap:TPixmap = GrabPixmap(pixelX,pixelY,1,1) Local pPointer:Byte Ptr = tempPixmap.PixelPtr(0,0) Local hexString:String hexString = Right$(Hex$(pPointer[2]),2)+Right$(Hex$(pPointer[1]),2)+Right$(Hex$(pPointer[0]),2) Return(Int("$ff"+hexString)) End Function |
| ||
All that integers-to-strings and string-to-integer stuff is a bit OTT..Function GetPixel:Int(pixelX:Int, pixelY:Int) Return GrabPixmap(pixelX,pixelY,1,1).ReadPixel( 0, 0 ) End Function At most it needs another line to avoid crashing if GrabPixmap fails. |
| ||
Kind of a terrible way to do it, it has to create a whole new pixmap object every time you read a single pixel. In OpenGL look you can do: Function GetPixel:Int(PixelX:Int,PixelY:Int) Local TestPixel:Int glReadPixels(PixelX,PixelY,1,1,GL_RGBA,GL_UNSIGNED_BYTE,Varptr(TestPixel)) Return TestPixel End Function which doesn't require anything to do with pixmaps. Faster, but if you want to access lots of pixel I suggest you think about keeping a copy of the screen in a pixmap all the time and access the pixmap using pointers. |
| ||
From my understanding pixelmaps are system memory resident so it doesn't matter what you do to it until you write... in which case it has to send the pixelmap acrosss the bus to the Video Card to update the image/texture. |
| ||
That is correct but he is calling GrabPixmap() which downloads data from the backbuffer to the pixmap over the graphics bus, plus initializes a whole pixmap object, which is being done for *every* pixel, which would also make more work for the garbage collector. It's a significant amount of overhead and does not benefit from the pixmaps pre-existing for Images. If he wasn't doing GrabPixmap for every pixel it would be okay to use ReadPixel(). |