Read/WritePixel Rgb Conversion
BlitzMax Forums/BlitzMax Programming/Read/WritePixel Rgb Conversion
| ||
Anyone know how to convert read/writepixel rgb values to seperate r,g,b values(In the range of 0-255) and back? Here's what I have presently. GetRGB appears to work, but genRGb is (bleep)ed up. Function GenRgb( red,green,blue,alpha ) Local rgb = ((alpha & $ff) Shl 24) | ((red & $ff) Shl 16) | (( green & $ff) Shl 8) | blue & $ff Return rgb End Function Function GetRGB(argb:Int,a Var,r Var, g Var, b Var) a=(argb Shr 24) & $ff r=(argb Shr 16) & $ff g=(argb Shr 8) & $ff b=argb & $ff End Function Does the internal format of the pixel require further pixel conversion? Why is this not in the docs? <Insert Rant> |
| ||
Isn't it...Function GenRgb( red,green,blue,alpha=255 ) RGB = (alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return rgb End Function Example... Function GenRgb( red,green,blue,alpha=255 ) RGB = (alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return rgb End Function Function GetRGB(argb:Int,a Var,r Var, g Var, b Var) a=(argb Shr 24) & $ff r=(argb Shr 16) & $ff g=(argb Shr 8) & $ff b=argb & $ff End Function Global alpha:Int,red:Int,green:Int,blue:Int GetRGB($ff00ff00,alpha,red,green,blue) Print alpha + " " + red + " " + green + " " + Blue my_rgb=genrgb(red, green, blue, alpha) GETRGB(my_rgb,alpha, red, green, blue) Print alpha + " " + red + " " + green + " " + Blue |
| ||
Thanks. Read pixel was still pretty shaky, But I found a cool way of bypassing any of that. P:Byte Ptr = Pixels.PixelPtr( x,y) Red = P[2] Green = p[1] Blue = p[0] Alpha = p[3] But I have to use genRgb to encode it back..for some ..odd reason. |