Black and white

BlitzPlus Forums/BlitzPlus Programming/Black and white

Hi guys,
I would like to change images from colored to black and white.

Here's what I've done:

setbuffer imagebuffer(im)
for x=0 to imagewidth(im)
for y=0 to imageheight(im)
getcolor x,y
c=(colorred()+colorgreen()+colorblue())/3
color c,c,c
plot x,y
next
next

But it's slow expecially for big images.
Is there a quicker way?

Thank you

Some possibilities:

1) Just use the red, green, or blue component (don't bother averaging them). Typically this looks pretty much similar to the greyscale version (usually RED or GREEN work better than BLUE).

2) Lock the buffers and use ReadPixelFast and WritePixelFast. You'll get color values in the form of a longint in ARGB format (I believe), which means that you'll need to do some modulo arithmetic to extract the RGB values (which may prove slower than the method you're using).

So something like:

c = ReadPixelFast(x,y,srcBuffer)
r = (c / 65536) mod 256
g = (c / 256) mod 256
b = c mod 256
greyvalue = (r + g + b) / 3
WritePixelFast(x,y,destBuffer)

Caveat Programmer!