#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main(void)
{
clrscr();
unsigned char color;
long int Doffset, w, h;
int i,n[256],gd=0, gm=0, y ,x;
FILE *flag, *flag2, *flag3, *flag4;
flag = fopen("C:\\TC\\BIN\\bmp1.bmp","r");
flag2 = fopen("C:\\TC\\BIN\\car.bmp","r");
flag3 = fopen("C:\\TC\\BIN\\bmp2.bmp","r");
flag4 = fopen("C:\\TC\\BIN\\bmp3.bmp","r");
initgraph(&gd, &gm, "c:\\tc\\bgi");
int gr = graphresult();
if (gr!=0)
{
printf ("Fail");
getch();
return 0;
}
cleardevice();
for(z=0; z<4; z++)
{
fseek(flag, 18, SEEK_SET);
fread(&w, 4, 1, flag);
fseek(flag, 22, SEEK_SET);
fread(&h, 4, 1, flag);
fseek(flag, 10, SEEK_SET);
fread(&Doffset, 4, 1, flag);
fseek(flag, Doffset, SEEK_SET);
for(i=0; i<256; i++)
n[i]=0;
for(y=h; y>0; y--)
{
for(x=0; x<w; x++)
{
fread(&color, 1, 1, flag);
putpixel(x, y, color);
n[color]++;
}
}
for(i=0; i<256; i++)
{
if(n[i] >0)
printf("pixels of color %d=%d\n", i, n[i]);
}
getch();
getch();
cleardevice();
fseek(flag2, 18, SEEK_SET);
fread(&w, 4, 1, flag2);
fseek(flag2, 22, SEEK_SET);
fread(&h, 4, 1, flag2);
fseek(flag2, 10, SEEK_SET);
fread(&Doffset, 4, 1, flag2);
fseek(flag2, Doffset, SEEK_SET);
for(i=0; i<256; i++)
n[i]=0;
for(y=h; y>0; y--)
{
for(x=0; x<w; x++)
{
fread(&color, 1, 1, flag2);
putpixel(x, y, color);
n[color]++;
}
}
for(i=0; i<256; i++)
{
if(n[i] >0)
printf("pixels of color %d=%d\n", i, n[i]);
}
getch();
getch();
cleardevice();
fseek(flag3, 18, SEEK_SET);
fread(&w, 4, 1, flag3);
fseek(flag3, 22, SEEK_SET);
fread(&h, 4, 1, flag3);
fseek(flag3, 10, SEEK_SET);
fread(&Doffset, 4, 1, flag3);
fseek(flag3, Doffset, SEEK_SET);
for(i=0; i<256; i++)
n[i]=0;
for(y=h; y>0; y--)
{
for(x=0; x<w; x++)
{
fread(&color, 1, 1, flag3);
putpixel(x, y, color);
n[color]++;
}
}
for(i=0; i<256; i++)
{
if(n[i] >0)
printf("pixels of color %d=%d\n", i, n[i]);
}
getch();
getch();
cleardevice;
fseek(flag4, 18, SEEK_SET);
fread(&w, 4, 1, flag4);
fseek(flag4, 22, SEEK_SET);
fread(&h, 4, 1, flag4);
fseek(flag4, 10, SEEK_SET);
fread(&Doffset, 4, 1, flag4);
fseek(flag4, Doffset, SEEK_SET);
for(i=0; i<256; i++)
n[i]=0;
for(y=h; y>0; y--)
{
for(x=0; x<w; x++)
{
fread(&color, 1, 1, flag4);
putpixel(x, y, color);
n[color]++;
}
}
for(i=0; i<256; i++)
{
if(n[i] >0)
printf("pixels of color %d=%d\n", i, n[i]);
}
getch();
getch();
}}