View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Anonymous Poster_Anonymous Poster_*  Guests

Posted 13 August 1999 - 02:09 PM

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.

### #2TANSTAAFL  Moderators

Posted 13 August 1999 - 04:24 AM

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.

### #3Anonymous Poster_Anonymous Poster_*  Guests

Posted 13 August 1999 - 07:48 AM

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?

### #4TANSTAAFL  Moderators

Posted 13 August 1999 - 02:09 PM

if individual pixels are the things you want to do, then i suggest you look up the following member functions of IDirectDrawSurface:

Lock()
Unlock()

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.