Solved

A question in DirectDraw

Posted on 1998-12-12
4
291 Views
Last Modified: 2013-11-20
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!
0
Comment
Question by:zwwise
  • 2
4 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1326102
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
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1326103
I would recommend reading that entire page, so you will know about any other potential limitations.
0
 

Author Comment

by:zwwise
ID: 1326104
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?
0
 

Accepted Solution

by:
JoeDol earned 10 total points
ID: 1326105
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.


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 91
Expand macro to include alternate header placement and naming 5 72
substring method in java 1 123
wordappend challenge 8 180
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question