Advertisement

palette difficulties

Started by January 30, 2002 10:36 AM
0 comments, last by Fundy Glostna 22 years, 10 months ago
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!
No, Canadians DON'T all live in igloos. They live in one BIG igloo!
Whoops! After hours of scrutiny, I discovered I left out the LR_CREATEDIBSECTION flag in the LoadImage function! This is a cruel API...
No, Canadians DON'T all live in igloos. They live in one BIG igloo!

This topic is closed to new replies.

Advertisement