Reading .bmp files

Started by
2 comments, last by zerwit 23 years, 7 months ago
I am trying to read a bitmap using the BITMAP structure. I have loaded in textures like this and bitblt them onto a ddraw surface, but how do you just read the raw data. I want to copy the bitmap data into a character array, how do I do that? Does it have something to do with the bmBits data member? Thanks. *** Triality ***
*** Triality ***
Advertisement
It is easy to view a bmp, just see the followwing codes:
static char *lrBmpFile(char *filename,long off,RGB *pal)
{ FILE *f; char *p,r,g,b,*img;
short i,j,palCount,bit; int wByte, wPixel, h, len, wid;

if ((f=fopen(filename,"rb"))==NULL) {
ldraw_error=LERR_NOTFIND;
return NULL;
}

fseek(f,2+off,SEEK_SET); fread(&wByte,4,1,f);
fseek(f,10+off,SEEK_SET); fread(&wPixel,4,1,f);
wByte-=wPixel; palCount=(wPixel-54)/4;
fseek(f,18+off,SEEK_SET); fread(&wPixel,4,1,f);
fread(&h,4,1,f); wByte/=h; len=wPixel; wid=h;

p=new char[len*wid+8]; img=p;
if (!p) {
fclose(f); ldraw_error=LERR_NOMEM;
return NULL;
}
*(short*)p=len; p+=2;
*(short*)p=wid; p+=2;

fseek(f,2,SEEK_CUR); bit=fgetc(f)+(int)fgetc(f)*256;
fseek(f,54+off,SEEK_SET);

for (i=0;i fscanf(f,"%c%c%c%*c",&b,&g,&r);
if (pal) { pal.r=r>>2; pal.g=g>>2; pal.b=b>>2; }<br> } p+=(int)len*(wid-1);<br> for (i=0;i<wid;i++,p-=len) {<br> for (j=0;j<len;j++) p[j]=j%256;<br> fread(p,1,len,f); <br> }<br> fclose(f); lsetHotXY(0,0,img);<br> ldraw_error=LERR_NONE;<br> return img;<br>} </i> <br><br>I am a game programming fan in china
I am crying in programming !
That is some of the most confusing code I have ever seen. Anyways, I wrote a .bmp loader last night, but it would''ve been a lot easier the other way.

*** Triality ***
*** Triality ***
Ha ha, welcome to see my RPG

I am crying in programming !
I am crying in programming !

This topic is closed to new replies.

Advertisement