I don't think that we understand the question? What standard 256 colors? AFAIK, there are only 16 standard colors, but when you move to 256, there are several "standard" palettes like the Internet Explorer, Netscape, etc...
Perhaps you can explain what you're trying to accomplish and that may help to give a better answer.
u are right. I was in the wrong impression that like the 16 basic colors, 256 colors also are standard colors.
what problem I am having is that I downloaded several bitmaps from the internet and converted them to 256 color. I am developing a card game and I want use these images on the back of the card. I am using CDIB class which was on the code guru developed by another person. At first when I tried to use the images before converting them into 256 it did not work. There are 8 bitmaps of 256 color. What I want to do is create a palette that contains all the colors from the 8 bitmaps.
what I did was I copied and pasted all the eight images in one 256 color bitmap and created a palette from it. But this also did not work.
I would appreciate very much if you could help me.
If you have access to a high end grapics package (Adobe, Corel, etc) you should be able to open all 8 images and have the application convert to 8bit/256 color in a standard palette; you also could have it create an optimized palette for each image. This can not be done in Visual Studio!!
If such an application is not available to you, and you need to programatically convert the images, you've got alot of work ahead of you. The simplest approach is to determine a good palette to use, the internet explore palette is a reasonable choice.
You then need to get/write code to load the image(s) and dither them to 256 colors, then save it out to a new file. You also need to ensure that your code is handling the palette realization correctly in your code. Conversly, you can create a single bitmap with all the images, determine an optimal palette and then dither.
You should start from the original 24bit color images for this, as you will get better images.
The GDI function ::CreateHalftonePalette (and its MFC counterpart CPalette::CreateHalftonePalette) will give you the "standard" 256 color palette you're probably thinking of. The problem with that palette is that it's a "one size fits all" palette that probably won't give you the color fidelity you want for your particular images.
If you want to down-convert 24-bit colors to a customized set of 256 (or smaller) color palette, the absolutely-best resource I've ever seen was given by Jeff Prosise in his October 1997 MSJ (now MSDN) "Wicked Code" article which can be found at http://www.microsoft.com/msj/1097/wicked1097.aspx
The article describes a utility he named PalGen that takes any number of color files and generates a custom-fit palette of any desired number of colors. The palette is output in ready-to-use format for incorporation into your code.
I use the PalGen program all the time when generating splash screens and graphics in dialogs, since there are still plenty of people out there who have 256 color displays, or who have 24 or 32 bit displays but for some reason like to run them at 256 color.
Both exe and source are in the article.
Mike
Last edited by MikeAThon; August 29th, 2003 at 04:55 PM.
The URL u stated did not work. Where else can I find the article.
The images I downloaded from the net I converted them to 256 color bitmaps. And to create the pallette containing all the colors from all the bitmaps I copied all the bitmaps to one larger 256 bitmap and created a palette from it.
It worked. But I know it was a cheap shot.
Can u tell me what could be the demerits to what I did since I am new to bitmaps and palette.
You might want to try the link again. I clicck on it at it worked for me (I've attached the source code, just in case).
Combining all the images into a bitmap is not bad, as it's a fast way to create a palette that's about right for all the images. Depending on what you used to create the palette it may or may not be as good as the given link.
From a program point of view, it may better to create the palette when you create the program, that way you don't pay the performance penality of doing it at runtime. However, if you anticipate that most of your users are running on 24 bit machines, you can avoid the conversion all together.
As Far As I Know (AFAIK), there is no "demerits" to your method other than what has already noted.
In my application I have used CDIB class which contains a fuction to select palette into the DIB using CPalette. The function is COPYPALETTE(CPalette *pPal).
This means before applying the fuction I have to create a CPalette object. The application you send generates .pal file. How can I attach this .pal file to the CPalette object.
It's really worth it to read both articles, since the code alone doesn't include the helpful explanations.
As for your implementation, although a fixed palette means the code is customized to your bitmaps, and is therefore a bit inflexible for future projects and new versions, ther's absolutely nothing wrong with the approach. It's fast and works very well.
Originally posted by miteshpandey
Thanks a lot for the software bytz.
In my application I have used CDIB class which contains a fuction to select palette into the DIB using CPalette. The function is COPYPALETTE(CPalette *pPal).
This means before applying the fuction I have to create a CPalette object. The application you send generates .pal file. How can I attach this .pal file to the CPalette object.
Please help.
I don't know much about how the .pal was written, it should be pretty clear if you look at the code. I have't tried this code out yet, but I was under the impression that it also converted the images... if so, all you need to do is to read in any one and create the palette from that. If not, you still need to dither/convert the images to the new palette.
Originally posted by miteshpandey .... How can I attach this .pal file to the CPalette object....
You really need to read the article.
The article explains that its output is designed to be cut-and-pasted right into the source code of your project. The output is a C++ declaration for a local scope array of BYTES that looks something like this:
I assume that you see something similar to that in your .pal file.
The article then explains how to cut-and-paste this into your code and use it:
From Jeff Prosise's article
First, paste these statements into a source code file. Then create a LOGPALETTE structure containing one PALETTEENTRY structure for each color in the palette, copy the color values from the byVals array to the corresponding PALETTEENTRYs, and call CreatePalette with a pointer to the initialized LOGPALETTE structure. In MFC, that's CPalette::CreatePalette. Figure 2 shows how it looks in code. Note that the number of PALETTEENTRY structures declared in the pal structure is one fewer than the number of colors in the palette. That's because LOGPALETTE contains one PALETTEENTRY structure already.
Originally posted by bytz
... I have't tried this code out yet, but I was under the impression that it also converted the images...
The program doesn't convert the images, and you probably wouldn't want that anyway.
As explained in the above post to miteshpandey, the program outputs color values for a palette that is optimally tailored to your particular images. You cut-and-paste those values into your code.
When it comes time to display the image, then if the user has a 24 (or 32) bit display, the un-palettized (is that a word?) image is displayed in full 24 bit color fidelity.
But if the user has an 8-bit paletted display, then (assuming you respond to the various palette-realted messages like WM_QUERYNEWPALETTE) the image is displayed using your palette. It's the Window's palette mapper that's responsible for deciding which color in the palette is closest to a particular color in your full-color original. You don't need to do any more work. For example, you don't need two different versions of the image (one 24-bit and the other 8-bit) with a selection of one or the other depending on the settings of the user's machine. In fact, if the user has 24 bit color selected, then Windows won't even send the palette-related messages.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.