1 |
/* Betriebssystem & Middleware |
2 |
* |
3 |
* Betriebssystemarchitektur SS 2006 |
4 |
* |
5 |
* Uebung 4.4 |
6 |
*/ |
7 |
#include <stdio.h> |
8 |
#include <errno.h> |
9 |
|
10 |
#define XSIZE 500 |
11 |
#define YSIZE 500 |
12 |
#include "algorithm.h" |
13 |
|
14 |
/* BMP Header */ |
15 |
unsigned char header[54]={0x42,0x4d, // signature BM |
16 |
0xe6,0x71,0x0b,0x0, // filesize 750054 |
17 |
0x0,0x0,0x0,0x0, // reserved |
18 |
0x36,0x0,0x0,0x0, // image offset 54 |
19 |
0x28,0x0,0x0,0x0, // size of header follows 40 |
20 |
0xf4,0x1,0x0,0x0, // with of image 500 |
21 |
0xf4,0x1,0x0,0x0, // height of image 500 |
22 |
0x1,0x0, // number of planes 1 |
23 |
0x18,0x0, // number of pixel 24 |
24 |
0x0,0x0,0x0,0x0, // compression |
25 |
0xb0,0x71,0x0b,0x0, // size of image 750000 |
26 |
0x0,0x0,0x0,0x0, // xres |
27 |
0x0,0x0,0x0,0x0, // yres |
28 |
0x0,0x0,0x0,0x0, // number of colortables |
29 |
0x0,0x0,0x0,0x0 // number of important colors |
30 |
}; |
31 |
|
32 |
int main(int argc, char *argv[]) |
33 |
{ |
34 |
FILE *fd; |
35 |
int len,x,y; |
36 |
char bgr[3]; |
37 |
short svalue; |
38 |
int lvalue; |
39 |
//unsigned char header[54],*ptr=&header[0]; |
40 |
|
41 |
fd=fopen("test.bmp","wb+"); |
42 |
if(NULL==fd) |
43 |
{ |
44 |
perror("open"); exit(1); |
45 |
} |
46 |
|
47 |
len=fwrite(header,1,sizeof(header),fd); //write header |
48 |
|
49 |
if(-1==len || len!=sizeof(header)) |
50 |
{ |
51 |
perror("write"); |
52 |
exit(2); |
53 |
} |
54 |
|
55 |
for(y=YSIZE-1;y>=0;y--) |
56 |
{ |
57 |
for(x=0;x<XSIZE;x++) |
58 |
{ |
59 |
getColorValuesAt(x * (2.0 / XSIZE) - 1.5, y * (2.0 / YSIZE) - 1.0,&bgr[2],&bgr[1],&bgr[0]); |
60 |
|
61 |
len=fwrite(bgr,1,3,fd); |
62 |
if(-1==len || len!=3) |
63 |
{ |
64 |
perror("write"); |
65 |
exit(4); |
66 |
} |
67 |
} |
68 |
/*no padding required because 1500%4 =0*/ |
69 |
} |
70 |
fclose(fd); |
71 |
|
72 |
} |