what does DWORD and WORD mean
is DWORD four bytes and WORD two bytes? Can an int or a long be used in replace of a DWORD and a short int be used instead of a WORD. I dont use Visual C++ but DJGPP so they dont have DWORD and WORD data types. I''ve tried to program a bitmap loader using the given data structures in Andrea LeMothe''s book and tried using an int for a DWORD and a short int for a WORD but did not work.
Please Help
Dark Star
UK
i believed there are defined "unsigned" tho.
DWORD and WORD are not keywords in Visual Studio either, they are typedefs.
if you include this in you DJGPP file (don''t know if it supports typedefs, never used DJGPP).
typedef unsigned int DWORD;
typedef unsigned short WORD;
if DJGPP does not support "typedefs" then use "#define".
#define DWORD unsigned int
#define WORD unsigned short
hope this helps.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
DWORD and WORD are not keywords in Visual Studio either, they are typedefs.
if you include this in you DJGPP file (don''t know if it supports typedefs, never used DJGPP).
typedef unsigned int DWORD;
typedef unsigned short WORD;
if DJGPP does not support "typedefs" then use "#define".
#define DWORD unsigned int
#define WORD unsigned short
hope this helps.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
ccheers mate,
I thought I tried that the other day but I''ll try again. Now finally I know what they mean
thanks
Dark Star
UK
I thought I tried that the other day but I''ll try again. Now finally I know what they mean
thanks
Dark Star
UK
ccheers mate,
I thought I tried that the other day but I''ll try again. Now finally I know what they mean
Also DJGPP allows typedefs
it does everything that VC does... in terms of being a C/C++ compilier!
thanks
Dark Star
UK
I thought I tried that the other day but I''ll try again. Now finally I know what they mean
Also DJGPP allows typedefs
it does everything that VC does... in terms of being a C/C++ compilier!
thanks
Dark Star
UK
If you want a bitmap loader...
Then simply:
CBitmap MyBitmap("Test.bmp";
Or.... CBitmap MyBitmap(); //And call MyBitmap.Load("Test.bmp";
Or.... CBitmap *MyBitmap = new CBitmap("Test.bmp";
Or.... CBitmap *MyBitmap = new CBitmap(); //And call MyBitmap->Load("Test.bmp";
Then just check if (!MyBitmap.Loaded) then Bitmap didn''t load properly!
Keep in mind, I typed this in this little window, so it may/may not have gramatical errors...
Billy - BillyB@mrsnj.com if you have any questions or need more help.
#include <stdio.h>class CBitmap{public: unsigned short Width, Height; unsigned char BitDetph; unsigned char *Data; unsigned char *Pallete; unsigned char Loaded;public: CBitmap(); CBitmap(char *fname); void Load(char *fname); void Kill(); ~CBitmap();};CBitmap::CBitmap(){ Loaded=0;}CBitmap::CBitmap(char *fname){ Loaded=0; Load(fname);}void CBitmap::Load(char *fname){ FILE *in; short tx,ty; char BytesPerPixel; unsigned long tOff, tSize; Kill(); //Kill if something is loaded already! in = fopen(fname,"rb"); if (!in) return; //File not found! if (getc(in)!=''B'' || getc(in)!=''M'') //Valid bitmap? { fclose(in); return; //invalid bmp header! } fseek(in,18,0); Width=getw(in); //Get Widht fseek(in,22,0); Height=getw(in); //Get Height fseek(in,28,0); BitDepth=getc(in); //Get Bit Depth if (BitDepth!=8 && BitDepth!=24) { fclose(in); return; //Only supports 8/24 bit bitmaps! } BytesPerPixel=BitDepth>>3; tSize=Width*Height*BytesPerPixel; Data = new unsigned char[tSize]; if (!Data) { fclose(in); return; //Not enough memory! } fseek(in,54,0); //Start of pallete(8-bit)/data(24-bit) if (BytesPerPixel==8) { Pallete = new unsigned char[768]; //256*3 if (!Pallete) { fclose(in); return; //Not enough memory! } tOff=0; for (tx=0;tx!=256;++tx) { Pallete[tOff+2]=getc(in); //Blue Pallete[tOff+1]=getc(in); //Green Pallete[tOff+0]=getc(in); //Red getc(in); //Intensity, we disregard! tOff+=3; } } for (ty=Height-1;ty!=-1;--ty) //Bitmaps are stored upside down! { tOff=ty*Width*BytesPerPixel; for (tx=0;tx!=Width;++tx) { if (BitDepth==8) Data[tOff++]=getc(in); //get color, and increment toff! else { Data[tOff+2]=getc(in); //Blue Data[tOff+1]=getc(in); //Green Data[tOff+0]=getc(in); //Red tOff+=3; } } } Loaded=1;}void CBitmap::Kill(){ if (Loaded) { if (Data) delete Data; if (Pallete) delete Pallete; Loaded=0; }}CBitmap::~CBitmap(){ Kill();}
Then simply:
CBitmap MyBitmap("Test.bmp";
Or.... CBitmap MyBitmap(); //And call MyBitmap.Load("Test.bmp";
Or.... CBitmap *MyBitmap = new CBitmap("Test.bmp";
Or.... CBitmap *MyBitmap = new CBitmap(); //And call MyBitmap->Load("Test.bmp";
Then just check if (!MyBitmap.Loaded) then Bitmap didn''t load properly!
Keep in mind, I typed this in this little window, so it may/may not have gramatical errors...
Billy - BillyB@mrsnj.com if you have any questions or need more help.
Thanks for your help, I''ve already successfully written a bitmap loader. I made one where it loads a bitmap and converts it into a format that cannot be opened by others in ANY paint package at all because it uses my own special format. This was done to stop people playing my games, editing the bitmaps and changing them around.
Thanks for all the help
Dark Star
UK
Thanks for all the help
Dark Star
UK
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement