Archived

This topic is now archived and is closed to further replies.

palette difficulties

This topic is 5797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m having a problem with palettes. I load a 8-bit, 256 color palette from a bitmap file, like this:
  
LPDIRECTDRAWPALETTE LoadPalette(LPDIRECTDRAW,LPCSTR);
LPDIRECTDRAWPALETTE LoadPalette(LPDIRECTDRAW lpdd, LPCSTR szbitmap)
{
    LPDIRECTDRAWPALETTE lpddpal;
    int filehandle;
    PALETTEENTRY ape[256];
    memset(ape,0,256*sizeof(PALETTEENTRY));

    if (szbitmap && (filehandle = _lopen(szbitmap, OF_READ))!=-1)
    {
        BITMAPFILEHEADER bf;
        BITMAPINFOHEADER bi;

	//Read file data into buffers

        _lread(filehandle,&bf,sizeof(BITMAPFILEHEADER));
        _lread(filehandle,&bi,sizeof(BITMAPINFOHEADER));
        _lread(filehandle,ape,256*sizeof(PALETTEENTRY));
        _lclose(filehandle);

      // For some reason, I don''t seem to have to flip the

      // red and blue components

       for(int i=0; i < 256; i++) {
			ape[i].peFlags = PC_NOCOLLAPSE;
        }
    }
	//Create the palette and return it

    if (lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,ape,&lpddpal,NULL)!=DD_OK)
    {
        return NULL;
    } else {
        return lpddpal;
    }
}
  
I call the function like this: It always returns successful.
  
        //Get the palette of a bitmap file

	LPDIRECTDRAWPALETTE lpddpal;
	if(!(lpddpal = LoadPalette(lpdd,"fireballs.bmp"))) {
		PostQuitMessage(0);
	}
	//Set it to the primary surface

	lpddsPrimary->SetPalette(lpddpal);
  
The problem is, when I blit the bitmap (loaded with a different function onto an offscreen surface) to the Backbuffer, and then flip it to the primary surface, the bitmap looks like it''s in 16 colour mode, not 256! I know the palette was set properly to the primary surface, because I can plot pixels in all 256 colors, but the bitmap''s colors are screwed!

Share this post


Link to post
Share on other sites