256 color bitmaps
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: 256 color bitmaps

  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    256 color bitmaps

    I am using a 256 colored bitmap. How can I get the RGB values for the 256 colors that is supported?

    Please help.

  2. #2
    Join Date
    May 2003
    Posts
    347
    Please search in MSDN GetBitmapBits / RGBQUAD

    else

    please see the Bitmap link in codeguru homepage

  3. #3
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688
    You can load the bitmap as a Device Independent Bitmap (DIB) and use GetDIBColorTable.

  4. #4
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    256 color bitmaps

    thanx for the help but I don't want the RGB values that the bitmap contains. I want to know the RGB value of the standard 256 colors.

    please help.

  5. #5
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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.
    bytz
    --This signature left intentionally blank--

  6. #6
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    256 color bitmaps

    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.

  7. #7
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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.
    bytz
    --This signature left intentionally blank--

  8. #8
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553
    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.

  9. #9
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    256 color bitmaps

    Thanx Mike

    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.

    I want to look at the article mentioned by you.

    Please help me to locate it.

  10. #10
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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.
    Attached Files Attached Files
    bytz
    --This signature left intentionally blank--

  11. #11
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    256 color bitmaps

    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.

  12. #12
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553
    Try the link again. I just checked it and it worked fine.

    Jeff Prosise wrote a companion article that also describes the issues you're facing. It's in the August 1996 MSJ, "Wicked Code" at http://www.microsoft.com/msj/archive/S3F1.aspx

    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.

    Mike

  13. #13
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509

    Re: 256 color bitmaps

    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.
    bytz
    --This signature left intentionally blank--

  14. #14
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: 256 color bitmaps

    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:
    Code:
    // 8 entries
     BYTE byVals[8][3] = {
         255, 240,  36,
         180,  64, 192,
           4,  32, 200,
         224,  85,  80,
         224, 128,   0,
          16,   0, 244,
         122,   7, 114,
          78, 255, 225      
     };
    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.
    It's easy and clean. Please read the articles.

    -Mike

  15. #15
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Re: 256 color bitmaps

    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.

    -Mike

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center