Code:
#include "fstream"
class Bitmap
{
private:
unsigned long BPP;
unsigned long width;
unsigned long height;
unsigned long size;
unsigned char *bitmap_Image;
unsigned int bps;
GLuint KompressionFormat;
public:
Bitmap();
~Bitmap();
void *LoadBitmap(const char *Filename);
void Load8BitKompression(const char *Filename);
void Load24BitKompression(const char *Filename);
#define BI_RGB 0L
#define BI_RLE4 2L
#define BI_RLE8 4L
#pragma pack(push,1);
//BITMAPFILEHEADER
typedef struct
{
WORD bfType;
DWORD bfSize;
DWORD bfReserved;
DWORD bfOffBits;
}BITMAPFILEHEADER;
//BITMAPINFOHEADER
typedef struct
{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
}BITMAPINFOHEADER;
#pragma pack(pop);
void Kompression();
BITMAPFILEHEADER FileHeader;
BITMAPINFOHEADER InfoHeader;
};
Bitmap::Bitmap()
{
BPP=0;
width=0;
height=0;
bitmap_Image=NULL;
size=0;
bps=0;
KompressionFormat=0;
}
Bitmap::~Bitmap()
{
BPP=NULL;
width=NULL;
height=NULL;
delete[] bitmap_Image;
KompressionFormat=NULL;
size=NULL;
bps=NULL;
}
void *Bitmap::LoadBitmap(const char *Filename)
{
Bitmap o_Bitmap;
FILE *File=NULL;
unsigned int ImageIdx=0;
unsigned char *bitmap_Image=NULL;
if(!Filename)
{
MessageBox(NULL,"Konnte Filename nicht finden!","Error",MB_OK|MB_ICONERROR);
return false;
}
else
{
File=fopen(Filename,"rb");
if(!File)
{
MessageBox(NULL,"'File' hat keinen Inhalt!","Error",MB_OK|MB_ICONERROR);
return 0;
}
}
fread(&o_Bitmap.FileHeader,sizeof(BITMAPFILEHEADER),1,File);
if(ferror(File))
{
MessageBox(NULL,"'FileHeader' konnte nicht gelesen werden!","Error",MB_OK|MB_ICONERROR);
fclose(File);
return 0;
}
fread(&o_Bitmap.InfoHeader,sizeof(BITMAPINFOHEADER),1,File);
if(ferror(File))
{
MessageBox(NULL,"'InfoHeader' konnte nicht gelesen werden!","Error",MB_OK|MB_ICONERROR);
fclose(File);
return 0;
}
fseek(File,o_Bitmap.FileHeader.bfOffBits,SEEK_SET);
if(ferror(File))
{
MessageBox(NULL,"Zu 'bfOffBits' konnte nicht gesprungen werden!","Error",MB_OK|MB_ICONERROR);
fclose(File);
return 0;
}
if(o_Bitmap.InfoHeader.biSizeImage != 0)
{
bitmap_Image=new unsigned char[o_Bitmap.InfoHeader.biSizeImage];
fread(bitmap_Image,o_Bitmap.InfoHeader.biSizeImage,1,File);
}
if(o_Bitmap.FileHeader.bfType != 0x4D42)
{
MessageBox(NULL,"Ungültiges Bildformat!","Error",MB_OK|MB_ICONERROR);
fclose(File);
}
if(!bitmap_Image)
{
free(bitmap_Image);
fclose(File);
}
if(bitmap_Image==NULL)
{
fclose(File);
}
switch(o_Bitmap.InfoHeader.biCompression)
{
case BI_RGB:
MessageBox(NULL,"Standardkompression ist aktiviert 'BI_RGB'!","Info",MB_OK);
break;
case BI_RLE4:
Load8BitKompression(Filename);
break;
case BI_RLE8:
Load24BitKompression(Filename);
break;
default:
MessageBox(NULL,"Keine Kompression vorhanden","Error",MB_OK|MB_ICONERROR);
}
fclose(File);
};
void Bitmap::Load8BitKompression(const char *Filename)
{
Bitmap o_Bitmap;
FILE *File=NULL;
MessageBox(NULL,"'BI_RLE4'-Kompression ist aktiviert!","Info",MB_OK);
File=fopen(Filename,"rb");
fread(&o_Bitmap.FileHeader,sizeof(BITMAPFILEHEADER),1,File);
fread(&o_Bitmap.InfoHeader,sizeof(BITMAPINFOHEADER),1,File);
if(FileHeader.bfType != 8)
{
MessageBox(NULL,"8-Bitzustand konnte nicht gefunden werden!","Error",MB_OK|MB_ICONERROR);
fclose(File);
}
BPP=o_Bitmap.InfoHeader.biBitCount;
width=o_Bitmap.InfoHeader.biHeight;
height=o_Bitmap.InfoHeader.biHeight;
KompressionFormat=GL_RGB;
if(InfoHeader.biSizeImage != 0)
{
bitmap_Image=new unsigned char[o_Bitmap.InfoHeader.biSizeImage];
fread(bitmap_Image,o_Bitmap.InfoHeader.biSizeImage,1,File);
}
};
void Bitmap::Load24BitKompression(const char *Filename)
{
Bitmap o_Bitmap;
FILE *File=NULL;
MessageBox(NULL,"'BI_RLE8'-Kompression ist aktiviert!","Info",MB_OK);
File=fopen(Filename,"rb");
fread(&o_Bitmap.FileHeader,sizeof(BITMAPFILEHEADER),1,File);
fread(&o_Bitmap.InfoHeader,sizeof(BITMAPINFOHEADER),1,File);
if(o_Bitmap.FileHeader.bfType != 24)
{
MessageBox(NULL,"24-Bitzustand konnte nicht gefunden werden!","Error",MB_OK|MB_ICONERROR);
fclose(File);
}
BPP=o_Bitmap.InfoHeader.biBitCount;
width=o_Bitmap.InfoHeader.biHeight;
height=o_Bitmap.InfoHeader.biHeight;
KompressionFormat=GL_COLOR_INDEX;
};
So, i don't think that you can find an error or mistake. I hope you enjoy it and thanks for everything.