Convert a 16-Bit-OffScreen-Surface into GrayScale?

Started by
3 comments, last by GameDev.net 24 years, 8 months ago
there are several methods of grayscaling colors, the one i present here will make most things still easy to differentiate.

first, you deconstruct the pixel into its R, G, and B

if in 565, divide the G component by two, so that everything is from 0 to 31

grayscaling is done simply by weighting the colors by percentages.

a good weight to use is:

Blue: 11%
Green: 59%
Red: 30%

so, now calculate:

NewRGB=(b*11+g*59+r*30)/100;

use this new value as the new red, green, and blue components (if in 565, multiply by 2 for green)

now reconstruct the pixel from these RGB values, and put the pixel

if you want a "yellowed paper" or "antique" look, multiply the blue by 7/8 or 3/4 (or whatever fraction you like, based on your preference)

you can also get a nice "smudge" or blurring effect by taking some areas and apply an anti-aliasing algorithm between every other pixel.

Get off my lawn!

Advertisement
Thanks, but I only know the Blt() to copy something in a surface. So I change my Question How can I read one Pixel from a Surface and get the color? Is there a funktion like Getpixel in Pascal?
How can I do it in DirectDraw? Is there a function?
I want to make a treasure-map, which I blit from an other OffScreen-surface and it should look old and not in 65000 colors.
Thanks for your help
if individual pixels are the things you want to do, then i suggest you look up the following member functions of IDirectDrawSurface:

(if you want "direct" memory access to the surface)
Lock()
Unlock()

(or, if you want the slower GDI route)
GetDC()
ReleaseDC()

Get off my lawn!

This topic is closed to new replies.

Advertisement