32 Bit ARGB Values?

BlitzMax Forums/BlitzMax Programming/32 Bit ARGB Values?

Twinprogrammer(Posted 2014) [#1]
Hello,

I am having trouble understanding the 32 bit ARGB Values for pixmaps. How do I set colors? I don't know how to read the value. Can you guys tell me how?


dan_upright(Posted 2014) [#2]
Yeah, you need to bit shift and mask.
pix = LoadPixmap("image.png")
argb = readpixel(pix, 0, 0)
blue = argb & 255 'this returns the bottom 8 bits
green = (argb shr 8) & 255 'this shifts the bits right 8 places then returns the bottom 8 bits
red = (argb shr 16) & 255

That might work, I'm not at the pc right now to check though.


GW(Posted 2014) [#3]
I find it easier to use a pointer.

argb = readpixel(pix, 0, 0)
argbP:byte ptr = Varptr argb

blue = argbP[0]
green = argbP[1]
red = argbP[2]
alpha = argbP[3]



Twinprogrammer(Posted 2014) [#4]
Ok. Do you know how I would use WritePixel() with the pointers?


GW(Posted 2014) [#5]
from the example:
argbP just points to argb, you can write to argbP and pass it into Writepixel()

argbP[0] = 255
.Writepixel(x,y,argb)


dan_upright(Posted 2014) [#6]
Just to elaborate on what GW is saying (nice move with the pointers btw, I can't believe that never occurred to me):
pix = LoadPixmap("image.png")
argb = pix.Readpixel(0, 0)
argbP:byte ptr = Varptr argb

blue = argbP[0]
green = argbP[1]
red = argbP[2]
alpha = argbP[3]

argbP[0] = blue
argbP[1] = green
argbP[2] = red
argbP[3] = alpha

pix.WritePixel(x, y, argb)



Twinprogrammer(Posted 2014) [#7]
Ok, thanks for all of the help!