Jump to content
  • Advertisement

Archived

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

zerwit

Reading .bmp files

This topic is 6526 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 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 ***

Share this post


Link to post
Share on other sites
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[i].g=g>>2; pal[i].b=b>>2; }
} p+=(int)len*(wid-1);
for (i=0;i for (j=0;j fread(p,1,len,f);
}
fclose(f); lsetHotXY(0,0,img);
ldraw_error=LERR_NONE;
return img;
}


I am a game programming fan in china

Share this post


Link to post
Share on other sites
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 ***

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!