-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIBDUMP Utility.C
158 lines (135 loc) · 4.44 KB
/
DIBDUMP Utility.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
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
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define BitCountToColors(x) (((x) == 1) ? 2 : (((x) == 4) ? 16 : (((x) == 8) ? 256 : 0)))
int main(int, char *[]);
int main(argc, argv)
int argc;
char *argv[];
{
char *pFileName;
FILE *pFile;
BITMAPFILEHEADER bmpFileHeader;
BITMAPINFOHEADER bmpInfoHeader;
RGBQUAD rgbQuad;
DWORD I;
if (argc < 3)
{
if (argc ==1)
pFileName = "test1.bmp";
else
pFileName = argv[1];
/*
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
*/
if (pFile = fopen(pFileName, "rb"))
{
printf("BITMAPFILEHEADER = %d bytes\n", sizeof(BITMAPFILEHEADER));
fread((char *)&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, pFile);
printf("bfType=%2X bfSize=%lu bfReserved1=%u bfReserved2=%u bfOffBits=%lu\n",
bmpFileHeader.bfType,
bmpFileHeader.bfSize,
bmpFileHeader.bfReserved1,
bmpFileHeader.bfReserved2,
bmpFileHeader.bfOffBits);
/*
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
*/
printf("BITMAPINFOHEADER = %d bytes\n", sizeof(BITMAPINFOHEADER));
fread((char *)&bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, pFile);
printf("biSize=%lu\nbiWidth=%ld\nbiHeight=%ld\nbiPlanes=%u\nbiBitCount=%u\nbiCompression=%lu\nbiSizeImage=%lu\nbiXPelsPerMeter=%ld\nbiYPelsPerMeter=%ld\nbiClrUsed=%lu\nbiClrImportant=%lu\n",
bmpInfoHeader.biSize,
bmpInfoHeader.biWidth,
bmpInfoHeader.biHeight,
bmpInfoHeader.biPlanes,
bmpInfoHeader.biBitCount,
bmpInfoHeader.biCompression,
bmpInfoHeader.biSizeImage,
bmpInfoHeader.biXPelsPerMeter,
bmpInfoHeader.biYPelsPerMeter,
bmpInfoHeader.biClrUsed,
bmpInfoHeader.biClrImportant);
printf("\n");
/*
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
typedef RGBQUAD FAR* LPRGBQUAD;
*/
if (bmpInfoHeader.biBitCount <= 8)
{
printf("RGBQUAD size = %d\n", sizeof(RGBQUAD));
for (I = 0; I < (DWORD)BitCountToColors(bmpInfoHeader.biBitCount); ++I)
{
fread((char *)&rgbQuad, sizeof(RGBQUAD), 1, pFile);
printf("%d\t%d\t%d\t%d\n",rgbQuad.rgbBlue, rgbQuad.rgbGreen, rgbQuad.rgbRed, rgbQuad.rgbReserved);
}
}
printf("\nPosition = %ld\n", ftell(pFile));
for (I = 0; I < 8; ++I)
{
fread((char *)&rgbQuad, sizeof(RGBQUAD), 1, pFile);
printf("%d\t%d\t%d\t%d\n",rgbQuad.rgbBlue, rgbQuad.rgbGreen, rgbQuad.rgbRed, rgbQuad.rgbReserved);
}
fclose(pFile);
}
else
perror(argv[1]);
}
else
printf("syntax:\nbitmap file\n");
return(0);
}
/* Bitmap Header Definition
typedef struct tagBITMAP
{
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
} BITMAP, *PBITMAP, NEAR *NPBITMAP, FAR *LPBITMAP;
*/
/* structures for defining DIBs
typedef struct tagBITMAPCOREHEADER {
DWORD bcSize; // used to get to color table
WORD bcWidth;
WORD bcHeight;
WORD bcPlanes;
WORD bcBitCount;
} BITMAPCOREHEADER, FAR *LPBITMAPCOREHEADER, *PBITMAPCOREHEADER;
*/
/*
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, FAR *LPBITMAPINFO, *PBITMAPINFO;
typedef struct tagBITMAPCOREINFO {
BITMAPCOREHEADER bmciHeader;
RGBTRIPLE bmciColors[1];
} BITMAPCOREINFO, FAR *LPBITMAPCOREINFO, *PBITMAPCOREINFO;
*/