Solved

A question in DirectDraw

Posted on 1998-12-12
4
293 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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