i have found the next code to load the bmp by (Justin Deltener); I have modifyed a little to make more comprensive to me:
Code:
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#define MAX_COLORS 256
void e(int n)
{
cout<<"Error "<<n<<endl;
getch();
}
BITMAPFILEHEADER fh;
BITMAPINFOHEADER ih;
struct PALETA
{
unsigned char blau;
unsigned char verd;
unsigned char roig;
unsigned char res;
PALETA()
{blau=verd=roig=0;
res=0;
}
};
PALETA paleta[MAX_COLORS];
int main()
{
FILE *arx;
if(!(arx=fopen("imatge2.bmp","rb"))) {e(0);return 0;}
if((fread(&fh,sizeof(BITMAPFILEHEADER),1,arx))==-1) {e(1);return 0;}
if((fread(&ih,sizeof(BITMAPINFOHEADER),1,arx))==-1) {e(1);return 0;}
printf("%d x %d\n\n",ih.biWidth,ih.biHeight);
for(int l=0;l<MAX_COLORS;l++)
{
if((fread(&paleta[l],sizeof(PALETA),1,arx))==-1) {e(2);return 0;}
}
int nc=MAX_COLORS;
if(ih.biClrImportant!=0) {nc=ih.biClrImportant;}
cout<<"PALETA"<<endl;
for(int l=0;l<nc;l++)
{
printf("%d %d %d ",paleta[l].roig,paleta[l].verd,paleta[l].blau);
printf("(%x%x%x)--",paleta[l].roig,paleta[l].verd,paleta[l].blau);
}
long tmapa=ih.biWidth*ih.biHeight;
long bloc=(ih.biHeight+3)&(~3);
printf("\ntmapa: %d, bloc: %d\n",tmapa,bloc);
unsigned long amp,alt;
amp=(unsigned long)ih.biWidth;
alt=(unsigned long)ih.biHeight;
unsigned char *mapa=new unsigned char[tmapa];
if((fread((unsigned char*)mapa,(long)tmapa,1,arx))== -1) {e(3);return 0;}
for(int q=alt;q>=0;q--)
{
printf("%d(%x)\n",alt-q,mapa[q]);
}
fclose(arx);
getch();
return 0;
}
Take a look to it: first read the file and info headers. Filter the params if you want (the 'if(bmpFileHead.bfType!=0x4d42)' etc...). Right then read the palette header to see what colors are involved in it. In the sample I assume the will have a max of 256 colors. Then calcule the map size and read it from the file.
Here suppose that with the treenef links you will be able to find aout how to relate each position of the map with its color from the palette.
Take a look at your 'Graphics File Formats: Bitmap-File Formats', there's a description about which colors read from the palette dependiong on the biBitCount value.
A very little help, I haven't more time to work with it )
Regards
Niara (jbosch(vosk))