Solved

A question in DirectDraw

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now