-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBitmap.h
85 lines (73 loc) · 1.88 KB
/
MyBitmap.h
1
2
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
#ifndef _BITMAP_H
#define _BITMAP_H
//File: Bitmap.h
//Written by: Mark Bernard
//on GameDev.net: Captain Jester
//e-mail: [email protected]
//Please feel free to use and abuse this code as much
//as you like. But, please give me some credit for
//starting you off on the right track.
//
//The file Bitmap.cpp goes along with this file
//
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const short BITMAP_MAGIC_NUMBER=19778;
const int RGB_BYTE_SIZE=3;
#pragma pack(push,bitmap_data,1)
typedef struct tagRGBQuad {
char rgbBlue;
char rgbGreen;
char rgbRed;
char rgbReserved;
} RGBQuad;
typedef struct tagBitmapFileHeader {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BitmapFileHeader;
typedef struct tagBitmapInfoHeader {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
} BitmapInfoHeader;
#pragma pack(pop,bitmap_data)
class MyBitmap {
public:
//variables
RGBQuad *colours;
char *data;
bool loaded;
int width,height;
unsigned short bpp;
string error;
//methods
MyBitmap(void);
MyBitmap(const char *);
~MyBitmap();
bool loadBMP(const char *);
private:
//variables
BitmapFileHeader bmfh;
BitmapInfoHeader bmih;
int byteWidth; //the width in bytes of the image
int padWidth; //the width in bytes of the added image
unsigned int dataSize; //size of the data in the file
//methods
void reset(void);
bool convert24(char *); //convert to 24bit RGB bottom up data
bool convert8(char *); //convert to 24bit RGB bottom up data
};
#endif //_BITMAP_H