Here's some code that might help you. I'm just going to cut/paste from my .c files, so it might not be pretty or commented, but if you can read it, I think it'll help you do what you want to do.
====================================
readBMP256("Splash.bmp", graphmem, SplashPal, 320*240);
h_pal = GpPaletteCreate(256, SplashPal);
if ( !h_pal )
{
//error
Quit("GpPaletteCreate error!");
}
//palette change
GpPaletteSelect(h_pal);
GpPaletteRealize();
====================================
int readBMP256(char *filename, byte* buffer, GP_PALETTEENTRY *GPpalette, unsigned long bufferSize)
{
BITMAPFILEHEADER tFileHeader;
BITMAPINFOHEADER tInfoHeader;
RGBQUAD BMPpalette[256];
int i, j;
int iFileHandle = 0;
char message[50];
unsigned long width, height, bpp;
byte garbage[16];
iFileHandle = OpenRead(filename);
if (iFileHandle == 0)
{
return -1;
}
//Read the header from the file
Read(iFileHandle, (void *)&tFileHeader, sizeof (BITMAPFILEHEADER));
//Are we looking at a BMP?
if (tFileHeader.bfType[0] != 0x42 && tFileHeader.bfType[1] != 0x4D)
{
PauseMessage("Not a BMP file!");
CloseRead(iFileHandle);
return -1;
}
//Read the BITMAPINFOHEADER from the file
Read(iFileHandle, (void *)&tInfoHeader, sizeof (BITMAPINFOHEADER));
width = tInfoHeader.biWidth[2]
| (tInfoHeader.biWidth[3] << 8)
| (tInfoHeader.biWidth[0] << 16)
| (tInfoHeader.biWidth[1] << 24);
height = tInfoHeader.biHeight[2]
| (tInfoHeader.biHeight[3] << 8)
| (tInfoHeader.biHeight[0] << 16)
| (tInfoHeader.biHeight[1] << 24);
bpp = tInfoHeader.biBitCount;
/*gm_sprintf(message, "width = %d", width);
PauseMessage(message);
gm_sprintf(message, "height = %d", height);
PauseMessage(message);*/
//We aren't going to process any BMP's except a 256 color BMP
if (bpp != 1)
{
gm_sprintf(message, "bpp= 0x%x", bpp);
PauseMessage(message);
CloseRead(iFileHandle);
return -1;
}
//Read in all 256 colors from the BMP file
i = Read(iFileHandle, (void *)BMPpalette, sizeof (RGBQUAD) * 256);
if(i != sizeof (RGBQUAD) * 256)
{
gm_sprintf(message, "read %d bytes", i);
PauseMessage(message);
CloseRead(iFileHandle);
return -1;
}
for ( i=0; i<256; i++)
{
//gm_sprintf(message, "i=%d r=%d g=%d b=%d rsv=%d", i, BMPpalette.rgbRed, BMPpalette.rgbGreen, BMPpalette.rgbBlue, BMPpalette.rgbReserved);
//PauseMessage(message);
GPpalette = ((BMPpalette.rgbRed>>3)<<11) | ((BMPpalette.rgbGreen>>3)<<6) | ((BMPpalette.rgbBlue>>3)<<1) | 1;
}
/*if(bufferSize == 0)
{
buffer = gp_mem_func.malloc(width * height * bpp);
}
else*/ if(bufferSize < (width * height * bpp))
{
gm_sprintf(message, "bufferSize < %d", (width * height * bpp));
PauseMessage(message);
CloseRead(iFileHandle);
return -1;
}
ReadSeek(iFileHandle, 0x0436, SEEK_SET);
for(j = height-1; j >= 0; j--)
{
i = Read(iFileHandle, (void *)&buffer[j*width], width * bpp);
if(width < 16)
Read(iFileHandle, (void *)garbage, 16-width);
if(i != width * bpp)
{
PauseMessage("i != width * bpp");
break;
}
}
CloseRead(iFileHandle);
return i*height;
}
====================================
typedef struct tagBITMAPFILEHEADER
{
byte bfType[2];
byte bfSize[4];
byte bfReserved1[2];
byte bfReserved2[2];
//byte bfOffBits[4];
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER
{
byte biSize[4];
byte biWidth[4];
byte biHeight[4];
short int biPlanes;
short int biBitCount;
byte biCompression[4];
byte biSizeImage[4];
byte biXPelsPerMeter[4];
byte biYPelsPerMeter[4];
byte biClrUsed[4];
byte biClrImportant[4];
} BITMAPINFOHEADER;
typedef struct tagRGBQUAD
{
byte rgbRed;
byte rgbReserved;
byte rgbBlue;
byte rgbGreen;
} RGBQUAD;
====================================