argb

Blitz3D Forums/Blitz3D Programming/argb

can someone tell me the formula for calculating ARGB for writepixel?

sure.
this returns the argb from r, g and b values:
Function ARGB(R%, G%, B%)
 Local res = B + G * 256 + R * 256 * 256
 Return res
End Function


and, if you want, there are also these functions:
Function Red(RGB)
 Local res = RGB / (256 * 256) + 256
 Return res
End Function

Function Green(RGB)
 Local res = (RGB Mod (256 * 256)) / 256 + 256
 Return res
End Function

Function Blue(RGB)
 Local res = (RGB Mod (256 * 256)) Mod 256 + 256
 Return res
End Function


these functions returns an integer value.

Thanks :)

You may also use bitshift operations, I don't know if they're faster, but in theory they should be:

rgb=readpixelfast(x,y) and $FFFFFF
r=(rgb shr 16) and $FF
g=(rgb shr 8) and $FF
b= rgb and $FF

and the other way:

argb= (alpha shl 24) or (r shl 16) or (g shl 8) or b

I'm under the impression that if a power of 2 is involved, then Blitz is clever enough to optimise that to a bitshift automagically.

Possibly, but I like to make as few assumptions about the itelligence of the compiler as possible, myself. I may be being too "oldskool" here, but I still consider jfk's way as being better.

Having said that, both ways still only work in 32-/24-bit modes. What if D-Grafix is using a 16-bit mode? :P