TGC Codebase Backup



code on rgb, images, memblocks, getting red, green, blue and alpha bytes of pixels, bitwise operatio by Duffer

23rd Nov 2006 2:19
Summary

see above - using bitwise operations to get alpha, red, green or blue bytes from pixel dwords in image memblocks or from rgb integer....



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rgb1 = rgb(100,200,250)
alpha2 = rgb1 >> 24
red2 = (rgb1 >> 16) && 0xff
green2 = (rgb1 >> 8) && 0xff
blue2 = rgb1 && 0xff

ink rgb(100,200,250),0
dot 1,1,rgb(100,200,250)
get image 1,1,1,5,5,1
cls
make memblock from image 1,1
width as dword
height as dword
depth as dword
width = memblock dword(1,0)
height = memblock dword(1,4)
depth = memblock dword(1,8)
pixel as dword
pixel = memblock dword(1,12)
alpha3 = pixel >> 24
red3 = (pixel >> 16) && 0xff
green3 = (pixel >> 8) && 0xff
blue3 = pixel && 0xff

print "WITH RGB:-"
print "red byte = " + str$(red2)
print "green byte = " + str$(green2)
print "blue byte = " + str$(blue2)
print "alpha byte = " + str$(alpha2)
print "  "
print "  "


print "WITH A 4x4 IMAGE - the top left pixel:-"
print "image width = " + str$(width)
print "image height = " + str$(height)
print "image depth = " + str$(depth)
print "pixel - alpha byte = " + str$(alpha3)
print "pixel - red byte = " + str$(red3)
print "pixel - green byte = " + str$(green3)
print "pixel - blue byte = " + str$(blue3)
wait key
end