#include <stdio.h>
#include <stdlib.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
{
	unsigned char r;
		unsigned char g;
		unsigned char b;
		unsigned char a;
}rgbquad;


int main(void)
{
	char * ptr;
	char c;
	int cnt;
//build header ... most of it will be wasted 
	ptr = (char*) &bmphead;
	for (cnt = 0 ; cnt < 14 ; cnt++ )
	{
		c = getchar();
		*(ptr+cnt) = c;
	}
	ptr = (char*) &dibhead;
	for (cnt = 0 ; cnt < 16 ; cnt++ )
	{
		c = getchar();
		*(ptr+cnt) = c;
	}
	if (dibhead.headsize == 40)
	{
		ptr = ((char*) &dibhead)+16;
		for (cnt = 0 ; cnt < 24 ; cnt++ )
		{
			c = getchar();
			*(ptr+cnt) = c;
		}
	}
//build palette 
	if ((dibhead.bitsperpixel != 16)&&(dibhead.bitsperpixel != 24)&&(dibhead.bitsperpixel != 32))
	{
		int palsize = 1;
		if (dibhead.palettecolorsnumber == 0)
		{
			for (cnt = 0 ; cnt < dibhead.bitsperpixel ; cnt ++)
			{
				palsize = palsize*2;
			}
		}
		else
		{
			palsize = dibhead.palettecolorsnumber;
		}	
		ptr = malloc(palsize* sizeof(rgbquad));
		for (cnt = 0; cnt < palsize*sizeof(rgbquad); cnt ++)
		{
			*(ptr+cnt) = getchar();
		}
	}
//now get color from bitmap and serialize !!!
	if (dibhead.bitsperpixel == 1)	{			free(ptr);return 0;	}
	if (dibhead.bitsperpixel == 4)	{			free(ptr);return 0;	}
	if (dibhead.bitsperpixel == 8)	{			free(ptr);return 0;	}
	if (dibhead.bitsperpixel == 16)	{		printf("16bits file not supported\n");	return 0;	}
	if (dibhead.bitsperpixel == 24)
	{
		int skip = dibhead.bmpwidth % 4;
		int x,y;
		for (y = 0 ; y < dibhead.bmpheight-1 ; y++)
		{
			for (x = 0 ; x < dibhead.bmpwidth-1 ; x++)
			{
				int r = getchar();
				int g = getchar();
				int b = getchar();

				printf("0.0:");
				printf("%f:",((float)r)/256);
				printf("%f:",((float)g)/256);
				printf("%f ",((float)b)/256);
			}
			for (cnt = 0; cnt < skip ; cnt++)
			{
				c = getchar();
			}
			printf("\n");
		}
	}
	if (dibhead.bitsperpixel == 32)
	{
		int x,y;
		for (y = 0 ; y < dibhead.bmpheight ; y++)
		{
//printf("line %d",y);
			for (x = 0 ; x < dibhead.bmpwidth ; x++)
			{
//printf("(%d, %d)",x,y);
				int r = getchar();
				int g = getchar();
				int b = getchar();
				int a = getchar();
				printf("%f:",((float)a)/256);
				printf("%f:",((float)r)/256);
				printf("%f:",((float)g)/256);
				printf("%f ",((float)b)/256);
			}
			printf("\n");
		}
	}
	
	putchar(EOF);

	return 0;
}
