A question in DirectDraw

I'm building a WINDOWED DirectDraw program to show some 256 gray level images. I create two surfaces: a primary surface and a offscreenplane surface with size of 512*512. Now, I use Lock(...) method to get a pointer (lpSurface) to the offscreenplane surface and render to this surface directly. That is, I write the color index data directly to the surface using the pointer. After rendering, I Unlock it and use Blt(...) method to transfer data in offscreenplane surface to primary surface to show the image in screen.
I also create a 256 gray level pallete and set it to both these two surface. But when I run this program, the 20 static system colors are shown in my images replacing the gray level of 0-9 and 246-255. What shall I do to correct this error?
Thank you!
Who is Participating?
JoeDolConnect With a Mentor Commented:
Well its seems you don't want to see the thruth. The situation is that if you are in windowed mode and there is simply no way to access the full 256 colors. Why ? Because in windowed mode you rely on the GDI palette management scheme. Which is cool for some stuff, but not very usefull in your case. The best you can do is using the SetSystemPaletteUse() function with the SYSPAL_NOSTATIC flag. This will allow you to use the entry [1..254] in the palette. The 0 and 255 entries are still locked by GDI. They contains black and white. So you might get what you are looking for, as you want to display a gray-level picture, I assume you have entries for black and white. Simply ensure that your entries map to the windows static ones.
An other solution is trying to look if you may run in a true color mode.
Also by experience, I know that you can reduce the number of colors in your image to 236 without noticeable degradation, after all you already reduced the number of different tones from some thousand probably to 256... And is you use the 236, you can still let the 20 windows static colors.

It is not an error.  It is part of DirectDraw's design.  You are going to have to let Windows keep those 20 colors, and get by with 236 colors.  

"Consideration number two—and this is a big one—is the 20 system or "static" colors that Windows reserves unto itself.. It guards these jealously, and if your game uses 256 different colors, it's too bad for you—20 of those colors will be mapped to the reserved colors, with results that may or may not be pleasing to the eye. So you have to either restrict your artists to 236 colors, or ensure that the static colors are present in the palette for every scene. For maximum performance you also want to ensure that the static colors are in the palette slots where Windows expects to find them. See Chapter 6 of Animation Techniques in Win32 for details on how to create an "identity palette" that has the static colors in the correct positions. "

Source:  http://www.microsoft.com/DEVNEWS/JanFeb97/MOBYGAME3.HTM
I would recommend reading that entire page, so you will know about any other potential limitations.
zwwiseAuthor Commented:
If I use the method of writing directly to offscreen as discribed above, is there no way to get rid of the 20 static colors displaying in my image? What shall I do to show my 256 gray image correctly using direct access method?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.