-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbitmap.cpp
66 lines (51 loc) · 1019 Bytes
/
bitmap.cpp
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
#include "stdio.h"
#include "bitmap.h"
Bitmap::Bitmap(char *file)
{
FILE *fp;
int i,j;
dx=0;
dy=0;
bitcount=24;
r=0;
g=0;
b=0;
fp=fopen(file,"rb+");
if (fp==NULL) return;
/* Tag: */
if (fgetc(fp)!='B' || fgetc(fp)!='M') return;
/* Saltarse Header: */
for(i=0;i<12;i++) fgetc(fp);
/* Info-Header: */
for(i=0;i<4;i++) fgetc(fp);
dx=fgetc(fp);
dx+=fgetc(fp)<<8;
fgetc(fp);
fgetc(fp);
dy=fgetc(fp);
dy+=fgetc(fp)<<8;
fgetc(fp);
fgetc(fp);
r=new unsigned char[dx*dy];
g=new unsigned char[dx*dy];
b=new unsigned char[dx*dy];
for(i=0;i<28;i++) fgetc(fp);
for(i=dy-1;i>=0;i--) {
for(j=0;j<dx;j++) {
b[i*dx+j]=fgetc(fp);
g[i*dx+j]=fgetc(fp);
r[i*dx+j]=fgetc(fp);
// fgetc(fp);
} /* for */
if ((dx*3)%4!=0) {
for(j=0;j<(4-(dx*3)%4);j++) fgetc(fp);
} /* if */
} /* for */
fclose(fp);
} /* Bitmap::Bitmap */
Bitmap::~Bitmap()
{
delete []r;
delete []g;
delete []b;
} /* Bitmap::~Bitmap */