#include <stdio.h>

struct bmphead
{
	unsigned char type1;
	unsigned char type2;
	unsigned long int filesize;
	unsigned long int reserved;
	unsigned long int offset;
}bmphead;

struct dibhead
{
	unsigned int headsize;		//should be 40
	int bmpwidth;
	int bmpheight;
	unsigned short numcolorsplanes; 	//should be 1
	unsigned short bitsperpixel;		//1 4 8 16 24 32
	unsigned int compression;		//we  will only support 0
	unsigned int imagesize;		//can be 0 if no compression 
	int horizontalppm;	//pixelpermeter can be 0
	int verticalppm;		//can be 0
	unsigned int palettecolorsnumber;	//if zero default = 2^bitsperpixels
	unsigned int importantcolorsused;	//can be 0
}dibhead;

typedef struct rgbquad
{
	char r;
	char g;
	char b;
	char a;
}rgbquad;


int main(void)
{
	printf ("bmp header\n");
	char * ptr;
	char c;
	int cnt;
	
	ptr = (char*) &bmphead;
	for (cnt = 0 ; cnt < 14 ; cnt++ )
	{
		c = getchar();
		*(ptr+cnt) = c;
	}
	printf("file type %c%c\n",bmphead.type1,bmphead.type2);
	printf("file size %d\n",bmphead.filesize);
	printf("reserved %d\n",bmphead.reserved);
	printf("offset %d\n",bmphead.offset);
	
	ptr = (char*) &dibhead;
	for (cnt = 0 ; cnt < 16 ; cnt++ )
	{
		c = getchar();
		*(ptr+cnt) = c;
	}
	printf("info header size %d\n",dibhead.headsize);
	printf("bitmap pixels width %d\n",dibhead.bmpwidth);
	printf("bitmap pixels height %d\n",dibhead.bmpheight);
	printf("number of colors planes %d\n",dibhead.numcolorsplanes);
	printf("bits per pixel %d\n",dibhead.bitsperpixel);
	
	if (dibhead.headsize == 40)
	{
		ptr = ((char*) &dibhead)+16;
		for (cnt = 0 ; cnt < 24 ; cnt++ )
		{
			c = getchar();
			*(ptr+cnt) = c;
		}
		printf("compression %d\n",dibhead.compression);
		printf("imagesize %d\n",dibhead.imagesize);			
		printf("horizontal %d\n",dibhead.horizontalppm);
		printf("vertical %d\n",dibhead.verticalppm);
		printf("number of colors in plalette %d\n",dibhead.palettecolorsnumber);
		printf("importantcolor %d\n",dibhead.importantcolorsused);
	}
	return 0;
}
