| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 
 | #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;
}; |