-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp.c
72 lines (59 loc) · 1.63 KB
/
bmp.c
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
#include "bmp.h"
// ********** Verify if the file exist **********
FILE* exist(char *name)
{
FILE *tmp;
tmp = fopen(name,"r+b");
if (!tmp)
{
printf("\nERROR: Ce fichier n'existe pas!\n");
exit(0);
}
fseek(tmp,0,0);
return(tmp);
}
// ********** Verify if the file is BMP *********
void isBMP(FILE* arq){
char type[3];
unsigned short int bpp;
fseek(arq,0,0);
fread(type,1,2,arq);
type[2] = '\0';
fseek(arq,28,0);
fread(&bpp,1,2,arq);
if (strcmp(type,"BM") || (bpp != 24)){
printf("\nCe fichier n'est pas un BMP 24 bits\n");
exit(0);
}
}
// ********** Read BMP info from file **********
INFOHEADER readInfo(FILE* arq){
INFOHEADER info;
// Image Width in pixels
fseek(arq,18,0);
fread(&info.width,1,4,arq);
// Image Height in pixels
fseek(arq,22,0);
fread(&info.height,1,4,arq);
// Color depth, BPP (bits per pixel)
fseek(arq,28,0);
fread(&info.bpp,1,2,arq);
// Compression type
// 0 = Normmally
// 1 = 8 bits per pixel
// 2 = 4 bits per pixel
fseek(arq,30,0);
fread(&info.compression,1,4,arq);
// Image size in bytes
fseek(arq,34,0);
fread(&info.imagesize,1,4,arq);
// Number of color used (NCL)
// value = 0 for full color set
fseek(arq,46,0);
fread(&info.colours,1,4,arq);
// Number of important color (NIC)
// value = 0 means all collors important
fseek(arq,50,0);
fread(&info.impcolours,1,4,arq);
return(info);
}