Best method to work with pixels

BlitzMax Forums/BlitzMax Programming/Best method to work with pixels

CopperCircle(Posted 2007) [#1]
Hi, I want to move my Blitz+ code over to BMax, most of it works on images at pixel level, reading, altering and writing pixels.
What is the best method in Max, I see there is DX and OpenGL Max2D also pixmaps seem to be the way.

Any help would be great just started play with Max and still quite lost.


Grey Alien(Posted 2007) [#2]
You have to use TPixmap (if you didn't know that already). I used to do lots of pixel level but found I didn't need to hardly at all with Bmax as I just started using setscale, setcolour, setblend, setrotation etc instead.


tonyg(Posted 2007) [#3]
For pixel level access use...
loadimage
lockimage
readpixel/writepixel
Unlockimage (not needed but in case it does something in the future).
drawimage


PantsOn(Posted 2007) [#4]
I found that the quickest way to work with pixels is to use PixmapPixelPtr and set the pixmap format to one that is easy to work with. this will give you the memory location of a pixel. so that

pixmap:tpixmap = createpixmap(100,100,PF_BGRA8888)
p:byte ptr = pixmappixelptr(pixmap,0,0)

' get RGB
b:int = p[0]
g:int = p[1]
r:int = p[2]

' set to orange
p[0] = 0
p[1] = 128
p[2] = 255


edit - got RGB the right way round now


CopperCircle(Posted 2007) [#5]
Thanks, thats a great start.


CopperCircle(Posted 2007) [#6]
Hi, I have been playing with pixmappixelptr and it is fast but when getting the pixmap from loading different types of images the pixel format changes depending on the image file, making the RGB colors change, I have tried to use ConvertPixmap(pixmap,PF_BGRA8888) but it seems to make no difference? any clues?

Thanks.


Jesse(Posted 2007) [#7]
are you shure you are using convertpixmap correctly?
the correct way is:
newpixmap:tpixmap = convertpixmap(pixmap,PF_BGRA8888)

the new image is stored in newpixmap, pixmap will still have the original loaded image/pixmap.


CopperCircle(Posted 2007) [#8]
Thanks, I was not doing that. I`ll give it a try.